mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
redis3: return a failed read of a node's membership
A failed read passed for a missing name: a lookup's leftover check reported no leftover, and a delete returned success with the name still listed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
64c2193375
commit
9c66285188
2 files changed
+31
-9
No files matched your search
@@ -280,8 +280,8 @@ func (nl *ItemList) DeleteName(name string) error {
|
||||
// case 2.1
|
||||
return nil
|
||||
}
|
||||
if !nl.NodeContainsItem(prevNode.Reference(), name) {
|
||||
return nil
|
||||
if contains, err := nl.NodeContainsItem(prevNode.Reference(), name); err != nil || !contains {
|
||||
return err
|
||||
}
|
||||
|
||||
// case 3
|
||||
@@ -375,7 +375,7 @@ func (nl *ItemList) ContainsName(name string) (bool, error) {
|
||||
if err != nil || node == nil {
|
||||
return false, err
|
||||
}
|
||||
return nl.NodeContainsItem(node.Reference(), name), nil
|
||||
return nl.NodeContainsItem(node.Reference(), name)
|
||||
}
|
||||
|
||||
func (nl *ItemList) IsEmpty() bool {
|
||||
@@ -407,16 +407,13 @@ func (nl *ItemList) RemoteAllListElement() error {
|
||||
|
||||
}
|
||||
|
||||
func (nl *ItemList) NodeContainsItem(node *skiplist.SkipListElementReference, item string) bool {
|
||||
func (nl *ItemList) NodeContainsItem(node *skiplist.SkipListElementReference, item string) (bool, error) {
|
||||
key := fmt.Sprintf("%s%dm", nl.prefix, node.ElementPointer)
|
||||
_, err := nl.client.ZScore(context.Background(), key, item).Result()
|
||||
if err == redis.Nil {
|
||||
return false
|
||||
return false, nil
|
||||
}
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return err == nil, err
|
||||
}
|
||||
|
||||
func (nl *ItemList) NodeSize(node *skiplist.SkipListElementReference) int {
|
||||
|
||||
@@ -91,6 +91,31 @@ func TestItemListContainsName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A failed read of the node that would hold a name is an error, not a missing name.
|
||||
func TestItemListContainsNameFailingARead(t *testing.T) {
|
||||
store, dir := newTestStore(t)
|
||||
key := store.getKey(genDirectoryListKey(string(dir)))
|
||||
for _, name := range []string{"b", "d"} {
|
||||
itemListOp(t, store, key, func(nl *ItemList) error { return nl.WriteName(name) })
|
||||
}
|
||||
|
||||
failing := &failingCommands{name: "zscore"}
|
||||
store.Client.AddHook(failing)
|
||||
failing.left.Store(1)
|
||||
data, err := store.Client.Get(context.Background(), key).Result()
|
||||
if err != nil {
|
||||
t.Fatalf("get %s: %v", key, err)
|
||||
}
|
||||
nl := LoadItemList([]byte(data), key, store.Client, newSkipListElementStore(key, store.Client), 2)
|
||||
if got, err := nl.ContainsName("d"); err == nil {
|
||||
t.Fatalf("ContainsName = %v, nil although reading the node failed", got)
|
||||
}
|
||||
failing.left.Store(1)
|
||||
if err := nl.DeleteName("d"); err == nil {
|
||||
t.Fatalf("DeleteName succeeded although reading the node failed")
|
||||
}
|
||||
}
|
||||
|
||||
// failingCommands lets the next skip commands of one name through, then fails
|
||||
// the next left of them before they reach redis.
|
||||
type failingCommands struct {
|
||||
|
||||
Reference in new issue
Block a user