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>
90 lines
2.9 KiB
Go
90 lines
2.9 KiB
Go
package migration
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
func nativePath(p string) (string, error) {
|
|
if !strings.HasPrefix(p, "/") || path.Clean(p) != p || p == "/" {
|
|
return "", fmt.Errorf("invalid Ceph data path %q", p)
|
|
}
|
|
|
|
return p, nil
|
|
}
|
|
|
|
// Access separates filesystem access from the shared snapshot/journal workflow.
|
|
type Access interface {
|
|
Inspect(context.Context, Config, Executor) (*Inspection, error)
|
|
Empty(context.Context, string) error
|
|
Claim(context.Context, Config, string, string) (io.Closer, error)
|
|
Prepare(context.Context, string, string, string) error
|
|
Apply(context.Context, string, string) error
|
|
Verify(context.Context, string, string, string) error
|
|
// Release deletes the claim of job id, and the claim directories if
|
|
// they are empty. A missing claim is not an error.
|
|
Release(context.Context, Config, string, string) error
|
|
}
|
|
|
|
func (e Engine) access() Access { return e.Access }
|
|
|
|
// Inspect checks both endpoints without changing them and reports what a
|
|
// migration would transfer.
|
|
func (e Engine) Inspect(ctx context.Context, c Config) (*Inspection, error) {
|
|
if e.Access == nil {
|
|
return nil, errors.New("missing access")
|
|
}
|
|
|
|
return e.Access.Inspect(ctx, c, e.Exec)
|
|
}
|
|
|
|
// Transport copies a source tree to the target and verifies the copy.
|
|
type Transport interface {
|
|
Copy(context.Context, string, string) error
|
|
Verify(context.Context, string, string) error
|
|
}
|
|
|
|
// Round describes one snapshot transfer handed to a RoundTransport.
|
|
// BaseName and BaseSourcePath name the last completed snapshot, if any,
|
|
// which allows an incremental transfer.
|
|
type Round struct {
|
|
SourcePath, TargetPath string
|
|
BaseName, BaseSourcePath string
|
|
Name, StatePath string
|
|
}
|
|
|
|
// RoundTransport is a Transport that keeps state across a snapshot round,
|
|
// such as the native backend's on-disk index.
|
|
type RoundTransport interface {
|
|
BeginRound(context.Context, Round) error
|
|
Published(string)
|
|
Commit(context.Context, string) error
|
|
Statistics() TransferStats
|
|
}
|
|
|
|
// TransferStats summarizes the work done for one snapshot round.
|
|
type TransferStats struct {
|
|
Mode string `json:"mode"`
|
|
BaseSnapshot string `json:"base_snapshot,omitempty"`
|
|
FilesVisited int64 `json:"files_visited"`
|
|
FilesCopied int64 `json:"files_copied"`
|
|
BytesCopied int64 `json:"bytes_copied"`
|
|
BytesVerified int64 `json:"bytes_verified"`
|
|
BlockDiffFiles int64 `json:"blockdiff_files"`
|
|
SnapDiffEntries int64 `json:"snapdiff_entries"`
|
|
// Seconds is the duration of the round from its start to the commit,
|
|
// including verification and snapshot creation.
|
|
Seconds float64 `json:"seconds"`
|
|
}
|
|
|
|
// NewEngine returns an Engine with the native libcephfs backend and a Closer
|
|
// that releases its connections. Builds without the build tag ceph return an
|
|
// error.
|
|
func NewEngine(ctx context.Context, c Config, x Executor, log io.Writer) (Engine, io.Closer, error) {
|
|
return openNativeEngine(ctx, c, x, log)
|
|
}
|