Browse code

Merge pull request #46681 from corhere/libn/datastore-misc-cleanups

Brian Goff authored on 2023/11/10 04:31:30
Showing 15 changed files
... ...
@@ -1,7 +1,6 @@
1 1
 package datastore
2 2
 
3 3
 import (
4
-	"errors"
5 4
 	"fmt"
6 5
 	"sync"
7 6
 
... ...
@@ -11,22 +10,22 @@ import (
11 11
 type kvMap map[string]KVObject
12 12
 
13 13
 type cache struct {
14
-	sync.Mutex
14
+	mu  sync.Mutex
15 15
 	kmm map[string]kvMap
16
-	ds  *Store
16
+	ds  store.Store
17 17
 }
18 18
 
19
-func newCache(ds *Store) *cache {
19
+func newCache(ds store.Store) *cache {
20 20
 	return &cache{kmm: make(map[string]kvMap), ds: ds}
21 21
 }
22 22
 
23 23
 func (c *cache) kmap(kvObject KVObject) (kvMap, error) {
24 24
 	var err error
25 25
 
26
-	c.Lock()
26
+	c.mu.Lock()
27 27
 	keyPrefix := Key(kvObject.KeyPrefix()...)
28 28
 	kmap, ok := c.kmm[keyPrefix]
29
-	c.Unlock()
29
+	c.mu.Unlock()
30 30
 
31 31
 	if ok {
32 32
 		return kmap, nil
... ...
@@ -34,13 +33,7 @@ func (c *cache) kmap(kvObject KVObject) (kvMap, error) {
34 34
 
35 35
 	kmap = kvMap{}
36 36
 
37
-	// Bail out right away if the kvObject does not implement KVConstructor
38
-	ctor, ok := kvObject.(KVConstructor)
39
-	if !ok {
40
-		return nil, errors.New("error while populating kmap, object does not implement KVConstructor interface")
41
-	}
42
-
43
-	kvList, err := c.ds.store.List(keyPrefix)
37
+	kvList, err := c.ds.List(keyPrefix)
44 38
 	if err != nil {
45 39
 		if err == store.ErrKeyNotFound {
46 40
 			// If the store doesn't have anything then there is nothing to
... ...
@@ -57,7 +50,7 @@ func (c *cache) kmap(kvObject KVObject) (kvMap, error) {
57 57
 			continue
58 58
 		}
59 59
 
60
-		dstO := ctor.New()
60
+		dstO := kvObject.New()
61 61
 		err = dstO.SetValue(kvPair.Value)
62 62
 		if err != nil {
63 63
 			return nil, err
... ...
@@ -74,15 +67,15 @@ out:
74 74
 	// There may multiple go routines racing to fill the
75 75
 	// cache. The one which places the kmap in c.kmm first
76 76
 	// wins. The others should just use what the first populated.
77
-	c.Lock()
77
+	c.mu.Lock()
78 78
 	kmapNew, ok := c.kmm[keyPrefix]
79 79
 	if ok {
80
-		c.Unlock()
80
+		c.mu.Unlock()
81 81
 		return kmapNew, nil
82 82
 	}
83 83
 
84 84
 	c.kmm[keyPrefix] = kmap
85
-	c.Unlock()
85
+	c.mu.Unlock()
86 86
 
87 87
 	return kmap, nil
88 88
 }
... ...
@@ -93,13 +86,13 @@ func (c *cache) add(kvObject KVObject, atomic bool) error {
93 93
 		return err
94 94
 	}
95 95
 
96
-	c.Lock()
96
+	c.mu.Lock()
97 97
 	// If atomic is true, cache needs to maintain its own index
98 98
 	// for atomicity and the add needs to be atomic.
99 99
 	if atomic {
100 100
 		if prev, ok := kmap[Key(kvObject.Key()...)]; ok {
101 101
 			if prev.Index() != kvObject.Index() {
102
-				c.Unlock()
102
+				c.mu.Unlock()
103 103
 				return ErrKeyModified
104 104
 			}
105 105
 		}
... ...
@@ -111,7 +104,7 @@ func (c *cache) add(kvObject KVObject, atomic bool) error {
111 111
 	}
112 112
 
113 113
 	kmap[Key(kvObject.Key()...)] = kvObject
114
-	c.Unlock()
114
+	c.mu.Unlock()
115 115
 	return nil
116 116
 }
117 117
 
... ...
@@ -121,20 +114,20 @@ func (c *cache) del(kvObject KVObject, atomic bool) error {
121 121
 		return err
122 122
 	}
123 123
 
124
-	c.Lock()
124
+	c.mu.Lock()
125 125
 	// If atomic is true, cache needs to maintain its own index
126 126
 	// for atomicity and del needs to be atomic.
127 127
 	if atomic {
128 128
 		if prev, ok := kmap[Key(kvObject.Key()...)]; ok {
129 129
 			if prev.Index() != kvObject.Index() {
130
-				c.Unlock()
130
+				c.mu.Unlock()
131 131
 				return ErrKeyModified
132 132
 			}
133 133
 		}
134 134
 	}
135 135
 
136 136
 	delete(kmap, Key(kvObject.Key()...))
137
-	c.Unlock()
137
+	c.mu.Unlock()
138 138
 	return nil
139 139
 }
140 140
 
... ...
@@ -144,20 +137,15 @@ func (c *cache) get(kvObject KVObject) error {
144 144
 		return err
145 145
 	}
146 146
 
147
-	c.Lock()
148
-	defer c.Unlock()
147
+	c.mu.Lock()
148
+	defer c.mu.Unlock()
149 149
 
150 150
 	o, ok := kmap[Key(kvObject.Key()...)]
151 151
 	if !ok {
152 152
 		return ErrKeyNotFound
153 153
 	}
154 154
 
155
-	ctor, ok := o.(KVConstructor)
156
-	if !ok {
157
-		return errors.New("kvobject does not implement KVConstructor interface. could not get object")
158
-	}
159
-
160
-	return ctor.CopyTo(kvObject)
155
+	return o.CopyTo(kvObject)
161 156
 }
162 157
 
163 158
 func (c *cache) list(kvObject KVObject) ([]KVObject, error) {
... ...
@@ -166,8 +154,8 @@ func (c *cache) list(kvObject KVObject) ([]KVObject, error) {
166 166
 		return nil, err
167 167
 	}
168 168
 
169
-	c.Lock()
170
-	defer c.Unlock()
169
+	c.mu.Lock()
170
+	defer c.mu.Unlock()
171 171
 
172 172
 	var kvol []KVObject
173 173
 	for _, v := range kmap {
... ...
@@ -9,7 +9,6 @@ import (
9 9
 	"github.com/docker/docker/libnetwork/discoverapi"
10 10
 	store "github.com/docker/docker/libnetwork/internal/kvstore"
11 11
 	"github.com/docker/docker/libnetwork/internal/kvstore/boltdb"
12
-	"github.com/docker/docker/libnetwork/scope"
13 12
 	"github.com/docker/docker/libnetwork/types"
14 13
 )
15 14
 
... ...
@@ -21,7 +20,6 @@ var (
21 21
 
22 22
 type Store struct {
23 23
 	mu    sync.Mutex
24
-	scope string
25 24
 	store store.Store
26 25
 	cache *cache
27 26
 }
... ...
@@ -43,14 +41,8 @@ type KVObject interface {
43 43
 	// Exists returns true if the object exists in the datastore, false if it hasn't been stored yet.
44 44
 	// When SetIndex() is called, the object has been stored.
45 45
 	Exists() bool
46
-	// DataScope indicates the storage scope of the KV object
47
-	DataScope() string
48 46
 	// Skip provides a way for a KV Object to avoid persisting it in the KV Store
49 47
 	Skip() bool
50
-}
51
-
52
-// KVConstructor interface defines methods which can construct a KVObject from another.
53
-type KVConstructor interface {
54 48
 	// New returns a new object which is created based on the
55 49
 	// source object
56 50
 	New() KVObject
... ...
@@ -143,10 +135,7 @@ func newClient(kv string, addr string, config *store.Config) (*Store, error) {
143 143
 		return nil, err
144 144
 	}
145 145
 
146
-	ds := &Store{scope: scope.Local, store: s}
147
-	ds.cache = newCache(ds)
148
-
149
-	return ds, nil
146
+	return &Store{store: s, cache: newCache(s)}, nil
150 147
 }
151 148
 
152 149
 // New creates a new Store instance.
... ...
@@ -189,18 +178,8 @@ func (ds *Store) Close() {
189 189
 	ds.store.Close()
190 190
 }
191 191
 
192
-// Scope returns the scope of the store.
193
-func (ds *Store) Scope() string {
194
-	return ds.scope
195
-}
196
-
197 192
 // PutObjectAtomic provides an atomic add and update operation for a Record.
198 193
 func (ds *Store) PutObjectAtomic(kvObject KVObject) error {
199
-	var (
200
-		previous *store.KVPair
201
-		pair     *store.KVPair
202
-		err      error
203
-	)
204 194
 	ds.mu.Lock()
205 195
 	defer ds.mu.Unlock()
206 196
 
... ...
@@ -214,34 +193,26 @@ func (ds *Store) PutObjectAtomic(kvObject KVObject) error {
214 214
 		return types.InvalidParameterErrorf("invalid KV Object with a nil Value for key %s", Key(kvObject.Key()...))
215 215
 	}
216 216
 
217
-	if kvObject.Skip() {
218
-		goto add_cache
219
-	}
220
-
221
-	if kvObject.Exists() {
222
-		previous = &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()}
223
-	} else {
224
-		previous = nil
225
-	}
226
-
227
-	pair, err = ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous)
228
-	if err != nil {
229
-		if err == store.ErrKeyExists {
230
-			return ErrKeyModified
217
+	if !kvObject.Skip() {
218
+		var previous *store.KVPair
219
+		if kvObject.Exists() {
220
+			previous = &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()}
231 221
 		}
232
-		return err
233
-	}
234 222
 
235
-	kvObject.SetIndex(pair.LastIndex)
223
+		pair, err := ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous)
224
+		if err != nil {
225
+			if err == store.ErrKeyExists {
226
+				return ErrKeyModified
227
+			}
228
+			return err
229
+		}
236 230
 
237
-add_cache:
238
-	if ds.cache != nil {
239
-		// If persistent store is skipped, sequencing needs to
240
-		// happen in cache.
241
-		return ds.cache.add(kvObject, kvObject.Skip())
231
+		kvObject.SetIndex(pair.LastIndex)
242 232
 	}
243 233
 
244
-	return nil
234
+	// If persistent store is skipped, sequencing needs to
235
+	// happen in cache.
236
+	return ds.cache.add(kvObject, kvObject.Skip())
245 237
 }
246 238
 
247 239
 // GetObject gets data from the store and unmarshals to the specified object.
... ...
@@ -249,23 +220,7 @@ func (ds *Store) GetObject(key string, o KVObject) error {
249 249
 	ds.mu.Lock()
250 250
 	defer ds.mu.Unlock()
251 251
 
252
-	if ds.cache != nil {
253
-		return ds.cache.get(o)
254
-	}
255
-
256
-	kvPair, err := ds.store.Get(key)
257
-	if err != nil {
258
-		return err
259
-	}
260
-
261
-	if err := o.SetValue(kvPair.Value); err != nil {
262
-		return err
263
-	}
264
-
265
-	// Make sure the object has a correct view of the DB index in
266
-	// case we need to modify it and update the DB.
267
-	o.SetIndex(kvPair.LastIndex)
268
-	return nil
252
+	return ds.cache.get(o)
269 253
 }
270 254
 
271 255
 func (ds *Store) ensureParent(parent string) error {
... ...
@@ -285,27 +240,10 @@ func (ds *Store) List(key string, kvObject KVObject) ([]KVObject, error) {
285 285
 	ds.mu.Lock()
286 286
 	defer ds.mu.Unlock()
287 287
 
288
-	if ds.cache != nil {
289
-		return ds.cache.list(kvObject)
290
-	}
291
-
292
-	var kvol []KVObject
293
-	err := ds.iterateKVPairsFromStore(key, kvObject, func(key string, val KVObject) {
294
-		kvol = append(kvol, val)
295
-	})
296
-	if err != nil {
297
-		return nil, err
298
-	}
299
-	return kvol, nil
288
+	return ds.cache.list(kvObject)
300 289
 }
301 290
 
302
-func (ds *Store) iterateKVPairsFromStore(key string, kvObject KVObject, callback func(string, KVObject)) error {
303
-	// Bail out right away if the kvObject does not implement KVConstructor
304
-	ctor, ok := kvObject.(KVConstructor)
305
-	if !ok {
306
-		return fmt.Errorf("error listing objects, object does not implement KVConstructor interface")
307
-	}
308
-
291
+func (ds *Store) iterateKVPairsFromStore(key string, ctor KVObject, callback func(string, KVObject)) error {
309 292
 	// Make sure the parent key exists
310 293
 	if err := ds.ensureParent(key); err != nil {
311 294
 		return err
... ...
@@ -362,24 +300,17 @@ func (ds *Store) DeleteObjectAtomic(kvObject KVObject) error {
362 362
 
363 363
 	previous := &store.KVPair{Key: Key(kvObject.Key()...), LastIndex: kvObject.Index()}
364 364
 
365
-	if kvObject.Skip() {
366
-		goto deleteCache
367
-	}
368
-
369
-	if err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil {
370
-		if err == store.ErrKeyExists {
371
-			return ErrKeyModified
365
+	if !kvObject.Skip() {
366
+		if err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil {
367
+			if err == store.ErrKeyExists {
368
+				return ErrKeyModified
369
+			}
370
+			return err
372 371
 		}
373
-		return err
374 372
 	}
375 373
 
376
-deleteCache:
377 374
 	// cleanup the cache only if AtomicDelete went through successfully
378
-	if ds.cache != nil {
379
-		// If persistent store is skipped, sequencing needs to
380
-		// happen in cache.
381
-		return ds.cache.del(kvObject, kvObject.Skip())
382
-	}
383
-
384
-	return nil
375
+	// If persistent store is skipped, sequencing needs to
376
+	// happen in cache.
377
+	return ds.cache.del(kvObject, kvObject.Skip())
385 378
 }
... ...
@@ -5,7 +5,6 @@ import (
5 5
 	"testing"
6 6
 
7 7
 	"github.com/docker/docker/libnetwork/options"
8
-	"github.com/docker/docker/libnetwork/scope"
9 8
 	"gotest.tools/v3/assert"
10 9
 	is "gotest.tools/v3/assert/cmp"
11 10
 )
... ...
@@ -14,7 +13,8 @@ const dummyKey = "dummy"
14 14
 
15 15
 // NewTestDataStore can be used by other Tests in order to use custom datastore
16 16
 func NewTestDataStore() *Store {
17
-	return &Store{scope: scope.Local, store: NewMockStore()}
17
+	s := NewMockStore()
18
+	return &Store{store: s, cache: newCache(s)}
18 19
 }
19 20
 
20 21
 func TestKey(t *testing.T) {
... ...
@@ -132,10 +132,6 @@ func (n *dummyObject) Skip() bool {
132 132
 	return n.SkipSave
133 133
 }
134 134
 
135
-func (n *dummyObject) DataScope() string {
136
-	return scope.Local
137
-}
138
-
139 135
 func (n *dummyObject) MarshalJSON() ([]byte, error) {
140 136
 	return json.Marshal(map[string]interface{}{
141 137
 		"name":        n.Name,
... ...
@@ -157,6 +153,18 @@ func (n *dummyObject) UnmarshalJSON(b []byte) error {
157 157
 	return nil
158 158
 }
159 159
 
160
+func (n *dummyObject) New() KVObject {
161
+	return &dummyObject{}
162
+}
163
+
164
+func (n *dummyObject) CopyTo(o KVObject) error {
165
+	if err := o.SetValue(n.Value()); err != nil {
166
+		return err
167
+	}
168
+	o.SetIndex(n.Index())
169
+	return nil
170
+}
171
+
160 172
 // dummy structure to test "recursive" cases
161 173
 type recStruct struct {
162 174
 	Name     string            `kv:"leaf"`
... ...
@@ -1,7 +1,7 @@
1 1
 package datastore
2 2
 
3 3
 import (
4
-	"errors"
4
+	"strings"
5 5
 
6 6
 	store "github.com/docker/docker/libnetwork/internal/kvstore"
7 7
 	"github.com/docker/docker/libnetwork/types"
... ...
@@ -23,16 +23,6 @@ func NewMockStore() *MockStore {
23 23
 	return &MockStore{db: make(map[string]*MockData)}
24 24
 }
25 25
 
26
-// Get the value at "key", returns the last modified index
27
-// to use in conjunction to CAS calls
28
-func (s *MockStore) Get(key string) (*store.KVPair, error) {
29
-	mData := s.db[key]
30
-	if mData == nil {
31
-		return nil, nil
32
-	}
33
-	return &store.KVPair{Value: mData.Data, LastIndex: mData.Index}, nil
34
-}
35
-
36 26
 // Put a value at "key"
37 27
 func (s *MockStore) Put(key string, value []byte) error {
38 28
 	mData := s.db[key]
... ...
@@ -52,7 +42,16 @@ func (s *MockStore) Exists(key string) (bool, error) {
52 52
 
53 53
 // List gets a range of values at "directory"
54 54
 func (s *MockStore) List(prefix string) ([]*store.KVPair, error) {
55
-	return nil, errors.New("not implemented")
55
+	var res []*store.KVPair
56
+	for k, v := range s.db {
57
+		if strings.HasPrefix(k, prefix) {
58
+			res = append(res, &store.KVPair{Key: k, Value: v.Data, LastIndex: v.Index})
59
+		}
60
+	}
61
+	if len(res) == 0 {
62
+		return nil, store.ErrKeyNotFound
63
+	}
64
+	return res, nil
56 65
 }
57 66
 
58 67
 // AtomicPut put a value at "key" if the key has not been
... ...
@@ -12,7 +12,6 @@ import (
12 12
 	"github.com/docker/docker/libnetwork/datastore"
13 13
 	"github.com/docker/docker/libnetwork/discoverapi"
14 14
 	"github.com/docker/docker/libnetwork/netlabel"
15
-	"github.com/docker/docker/libnetwork/scope"
16 15
 	"github.com/docker/docker/libnetwork/types"
17 16
 )
18 17
 
... ...
@@ -267,10 +266,6 @@ func (ncfg *networkConfiguration) CopyTo(o datastore.KVObject) error {
267 267
 	return nil
268 268
 }
269 269
 
270
-func (ncfg *networkConfiguration) DataScope() string {
271
-	return scope.Local
272
-}
273
-
274 270
 func (ep *bridgeEndpoint) MarshalJSON() ([]byte, error) {
275 271
 	epMap := make(map[string]interface{})
276 272
 	epMap["id"] = ep.id
... ...
@@ -384,10 +379,6 @@ func (ep *bridgeEndpoint) CopyTo(o datastore.KVObject) error {
384 384
 	return nil
385 385
 }
386 386
 
387
-func (ep *bridgeEndpoint) DataScope() string {
388
-	return scope.Local
389
-}
390
-
391 387
 func (n *bridgeNetwork) restorePortAllocations(ep *bridgeEndpoint) {
392 388
 	if ep.extConnConfig == nil ||
393 389
 		ep.extConnConfig.ExposedPorts == nil ||
... ...
@@ -12,7 +12,6 @@ import (
12 12
 	"github.com/docker/docker/libnetwork/datastore"
13 13
 	"github.com/docker/docker/libnetwork/discoverapi"
14 14
 	"github.com/docker/docker/libnetwork/netlabel"
15
-	"github.com/docker/docker/libnetwork/scope"
16 15
 	"github.com/docker/docker/libnetwork/types"
17 16
 )
18 17
 
... ...
@@ -258,10 +257,6 @@ func (config *configuration) CopyTo(o datastore.KVObject) error {
258 258
 	return nil
259 259
 }
260 260
 
261
-func (config *configuration) DataScope() string {
262
-	return scope.Local
263
-}
264
-
265 261
 func (ep *endpoint) MarshalJSON() ([]byte, error) {
266 262
 	epMap := make(map[string]interface{})
267 263
 	epMap["id"] = ep.id
... ...
@@ -357,7 +352,3 @@ func (ep *endpoint) CopyTo(o datastore.KVObject) error {
357 357
 	*dstEp = *ep
358 358
 	return nil
359 359
 }
360
-
361
-func (ep *endpoint) DataScope() string {
362
-	return scope.Local
363
-}
... ...
@@ -12,7 +12,6 @@ import (
12 12
 	"github.com/docker/docker/libnetwork/datastore"
13 13
 	"github.com/docker/docker/libnetwork/discoverapi"
14 14
 	"github.com/docker/docker/libnetwork/netlabel"
15
-	"github.com/docker/docker/libnetwork/scope"
16 15
 	"github.com/docker/docker/libnetwork/types"
17 16
 )
18 17
 
... ...
@@ -252,10 +251,6 @@ func (config *configuration) CopyTo(o datastore.KVObject) error {
252 252
 	return nil
253 253
 }
254 254
 
255
-func (config *configuration) DataScope() string {
256
-	return scope.Local
257
-}
258
-
259 255
 func (ep *endpoint) MarshalJSON() ([]byte, error) {
260 256
 	epMap := make(map[string]interface{})
261 257
 	epMap["id"] = ep.id
... ...
@@ -351,7 +346,3 @@ func (ep *endpoint) CopyTo(o datastore.KVObject) error {
351 351
 	*dstEp = *ep
352 352
 	return nil
353 353
 }
354
-
355
-func (ep *endpoint) DataScope() string {
356
-	return scope.Local
357
-}
... ...
@@ -12,7 +12,6 @@ import (
12 12
 	"github.com/docker/docker/libnetwork/datastore"
13 13
 	"github.com/docker/docker/libnetwork/discoverapi"
14 14
 	"github.com/docker/docker/libnetwork/netlabel"
15
-	"github.com/docker/docker/libnetwork/scope"
16 15
 	"github.com/docker/docker/libnetwork/types"
17 16
 )
18 17
 
... ...
@@ -221,10 +220,6 @@ func (ncfg *networkConfiguration) CopyTo(o datastore.KVObject) error {
221 221
 	return nil
222 222
 }
223 223
 
224
-func (ncfg *networkConfiguration) DataScope() string {
225
-	return scope.Local
226
-}
227
-
228 224
 func (ep *hnsEndpoint) MarshalJSON() ([]byte, error) {
229 225
 	epMap := make(map[string]interface{})
230 226
 	epMap["id"] = ep.id
... ...
@@ -333,7 +328,3 @@ func (ep *hnsEndpoint) CopyTo(o datastore.KVObject) error {
333 333
 	*dstEp = *ep
334 334
 	return nil
335 335
 }
336
-
337
-func (ep *hnsEndpoint) DataScope() string {
338
-	return scope.Local
339
-}
... ...
@@ -1019,10 +1019,6 @@ func JoinOptionPriority(prio int) EndpointOption {
1019 1019
 	}
1020 1020
 }
1021 1021
 
1022
-func (ep *Endpoint) DataScope() string {
1023
-	return ep.getNetwork().DataScope()
1024
-}
1025
-
1026 1022
 func (ep *Endpoint) assignAddress(ipam ipamapi.Ipam, assignIPv4, assignIPv6 bool) error {
1027 1023
 	var err error
1028 1024
 
... ...
@@ -97,10 +97,6 @@ func (ec *endpointCnt) CopyTo(o datastore.KVObject) error {
97 97
 	return nil
98 98
 }
99 99
 
100
-func (ec *endpointCnt) DataScope() string {
101
-	return ec.n.DataScope()
102
-}
103
-
104 100
 func (ec *endpointCnt) EndpointCnt() uint64 {
105 101
 	ec.Lock()
106 102
 	defer ec.Unlock()
... ...
@@ -111,7 +107,7 @@ func (ec *endpointCnt) EndpointCnt() uint64 {
111 111
 func (ec *endpointCnt) updateStore() error {
112 112
 	store := ec.n.getController().getStore()
113 113
 	if store == nil {
114
-		return fmt.Errorf("store not found for scope %s on endpoint count update", ec.DataScope())
114
+		return fmt.Errorf("store not found on endpoint count update")
115 115
 	}
116 116
 	// make a copy of count and n to avoid being overwritten by store.GetObject
117 117
 	count := ec.EndpointCnt()
... ...
@@ -140,7 +136,7 @@ func (ec *endpointCnt) setCnt(cnt uint64) error {
140 140
 func (ec *endpointCnt) atomicIncDecEpCnt(inc bool) error {
141 141
 	store := ec.n.getController().getStore()
142 142
 	if store == nil {
143
-		return fmt.Errorf("store not found for scope %s", ec.DataScope())
143
+		return fmt.Errorf("store not found on endpoint count atomic inc/dec")
144 144
 	}
145 145
 
146 146
 	tmp := &endpointCnt{n: ec.n}
... ...
@@ -109,44 +109,6 @@ func (b *BoltDB) releaseDBhandle() {
109 109
 	}
110 110
 }
111 111
 
112
-// Get the value at "key". BoltDB doesn't provide an inbuilt last modified index with every kv pair. Its implemented by
113
-// by a atomic counter maintained by the libkv and appened to the value passed by the client.
114
-func (b *BoltDB) Get(key string) (*store.KVPair, error) {
115
-	b.mu.Lock()
116
-	defer b.mu.Unlock()
117
-
118
-	db, err := b.getDBhandle()
119
-	if err != nil {
120
-		return nil, err
121
-	}
122
-	defer b.releaseDBhandle()
123
-
124
-	var val []byte
125
-	err = db.View(func(tx *bolt.Tx) error {
126
-		bucket := tx.Bucket(b.boltBucket)
127
-		if bucket == nil {
128
-			return store.ErrKeyNotFound
129
-		}
130
-
131
-		v := bucket.Get([]byte(key))
132
-		val = make([]byte, len(v))
133
-		copy(val, v)
134
-
135
-		return nil
136
-	})
137
-	if err != nil {
138
-		return nil, err
139
-	}
140
-	if len(val) == 0 {
141
-		return nil, store.ErrKeyNotFound
142
-	}
143
-
144
-	dbIndex := binary.LittleEndian.Uint64(val[:libkvmetadatalen])
145
-	val = val[libkvmetadatalen:]
146
-
147
-	return &store.KVPair{Key: key, Value: val, LastIndex: dbIndex}, nil
148
-}
149
-
150 112
 // Put the key, value pair. index number metadata is prepended to the value
151 113
 func (b *BoltDB) Put(key string, value []byte) error {
152 114
 	b.mu.Lock()
... ...
@@ -39,9 +39,6 @@ type Store interface {
39 39
 	// Put a value at the specified key
40 40
 	Put(key string, value []byte) error
41 41
 
42
-	// Get a value given its key
43
-	Get(key string) (*KVPair, error)
44
-
45 42
 	// Exists verifies if a Key exists in the store.
46 43
 	Exists(key string) (bool, error)
47 44
 
... ...
@@ -510,15 +510,6 @@ func (n *Network) CopyTo(o datastore.KVObject) error {
510 510
 	return nil
511 511
 }
512 512
 
513
-func (n *Network) DataScope() string {
514
-	s := n.Scope()
515
-	// All swarm scope networks have local datascope
516
-	if s == scope.Swarm {
517
-		s = scope.Local
518
-	}
519
-	return s
520
-}
521
-
522 513
 func (n *Network) getEpCnt() *endpointCnt {
523 514
 	n.mu.Lock()
524 515
 	defer n.mu.Unlock()
... ...
@@ -1773,7 +1764,7 @@ func (n *Network) deriveAddressSpace() (string, error) {
1773 1773
 	if err != nil {
1774 1774
 		return "", types.NotFoundErrorf("failed to get default address space: %v", err)
1775 1775
 	}
1776
-	if n.DataScope() == scope.Global {
1776
+	if n.Scope() == scope.Global {
1777 1777
 		return global, nil
1778 1778
 	}
1779 1779
 	return local, nil
... ...
@@ -9,7 +9,6 @@ import (
9 9
 	"github.com/containerd/log"
10 10
 	"github.com/docker/docker/libnetwork/datastore"
11 11
 	"github.com/docker/docker/libnetwork/osl"
12
-	"github.com/docker/docker/libnetwork/scope"
13 12
 )
14 13
 
15 14
 const (
... ...
@@ -122,10 +121,6 @@ func (sbs *sbState) CopyTo(o datastore.KVObject) error {
122 122
 	return nil
123 123
 }
124 124
 
125
-func (sbs *sbState) DataScope() string {
126
-	return scope.Local
127
-}
128
-
129 125
 func (sb *Sandbox) storeUpdate() error {
130 126
 	sbs := &sbState{
131 127
 		c:          sb.controller,
... ...
@@ -184,7 +179,7 @@ func (c *Controller) sandboxCleanup(activeSandboxes map[string]interface{}) erro
184 184
 			// It's normal for no sandboxes to be found. Just bail out.
185 185
 			return nil
186 186
 		}
187
-		return fmt.Errorf("failed to get sandboxes for scope %s: %v", store.Scope(), err)
187
+		return fmt.Errorf("failed to get sandboxes: %v", err)
188 188
 	}
189 189
 
190 190
 	for _, s := range sandboxStates {
... ...
@@ -68,7 +68,7 @@ func (c *Controller) getNetworks() ([]*Network, error) {
68 68
 
69 69
 		n.epCnt = ec
70 70
 		if n.scope == "" {
71
-			n.scope = store.Scope()
71
+			n.scope = scope.Local
72 72
 		}
73 73
 		nl = append(nl, n)
74 74
 	}
... ...
@@ -105,7 +105,7 @@ func (c *Controller) getNetworksFromStore() []*Network { // FIXME: unify with c.
105 105
 			n.epCnt = ec
106 106
 		}
107 107
 		if n.scope == "" {
108
-			n.scope = store.Scope()
108
+			n.scope = scope.Local
109 109
 		}
110 110
 		n.mu.Unlock()
111 111
 		nl = append(nl, n)
... ...
@@ -132,8 +132,8 @@ func (n *Network) getEndpointsFromStore() ([]*Endpoint, error) {
132 132
 	kvol, err := store.List(datastore.Key(tmp.KeyPrefix()...), &Endpoint{network: n})
133 133
 	if err != nil {
134 134
 		if err != datastore.ErrKeyNotFound {
135
-			return nil, fmt.Errorf("failed to get endpoints for network %s scope %s: %w",
136
-				n.Name(), store.Scope(), err)
135
+			return nil, fmt.Errorf("failed to get endpoints for network %s: %w",
136
+				n.Name(), err)
137 137
 		}
138 138
 		return nil, nil
139 139
 	}