filer: aggregated metadata stream reads the log files of peers with their own store (#13116)

* filer: pass the reader's context to persisted metadata log listings

The day and minute listings behind ReadPersistedLogBuffer used
context.Background(), so nothing scoped to the subscription reached them.
List through one helper that takes the caller's context.

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

* filer: aggregated metadata stream reads the log files of peers with their own store

A filer with its own store never holds another filer's persisted
metadata log: log file writes emit no events and the bootstrap traverse
skips the log directory. The aggregated stream read history from the
local log directory and the in-memory aggregate ring only, and the ring
restarts empty, refilled from each peer's saved offset. A subscriber whose
cursor was older than that missed every event a peer recorded before it,
for example the S3 lifecycle worker replaying expirations.

Aggregated reads now also list the log directories of followed peers not
known to share this filer's store, merged by file name, so the existing
ordered reader and chunk-ref path serve their history. Local streams, which
peers aggregate from, stay local.

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

* filer: bound peer log listings and fail the read when one fails

Each peer listing gets its own deadline, so a peer that stalls mid-listing
cannot hold the read. A failed listing now fails the read instead of
silently hiding that peer's persisted files; peers already retired as
unreachable are left out. Peers are asked from the same start name the
caller uses for its own store instead of the whole directory.

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

* filer: keep a still-unreachable peer out of log listings after its mark expires

A followed peer that keeps refusing connections is marked removed once, and
the mark is dropped with its resume point an hour later. It was then listed
again and its failing listing ended every aggregated persisted-log read.
Leave out any peer refusing connections for peerUnreachableRemovalAfter,
marked or not.

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

* filer: subscribe tests track their peers on the test filer's store

Aggregated reads now list the log files of followed peers with their own
store. The subscribe tests' peers have no server and share the test
filer's store, so record that instead of dialing them.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 authored and GitHub committed 2026-11-29 17:46:29 -08:00
1 parent 12ef22477a
commit 3d076dfcdf
10 files changed
+315 -15

No files matched your search

+1 -1
View File
@@ -473,7 +473,7 @@ func (f *Filer) ReadPersistedLogBuffer(ctx context.Context, startPosition log_bu
return 0, false, ctx.Err()
}
visitor, visitErr := f.collectPersistedLogBuffer(startPosition, stopTsNs)
visitor, visitErr := f.collectPersistedLogBuffer(ctx, startPosition, stopTsNs)
if visitErr != nil {
if visitErr == io.EOF {
return
+43 -9
View File
@@ -147,7 +147,7 @@ func PersistedLogScanStartTsNs(t time.Time) int64 {
return persistedLogScanStart(t).Truncate(time.Minute).UnixNano()
}
func (f *Filer) collectPersistedLogBuffer(startPosition log_buffer.MessagePosition, stopTsNs int64) (v *OrderedLogVisitor, err error) {
func (f *Filer) collectPersistedLogBuffer(ctx context.Context, startPosition log_buffer.MessagePosition, stopTsNs int64) (v *OrderedLogVisitor, err error) {
if stopTsNs != 0 && startPosition.Time.UnixNano() > stopTsNs {
return nil, io.EOF
@@ -156,12 +156,12 @@ func (f *Filer) collectPersistedLogBuffer(startPosition log_buffer.MessagePositi
scanFrom := persistedLogScanStart(startPosition.Time)
startDate := fmt.Sprintf("%04d-%02d-%02d", scanFrom.Year(), scanFrom.Month(), scanFrom.Day())
dayEntries, _, listDayErr := f.ListDirectoryEntries(context.Background(), SystemLogDir, startDate, true, math.MaxInt32, "", "", "")
dayEntries, listDayErr := f.listLogDir(ctx, SystemLogDir, startDate, true)
if listDayErr != nil {
return nil, fmt.Errorf("fail to list log by day: %w", listDayErr)
}
return NewOrderedLogVisitor(f, startPosition, stopTsNs, dayEntries)
return NewOrderedLogVisitor(ctx, f, startPosition, stopTsNs, dayEntries)
}
@@ -183,7 +183,7 @@ func (f *Filer) CollectLogFileRefs(ctx context.Context, startPosition log_buffer
stopHourMinute = fmt.Sprintf("%02d-%02d", stopTime.Hour(), stopTime.Minute())
}
dayEntries, _, listDayErr := f.ListDirectoryEntries(ctx, SystemLogDir, startDate, true, math.MaxInt32, "", "", "")
dayEntries, listDayErr := f.listLogDir(ctx, SystemLogDir, startDate, true)
if listDayErr != nil {
return nil, 0, fmt.Errorf("fail to list log by day: %w", listDayErr)
}
@@ -194,7 +194,7 @@ func (f *Filer) CollectLogFileRefs(ctx context.Context, startPosition log_buffer
}
listFrom, inclusive := f.logDayListStart(dayEntry.Name(), startDate, startHourMinute)
hourMinuteEntries, _, listErr := f.ListDirectoryEntries(ctx, util.NewFullPath(SystemLogDir, dayEntry.Name()), listFrom, inclusive, math.MaxInt32, "", "", "")
hourMinuteEntries, listErr := f.listLogDir(ctx, util.NewFullPath(SystemLogDir, dayEntry.Name()), listFrom, inclusive)
if listErr != nil {
return nil, 0, fmt.Errorf("fail to list log %s: %w", dayEntry.Name(), listErr)
}
@@ -250,6 +250,38 @@ func clampLogRefsCursor(lastTsNs, startTsNs int64) int64 {
return lastTsNs
}
// listLogDir lists a metadata log directory from startFileName. Under
// WithPeerLogFiles the files of peers with their own store are merged in by
// name, as one shared store lists the same file on every filer using it.
func (f *Filer) listLogDir(ctx context.Context, dir util.FullPath, startFileName string, inclusive bool) ([]*Entry, error) {
entries, _, err := f.ListDirectoryEntries(ctx, dir, startFileName, inclusive, math.MaxInt32, "", "", "")
if err != nil || !readsPeerLogFiles(ctx) || f.MetaAggregator == nil {
return entries, err
}
names := make(map[string]bool, len(entries))
for _, entry := range entries {
names[entry.Name()] = true
}
peerEntries, err := f.MetaAggregator.listPeerLogDir(ctx, dir, startFileName, inclusive)
if err != nil {
return nil, err
}
merged := false
for _, entry := range peerEntries {
name := entry.Name()
if names[name] || name < startFileName || (name == startFileName && !inclusive) {
continue
}
names[name] = true
entries = append(entries, entry)
merged = true
}
if merged {
sort.Slice(entries, func(i, j int) bool { return entries[i].Name() < entries[j].Name() })
}
return entries, nil
}
func (f *Filer) HasPersistedLogFiles(startPosition log_buffer.MessagePosition) (bool, error) {
startDate := fmt.Sprintf("%04d-%02d-%02d", startPosition.Time.Year(), startPosition.Time.Month(), startPosition.Time.Day())
dayEntries, _, listDayErr := f.ListDirectoryEntries(context.Background(), SystemLogDir, startDate, true, 1, "", "", "")
@@ -296,7 +328,7 @@ type OrderedLogVisitor struct {
logFileEntryCollector *LogFileEntryCollector
}
func NewOrderedLogVisitor(f *Filer, startPosition log_buffer.MessagePosition, stopTsNs int64, dayEntries []*Entry) (*OrderedLogVisitor, error) {
func NewOrderedLogVisitor(ctx context.Context, f *Filer, startPosition log_buffer.MessagePosition, stopTsNs int64, dayEntries []*Entry) (*OrderedLogVisitor, error) {
perFilerQueueMap := make(map[string]*LogFileQueueIterator)
// initialize the priority queue
@@ -306,7 +338,7 @@ func NewOrderedLogVisitor(f *Filer, startPosition log_buffer.MessagePosition, st
t := &OrderedLogVisitor{
perFilerIteratorMap: perFilerQueueMap,
pq: pq,
logFileEntryCollector: NewLogFileEntryCollector(f, startPosition, stopTsNs, dayEntries),
logFileEntryCollector: NewLogFileEntryCollector(ctx, f, startPosition, stopTsNs, dayEntries),
}
if err := t.logFileEntryCollector.collectMore(t); err != nil && err != io.EOF {
return nil, err
@@ -374,6 +406,7 @@ func (f *Filer) logDayListStart(day, startDate, startHourMinute string) (startFi
// ----------
type LogFileEntryCollector struct {
ctx context.Context
f *Filer
startTsNs int64
stopTsNs int64
@@ -384,7 +417,7 @@ type LogFileEntryCollector struct {
stopHourMinute string
}
func NewLogFileEntryCollector(f *Filer, startPosition log_buffer.MessagePosition, stopTsNs int64, dayEntries []*Entry) *LogFileEntryCollector {
func NewLogFileEntryCollector(ctx context.Context, f *Filer, startPosition log_buffer.MessagePosition, stopTsNs int64, dayEntries []*Entry) *LogFileEntryCollector {
dayEntryQueue := util.NewQueue[*Entry]()
for _, dayEntry := range dayEntries {
dayEntryQueue.Enqueue(dayEntry)
@@ -402,6 +435,7 @@ func NewLogFileEntryCollector(f *Filer, startPosition log_buffer.MessagePosition
}
return &LogFileEntryCollector{
ctx: ctx,
f: f,
startTsNs: startPosition.Time.UnixNano(),
stopTsNs: stopTsNs,
@@ -426,7 +460,7 @@ func (c *LogFileEntryCollector) collectMore(v *OrderedLogVisitor) (err error) {
}
listFrom, inclusive := c.f.logDayListStart(dayEntry.Name(), c.startDate, c.startHourMinute)
hourMinuteEntries, _, listHourMinuteErr := c.f.ListDirectoryEntries(context.Background(), util.NewFullPath(SystemLogDir, dayEntry.Name()), listFrom, inclusive, math.MaxInt32, "", "", "")
hourMinuteEntries, listHourMinuteErr := c.f.listLogDir(c.ctx, util.NewFullPath(SystemLogDir, dayEntry.Name()), listFrom, inclusive)
if listHourMinuteErr != nil {
return fmt.Errorf("fail to list log %s by day: %v", dayEntry.Name(), listHourMinuteErr)
}
+2 -2
View File
@@ -95,7 +95,7 @@ func TestPersistedLogScanListsFromScanStart(t *testing.T) {
f.persistedLogCache = newPersistedLogCache(1 << 20)
fillLogDay(store.stubFilerStore, "2026-10-25", 12*60+30, false)
v, err := f.collectPersistedLogBuffer(log_buffer.NewMessagePosition(listingTestCursor.UnixNano(), -2), 0)
v, err := f.collectPersistedLogBuffer(context.Background(), log_buffer.NewMessagePosition(listingTestCursor.UnixNano(), -2), 0)
if err != nil {
t.Fatalf("collectPersistedLogBuffer: %v", err)
}
@@ -166,7 +166,7 @@ func TestLogListingsOnUnorderedStoreListWholeDay(t *testing.T) {
})
t.Run("persisted log scan", func(t *testing.T) {
store, f := newStore(false)
v, err := f.collectPersistedLogBuffer(log_buffer.NewMessagePosition(listingTestCursor.UnixNano(), -2), 0)
v, err := f.collectPersistedLogBuffer(context.Background(), log_buffer.NewMessagePosition(listingTestCursor.UnixNano(), -2), 0)
if err != nil {
t.Fatalf("collectPersistedLogBuffer: %v", err)
}
+182
View File
@@ -0,0 +1,182 @@
package filer
import (
"context"
"os"
"sort"
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/seaweedfs/weed/util"
"github.com/seaweedfs/seaweedfs/weed/util/log_buffer"
)
func peerTestLogFile(day, name string, withChunks bool) *Entry {
entry := &Entry{FullPath: util.NewFullPath(string(util.NewFullPath(SystemLogDir, day)), name)}
if withChunks {
entry.Chunks = []*filer_pb.FileChunk{{FileId: "1,0a", Size: 10}}
}
return entry
}
func peerTestLogDay(day string) *Entry {
return &Entry{FullPath: util.NewFullPath(SystemLogDir, day), Attr: Attr{Mode: os.ModeDir | 0755}}
}
// newPeerLogTestFiler returns a filer whose own store holds its 12-30 file and
// that follows a peer with its own store, a peer on its store, and itself.
// Only the first is asked for its log directories.
func newPeerLogTestFiler(t *testing.T, withChunks bool) *Filer {
store := newStubFilerStore()
f := newReplayTestFiler(store)
store.entries[string(SystemLogDir)] = &Entry{FullPath: SystemLogDir, Attr: Attr{Mode: os.ModeDir | 0755}}
for _, e := range []*Entry{peerTestLogDay("2026-10-25"), peerTestLogFile("2026-10-25", "12-30.0000abcd", withChunks)} {
store.entries[string(e.FullPath)] = e
}
own := pb.ServerAddress("own:8888")
shared := pb.ServerAddress("shared:8888")
self := pb.ServerAddress("self:8888")
ma := NewMetaAggregator(f, self, nil)
for _, peer := range []pb.ServerAddress{own, shared, self} {
ma.peerChans[peer] = make(chan struct{})
}
ma.peerSharesStore[shared] = true
peerDirs := map[util.FullPath][]*Entry{
SystemLogDir: {peerTestLogDay("2026-10-24"), peerTestLogDay("2026-10-25")},
util.NewFullPath(SystemLogDir, "2026-10-24"): {peerTestLogFile("2026-10-24", "23-59.0000beef", withChunks)},
util.NewFullPath(SystemLogDir, "2026-10-25"): {
peerTestLogFile("2026-10-25", "12-28.0000beef", withChunks),
peerTestLogFile("2026-10-25", "12-29.0000beef", withChunks),
peerTestLogFile("2026-10-25", "12-30.0000abcd", withChunks),
peerTestLogFile("2026-10-25", "12-31.0000beef", withChunks),
},
}
ma.peerLogDirLister = func(ctx context.Context, peer pb.ServerAddress, dir util.FullPath, startFileName string, inclusive bool) ([]*Entry, error) {
if peer != own {
t.Errorf("listed %s on %s, which needs no listing", dir, peer)
}
return peerDirs[dir], nil
}
f.MetaAggregator = ma
return f
}
func refNames(refs []*filer_pb.LogFileChunkRef) []string {
var names []string
for _, ref := range refs {
names = append(names, time.Unix(0, ref.FileTsNs).UTC().Format("15-04")+"."+ref.FilerId)
}
sort.Strings(names)
return names
}
// TestAggregatedLogFileRefsIncludePeerFiles: a peer with its own store keeps
// its log files there, so the aggregated read lists them from the peer, from
// the scan start on and once per name. A local read stays local.
func TestAggregatedLogFileRefsIncludePeerFiles(t *testing.T) {
f := newPeerLogTestFiler(t, true)
start := log_buffer.NewMessagePosition(listingTestCursor.UnixNano(), -2)
refs, _, err := f.CollectLogFileRefs(WithPeerLogFiles(context.Background()), start, 0)
if err != nil {
t.Fatalf("CollectLogFileRefs: %v", err)
}
want := []string{"12-29.0000beef", "12-30.0000abcd", "12-31.0000beef"}
if got := refNames(refs); !equalStrings(got, want) {
t.Fatalf("aggregated refs = %v, want %v", got, want)
}
refs, _, err = f.CollectLogFileRefs(context.Background(), start, 0)
if err != nil {
t.Fatalf("CollectLogFileRefs: %v", err)
}
if got := refNames(refs); !equalStrings(got, []string{"12-30.0000abcd"}) {
t.Fatalf("local refs = %v, want only the own file", got)
}
}
// TestAggregatedPersistedLogScanIncludesPeerFiles: the same for the pass that
// reads the persisted log for an aggregated subscription.
func TestAggregatedPersistedLogScanIncludesPeerFiles(t *testing.T) {
// cached mode: the files hold no chunks, so nothing is read from volumes
f := newPeerLogTestFiler(t, false)
f.persistedLogCache = newPersistedLogCache(1 << 20)
start := log_buffer.NewMessagePosition(listingTestCursor.UnixNano(), -2)
for _, tc := range []struct {
ctx context.Context
want []string
}{
{WithPeerLogFiles(context.Background()), []string{"0000abcd", "0000beef"}},
{context.Background(), []string{"0000abcd"}},
} {
v, err := f.collectPersistedLogBuffer(tc.ctx, start, 0)
if err != nil {
t.Fatalf("collectPersistedLogBuffer: %v", err)
}
var got []string
for filerId := range v.perFilerIteratorMap {
got = append(got, filerId)
}
sort.Strings(got)
if !equalStrings(got, tc.want) {
t.Fatalf("filers read = %v, want %v", got, tc.want)
}
}
}
func equalStrings(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
// TestAggregatedLogListingFailsOnPeerError: a peer listing that fails fails
// the read instead of hiding that peer's files, unless the peer was already
// retired as unreachable, also once its removal mark expired.
func TestAggregatedLogListingFailsOnPeerError(t *testing.T) {
f := newPeerLogTestFiler(t, true)
ma := f.MetaAggregator
ma.peerLogDirLister = func(ctx context.Context, peer pb.ServerAddress, dir util.FullPath, startFileName string, inclusive bool) ([]*Entry, error) {
return nil, context.DeadlineExceeded
}
start := log_buffer.NewMessagePosition(listingTestCursor.UnixNano(), -2)
if _, _, err := f.CollectLogFileRefs(WithPeerLogFiles(context.Background()), start, 0); err == nil {
t.Fatalf("CollectLogFileRefs succeeded with a peer it could not list")
}
own := pb.ServerAddress("own:8888")
ma.peerUnreachableSinceNs[own] = time.Now().UnixNano()
if _, _, err := f.CollectLogFileRefs(WithPeerLogFiles(context.Background()), start, 0); err == nil {
t.Fatalf("CollectLogFileRefs succeeded with a peer unreachable only briefly")
}
for _, retire := range []struct {
name string
mark func()
}{
{"marked removed", func() { ma.peerRemovedAtNs[own] = time.Now().UnixNano() }},
{"mark expired, still unreachable", func() {
delete(ma.peerRemovedAtNs, own)
ma.peerUnreachableSinceNs[own] = time.Now().Add(-peerUnreachableRemovalAfter - time.Hour).UnixNano()
}},
} {
retire.mark()
refs, _, err := f.CollectLogFileRefs(WithPeerLogFiles(context.Background()), start, 0)
if err != nil {
t.Fatalf("%s: CollectLogFileRefs: %v", retire.name, err)
}
if got := refNames(refs); !equalStrings(got, []string{"12-30.0000abcd"}) {
t.Fatalf("%s: refs = %v, want only the own file", retire.name, got)
}
}
}
+50
View File
@@ -84,6 +84,9 @@ type MetaAggregator struct {
// peerSubscribeLoop is replaceable so a test can observe the subscribe
// start without a live peer.
peerSubscribeLoop func(f *Filer, self, peer pb.ServerAddress, startFrom time.Time, stopChan chan struct{})
// peerLogDirLister is replaceable so a test can serve a peer's log files
// without a live peer.
peerLogDirLister func(ctx context.Context, peer pb.ServerAddress, dir util.FullPath, startFileName string, inclusive bool) ([]*Entry, error)
// stopped is set under peerChansLock by Shutdown; OnPeerUpdate then
// rejects adds so no subscription can outlive the shutdown wait and run
// against a store Filer.Shutdown has already closed.
@@ -107,6 +110,7 @@ func NewMetaAggregator(filer *Filer, self pb.ServerAddress, grpcDialOption grpc.
peerSharesStore: make(map[pb.ServerAddress]bool),
}
t.peerSubscribeLoop = t.loopSubscribeToOneFiler
t.peerLogDirLister = t.readPeerLogDir
// nil notifyFn: aggregated subscribers wake through the buffer's
// subscriber channels, not a cond.
t.MetaLogBuffer = log_buffer.NewLogBuffer("aggr", LogFlushInterval, nil, nil, nil)
@@ -227,6 +231,52 @@ func (ma *MetaAggregator) SharesStore(peer pb.ServerAddress) bool {
return ma.peerSharesStore[peer]
}
// peerLogListTimeout bounds one peer's log directory listing.
const peerLogListTimeout = 30 * time.Second
// listPeerLogDir lists a metadata log directory on every followed peer not
// known to share this filer's store, from the bound the caller chose for its
// own store. A failed listing fails the read: the files it hides would be
// skipped for good. Peers marked removed, or refusing connections for
// peerUnreachableRemovalAfter even after their mark expired, are left out, as
// their unflushed events are once the settled horizon passes.
func (ma *MetaAggregator) listPeerLogDir(ctx context.Context, dir util.FullPath, startFileName string, inclusive bool) (entries []*Entry, err error) {
nowNs := time.Now().UnixNano()
ma.peerChansLock.Lock()
ma.peerWatermarksLock.Lock()
var peers []pb.ServerAddress
for peer := range ma.peerChans {
_, removed := ma.peerRemovedAtNs[peer]
since, failing := ma.peerUnreachableSinceNs[peer]
retired := removed || failing && nowNs-since >= int64(peerUnreachableRemovalAfter)
if peer != ma.self && !ma.peerSharesStore[peer] && !retired {
peers = append(peers, peer)
}
}
ma.peerWatermarksLock.Unlock()
ma.peerChansLock.Unlock()
for _, peer := range peers {
listCtx, cancel := context.WithTimeout(ctx, peerLogListTimeout)
peerEntries, listErr := ma.peerLogDirLister(listCtx, peer, dir, startFileName, inclusive)
cancel()
if listErr != nil {
return nil, fmt.Errorf("list %s on peer %s: %w", dir, peer, listErr)
}
entries = append(entries, peerEntries...)
}
return entries, nil
}
func (ma *MetaAggregator) readPeerLogDir(ctx context.Context, peer pb.ServerAddress, dir util.FullPath, startFileName string, inclusive bool) (entries []*Entry, err error) {
err = pb.WithFilerClient(false, 0, peer, ma.grpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
return filer_pb.SeaweedList(ma.filer.peerCallContext(ctx), client, string(dir), "", func(entry *filer_pb.Entry, isLast bool) error {
entries = append(entries, FromPbEntry(string(dir), entry))
return nil
}, startFileName, inclusive, math.MaxInt32)
})
return entries, err
}
// initPeerWatermark adds the peer with a zero (unknown) watermark; a re-added
// peer keeps its prior values and stops being considered removed.
func (ma *MetaAggregator) initPeerWatermark(peer pb.ServerAddress) {
+8
View File
@@ -33,3 +33,11 @@ func (ma *MetaAggregator) ReportPeerWatermarksForTesting(peer pb.ServerAddress,
ma.advancePeerWatermark(peer, deliveredTsNs)
ma.advancePeerFlushWatermark(peer, flushedTsNs)
}
// NotePeerStoreForTesting records whether a tracked peer runs on this filer's
// store, as its stream does once connected. Test support only.
func (ma *MetaAggregator) NotePeerStoreForTesting(peer pb.ServerAddress, sharesStore bool) {
ma.peerChansLock.Lock()
defer ma.peerChansLock.Unlock()
ma.peerSharesStore[peer] = sharesStore
}
+17
View File
@@ -37,3 +37,20 @@ func recordCreatedParent(ctx context.Context, dirEntry *Entry) bool {
*created = append(*created, dirEntry)
return true
}
type peerLogFilesKey struct{}
// WithPeerLogFiles makes persisted-log reads under ctx also list the log
// files of followed peers that keep their own store. The aggregated stream
// needs them: those files never reach this filer's store.
func WithPeerLogFiles(ctx context.Context) context.Context {
return context.WithValue(ctx, peerLogFilesKey{}, true)
}
func readsPeerLogFiles(ctx context.Context) bool {
if ctx == nil {
return false
}
peers, _ := ctx.Value(peerLogFilesKey{}).(bool)
return peers
}
@@ -704,6 +704,7 @@ func (fs *FilerServer) SubscribeMetadata(req *filer_pb.SubscribeMetadataRequest,
defer cancelSubscription()
defer func() { err = fs.endOfSubscription(stream.Context(), err) }()
peerAddress := findClientAddress(ctx, 0)
ctx = filer.WithPeerLogFiles(ctx)
isReplacing, alreadyKnown, clientName := fs.addClient("", req.ClientName, peerAddress, req.PathPrefix, req.ClientId, req.ClientEpoch)
if isReplacing {
+9 -1
View File
@@ -34,12 +34,19 @@ const (
func (h *subscribeHarness) startAggregator() *filer.MetaAggregator {
ma := filer.NewMetaAggregator(h.f, testSelfAddress, nil)
ma.TrackPeerForTesting(testSelfAddress)
ma.TrackPeerForTesting(testPeerAddress)
trackPeerOnStore(ma, testPeerAddress)
h.f.MetaAggregator = ma
h.t.Cleanup(ma.MetaLogBuffer.ShutdownLogBuffer)
return ma
}
// trackPeerOnStore tracks a peer on the harness's store: no peer server runs
// to list log files from, so the peer must not count as keeping its own.
func trackPeerOnStore(ma *filer.MetaAggregator, peer pb.ServerAddress) {
ma.TrackPeerForTesting(peer)
ma.NotePeerStoreForTesting(peer, true)
}
// reportPeers stands in for both peers' streams reporting through tsNs.
func reportPeers(ma *filer.MetaAggregator, tsNs int64) {
reportPeersAt(ma, tsNs, tsNs)
@@ -369,6 +376,7 @@ func TestSubscribeLoop_AggregatedNewPeerHistoryReadFromDisk(t *testing.T) {
ma := h.startAggregator()
newPeer := pb.ServerAddress("new-peer:8888")
ma.StartPeerForTesting(newPeer, now.Add(-15*time.Second))
ma.NotePeerStoreForTesting(newPeer, true)
h.appendAggregated(now.Add(-30 * time.Second).UnixNano())
live := now.Add(-10 * time.Second).UnixNano()
h.appendAggregated(live)
+2 -2
View File
@@ -43,7 +43,7 @@ func TestSubscribeMetadataLocalStreamEndsWhenRemotePeerAppears(t *testing.T) {
waitForEvents(t, r, []int64{localTs}, 3*time.Second)
// The master announces a second filer, as OnPeerUpdate does in production.
ma.TrackPeerForTesting(testPeerAddress)
trackPeerOnStore(ma, testPeerAddress)
// The local stream must end so the client reconnects to the aggregated path.
select {
@@ -72,7 +72,7 @@ func TestSubscribeMetadataAggregatedPathAfterPeerArrival(t *testing.T) {
r := h.subscribeAggregated(0)
waitForEvents(t, r, []int64{localTs}, 3*time.Second)
ma.TrackPeerForTesting(testPeerAddress)
trackPeerOnStore(ma, testPeerAddress)
select {
case <-r.done:
case <-time.After(5 * time.Second):