From 824abbf8d98063a991b1301f60da8893e7f5a6cf Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 2 Jul 2023 15:21:03 +0200 Subject: [PATCH] libnetwork/datastore: remove redundant datastore.sequential The sequential field determined whether a lock was needed when storing and retrieving data. This field was always set to true, with the exception of NewTestDataStore() in the tests. This field was added in https://github.com/moby/libnetwork/commit/a18e2f9965b0d772ed2b552bb4e26ea43bf90c95 to make locking optional for non-local scoped stores. Such stores are no longer used, so we can remove this field. Signed-off-by: Sebastiaan van Stijn --- libnetwork/datastore/datastore.go | 59 +++++++++++-------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/libnetwork/datastore/datastore.go b/libnetwork/datastore/datastore.go index 283c67e223..e44721b0c9 100644 --- a/libnetwork/datastore/datastore.go +++ b/libnetwork/datastore/datastore.go @@ -54,11 +54,10 @@ var ( ) type datastore struct { - scope string - store store.Store - cache *cache - watchCh chan struct{} - sequential bool + scope string + store store.Store + cache *cache + watchCh chan struct{} sync.Mutex } @@ -207,7 +206,7 @@ func newClient(kv string, addr string, config *store.Config) (DataStore, error) return nil, err } - ds := &datastore{scope: LocalScope, store: s, watchCh: make(chan struct{}), sequential: true} + ds := &datastore{scope: LocalScope, store: s, watchCh: make(chan struct{})} ds.cache = newCache(ds) return ds, nil @@ -346,10 +345,8 @@ func (ds *datastore) PutObjectAtomic(kvObject KVObject) error { pair *store.KVPair err error ) - if ds.sequential { - ds.Lock() - defer ds.Unlock() - } + ds.Lock() + defer ds.Unlock() if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") @@ -393,10 +390,8 @@ add_cache: // PutObject adds a new Record based on an object into the datastore func (ds *datastore) PutObject(kvObject KVObject) error { - if ds.sequential { - ds.Lock() - defer ds.Unlock() - } + ds.Lock() + defer ds.Unlock() if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") @@ -431,10 +426,8 @@ func (ds *datastore) putObjectWithKey(kvObject KVObject, key ...string) error { // GetObject returns a record matching the key func (ds *datastore) GetObject(key string, o KVObject) error { - if ds.sequential { - ds.Lock() - defer ds.Unlock() - } + ds.Lock() + defer ds.Unlock() if ds.cache != nil { return ds.cache.get(key, o) @@ -467,10 +460,8 @@ func (ds *datastore) ensureParent(parent string) error { } func (ds *datastore) List(key string, kvObject KVObject) ([]KVObject, error) { - if ds.sequential { - ds.Lock() - defer ds.Unlock() - } + ds.Lock() + defer ds.Unlock() if ds.cache != nil { return ds.cache.list(kvObject) @@ -524,10 +515,8 @@ func (ds *datastore) iterateKVPairsFromStore(key string, kvObject KVObject, call } func (ds *datastore) Map(key string, kvObject KVObject) (map[string]KVObject, error) { - if ds.sequential { - ds.Lock() - defer ds.Unlock() - } + ds.Lock() + defer ds.Unlock() kvol := make(map[string]KVObject) cb := func(key string, val KVObject) { @@ -543,10 +532,8 @@ func (ds *datastore) Map(key string, kvObject KVObject) (map[string]KVObject, er // DeleteObject unconditionally deletes a record from the store func (ds *datastore) DeleteObject(kvObject KVObject) error { - if ds.sequential { - ds.Lock() - defer ds.Unlock() - } + ds.Lock() + defer ds.Unlock() // cleanup the cache first if ds.cache != nil { @@ -564,10 +551,8 @@ func (ds *datastore) DeleteObject(kvObject KVObject) error { // DeleteObjectAtomic performs atomic delete on a record func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error { - if ds.sequential { - ds.Lock() - defer ds.Unlock() - } + ds.Lock() + defer ds.Unlock() if kvObject == nil { return types.BadRequestErrorf("invalid KV Object : nil") @@ -599,10 +584,8 @@ del_cache: // DeleteTree unconditionally deletes a record from the store func (ds *datastore) DeleteTree(kvObject KVObject) error { - if ds.sequential { - ds.Lock() - defer ds.Unlock() - } + ds.Lock() + defer ds.Unlock() // cleanup the cache first if ds.cache != nil {