feat(native): skip unchanged subtrees in intermediate sync rounds
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>
This commit is contained in:
1 parent
b7d2a0687e
commit
83e15bccb2
9 files changed
+394
-12
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
@@ -48,6 +49,7 @@ type nativeTransport struct {
|
||||
visited, copied, written atomic.Int64
|
||||
checked, blockFiles atomic.Int64
|
||||
diffEntries, rateBytes atomic.Int64
|
||||
skippedSubtrees atomic.Int64
|
||||
}
|
||||
|
||||
func (b *nativeTransport) Close() error {
|
||||
@@ -120,6 +122,7 @@ 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)
|
||||
@@ -215,6 +218,20 @@ 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
|
||||
}
|
||||
@@ -294,6 +311,22 @@ 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{
|
||||
@@ -502,7 +535,7 @@ func (b *nativeTransport) prune(ctx context.Context, from, to string) error {
|
||||
}
|
||||
|
||||
if present {
|
||||
return nil
|
||||
return b.skipped(rel)
|
||||
}
|
||||
|
||||
// Removing one name of a hardlinked inode resets its ctime; the
|
||||
@@ -595,7 +628,118 @@ 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()}
|
||||
BlockDiffFiles: b.blockFiles.Load(), SnapDiffEntries: b.diffEntries.Load(),
|
||||
SkippedSubtrees: b.skippedSubtrees.Load()}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
func (b *nativeTransport) rate(ctx context.Context, n int) error {
|
||||
|
||||
Reference in new issue
Block a user