libnet/ds: remove unused param key
from GetObject
Since 43dccc6
the `key` param is never used and can be safely
removed.
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
parent
e8346c53d9
commit
f7ef0e9fc7
10 changed files with 19 additions and 21 deletions
|
@ -216,7 +216,7 @@ func (ds *Store) PutObjectAtomic(kvObject KVObject) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetObject gets data from the store and unmarshals to the specified object.
|
// GetObject gets data from the store and unmarshals to the specified object.
|
||||||
func (ds *Store) GetObject(key string, o KVObject) error {
|
func (ds *Store) GetObject(o KVObject) error {
|
||||||
ds.mu.Lock()
|
ds.mu.Lock()
|
||||||
defer ds.mu.Unlock()
|
defer ds.mu.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ func TestKVObjectFlatKey(t *testing.T) {
|
||||||
assert.Check(t, err)
|
assert.Check(t, err)
|
||||||
|
|
||||||
n := dummyObject{ID: "1000"} // GetObject uses KVObject.Key() for cache lookup.
|
n := dummyObject{ID: "1000"} // GetObject uses KVObject.Key() for cache lookup.
|
||||||
err = store.GetObject(Key(dummyKey, "1000"), &n)
|
err = store.GetObject(&n)
|
||||||
assert.Check(t, err)
|
assert.Check(t, err)
|
||||||
assert.Check(t, is.Equal(n.Name, expected.Name))
|
assert.Check(t, is.Equal(n.Name, expected.Name))
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ func TestAtomicKVObjectFlatKey(t *testing.T) {
|
||||||
// Get the latest index and try PutObjectAtomic again for the same Key
|
// Get the latest index and try PutObjectAtomic again for the same Key
|
||||||
// This must succeed as well
|
// This must succeed as well
|
||||||
n := dummyObject{ID: "1111"} // GetObject uses KVObject.Key() for cache lookup.
|
n := dummyObject{ID: "1111"} // GetObject uses KVObject.Key() for cache lookup.
|
||||||
err = store.GetObject(Key(expected.Key()...), &n)
|
err = store.GetObject(&n)
|
||||||
assert.Check(t, err)
|
assert.Check(t, err)
|
||||||
n.ReturnValue = true
|
n.ReturnValue = true
|
||||||
err = store.PutObjectAtomic(&n)
|
err = store.PutObjectAtomic(&n)
|
||||||
|
@ -69,7 +69,7 @@ func TestAtomicKVObjectFlatKey(t *testing.T) {
|
||||||
|
|
||||||
// Get the Object using GetObject, then set again.
|
// Get the Object using GetObject, then set again.
|
||||||
newObj := dummyObject{ID: "1111"} // GetObject uses KVObject.Key() for cache lookup.
|
newObj := dummyObject{ID: "1111"} // GetObject uses KVObject.Key() for cache lookup.
|
||||||
err = store.GetObject(Key(expected.Key()...), &newObj)
|
err = store.GetObject(&newObj)
|
||||||
assert.Check(t, err)
|
assert.Check(t, err)
|
||||||
assert.Check(t, newObj.Exists())
|
assert.Check(t, newObj.Exists())
|
||||||
err = store.PutObjectAtomic(&n)
|
err = store.PutObjectAtomic(&n)
|
||||||
|
|
|
@ -122,7 +122,7 @@ func (d *driver) storeDelete(kvObject datastore.KVObject) error {
|
||||||
retry:
|
retry:
|
||||||
if err := d.store.DeleteObjectAtomic(kvObject); err != nil {
|
if err := d.store.DeleteObjectAtomic(kvObject); err != nil {
|
||||||
if err == datastore.ErrKeyModified {
|
if err == datastore.ErrKeyModified {
|
||||||
if err := d.store.GetObject(datastore.Key(kvObject.Key()...), kvObject); err != nil {
|
if err := d.store.GetObject(kvObject); err != nil {
|
||||||
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
|
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
|
||||||
}
|
}
|
||||||
goto retry
|
goto retry
|
||||||
|
|
|
@ -137,7 +137,7 @@ func (d *driver) storeDelete(kvObject datastore.KVObject) error {
|
||||||
retry:
|
retry:
|
||||||
if err := d.store.DeleteObjectAtomic(kvObject); err != nil {
|
if err := d.store.DeleteObjectAtomic(kvObject); err != nil {
|
||||||
if err == datastore.ErrKeyModified {
|
if err == datastore.ErrKeyModified {
|
||||||
if err := d.store.GetObject(datastore.Key(kvObject.Key()...), kvObject); err != nil {
|
if err := d.store.GetObject(kvObject); err != nil {
|
||||||
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
|
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
|
||||||
}
|
}
|
||||||
goto retry
|
goto retry
|
||||||
|
|
|
@ -136,7 +136,7 @@ func (d *driver) storeDelete(kvObject datastore.KVObject) error {
|
||||||
retry:
|
retry:
|
||||||
if err := d.store.DeleteObjectAtomic(kvObject); err != nil {
|
if err := d.store.DeleteObjectAtomic(kvObject); err != nil {
|
||||||
if err == datastore.ErrKeyModified {
|
if err == datastore.ErrKeyModified {
|
||||||
if err := d.store.GetObject(datastore.Key(kvObject.Key()...), kvObject); err != nil {
|
if err := d.store.GetObject(kvObject); err != nil {
|
||||||
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
|
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
|
||||||
}
|
}
|
||||||
goto retry
|
goto retry
|
||||||
|
|
|
@ -122,7 +122,7 @@ func (d *driver) storeDelete(kvObject datastore.KVObject) error {
|
||||||
retry:
|
retry:
|
||||||
if err := d.store.DeleteObjectAtomic(kvObject); err != nil {
|
if err := d.store.DeleteObjectAtomic(kvObject); err != nil {
|
||||||
if err == datastore.ErrKeyModified {
|
if err == datastore.ErrKeyModified {
|
||||||
if err := d.store.GetObject(datastore.Key(kvObject.Key()...), kvObject); err != nil {
|
if err := d.store.GetObject(kvObject); err != nil {
|
||||||
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
|
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
|
||||||
}
|
}
|
||||||
goto retry
|
goto retry
|
||||||
|
|
|
@ -116,7 +116,7 @@ func (ec *endpointCnt) updateStore() error {
|
||||||
if err := ec.n.getController().updateToStore(ec); err == nil || err != datastore.ErrKeyModified {
|
if err := ec.n.getController().updateToStore(ec); err == nil || err != datastore.ErrKeyModified {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := store.GetObject(datastore.Key(ec.Key()...), ec); err != nil {
|
if err := store.GetObject(ec); err != nil {
|
||||||
return fmt.Errorf("could not update the kvobject to latest on endpoint count update: %v", err)
|
return fmt.Errorf("could not update the kvobject to latest on endpoint count update: %v", err)
|
||||||
}
|
}
|
||||||
ec.Lock()
|
ec.Lock()
|
||||||
|
@ -140,7 +140,7 @@ func (ec *endpointCnt) atomicIncDecEpCnt(inc bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp := &endpointCnt{n: ec.n}
|
tmp := &endpointCnt{n: ec.n}
|
||||||
if err := store.GetObject(datastore.Key(ec.Key()...), tmp); err != nil {
|
if err := store.GetObject(tmp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
retry:
|
retry:
|
||||||
|
@ -156,7 +156,7 @@ retry:
|
||||||
|
|
||||||
if err := ec.n.getController().updateToStore(ec); err != nil {
|
if err := ec.n.getController().updateToStore(ec); err != nil {
|
||||||
if err == datastore.ErrKeyModified {
|
if err == datastore.ErrKeyModified {
|
||||||
if err := store.GetObject(datastore.Key(ec.Key()...), ec); err != nil {
|
if err := store.GetObject(ec); err != nil {
|
||||||
return fmt.Errorf("could not update the kvobject to latest when trying to atomic add endpoint count: %v", err)
|
return fmt.Errorf("could not update the kvobject to latest when trying to atomic add endpoint count: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ func (c *Controller) getNetworks() ([]*Network, error) {
|
||||||
n.ctrlr = c
|
n.ctrlr = c
|
||||||
|
|
||||||
ec := &endpointCnt{n: n}
|
ec := &endpointCnt{n: n}
|
||||||
err = store.GetObject(datastore.Key(ec.Key()...), ec)
|
err = store.GetObject(ec)
|
||||||
if err != nil && !n.inDelete {
|
if err != nil && !n.inDelete {
|
||||||
log.G(context.TODO()).Warnf("Could not find endpoint count key %s for network %s while listing: %v", datastore.Key(ec.Key()...), n.Name(), err)
|
log.G(context.TODO()).Warnf("Could not find endpoint count key %s for network %s while listing: %v", datastore.Key(ec.Key()...), n.Name(), err)
|
||||||
continue
|
continue
|
||||||
|
@ -118,7 +118,7 @@ func (c *Controller) getNetworksFromStore(ctx context.Context) []*Network { // F
|
||||||
func (n *Network) getEndpointFromStore(eid string) (*Endpoint, error) {
|
func (n *Network) getEndpointFromStore(eid string) (*Endpoint, error) {
|
||||||
store := n.ctrlr.getStore()
|
store := n.ctrlr.getStore()
|
||||||
ep := &Endpoint{id: eid, network: n}
|
ep := &Endpoint{id: eid, network: n}
|
||||||
err := store.GetObject(datastore.Key(ep.Key()...), ep)
|
err := store.GetObject(ep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not find endpoint %s: %w", eid, err)
|
return nil, fmt.Errorf("could not find endpoint %s: %w", eid, err)
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ func (c *Controller) deleteFromStore(kvObject datastore.KVObject) error {
|
||||||
retry:
|
retry:
|
||||||
if err := cs.DeleteObjectAtomic(kvObject); err != nil {
|
if err := cs.DeleteObjectAtomic(kvObject); err != nil {
|
||||||
if err == datastore.ErrKeyModified {
|
if err == datastore.ErrKeyModified {
|
||||||
if err := cs.GetObject(datastore.Key(kvObject.Key()...), kvObject); err != nil {
|
if err := cs.GetObject(kvObject); err != nil {
|
||||||
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
|
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
|
||||||
}
|
}
|
||||||
log.G(context.TODO()).Warnf("Error (%v) deleting object %v, retrying....", err, kvObject.Key())
|
log.G(context.TODO()).Warnf("Error (%v) deleting object %v, retrying....", err, kvObject.Key())
|
||||||
|
|
|
@ -50,9 +50,8 @@ func TestNoPersist(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer testController.Stop()
|
defer testController.Stop()
|
||||||
|
|
||||||
// FIXME(thaJeztah): GetObject uses the given key for lookups if no cache-store is present, but the KvObject's Key() to look up in cache....
|
|
||||||
nwKVObject := &Network{id: nw.ID()}
|
nwKVObject := &Network{id: nw.ID()}
|
||||||
err = testController.getStore().GetObject(datastore.Key(datastore.NetworkKeyPrefix, nw.ID()), nwKVObject)
|
err = testController.getStore().GetObject(nwKVObject)
|
||||||
if !errors.Is(err, store.ErrKeyNotFound) {
|
if !errors.Is(err, store.ErrKeyNotFound) {
|
||||||
t.Errorf("Expected %q error when retrieving network from store, got: %q", store.ErrKeyNotFound, err)
|
t.Errorf("Expected %q error when retrieving network from store, got: %q", store.ErrKeyNotFound, err)
|
||||||
}
|
}
|
||||||
|
@ -61,7 +60,7 @@ func TestNoPersist(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
epKVObject := &Endpoint{network: nw, id: ep.ID()}
|
epKVObject := &Endpoint{network: nw, id: ep.ID()}
|
||||||
err = testController.getStore().GetObject(datastore.Key(datastore.EndpointKeyPrefix, nw.ID(), ep.ID()), epKVObject)
|
err = testController.getStore().GetObject(epKVObject)
|
||||||
if !errors.Is(err, store.ErrKeyNotFound) {
|
if !errors.Is(err, store.ErrKeyNotFound) {
|
||||||
t.Errorf("Expected %v error when retrieving endpoint from store, got: %v", store.ErrKeyNotFound, err)
|
t.Errorf("Expected %v error when retrieving endpoint from store, got: %v", store.ErrKeyNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/libnetwork/config"
|
"github.com/docker/docker/libnetwork/config"
|
||||||
"github.com/docker/docker/libnetwork/datastore"
|
|
||||||
store "github.com/docker/docker/libnetwork/internal/kvstore"
|
store "github.com/docker/docker/libnetwork/internal/kvstore"
|
||||||
"github.com/docker/docker/libnetwork/netlabel"
|
"github.com/docker/docker/libnetwork/netlabel"
|
||||||
"github.com/docker/docker/libnetwork/options"
|
"github.com/docker/docker/libnetwork/options"
|
||||||
|
@ -36,9 +35,9 @@ func testLocalBackend(t *testing.T, provider, url string, storeConfig *store.Con
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error creating endpoint: %v", err)
|
t.Fatalf("Error creating endpoint: %v", err)
|
||||||
}
|
}
|
||||||
// FIXME(thaJeztah): GetObject uses the given key for lookups if no cache-store is present, but the KvObject's Key() to look up in cache....
|
|
||||||
nwKVObject := &Network{id: nw.ID()}
|
nwKVObject := &Network{id: nw.ID()}
|
||||||
err = testController.getStore().GetObject(datastore.Key(datastore.NetworkKeyPrefix, nw.ID()), nwKVObject)
|
err = testController.getStore().GetObject(nwKVObject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error when retrieving network key from store: %v", err)
|
t.Errorf("Error when retrieving network key from store: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -47,7 +46,7 @@ func testLocalBackend(t *testing.T, provider, url string, storeConfig *store.Con
|
||||||
}
|
}
|
||||||
|
|
||||||
epKVObject := &Endpoint{network: nw, id: ep.ID()}
|
epKVObject := &Endpoint{network: nw, id: ep.ID()}
|
||||||
err = testController.getStore().GetObject(datastore.Key(datastore.EndpointKeyPrefix, nw.ID(), ep.ID()), epKVObject)
|
err = testController.getStore().GetObject(epKVObject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error when retrieving Endpoint key from store: %v", err)
|
t.Errorf("Error when retrieving Endpoint key from store: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue