Files
seaweedfs/weed/server/filer_subscribe_upgrade_test.go
T
Chris LuandClaude Opus 5.5 3d076dfcdf 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>
2026-11-29 17:46:29 -08:00

117 lines
4.0 KiB
Go

package weed_server
// Regression tests for the aggregated-subscribe entrypoint's peer-discovery
// window. SubscribeMetadata delegates to the local loop when the aggregator
// knows no remote peers yet; these tests pin the upgrade: the local stream
// ends when a remote peer appears, so the client reconnects into the
// aggregated stream.
import (
"testing"
"time"
"github.com/seaweedfs/seaweedfs/weed/filer"
)
// startAggregatorWithoutPeers gives the harness an aggregator that tracks
// only self, the state of a filer whose gRPC server is up but whose master
// connection has not announced the other filers yet.
func (h *subscribeHarness) startAggregatorWithoutPeers() *filer.MetaAggregator {
ma := filer.NewMetaAggregator(h.f, testSelfAddress, nil)
ma.TrackPeerForTesting(testSelfAddress)
h.f.MetaAggregator = ma
h.t.Cleanup(ma.MetaLogBuffer.ShutdownLogBuffer)
return ma
}
// TestSubscribeMetadataLocalStreamEndsWhenRemotePeerAppears pins the upgrade
// path: a stream that started local-only must end when the first remote peer
// appears, so the client reconnects into the aggregated stream.
func TestSubscribeMetadataLocalStreamEndsWhenRemotePeerAppears(t *testing.T) {
h := newSubscribeHarness(t)
ma := h.startAggregatorWithoutPeers()
if ma.HasRemotePeers() {
t.Fatal("test setup: aggregator must start without remote peers")
}
localTs := time.Now().UnixNano()
h.append(localTs)
// The subscriber connects inside the discovery window.
r := h.subscribeAggregated(0)
waitForEvents(t, r, []int64{localTs}, 3*time.Second)
// The master announces a second filer, as OnPeerUpdate does in production.
trackPeerOnStore(ma, testPeerAddress)
// The local stream must end so the client reconnects to the aggregated path.
select {
case err := <-r.done:
if err == nil {
t.Fatal("local stream ended cleanly; the upgrade must surface as an error so RetryUntil-driven followers reconnect")
}
case <-time.After(5 * time.Second):
t.Fatal("local-only stream stayed alive after a remote peer appeared; the subscriber is pinned to a partial cluster view")
}
}
// TestSubscribeMetadataAggregatedPathAfterPeerArrival pins the other half:
// after the upgrade, a re-subscribe from the last delivered offset takes the
// aggregated path and receives the peer's events.
func TestSubscribeMetadataAggregatedPathAfterPeerArrival(t *testing.T) {
h := newSubscribeHarness(t)
ma := h.startAggregatorWithoutPeers()
if ma.HasRemotePeers() {
t.Fatal("test setup: aggregator must start without remote peers")
}
localTs := time.Now().UnixNano()
h.append(localTs)
r := h.subscribeAggregated(0)
waitForEvents(t, r, []int64{localTs}, 3*time.Second)
trackPeerOnStore(ma, testPeerAddress)
select {
case <-r.done:
case <-time.After(5 * time.Second):
t.Fatal("local-only stream stayed alive after a remote peer appeared")
}
// The client reconnects from the last delivered offset; the aggregated
// path now serves the peer's events.
peerTs := time.Now().UnixNano()
h.appendAggregated(peerTs)
reportPeers(ma, peerTs)
r2 := h.subscribeAggregated(localTs)
waitForEvents(t, r2, []int64{peerTs}, 3*time.Second)
}
// TestSubscribeMetadataLocalStreamPersistsWithoutPeers pins the boundary: on
// a standalone filer the local stream keeps serving indefinitely.
func TestSubscribeMetadataLocalStreamPersistsWithoutPeers(t *testing.T) {
h := newSubscribeHarness(t)
ma := h.startAggregatorWithoutPeers()
if ma.HasRemotePeers() {
t.Fatal("test setup: aggregator must start without remote peers")
}
localTs := time.Now().UnixNano()
h.append(localTs)
r := h.subscribeAggregated(0)
waitForEvents(t, r, []int64{localTs}, 3*time.Second)
// No peer ever appears; the stream must still be alive and still deliver.
moreTs := time.Now().UnixNano()
h.append(moreTs)
waitForEventsAtLeastOnce(t, r, []int64{localTs, moreTs}, 3*time.Second)
select {
case err := <-r.done:
t.Fatalf("local stream ended (%v) on a standalone filer; it must keep serving", err)
case <-time.After(200 * time.Millisecond):
}
}