diff --git a/seaweed-block/core/storage/wal_admission.go b/seaweed-block/core/storage/wal_admission.go index fb3d9ebda0..8f161c370a 100644 --- a/seaweed-block/core/storage/wal_admission.go +++ b/seaweed-block/core/storage/wal_admission.go @@ -41,7 +41,6 @@ type walAdmission struct { active *walAdmissionTicket // an admitted append cannot be preempted nextOrder uint64 headVersion uint64 - changed chan struct{} sem chan struct{} // counting semaphore for concurrent appenders walUsed func() float64 notifyFn func() // wakes flusher diff --git a/seaweed-block/core/storage/wal_admission_fifo.go b/seaweed-block/core/storage/wal_admission_fifo.go index 7a32f500ab..376c76d974 100644 --- a/seaweed-block/core/storage/wal_admission_fifo.go +++ b/seaweed-block/core/storage/wal_admission_fifo.go @@ -9,6 +9,7 @@ import ( // capacity decision. Granting the next ticket earlier permits it to consume // the oldest writer's capacity even if semaphore grants were in FIFO order. type walAdmissionTicket struct { + ready chan struct{} prev, next *walAdmissionTicket arrival time.Time order uint64 @@ -26,7 +27,7 @@ func (a *walAdmission) newCommandOrder() uint64 { func (a *walAdmission) enqueueTicket(arrival *walWriteArrival) *walAdmissionTicket { a.queueMu.Lock() defer a.queueMu.Unlock() - t := &walAdmissionTicket{arrival: time.Now()} + t := &walAdmissionTicket{arrival: time.Now(), ready: make(chan struct{}, 1)} if arrival != nil { t.arrival, t.order = arrival.arrival, arrival.order } else { @@ -59,16 +60,20 @@ func (a *walAdmission) enqueueTicket(arrival *walWriteArrival) *walAdmissionTick func (a *walAdmission) notifyHeadLocked() { a.headVersion++ - if a.changed != nil { - close(a.changed) + if a.first != nil { + // Only the new head needs to wake. A buffered notification also covers + // a previously displaced head without waking every queued command. + select { + case a.first.ready <- struct{}{}: + default: + } } - a.changed = make(chan struct{}) } func (a *walAdmission) headState(t *walAdmissionTicket) (bool, <-chan struct{}, uint64) { a.queueMu.Lock() defer a.queueMu.Unlock() - return a.first == t, a.changed, a.headVersion + return a.first == t, t.ready, a.headVersion } func (a *walAdmission) tryGrantTicket(t *walAdmissionTicket, version uint64) bool {