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
@@ -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