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:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-12-03 20:19:31 +01:00
1 parent b7d2a0687e
commit 83e15bccb2
9 files changed
+394 -12

No files matched your search

+82 -5
View File
@@ -11,30 +11,45 @@ import (
bolt "go.etcd.io/bbolt"
)
var nativeBuckets = []string{"meta", "paths", "groups", "aliases", "dirs", "full", "ranges", "changed", "delete", "relinked"}
var nativeBuckets = []string{"meta", "paths", "groups", "aliases", "dirs", "full", "ranges", "changed", "delete", "relinked", "subtrees"}
type nativeIndex struct {
db *bolt.DB
path string
}
type baseEntry struct{ Inode, Version, Size, TargetInode uint64 }
// 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.
type baseEntry struct {
Inode, Version, Size, TargetInode uint64
Carried bool
}
func encodeEntry(e baseEntry) []byte {
b := make([]byte, 32)
b := make([]byte, 33)
binary.BigEndian.PutUint64(b, e.Inode)
binary.BigEndian.PutUint64(b[8:], e.Version)
binary.BigEndian.PutUint64(b[16:], e.Size)
binary.BigEndian.PutUint64(b[24:], e.TargetInode)
if e.Carried {
b[32] = 1
}
return b
}
// decodeEntry also accepts the 32-byte records written before Carried existed.
func decodeEntry(b []byte) (baseEntry, bool) {
if len(b) != 32 {
if len(b) != 32 && (len(b) != 33 || b[32] > 1) {
return baseEntry{}, false
}
return baseEntry{binary.BigEndian.Uint64(b), binary.BigEndian.Uint64(b[8:]), binary.BigEndian.Uint64(b[16:]), binary.BigEndian.Uint64(b[24:])}, true
e := baseEntry{Inode: binary.BigEndian.Uint64(b), Version: binary.BigEndian.Uint64(b[8:]),
Size: binary.BigEndian.Uint64(b[16:]), TargetInode: binary.BigEndian.Uint64(b[24:])}
e.Carried = len(b) == 33 && b[32] == 1
return e, true
}
func createNativeIndex(parent string) (*nativeIndex, error) {
@@ -148,6 +163,68 @@ 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 {