mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
* 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>
89 lines
2.0 KiB
Go
89 lines
2.0 KiB
Go
package command
|
|
|
|
import (
|
|
"errors"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
type cursorSave struct {
|
|
tsNs int64
|
|
checkpointed bool
|
|
}
|
|
|
|
func startKeepSyncCursor(t *testing.T, stored int64, failures int) (firstSeenTsNs *atomic.Int64, firstSeen chan struct{}, tick chan time.Time, saves chan cursorSave) {
|
|
var storedOffsetTsNs atomic.Int64
|
|
storedOffsetTsNs.Store(stored)
|
|
firstSeenTsNs = &atomic.Int64{}
|
|
firstSeen = make(chan struct{})
|
|
tick = make(chan time.Time)
|
|
saves = make(chan cursorSave, 16)
|
|
stop := make(chan struct{})
|
|
done := make(chan struct{})
|
|
t.Cleanup(func() {
|
|
close(stop)
|
|
<-done
|
|
})
|
|
go func() {
|
|
defer close(done)
|
|
keepSyncCursor(stop, firstSeen, tick, &storedOffsetTsNs, firstSeenTsNs, func(tsNs int64, checkpointed bool) error {
|
|
saves <- cursorSave{tsNs, checkpointed}
|
|
if failures > 0 {
|
|
failures--
|
|
return errors.New("filer unavailable")
|
|
}
|
|
return nil
|
|
})
|
|
}()
|
|
return
|
|
}
|
|
|
|
func expectCursorSave(t *testing.T, saves chan cursorSave, want cursorSave) {
|
|
t.Helper()
|
|
select {
|
|
case got := <-saves:
|
|
if got != want {
|
|
t.Fatalf("saved %+v, want %+v", got, want)
|
|
}
|
|
case <-time.After(5 * time.Second):
|
|
t.Fatalf("no cursor save, want %+v", want)
|
|
}
|
|
}
|
|
|
|
func expectNoCursorSave(t *testing.T, saves chan cursorSave) {
|
|
t.Helper()
|
|
select {
|
|
case got := <-saves:
|
|
t.Fatalf("unexpected cursor save %+v", got)
|
|
default:
|
|
}
|
|
}
|
|
|
|
func TestKeepSyncCursorSavesOnFirstEvent(t *testing.T) {
|
|
firstSeenTsNs, firstSeen, tick, saves := startKeepSyncCursor(t, 0, 0)
|
|
tick <- time.Now()
|
|
expectNoCursorSave(t, saves)
|
|
|
|
firstSeenTsNs.Store(100)
|
|
close(firstSeen)
|
|
expectCursorSave(t, saves, cursorSave{99, false})
|
|
|
|
tick <- time.Now()
|
|
tick <- time.Now()
|
|
expectNoCursorSave(t, saves)
|
|
}
|
|
|
|
func TestKeepSyncCursorRetriesFailedSave(t *testing.T) {
|
|
_, _, tick, saves := startKeepSyncCursor(t, 500, 2)
|
|
expectCursorSave(t, saves, cursorSave{500, true})
|
|
tick <- time.Now()
|
|
expectCursorSave(t, saves, cursorSave{500, true})
|
|
tick <- time.Now()
|
|
expectCursorSave(t, saves, cursorSave{500, true})
|
|
|
|
tick <- time.Now()
|
|
tick <- time.Now()
|
|
expectNoCursorSave(t, saves)
|
|
}
|