Skip to content

Commit

Permalink
bugfix: the same prefix key lock error (openyurtio#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
rambohe-ch authored Jul 28, 2021
1 parent 1b499bf commit a514d91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/yurthub/storage/disk/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,16 +460,19 @@ func (ds *diskStorage) lockKey(key string) bool {
ds.Lock()
defer ds.Unlock()
if _, ok := ds.keyPendingStatus[key]; ok {
klog.Infof("key(%s) storage is pending, just skip it", key)
return false
}

for pendingKey := range ds.keyPendingStatus {
if len(key) > len(pendingKey) {
if strings.Contains(key, pendingKey) {
if strings.Contains(key, fmt.Sprintf("%s/", pendingKey)) {
klog.Infof("key(%s) storage is pending, skip to store key(%s)", pendingKey, key)
return false
}
} else {
if strings.Contains(pendingKey, key) {
if strings.Contains(pendingKey, fmt.Sprintf("%s/", key)) {
klog.Infof("key(%s) storage is pending, skip to store key(%s)", pendingKey, key)
return false
}
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/yurthub/storage/disk/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@ func TestLockKey(t *testing.T) {
lockResult: true,
lockVerifyResult: false,
},
"lock same prefix key with pre-locked key ": {
preLockedKeys: []string{"kubelet/pods/kube-system/foo"},
lockKey: "kubelet/pods/kube-system/foo2",
lockResult: true,
lockVerifyResult: false,
},
}

s := &diskStorage{
Expand Down

0 comments on commit a514d91

Please sign in to comment.