From ed941455e1de2d26fcb6d041560c61637fee258a Mon Sep 17 00:00:00 2001 From: carabasdaniel Date: Thu, 26 Oct 2023 10:58:25 +0300 Subject: [PATCH] Remove eds locker and pass context --- eds.go | 6 ++++-- pkg/directory/directory.go | 3 ++- pkg/server/eds-lock.go | 27 --------------------------- pkg/server/test-edge-ds.go | 2 +- 4 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 pkg/server/eds-lock.go diff --git a/eds.go b/eds.go index b5dd418..62fb6e5 100644 --- a/eds.go +++ b/eds.go @@ -1,14 +1,16 @@ package eds import ( + "context" + "github.com/aserto-dev/go-edge-ds/pkg/directory" "github.com/rs/zerolog" ) -func New(config *directory.Config, logger *zerolog.Logger) (*directory.Directory, error) { +func New(ctx context.Context, config *directory.Config, logger *zerolog.Logger) (*directory.Directory, error) { newLogger := logger.With().Str("component", "edge-ds").Logger() - ds, err := directory.New(config, &newLogger) + ds, err := directory.New(ctx, config, &newLogger) if err != nil { return nil, err } diff --git a/pkg/directory/directory.go b/pkg/directory/directory.go index 376e4d9..5888e74 100644 --- a/pkg/directory/directory.go +++ b/pkg/directory/directory.go @@ -1,6 +1,7 @@ package directory import ( + "context" "errors" "time" @@ -53,7 +54,7 @@ type Directory struct { writer3 dsw3.WriterServer } -func New(config *Config, logger *zerolog.Logger) (*Directory, error) { +func New(ctx context.Context, config *Config, logger *zerolog.Logger) (*Directory, error) { newLogger := logger.With().Str("component", "directory").Logger() cfg := bdb.Config{ diff --git a/pkg/server/eds-lock.go b/pkg/server/eds-lock.go deleted file mode 100644 index 205a393..0000000 --- a/pkg/server/eds-lock.go +++ /dev/null @@ -1,27 +0,0 @@ -package server - -import ( - eds "github.com/aserto-dev/go-edge-ds" - "github.com/aserto-dev/go-edge-ds/pkg/directory" - "github.com/pkg/errors" - "github.com/rs/zerolog" -) - -type EdgeDirLock struct { - open bool - edgeDir *directory.Directory -} - -func (lock *EdgeDirLock) New(cfg *directory.Config, logger *zerolog.Logger) (*directory.Directory, error) { - if lock.open { - return lock.edgeDir, nil - } - - edgeDir, err := eds.New(cfg, logger) - if err != nil { - return nil, errors.Wrapf(err, "failed to create edge directory server") - } - lock.open = true - lock.edgeDir = edgeDir - return edgeDir, err -} diff --git a/pkg/server/test-edge-ds.go b/pkg/server/test-edge-ds.go index 6914c31..64e5286 100644 --- a/pkg/server/test-edge-ds.go +++ b/pkg/server/test-edge-ds.go @@ -50,7 +50,7 @@ func NewTestEdgeServer(ctx context.Context, logger *zerolog.Logger, cfg *directo edgeDSLogger := logger.With().Str("component", "api.edge-directory").Logger() - edgeDirServer, err := eds.New(cfg, &edgeDSLogger) + edgeDirServer, err := eds.New(context.Background(), cfg, &edgeDSLogger) if err != nil { logger.Error().Err(err).Msg("failed to start edge directory server") }