diff --git a/.github/workflows/eventbase-ci.yml b/.github/workflows/eventbase-ci.yml index b0918b7a3..5c872a6b7 100644 --- a/.github/workflows/eventbase-ci.yml +++ b/.github/workflows/eventbase-ci.yml @@ -38,4 +38,25 @@ jobs: export TEST_DB_MODE=etcd export TEST_DB_URI=http://127.0.0.1:2379 cd eventbase - time go test -short -covermode=atomic $(go list ./... | grep -v mongo | grep -v third_party | grep -v examples) \ No newline at end of file + time go test -short -covermode=atomic $(go list ./... | grep -v mongo | grep -v third_party | grep -v examples) + etcd-storage-with-localstorage: + runs-on: ubuntu-latest + steps: + - name: Set up Go + uses: actions/setup-go@v1 + with: + go-version: 1.18 + id: go + - name: Check out source code + uses: actions/checkout@v1 + - name: UT for etcd + run: | + time docker run -d -p 2379:2379 --name etcd quay.io/coreos/etcd etcd -name etcd --advertise-client-urls http://0.0.0.0:2379 --listen-client-urls http://0.0.0.0:2379 + while ! nc -z 127.0.0.1 2379; do + sleep 1 + done + export TEST_DB_MODE=etcd + export TEST_DB_URI=http://127.0.0.1:2379 + export SCHEMA_ROOT_PATH=/data/kvs + cd eventbase + sudo time go test -short -covermode=atomic $(go list ./... | grep -v mongo | grep -v third_party | grep -v examples) \ No newline at end of file diff --git a/datasource/etcd/ms.go b/datasource/etcd/ms.go index cc2c8705d..440b7748c 100644 --- a/datasource/etcd/ms.go +++ b/datasource/etcd/ms.go @@ -22,18 +22,11 @@ import ( "encoding/json" "errors" "fmt" - "github.com/apache/servicecomb-service-center/datasource/local" + "os" "path/filepath" "strconv" "time" - "github.com/apache/servicecomb-service-center/syncer/service/event" - pb "github.com/go-chassis/cari/discovery" - "github.com/go-chassis/cari/pkg/errsvc" - "github.com/go-chassis/cari/sync" - "github.com/go-chassis/foundation/gopool" - "github.com/little-cui/etcdadpt" - "github.com/apache/servicecomb-service-center/datasource" "github.com/apache/servicecomb-service-center/datasource/etcd/cache" "github.com/apache/servicecomb-service-center/datasource/etcd/path" @@ -42,12 +35,19 @@ import ( esync "github.com/apache/servicecomb-service-center/datasource/etcd/sync" eutil "github.com/apache/servicecomb-service-center/datasource/etcd/util" serviceUtil "github.com/apache/servicecomb-service-center/datasource/etcd/util" + "github.com/apache/servicecomb-service-center/datasource/local" "github.com/apache/servicecomb-service-center/datasource/schema" "github.com/apache/servicecomb-service-center/pkg/log" "github.com/apache/servicecomb-service-center/pkg/util" "github.com/apache/servicecomb-service-center/server/core" "github.com/apache/servicecomb-service-center/server/plugin/uuid" quotasvc "github.com/apache/servicecomb-service-center/server/service/quota" + "github.com/apache/servicecomb-service-center/syncer/service/event" + pb "github.com/go-chassis/cari/discovery" + "github.com/go-chassis/cari/pkg/errsvc" + "github.com/go-chassis/cari/sync" + "github.com/go-chassis/foundation/gopool" + "github.com/little-cui/etcdadpt" ) type MetadataManager struct { @@ -1506,6 +1506,10 @@ func (ds *MetadataManager) UnregisterService(ctx context.Context, request *pb.De if rollbackErr != nil { log.Error("clean tmp dir error when rollback in UnregisterService", err) } + rollbackErr = os.Remove(originPath) + if rollbackErr != nil { + log.Error("clean origin dir error when rollback in UnregisterService", err) + } } } }() diff --git a/datasource/local/schema.go b/datasource/local/schema.go index 69aab4eda..05e6e247e 100644 --- a/datasource/local/schema.go +++ b/datasource/local/schema.go @@ -21,6 +21,12 @@ import ( "context" "encoding/json" "fmt" + "io/fs" + "os" + pathutil "path" + "strings" + "sync" + "github.com/apache/servicecomb-service-center/datasource" "github.com/apache/servicecomb-service-center/datasource/etcd/path" etcdsync "github.com/apache/servicecomb-service-center/datasource/etcd/sync" @@ -30,33 +36,28 @@ import ( "github.com/go-chassis/cari/discovery" "github.com/go-chassis/openlog" "github.com/little-cui/etcdadpt" - "io/fs" - "os" - pathutil "path" + "path/filepath" - "strings" - "sync" ) -var MutexMap = make(map[string]*sync.Mutex) +var MutexMap = make(map[string]*sync.RWMutex) var mutexMapLock = &sync.Mutex{} var rollbackMutexLock = &sync.Mutex{} var createDirMutexLock = &sync.Mutex{} func init() { - schema.Install("local_with_embeded_etcd", NewSchemaDAO) - schema.Install("local_with_embedded_etcd", NewSchemaDAO) + schema.Install("local", NewSchemaDAO) } func NewSchemaDAO(opts schema.Options) (schema.DAO, error) { return &SchemaDAO{}, nil } -func GetOrCreateMutex(path string) *sync.Mutex { +func GetOrCreateMutex(path string) *sync.RWMutex { mutexMapLock.Lock() mutex, ok := MutexMap[path] if !ok { - mutex = &sync.Mutex{} + mutex = &sync.RWMutex{} MutexMap[path] = mutex } mutexMapLock.Unlock() @@ -244,8 +245,8 @@ func CleanDir(dir string) error { func ReadFile(filepath string) ([]byte, error) { mutex := GetOrCreateMutex(filepath) - mutex.Lock() - defer mutex.Unlock() + mutex.RLock() + defer mutex.RUnlock() // check the file is empty content, err := os.ReadFile(filepath) diff --git a/datasource/schema/init.go b/datasource/schema/init.go index 77934ab2c..d65c12e67 100644 --- a/datasource/schema/init.go +++ b/datasource/schema/init.go @@ -19,9 +19,10 @@ package schema import ( "fmt" + "strings" + "github.com/apache/servicecomb-service-center/pkg/log" "github.com/apache/servicecomb-service-center/server/config" - "strings" ) var StorageType = "" @@ -46,8 +47,9 @@ func Init(opts Options) error { return nil } kind := opts.Kind - if strings.Trim(config.GetRegistry().SchemaRootPath, " ") != "" { - kind = "local_with_embeded_etcd" + if strings.Trim(config.GetString("schema.root.path", "", config.WithStandby("schemaRootPath")), " ") != "" { + log.Warn("llllllllllocal") + kind = "local" StorageType = "local" RootFilePath = config.GetRegistry().SchemaRootPath }