mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
mq broker: bound the fence take's filer calls
A partition is loaded under accessLock, and the fence take's lookups and transaction had no deadline, so a filer that accepted a call and never answered held every partition operation on the broker. A take that runs out of time leaves the partition unserved for a later attempt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a3e08cc1ae
commit
b0b34f41d1
2 files changed
+35
-2
No files matched your search
@@ -24,10 +24,15 @@ var (
|
||||
errTransactionFailed = errors.New("transaction failed")
|
||||
)
|
||||
|
||||
// fenceTakeTimeout bounds the filer calls a fence take makes while holding accessLock.
|
||||
var fenceTakeTimeout = 10 * time.Second
|
||||
|
||||
// newLeaderPartition takes the partition's fence for epoch before anything reads
|
||||
// the partition's files, so a previous leader can no longer add to them.
|
||||
func (b *MessageQueueBroker) newLeaderPartition(t topic.Topic, partition topic.Partition, epoch int64) (*topic.LocalPartition, error) {
|
||||
fence, err := b.takePartitionFence(context.Background(), t, partition, epoch)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), fenceTakeTimeout)
|
||||
defer cancel()
|
||||
fence, err := b.takePartitionFence(ctx, t, partition, epoch)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("take fence of %s %s at epoch %d: %w", t, partition, epoch, err)
|
||||
}
|
||||
|
||||
@@ -41,14 +41,21 @@ type fencingFiler struct {
|
||||
failMutations int
|
||||
// lookups answer from these entries, as a filer that has not caught up with the owner does
|
||||
lagging map[string]*filer_pb.Entry
|
||||
// lookups wait for their caller to give up, as a stalled filer does
|
||||
stalled bool
|
||||
// runs under the lock before a transaction applies, to interleave another writer
|
||||
beforeApply func()
|
||||
volume *httptest.Server
|
||||
uploads atomic.Int32
|
||||
}
|
||||
|
||||
func (f *fencingFiler) LookupDirectoryEntry(_ context.Context, req *filer_pb.LookupDirectoryEntryRequest) (*filer_pb.LookupDirectoryEntryResponse, error) {
|
||||
func (f *fencingFiler) LookupDirectoryEntry(ctx context.Context, req *filer_pb.LookupDirectoryEntryRequest) (*filer_pb.LookupDirectoryEntryResponse, error) {
|
||||
f.mu.Lock()
|
||||
if f.stalled {
|
||||
f.mu.Unlock()
|
||||
<-ctx.Done()
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
defer f.mu.Unlock()
|
||||
entries := f.entries
|
||||
if f.lagging != nil {
|
||||
@@ -272,3 +279,24 @@ func TestTakeFenceLosingTheRace(t *testing.T) {
|
||||
t.Fatalf("took a fence another broker wrote first: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTakeFenceGivesUpOnAStalledFiler(t *testing.T) {
|
||||
f, b := newFencingFiler(t)
|
||||
f.stalled = true
|
||||
defer func(timeout time.Duration) { fenceTakeTimeout = timeout }(fenceTakeTimeout)
|
||||
fenceTakeTimeout = 100 * time.Millisecond
|
||||
|
||||
done := make(chan error, 1)
|
||||
go func() {
|
||||
_, err := b.newLeaderPartition(fenceTestTopic, fenceTestPartition, 1)
|
||||
done <- err
|
||||
}()
|
||||
select {
|
||||
case err := <-done:
|
||||
if err == nil {
|
||||
t.Fatal("took a fence through a stalled filer")
|
||||
}
|
||||
case <-time.After(10 * time.Second):
|
||||
t.Fatal("fence take waited on a stalled filer")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user