Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: the same prefix key lock error #396

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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