Files
seaweedfs/weed/command/filer_sync_log_gap_test.go
Chris LuandClaude Opus 5.5 c637d60dfc filer.sync: keep an informational replay cursor on the source, and let the log purge honor it (#13176)
* filer.sync: save the sync position on the source filer as a replay cursor

The position stays authoritative on the target. The source copy holds the
last position the target checkpoint stored (a fresh sync without one holds
just before the first event it received) and is rewritten hourly while the
sync runs, even when the position does not move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer.sync: do not replicate the sync cursors of the source

A target never holds cursors that describe the source's log. A rename into
or out of the cursor directory replicates the ordinary side.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* metadata log purge: keep the logs a filer.sync still needs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer.sync: describe the sync in its source cursor

The source cursor is informational: besides the position it records the
source and target filers and paths, exclusions, host, version, when the
sync started, whether the position is a target checkpoint, and the
processed and failed event times, for display in admin tools. The
target checkpoint stays authoritative.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer.sync: save the first sync cursor when the first event arrives and retry failed saves

A fresh sync only saved its cursor on the next minute tick, and a failed
save still pushed the next attempt out by an hour, leaving the purge
without a cursor while the sync replayed old log days.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer.backup: do not seed the source's sync cursors in the initial snapshot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* metadata log purge: say that a position not saved for 7 days stops holding the log

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer.backup test: lock the recording sink for concurrent snapshot workers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* filer.sync: leave the sync cursors out of the metadata log gap check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 13:09:23 -08:00

78 lines
3.4 KiB
Go

package command
import (
"context"
"strings"
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
)
func TestMetadataLogGap(t *testing.T) {
logStart := time.Date(2026, 11, 30, 3, 7, 0, 0, time.UTC)
logs := map[string][]*filer_pb.Entry{
filer.SystemLogDir: {
{Name: "2026-12-01", IsDirectory: true},
{Name: "2026-11-30", IsDirectory: true},
{Name: "not-a-day", IsDirectory: true},
},
filer.SystemLogDir + "/2026-11-30": {
{Name: "05-00.0000000a"},
{Name: "03-07.0000000b"},
},
}
child := func(name string, commitTsNs int64, mtime time.Time) *filer_pb.Entry {
return &filer_pb.Entry{Name: name, IsDirectory: true, CommitTsNs: commitTsNs, Attributes: &filer_pb.FuseAttributes{Mtime: mtime.Unix()}}
}
before, after := logStart.Add(-time.Hour), logStart.Add(time.Hour)
tests := []struct {
name string
dirs map[string][]*filer_pb.Entry
sourcePath string
exclude []string
offsetTsNs int64
want string
}{
{name: "no metadata log", dirs: map[string][]*filer_pb.Entry{"/buckets": {child("old", before.UnixNano(), before)}}, sourcePath: "/buckets"},
{name: "position inside the log", offsetTsNs: after.UnixNano()},
{name: "position at the oldest file", offsetTsNs: logStart.UnixNano()},
{name: "position before the log", offsetTsNs: before.UnixNano(), want: "after the saved sync position 2026-11-30T02:07:00Z"},
{name: "fresh sync, every entry in the log", dirs: map[string][]*filer_pb.Entry{"/buckets": {child("recent", after.UnixNano(), before)}}, sourcePath: "/buckets"},
{name: "fresh sync, entry changed before the log", dirs: map[string][]*filer_pb.Entry{"/buckets": {child("recent", after.UnixNano(), after), child("historical", before.UnixNano(), before)}}, sourcePath: "/buckets", want: "/buckets/historical was last changed at 2026-11-30T02:07:00Z"},
{name: "fresh sync, entry without commit time", dirs: map[string][]*filer_pb.Entry{"/buckets": {child("historical", 0, before)}}, sourcePath: "/buckets", want: "/buckets/historical"},
{name: "fresh sync of the root skips the log directory", dirs: map[string][]*filer_pb.Entry{"/": {child("topics", before.UnixNano(), before)}}, sourcePath: "/"},
{name: "fresh sync skips excluded entries", dirs: map[string][]*filer_pb.Entry{"/buckets": {child("archive", before.UnixNano(), before), child("recent", after.UnixNano(), after)}}, sourcePath: "/buckets", exclude: []string{"/buckets/archive"}},
{name: "fresh sync skips the sync cursors", dirs: map[string][]*filer_pb.Entry{"/etc/seaweedfs": {child("filer_sync", before.UnixNano(), before)}}, sourcePath: "/etc/seaweedfs"},
{name: "fresh sync skips multipart uploads", dirs: map[string][]*filer_pb.Entry{"/buckets/b": {child(".uploads", before.UnixNano(), before)}}, sourcePath: "/buckets/b"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dirs := map[string][]*filer_pb.Entry{}
if tt.name != "no metadata log" {
for k, v := range logs {
dirs[k] = v
}
}
for k, v := range tt.dirs {
dirs[k] = v
}
got, err := metadataLogGap(context.Background(), &verifyTestInnerClient{entriesByDir: dirs}, tt.sourcePath, tt.exclude, tt.offsetTsNs)
if err != nil {
t.Fatalf("metadataLogGap: %v", err)
}
if tt.want == "" {
if got != "" {
t.Fatalf("got gap %q, want none", got)
}
return
}
if !strings.Contains(got, tt.want) {
t.Fatalf("got gap %q, want it to mention %q", got, tt.want)
}
})
}
}