mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
filer: cap list snapshots at the peers' delivery watermark
A listing's snapshot only accounted for this filer's in-flight writes. A peer on the same store can have stamped a write below it that is not committed yet; the listing misses it and the client drops its event as already listed, leaving a stale entry (a mount reads a just-closed file as empty) until the next listing.
This commit is contained in:
1 parent
7092edfb06
commit
8ff23c85b9
2 files changed
+43
-1
No files matched your search
@@ -62,6 +62,19 @@ func (fs *FilerServer) LookupDirectoryEntry(ctx context.Context, req *filer_pb.L
|
||||
}, nil
|
||||
}
|
||||
|
||||
// listSnapshotTsNs is the position a listing claims to be complete through.
|
||||
// The local claim only accounts for this filer's in-flight writes; a peer on
|
||||
// the same store may have stamped a write below it that is not committed yet.
|
||||
// Capping at the aggregated subscription's hold keeps such a write above the
|
||||
// snapshot, so the client applies its event instead of dropping it as listed.
|
||||
func (fs *FilerServer) listSnapshotTsNs(nowNs int64) int64 {
|
||||
snapshotTsNs := fs.filer.LocalDeliveredThroughTsNs(nowNs)
|
||||
if ma := fs.filer.MetaAggregator; ma != nil {
|
||||
snapshotTsNs = min(snapshotTsNs, resolveAggReadHoldTsNs(ma.PeerLowWatermarkTsNs(), nowNs, metadataGapSettledHorizon))
|
||||
}
|
||||
return snapshotTsNs
|
||||
}
|
||||
|
||||
func (fs *FilerServer) ListEntries(req *filer_pb.ListEntriesRequest, stream filer_pb.SeaweedFiler_ListEntriesServer) (err error) {
|
||||
|
||||
glog.V(4).Infof("ListEntries %v", req)
|
||||
@@ -80,7 +93,7 @@ func (fs *FilerServer) ListEntries(req *filer_pb.ListEntriesRequest, stream file
|
||||
includeLastFile := req.InclusiveStartFrom
|
||||
snapshotTsNs := req.SnapshotTsNs
|
||||
if snapshotTsNs == 0 {
|
||||
snapshotTsNs = fs.filer.LocalDeliveredThroughTsNs(time.Now().UnixNano())
|
||||
snapshotTsNs = fs.listSnapshotTsNs(time.Now().UnixNano())
|
||||
}
|
||||
sentSnapshot := false
|
||||
var listErr error
|
||||
|
||||
@@ -4,10 +4,13 @@ import (
|
||||
"context"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/filer"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
)
|
||||
|
||||
@@ -72,3 +75,29 @@ func TestListEntriesSnapshotBelowUnfinishedAndLaterStamps(t *testing.T) {
|
||||
t.Fatalf("stamp %d issued after the listing is not above its snapshot %d", laterTsNs, snapshotTsNs)
|
||||
}
|
||||
}
|
||||
|
||||
// A peer on the same store commits writes this filer does not track in
|
||||
// flight. Until the peer's stream has delivered past a write's stamp, the
|
||||
// write may be missing from the store, so the snapshot must stay below the
|
||||
// peers' delivery watermark too, or the client drops the write's event.
|
||||
func TestListEntriesSnapshotBelowPeerWatermark(t *testing.T) {
|
||||
store := newRenameTestStore()
|
||||
store.entries["/dir"] = newDirectoryEntry("/dir", 100)
|
||||
f := newRenameTestFiler(t, store)
|
||||
fs := &FilerServer{filer: f, option: &FilerOption{DirListingLimit: 1000}}
|
||||
ma := filer.NewMetaAggregator(f, "self:8888", nil)
|
||||
f.MetaAggregator = ma
|
||||
t.Cleanup(ma.Shutdown)
|
||||
peer := pb.ServerAddress("peer:8888")
|
||||
ma.TrackPeerForTesting(peer)
|
||||
peerTsNs := time.Now().Add(-time.Second).UnixNano()
|
||||
ma.ReportPeerWatermarksForTesting(peer, peerTsNs, peerTsNs)
|
||||
|
||||
stream := &captureListStream{}
|
||||
if err := fs.ListEntries(&filer_pb.ListEntriesRequest{Directory: "/dir"}, stream); err != nil {
|
||||
t.Fatalf("ListEntries: %v", err)
|
||||
}
|
||||
if snapshotTsNs := stream.snapshotTsNs(t); snapshotTsNs > peerTsNs {
|
||||
t.Fatalf("snapshot %d is past the peer's delivery watermark %d", snapshotTsNs, peerTsNs)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user