Intermediate cephmig round snapshots skip a subdirectory whose inode, inode version and ceph.dir.rctime equal those in the base snapshot. The index carries the subtree's entries over from the base and marks them carried; carried entries never serve as base for a block delta. Snapdiff, copy, pruning and verification leave skipped subtrees out. Application snapshots and finalize always scan everything, so a change missed because of delayed rctime propagation or a lagging client clock costs extra work but cannot reach the final state. The config option full_scan disables the shortcut; the journal reports skipped_subtrees. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
129 lines
3.1 KiB
Go
129 lines
3.1 KiB
Go
package migration
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"testing"
|
|
|
|
"git.zb-server.de/Sebi/CephfsMig/internal/storage"
|
|
)
|
|
|
|
func TestEntryEncodingCarriedAndLegacy(t *testing.T) {
|
|
e := baseEntry{Inode: 1, Version: 2, Size: 3, TargetInode: 4, Carried: true}
|
|
got, ok := decodeEntry(encodeEntry(e))
|
|
if !ok || got != e {
|
|
t.Fatalf("round trip: %+v %v", got, ok)
|
|
}
|
|
|
|
legacy := encodeEntry(baseEntry{Inode: 1, Version: 2, Size: 3, TargetInode: 4})[:32]
|
|
if got, ok := decodeEntry(legacy); !ok || got.Carried || got.TargetInode != 4 {
|
|
t.Fatalf("legacy record: %+v %v", got, ok)
|
|
}
|
|
|
|
for _, bad := range [][]byte{make([]byte, 31), append(make([]byte, 32), 2)} {
|
|
if _, ok := decodeEntry(bad); ok {
|
|
t.Fatalf("accepted %d-byte record", len(bad))
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestCarryCopiesExactlyTheSubtree(t *testing.T) {
|
|
dir := t.TempDir()
|
|
base, err := createNativeIndex(dir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
defer base.close()
|
|
// "a b", "a-x" and "a.x" sort between "a" and "a/"; "ab" sorts after it.
|
|
paths := []string{".", "a", "a b", "a b/x", "a-x", "a.x", "a/1", "a/2/3", "ab", "b"}
|
|
for i := 0; i < 5000; i++ {
|
|
paths = append(paths, filepath.Join("a/many", string(rune('a'+i%26)), string(rune('a'+i/26%26)), string(rune('a'+i/676))))
|
|
}
|
|
|
|
for i, p := range paths {
|
|
if err := base.put("paths", []byte(p), encodeEntry(baseEntry{Inode: uint64(i + 1), TargetInode: 9})); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
pending, err := createNativeIndex(dir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
defer pending.close()
|
|
if err := pending.carry(base, "a"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var carried []string
|
|
if err := pending.each("paths", false, func(k, v []byte) error {
|
|
e, ok := decodeEntry(v)
|
|
if !ok || !e.Carried || e.TargetInode != 9 {
|
|
t.Fatalf("entry %s: %+v", k, e)
|
|
}
|
|
|
|
carried = append(carried, string(k))
|
|
return nil
|
|
}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var want []string
|
|
for _, p := range paths {
|
|
if p == "a" || len(p) > 2 && p[:2] == "a/" {
|
|
want = append(want, p)
|
|
}
|
|
}
|
|
|
|
slices.Sort(want)
|
|
want = slices.Compact(want)
|
|
if !slices.Equal(carried, want) {
|
|
t.Fatalf("carried %d entries, want %d; first difference near %v", len(carried), len(want), carried[:min(5, len(carried))])
|
|
}
|
|
}
|
|
|
|
func TestWalkNativeSkipsSubtree(t *testing.T) {
|
|
root := t.TempDir()
|
|
for _, p := range []string{"keep/x", "skip/deep/y", "z"} {
|
|
if err := os.MkdirAll(filepath.Join(root, filepath.Dir(p)), 0700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := os.WriteFile(filepath.Join(root, p), nil, 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
var seen []string
|
|
err := walkNative(context.Background(), inventoryTargetFS{}, root, func(p string, _ storage.Node, _ int) error {
|
|
rel, _ := filepath.Rel(root, p)
|
|
seen = append(seen, rel)
|
|
if rel == "skip" {
|
|
return errSkipSubtree
|
|
}
|
|
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
slices.Sort(seen)
|
|
if !slices.Equal(seen, []string{".", "keep", "keep/x", "skip", "z"}) {
|
|
t.Fatalf("visited %v", seen)
|
|
}
|
|
}
|
|
|
|
func TestFullScanMayChangeOnResume(t *testing.T) {
|
|
a := testConfig()
|
|
b := a
|
|
b.FullScan = true
|
|
if !sameMigrationIdentity(a, b) {
|
|
t.Fatal("full_scan must not change the migration identity")
|
|
}
|
|
}
|