mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
storage: enforce the sticky fault where callers commit, not only at entry
A Sync queued behind a failing fsync, and writers waiting for the store lock behind a failing append, passed the entry check before the fault was latched. The latch is now checked where they commit: - syncWALBatch, before its dedup return and before any fsync, so a batch queued behind a failed fsync neither fsyncs again nor reports success; - Sync, under the store lock before it publishes a frontier (covering a deduplicated Sync and a fault latched by a flusher fsync); - Write, WriteBatch (including the multi-block path) and ApplyEntry, under the append lock before allocating LSNs or touching the WAL; - persistCheckpoint, under the store lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c6ae103276
commit
45efc13cf6
1 file changed
+27
@@ -397,6 +397,9 @@ func (s *WALStore) persistCheckpointAndRelease(highestLSN, entryPhys, entryLen u
|
||||
func (s *WALStore) persistCheckpointReleasing(highestLSN, entryPhys, entryLen uint64, release bool) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if err := s.stickyIOFault(); err != nil {
|
||||
return err // no checkpoint advance after a fault, whenever it latched
|
||||
}
|
||||
requested := highestLSN
|
||||
// Clamp the proposed checkpoint to the recycle floor reported
|
||||
// by an external coordinator (e.g., the recovery package's
|
||||
@@ -650,6 +653,12 @@ func (s *WALStore) Write(lba uint32, data []byte) (uint64, error) {
|
||||
s.mu.Unlock()
|
||||
return 0, errors.New("storage: Write after Close")
|
||||
}
|
||||
// Recheck under the append lock: an append that failed while this call
|
||||
// waited latched the fault and left nextLSN and the head unmoved.
|
||||
if err := s.stickyIOFault(); err != nil {
|
||||
s.mu.Unlock()
|
||||
return 0, err
|
||||
}
|
||||
lsn := s.nextLSN
|
||||
|
||||
entry := &walEntry{
|
||||
@@ -720,6 +729,10 @@ func (s *WALStore) WriteBatch(startLBA uint32, blocks [][]byte) ([]uint64, error
|
||||
s.mu.Unlock()
|
||||
return nil, errors.New("storage: WriteBatch after Close")
|
||||
}
|
||||
if err := s.stickyIOFault(); err != nil { // recheck under the append lock
|
||||
s.mu.Unlock()
|
||||
return nil, err
|
||||
}
|
||||
firstLSN := s.nextLSN
|
||||
useMultiBlock := s.multiBlockRecords && len(blocks) > 1
|
||||
|
||||
@@ -979,6 +992,12 @@ func (s *WALStore) Sync() (uint64, error) {
|
||||
s.syncs.Add(1)
|
||||
|
||||
s.mu.Lock()
|
||||
// A fault latched while this Sync waited (another caller's fsync or
|
||||
// append, or a flusher fsync) refuses it: nothing is acknowledged.
|
||||
if err := s.stickyIOFault(); err != nil {
|
||||
s.mu.Unlock()
|
||||
return 0, err
|
||||
}
|
||||
if targetDirectFrontier > s.checkpointLSN && targetDirectFrontier <= targetHead {
|
||||
if s.metadata != nil {
|
||||
if err := s.metadata.BeforeCheckpointAdvance(targetDirectFrontier); err != nil {
|
||||
@@ -1214,6 +1233,9 @@ func (s *WALStore) ApplyEntry(lba uint32, data []byte, lsn uint64) error {
|
||||
if s.closed {
|
||||
return errors.New("storage: ApplyEntry after Close")
|
||||
}
|
||||
if err := s.stickyIOFault(); err != nil { // recheck under the append lock
|
||||
return err
|
||||
}
|
||||
dataCopy := make([]byte, len(data))
|
||||
copy(dataCopy, data)
|
||||
entry := &walEntry{
|
||||
@@ -1413,6 +1435,11 @@ func (s *WALStore) walSyncCovered() bool {
|
||||
// Requests queued during a sync can reuse it only if their mutations predate its
|
||||
// captured cut. Failure leaves the previous durable generation unchanged.
|
||||
func (s *WALStore) syncWALBatch() error {
|
||||
// A batch queued behind a failed fsync must not fsync again (or report
|
||||
// a covered cut as durable): the failed fsync may have dropped pages.
|
||||
if err := s.stickyIOFault(); err != nil {
|
||||
return err
|
||||
}
|
||||
cut := s.walMutation.Load()
|
||||
if !s.bypassSyncDedup.Load() && s.chunk.Load() == nil && cut <= s.durableMutation.Load() {
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user