mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
redis3: key the upper half of a split node by its smallest name
When a full node splits and the new name goes to the lower half, the upper half was keyed by that new name, which it does not hold. Deleting the name then matched the upper node by key and removed nothing, so the name stayed listed, and listings from a start name could come back out of order. Only a directory list of more than one node splits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7983e51b4a
commit
e58ad14e30
2 files changed
+57
-2
No files matched your search
@@ -143,8 +143,8 @@ func (nl *ItemList) WriteName(name string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// point skip list to current Y
|
||||
if err := nl.ItemAdd(lookupKey, prevNodeReference.ElementPointer); err != nil {
|
||||
// point skip list to current Y, keyed by its smallest name now that name went to X
|
||||
if err := nl.ItemAdd([]byte(nl.NodeMin(prevNodeReference)), prevNodeReference.ElementPointer); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package redis3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
// itemListOp runs fn on the directory list of dir with a small batch size, so
|
||||
// a few names already split it into several nodes, and saves what fn changed.
|
||||
func itemListOp(t *testing.T, store *UniversalRedis3Store, key string, fn func(nl *ItemList) error) {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
data, err := store.Client.Get(ctx, key).Result()
|
||||
if err != nil && err != redis.Nil {
|
||||
t.Fatalf("get %s: %v", key, err)
|
||||
}
|
||||
nl := LoadItemList([]byte(data), key, store.Client, newSkipListElementStore(key, store.Client), 2)
|
||||
if err := fn(nl); err != nil {
|
||||
t.Fatalf("item list %s: %v", key, err)
|
||||
}
|
||||
if nl.HasChanges() {
|
||||
if err := store.Client.Set(ctx, key, nl.ToBytes(), 0).Err(); err != nil {
|
||||
t.Fatalf("set %s: %v", key, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func itemListNames(t *testing.T, store *UniversalRedis3Store, key string, startFrom string) string {
|
||||
t.Helper()
|
||||
var names []string
|
||||
itemListOp(t, store, key, func(nl *ItemList) error {
|
||||
return nl.ListNames(startFrom, func(name string) bool {
|
||||
names = append(names, name)
|
||||
return true
|
||||
})
|
||||
})
|
||||
return fmt.Sprint(names)
|
||||
}
|
||||
|
||||
// A full node [a c] splits on b into [a b] and [c]. The upper node has to be
|
||||
// keyed by c: keyed by b, deleting b found it there and left b listed.
|
||||
func TestItemListSplitKeysTheUpperNodeByItsSmallestName(t *testing.T) {
|
||||
store, dir := newTestStore(t)
|
||||
key := store.getKey(genDirectoryListKey(string(dir)))
|
||||
for _, name := range []string{"a", "c", "b"} {
|
||||
itemListOp(t, store, key, func(nl *ItemList) error { return nl.WriteName(name) })
|
||||
}
|
||||
itemListOp(t, store, key, func(nl *ItemList) error { return nl.DeleteName("b") })
|
||||
if got := itemListNames(t, store, key, ""); got != "[a c]" {
|
||||
t.Fatalf("after deleting b: %s, want [a c]", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user