fix!: remove skipping of unchanged subtrees
Intermediate rounds skipped a directory when its inode version and its ceph.dir.rctime matched the previous round. In the 10,000-file lab test a round snapshot taken seconds after changes skipped tree/ with about 250 changed files in its subdirectories: the inode version of tree/ changes only with its own entries, and Ceph had not yet propagated the rctime of the grandchildren. The target snapshot of that round was incomplete, and its verification skipped the same subtrees; only finalize closed the gap. Every round now scans all metadata again. Base index entries that the old version marked carried are never trusted, so such files are copied in full in the next round. The smallfiles verification now checks only snapshots that sync did not remove. BREAKING CHANGE: the configuration field "full_scan" and the transfer statistic "skipped_subtrees" are removed; a configuration with "full_scan" is rejected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
82c64f9908
commit
6dcb7b676f
16 files changed
+117
-448
No files matched your search
@@ -50,13 +50,11 @@ type Transport interface {
|
||||
|
||||
// Round describes one snapshot transfer handed to a RoundTransport.
|
||||
// BaseName and BaseSourcePath name the last completed snapshot, if any,
|
||||
// which allows an incremental transfer. SkipUnchanged permits skipping
|
||||
// subtrees whose recursive ctime did not change since the base.
|
||||
// which allows an incremental transfer.
|
||||
type Round struct {
|
||||
SourcePath, TargetPath string
|
||||
BaseName, BaseSourcePath string
|
||||
Name, StatePath string
|
||||
SkipUnchanged bool
|
||||
}
|
||||
|
||||
// RoundTransport is a Transport that keeps state across a snapshot round,
|
||||
@@ -78,7 +76,6 @@ type TransferStats struct {
|
||||
BytesVerified int64 `json:"bytes_verified"`
|
||||
BlockDiffFiles int64 `json:"blockdiff_files"`
|
||||
SnapDiffEntries int64 `json:"snapdiff_entries"`
|
||||
SkippedSubtrees int64 `json:"skipped_subtrees,omitempty"`
|
||||
// Seconds is the duration of the round from its start to the commit,
|
||||
// including verification and snapshot creation.
|
||||
Seconds float64 `json:"seconds"`
|
||||
|
||||
@@ -29,10 +29,6 @@ type Config struct {
|
||||
Source Endpoint `json:"source"`
|
||||
Target Endpoint `json:"target"`
|
||||
BandwidthKiB int64 `json:"bandwidth_kib,omitempty"`
|
||||
|
||||
// FullScan disables the rctime shortcut of the native backend, so every
|
||||
// round reads all metadata. finalize always does.
|
||||
FullScan bool `json:"full_scan,omitempty"`
|
||||
}
|
||||
|
||||
// ReadConfig reads exactly one JSON object from the regular file at path,
|
||||
|
||||
@@ -433,7 +433,6 @@ func (e Engine) Sync(ctx context.Context, c Config, statePath string, final bool
|
||||
func sameMigrationIdentity(a, b Config) bool {
|
||||
a.Workers, b.Workers = 0, 0
|
||||
a.BandwidthKiB, b.BandwidthKiB = 0, 0
|
||||
a.FullScan, b.FullScan = false, false
|
||||
// "" and "native" select the same backend.
|
||||
a.Backend, b.Backend = "", ""
|
||||
return reflect.DeepEqual(a, b)
|
||||
@@ -484,10 +483,7 @@ func (e Engine) transfer(ctx context.Context, src, dst ceph, target, statePath s
|
||||
aware, isNative := e.Transport.(RoundTransport)
|
||||
existed := slices.Contains(targetNames, snap.Name)
|
||||
if isNative {
|
||||
// Only intermediate round snapshots may skip unchanged subtrees. They are
|
||||
// deleted later, and finalize scans everything again.
|
||||
round := Round{SourcePath: from, TargetPath: target, Name: snap.Name, StatePath: statePath, BaseName: s.LiveSnapshot,
|
||||
SkipUnchanged: snap.Owned && !snap.Final && !s.Config.FullScan}
|
||||
round := Round{SourcePath: from, TargetPath: target, Name: snap.Name, StatePath: statePath, BaseName: s.LiveSnapshot}
|
||||
if s.LiveSnapshot != "" {
|
||||
round.BaseSourcePath, err = src.snapshotPath(ctx, s.LiveSnapshot)
|
||||
if err != nil {
|
||||
|
||||
@@ -54,6 +54,14 @@ func allZero(b []byte) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// baseTrusted reports whether the base entry previous still describes the
|
||||
// source node n and its target copy, so the copy may be skipped or patched.
|
||||
// A carried entry was written by an earlier version that skipped subtrees;
|
||||
// it may describe an older round and is never trusted.
|
||||
func baseTrusted(previous baseEntry, n, target storage.Node) bool {
|
||||
return !previous.Carried && previous.Inode == n.Inode && previous.TargetInode == target.Inode && previous.Size == target.Size
|
||||
}
|
||||
|
||||
func (b *nativeTransport) copyRegular(ctx context.Context, job nativeJob) error {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
@@ -80,7 +88,7 @@ func (b *nativeTransport) copyRegular(ctx context.Context, job nativeJob) error
|
||||
return err
|
||||
}
|
||||
|
||||
trusted = ok && previous.Inode == job.node.Inode && previous.TargetInode == target.Inode && previous.Size == target.Size
|
||||
trusted = ok && baseTrusted(previous, job.node, target)
|
||||
}
|
||||
|
||||
changed := true
|
||||
@@ -95,9 +103,7 @@ func (b *nativeTransport) copyRegular(ctx context.Context, job nativeJob) error
|
||||
|
||||
if changed {
|
||||
usedBlockDiff := false
|
||||
// A carried entry describes an older round than the base snapshot, so
|
||||
// a block delta against the base could miss changes.
|
||||
if trusted && !previous.Carried && job.node.Size >= nativeBlockThreshold {
|
||||
if trusted && job.node.Size >= nativeBlockThreshold {
|
||||
old, err := b.source.Stat(path.Join(b.round.BaseSourcePath, job.rel))
|
||||
if err == nil && old.Kind() == storage.Regular && old.Inode == job.node.Inode {
|
||||
stream, err := b.source.BlockDiff(b.snapRoot, path.Join(b.snapRel, job.rel), b.round.BaseName, b.round.Name)
|
||||
@@ -361,8 +367,8 @@ func (b *nativeTransport) Verify(ctx context.Context, from, to string) error {
|
||||
defer scratch.cleanup()
|
||||
v := &nativeVerification{b: b, to: to, skipData: skipData, index: scratch.index}
|
||||
|
||||
// The walk and the directories stay serial, so subtree skips apply in walk
|
||||
// order. Every other entry is checked by one of the workers.
|
||||
// The walk and the directories stay serial; every other entry is checked by
|
||||
// one of the workers.
|
||||
ctx, cancel := context.WithCancelCause(ctx)
|
||||
defer cancel(nil)
|
||||
workers := b.config.Workers
|
||||
@@ -408,11 +414,7 @@ func (b *nativeTransport) Verify(ctx context.Context, from, to string) error {
|
||||
}
|
||||
|
||||
if n.Kind() == storage.Directory {
|
||||
if err = v.entry(ctx, p, rel, n); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return b.skipped(rel)
|
||||
return v.entry(ctx, p, rel, n)
|
||||
}
|
||||
|
||||
select {
|
||||
@@ -576,7 +578,7 @@ func (b *nativeTransport) verifyInventory(ctx context.Context, to string) error
|
||||
return fmt.Errorf("unexpected native target entry %s", rel)
|
||||
}
|
||||
|
||||
return b.skipped(rel)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,6 @@ import (
|
||||
"git.zb-server.de/Sebi/CephfsMig/internal/storage"
|
||||
)
|
||||
|
||||
// errSkipSubtree, returned by a walkNative visitor for a directory, skips
|
||||
// the entries below it.
|
||||
var errSkipSubtree = errors.New("skip subtree")
|
||||
|
||||
// quotaKeys are the directory quota xattrs that the migration copies.
|
||||
var quotaKeys = []string{"ceph.quota.max_bytes", "ceph.quota.max_files"}
|
||||
|
||||
@@ -32,9 +28,7 @@ func walkNative(ctx context.Context, fs storage.FS, root string, visit func(stri
|
||||
return errors.New("native directory depth exceeds 128")
|
||||
}
|
||||
|
||||
if err := visit(p, n, depth); errors.Is(err, errSkipSubtree) && n.Kind() == storage.Directory {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
if err := visit(p, n, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
bolt "go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
var nativeBuckets = []string{"meta", "paths", "groups", "aliases", "dirs", "full", "ranges", "changed", "delete", "relinked", "subtrees"}
|
||||
var nativeBuckets = []string{"meta", "paths", "groups", "aliases", "dirs", "full", "ranges", "changed", "delete", "relinked"}
|
||||
|
||||
type nativeIndex struct {
|
||||
db *bolt.DB
|
||||
@@ -19,9 +19,9 @@ type nativeIndex struct {
|
||||
}
|
||||
|
||||
// baseEntry is the inventory record of one source path. Carried marks an
|
||||
// entry taken over unexamined from the previous base because its subtree was
|
||||
// skipped: it still describes the state of an older round, so it must not
|
||||
// serve as base for a block delta.
|
||||
// entry that an earlier version took over unexamined when it skipped an
|
||||
// unchanged-looking subtree. Such an entry may describe an older round, so
|
||||
// it is never trusted. Current versions do not write it.
|
||||
type baseEntry struct {
|
||||
Inode, Version, Size, TargetInode uint64
|
||||
Carried bool
|
||||
@@ -163,68 +163,6 @@ func (x *nativeIndex) putEntryIfChanged(rel string, entry baseEntry) error {
|
||||
return x.put("paths", []byte(rel), encodeEntry(entry))
|
||||
}
|
||||
|
||||
// carry copies the inventory of the subtree rel, including rel itself, from
|
||||
// base and marks every entry Carried. It writes in bounded transactions.
|
||||
func (x *nativeIndex) carry(base *nativeIndex, rel string) error {
|
||||
type record struct{ k, v []byte }
|
||||
prefix := []byte(rel + "/")
|
||||
next := []byte(rel)
|
||||
for next != nil {
|
||||
var batch []record
|
||||
err := base.db.View(func(tx *bolt.Tx) error {
|
||||
c := tx.Bucket([]byte("paths")).Cursor()
|
||||
k, v := c.Seek(next)
|
||||
next = nil
|
||||
for ; k != nil && len(batch) < 4096; k, v = c.Next() {
|
||||
if string(k) != rel && !bytes.HasPrefix(k, prefix) {
|
||||
if string(k) > rel && bytes.Compare(k, prefix) < 0 {
|
||||
// Siblings such as "a b" sort between "a" and "a/".
|
||||
k, v = c.Seek(prefix)
|
||||
if k == nil || !bytes.HasPrefix(k, prefix) {
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
e, ok := decodeEntry(v)
|
||||
if !ok {
|
||||
return errors.New("invalid base inventory entry")
|
||||
}
|
||||
|
||||
e.Carried = true
|
||||
batch = append(batch, record{bytes.Clone(k), encodeEntry(e)})
|
||||
}
|
||||
|
||||
if k != nil && bytes.HasPrefix(k, prefix) {
|
||||
next = bytes.Clone(k)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = x.db.Update(func(tx *bolt.Tx) error {
|
||||
b := tx.Bucket([]byte("paths"))
|
||||
for _, r := range batch {
|
||||
if err := b.Put(r.k, r.v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *nativeIndex) requireInventory() error {
|
||||
complete, err := x.get("meta", []byte("inventory_complete"))
|
||||
if err != nil {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"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 TestBaseTrustRejectsCarriedEntries(t *testing.T) {
|
||||
n := storage.Node{Inode: 1, Size: 3}
|
||||
target := storage.Node{Inode: 4, Size: 3}
|
||||
e := baseEntry{Inode: 1, Version: 2, Size: 3, TargetInode: 4}
|
||||
if !baseTrusted(e, n, target) {
|
||||
t.Fatal("matching entry not trusted")
|
||||
}
|
||||
|
||||
e.Carried = true
|
||||
if baseTrusted(e, n, target) {
|
||||
t.Fatal("carried entry trusted")
|
||||
}
|
||||
|
||||
e.Carried = false
|
||||
target.Inode = 5
|
||||
if baseTrusted(e, n, target) {
|
||||
t.Fatal("entry of a replaced target trusted")
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
@@ -49,7 +48,6 @@ type nativeTransport struct {
|
||||
visited, copied, written atomic.Int64
|
||||
checked, blockFiles atomic.Int64
|
||||
diffEntries, rateBytes atomic.Int64
|
||||
skippedSubtrees atomic.Int64
|
||||
}
|
||||
|
||||
func (b *nativeTransport) Close() error {
|
||||
@@ -122,7 +120,6 @@ func (b *nativeTransport) BeginRound(ctx context.Context, r Round) error {
|
||||
b.blockFiles.Store(0)
|
||||
b.diffEntries.Store(0)
|
||||
b.rateBytes.Store(0)
|
||||
b.skippedSubtrees.Store(0)
|
||||
b.started = time.Now()
|
||||
marker := "/.snap/" + r.Name
|
||||
at := strings.LastIndex(r.SourcePath, marker)
|
||||
@@ -218,20 +215,6 @@ func (b *nativeTransport) collectChanges(ctx context.Context, rel, current strin
|
||||
}
|
||||
|
||||
if n.Kind() == storage.Directory {
|
||||
sourceRel, err := relativeNative(b.round.SourcePath, child)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
unchanged, err := b.subtreeUnchanged(sourceRel, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if unchanged {
|
||||
continue
|
||||
}
|
||||
|
||||
if err = b.collectChanges(ctx, path.Join(rel, name), child, depth+1); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -311,22 +294,6 @@ func (b *nativeTransport) Copy(ctx context.Context, from, to string) error {
|
||||
}
|
||||
|
||||
target := path.Join(to, rel)
|
||||
if n.Kind() == storage.Directory {
|
||||
unchanged, err := b.subtreeUnchanged(rel, n)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if unchanged {
|
||||
b.skippedSubtrees.Add(1)
|
||||
if err = b.pending.carry(b.base, rel); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return errSkipSubtree
|
||||
}
|
||||
}
|
||||
|
||||
// Record every immutable source entry before dispatching work. This local
|
||||
// inventory replaces source path lookups during pruning and verification.
|
||||
if err = b.pending.put("paths", []byte(rel), encodeEntry(baseEntry{
|
||||
@@ -535,7 +502,7 @@ func (b *nativeTransport) prune(ctx context.Context, from, to string) error {
|
||||
}
|
||||
|
||||
if present {
|
||||
return b.skipped(rel)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Removing one name of a hardlinked inode resets its ctime; the
|
||||
@@ -629,118 +596,7 @@ func (b *nativeTransport) Statistics() TransferStats {
|
||||
return TransferStats{Mode: mode, BaseSnapshot: base, FilesVisited: b.visited.Load(),
|
||||
FilesCopied: b.copied.Load(), BytesCopied: b.written.Load(), BytesVerified: b.checked.Load(),
|
||||
BlockDiffFiles: b.blockFiles.Load(), SnapDiffEntries: b.diffEntries.Load(),
|
||||
SkippedSubtrees: b.skippedSubtrees.Load(),
|
||||
Seconds: math.Round(time.Since(b.started).Seconds()*1000) / 1000}
|
||||
}
|
||||
|
||||
// subtreeUnchanged reports whether the source directory rel, with node n,
|
||||
// may be skipped in this round. That requires a round that permits it, a
|
||||
// confirmed base, the same directory inode and inode version in the base
|
||||
// snapshot, an equal ceph.dir.rctime there, a base inventory entry and a
|
||||
// target directory.
|
||||
//
|
||||
// Changes deeper in the subtree are seen only through the rctime, which Ceph
|
||||
// propagates with a delay, and through client clocks. A round may therefore
|
||||
// miss them; the next round or the full scan of finalize catches them, and
|
||||
// carried entries never serve as base for a block delta. The result is
|
||||
// cached per round.
|
||||
func (b *nativeTransport) subtreeUnchanged(rel string, n storage.Node) (bool, error) {
|
||||
if !b.round.SkipUnchanged || !b.delta || rel == "." {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
cached, err := b.pending.get("subtrees", []byte(rel))
|
||||
if err != nil || cached != nil {
|
||||
return len(cached) == 1 && cached[0] == 1, err
|
||||
}
|
||||
|
||||
unchanged, err := b.compareSubtree(rel, n)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
flag := []byte{0}
|
||||
if unchanged {
|
||||
flag[0] = 1
|
||||
}
|
||||
|
||||
return unchanged, b.pending.put("subtrees", []byte(rel), flag)
|
||||
}
|
||||
|
||||
func (b *nativeTransport) compareSubtree(rel string, n storage.Node) (bool, error) {
|
||||
missing := func(err error) bool {
|
||||
return errors.Is(err, syscall.ENOENT) || errors.Is(err, syscall.ENOTDIR) || errors.Is(err, syscall.ENODATA)
|
||||
}
|
||||
|
||||
basePath := path.Join(b.round.BaseSourcePath, rel)
|
||||
old, err := b.source.Stat(basePath)
|
||||
if missing(err) {
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// The directory's own inode version changes at once with every entry
|
||||
// added or removed and every change of its own metadata; the rctime
|
||||
// reaches the snapshot only after a delay (measured in the lab).
|
||||
if old.Kind() != storage.Directory || old.Inode != n.Inode || n.Version == 0 || old.Version != n.Version {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
entry, known, err := b.base.entry(rel)
|
||||
if err != nil || !known || entry.Inode != n.Inode {
|
||||
return false, err
|
||||
}
|
||||
|
||||
target, err := b.target.Stat(path.Join(b.round.TargetPath, rel))
|
||||
if missing(err) {
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if target.Kind() != storage.Directory {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
now, err := b.source.GetXattr(path.Join(b.round.SourcePath, rel), "ceph.dir.rctime")
|
||||
if missing(err) {
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
then, err := b.source.GetXattr(basePath, "ceph.dir.rctime")
|
||||
if missing(err) {
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return len(now) > 0 && bytes.Equal(now, then), nil
|
||||
}
|
||||
|
||||
// skipped returns errSkipSubtree for a directory rel that this round skipped,
|
||||
// so walks of the target or of a snapshot leave it out as well.
|
||||
func (b *nativeTransport) skipped(rel string) error {
|
||||
if !b.round.SkipUnchanged || rel == "." {
|
||||
return nil
|
||||
}
|
||||
|
||||
v, err := b.pending.get("subtrees", []byte(rel))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(v) == 1 && v[0] == 1 {
|
||||
return errSkipSubtree
|
||||
}
|
||||
|
||||
return nil
|
||||
Seconds: math.Round(time.Since(b.started).Seconds()*1000) / 1000}
|
||||
}
|
||||
|
||||
func (b *nativeTransport) rate(ctx context.Context, n int) error {
|
||||
|
||||
Reference in new issue
Block a user