mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove Lock in datastore for global scope
Signed-off-by: menghui.chen <menghui.chen@alibaba-inc.com>
This commit is contained in:
parent
2dd111e74c
commit
115cdb52b3
1 changed files with 39 additions and 20 deletions
|
@ -59,6 +59,7 @@ type datastore struct {
|
||||||
cache *cache
|
cache *cache
|
||||||
watchCh chan struct{}
|
watchCh chan struct{}
|
||||||
active bool
|
active bool
|
||||||
|
sequential bool
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,6 +191,10 @@ func newClient(scope string, kv string, addr string, config *store.Config, cache
|
||||||
if cached && scope != LocalScope {
|
if cached && scope != LocalScope {
|
||||||
return nil, fmt.Errorf("caching supported only for scope %s", LocalScope)
|
return nil, fmt.Errorf("caching supported only for scope %s", LocalScope)
|
||||||
}
|
}
|
||||||
|
sequential := false
|
||||||
|
if scope == LocalScope {
|
||||||
|
sequential = true
|
||||||
|
}
|
||||||
|
|
||||||
if config == nil {
|
if config == nil {
|
||||||
config = &store.Config{}
|
config = &store.Config{}
|
||||||
|
@ -216,7 +221,7 @@ func newClient(scope string, kv string, addr string, config *store.Config, cache
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ds := &datastore{scope: scope, store: store, active: true, watchCh: make(chan struct{})}
|
ds := &datastore{scope: scope, store: store, active: true, watchCh: make(chan struct{}), sequential: sequential}
|
||||||
if cached {
|
if cached {
|
||||||
ds.cache = newCache(ds)
|
ds.cache = newCache(ds)
|
||||||
}
|
}
|
||||||
|
@ -375,8 +380,10 @@ func (ds *datastore) PutObjectAtomic(kvObject KVObject) error {
|
||||||
pair *store.KVPair
|
pair *store.KVPair
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
if ds.sequential {
|
||||||
ds.Lock()
|
ds.Lock()
|
||||||
defer ds.Unlock()
|
defer ds.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
if kvObject == nil {
|
if kvObject == nil {
|
||||||
return types.BadRequestErrorf("invalid KV Object : nil")
|
return types.BadRequestErrorf("invalid KV Object : nil")
|
||||||
|
@ -418,8 +425,10 @@ add_cache:
|
||||||
|
|
||||||
// PutObject adds a new Record based on an object into the datastore
|
// PutObject adds a new Record based on an object into the datastore
|
||||||
func (ds *datastore) PutObject(kvObject KVObject) error {
|
func (ds *datastore) PutObject(kvObject KVObject) error {
|
||||||
|
if ds.sequential {
|
||||||
ds.Lock()
|
ds.Lock()
|
||||||
defer ds.Unlock()
|
defer ds.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
if kvObject == nil {
|
if kvObject == nil {
|
||||||
return types.BadRequestErrorf("invalid KV Object : nil")
|
return types.BadRequestErrorf("invalid KV Object : nil")
|
||||||
|
@ -452,8 +461,10 @@ func (ds *datastore) putObjectWithKey(kvObject KVObject, key ...string) error {
|
||||||
|
|
||||||
// GetObject returns a record matching the key
|
// GetObject returns a record matching the key
|
||||||
func (ds *datastore) GetObject(key string, o KVObject) error {
|
func (ds *datastore) GetObject(key string, o KVObject) error {
|
||||||
|
if ds.sequential {
|
||||||
ds.Lock()
|
ds.Lock()
|
||||||
defer ds.Unlock()
|
defer ds.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
if ds.cache != nil {
|
if ds.cache != nil {
|
||||||
return ds.cache.get(key, o)
|
return ds.cache.get(key, o)
|
||||||
|
@ -486,8 +497,10 @@ func (ds *datastore) ensureParent(parent string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ds *datastore) List(key string, kvObject KVObject) ([]KVObject, error) {
|
func (ds *datastore) List(key string, kvObject KVObject) ([]KVObject, error) {
|
||||||
|
if ds.sequential {
|
||||||
ds.Lock()
|
ds.Lock()
|
||||||
defer ds.Unlock()
|
defer ds.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
if ds.cache != nil {
|
if ds.cache != nil {
|
||||||
return ds.cache.list(kvObject)
|
return ds.cache.list(kvObject)
|
||||||
|
@ -532,8 +545,10 @@ func (ds *datastore) List(key string, kvObject KVObject) ([]KVObject, error) {
|
||||||
|
|
||||||
// DeleteObject unconditionally deletes a record from the store
|
// DeleteObject unconditionally deletes a record from the store
|
||||||
func (ds *datastore) DeleteObject(kvObject KVObject) error {
|
func (ds *datastore) DeleteObject(kvObject KVObject) error {
|
||||||
|
if ds.sequential {
|
||||||
ds.Lock()
|
ds.Lock()
|
||||||
defer ds.Unlock()
|
defer ds.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
// cleaup the cache first
|
// cleaup the cache first
|
||||||
if ds.cache != nil {
|
if ds.cache != nil {
|
||||||
|
@ -549,8 +564,10 @@ func (ds *datastore) DeleteObject(kvObject KVObject) error {
|
||||||
|
|
||||||
// DeleteObjectAtomic performs atomic delete on a record
|
// DeleteObjectAtomic performs atomic delete on a record
|
||||||
func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error {
|
func (ds *datastore) DeleteObjectAtomic(kvObject KVObject) error {
|
||||||
|
if ds.sequential {
|
||||||
ds.Lock()
|
ds.Lock()
|
||||||
defer ds.Unlock()
|
defer ds.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
if kvObject == nil {
|
if kvObject == nil {
|
||||||
return types.BadRequestErrorf("invalid KV Object : nil")
|
return types.BadRequestErrorf("invalid KV Object : nil")
|
||||||
|
@ -580,8 +597,10 @@ del_cache:
|
||||||
|
|
||||||
// DeleteTree unconditionally deletes a record from the store
|
// DeleteTree unconditionally deletes a record from the store
|
||||||
func (ds *datastore) DeleteTree(kvObject KVObject) error {
|
func (ds *datastore) DeleteTree(kvObject KVObject) error {
|
||||||
|
if ds.sequential {
|
||||||
ds.Lock()
|
ds.Lock()
|
||||||
defer ds.Unlock()
|
defer ds.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
// cleaup the cache first
|
// cleaup the cache first
|
||||||
if ds.cache != nil {
|
if ds.cache != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue