mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-20 13:30:46 +02:00
Add SimulatedMaster test helper + 20 assignment sequence tests (8 sequence, 5 failover, 5 adversarial, 2 status). Add BlockVolumeStatus struct and Status() method. Includes QA test files for CP1-CP4a. 940 total unit tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package blockvol
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
// MakeDistributedSync creates a sync function that runs local WAL fsync and
|
|
// replica barrier in parallel. If no replica is configured or the replica is
|
|
// degraded, it falls back to local-only sync (Phase 3 behavior).
|
|
//
|
|
// walSync: the local fsync function (typically fd.Sync)
|
|
// shipper: the WAL shipper to the replica (may be nil)
|
|
// vol: the BlockVol (used to read nextLSN and trigger degradation)
|
|
func MakeDistributedSync(walSync func() error, shipper *WALShipper, vol *BlockVol) func() error {
|
|
return func() error {
|
|
if shipper == nil || shipper.IsDegraded() {
|
|
return walSync()
|
|
}
|
|
|
|
// The highest LSN that needs to be durable is nextLSN-1.
|
|
lsnMax := vol.nextLSN.Load() - 1
|
|
|
|
var localErr, remoteErr error
|
|
var wg sync.WaitGroup
|
|
wg.Add(2)
|
|
go func() {
|
|
defer wg.Done()
|
|
localErr = walSync()
|
|
}()
|
|
go func() {
|
|
defer wg.Done()
|
|
remoteErr = shipper.Barrier(lsnMax)
|
|
}()
|
|
wg.Wait()
|
|
|
|
if localErr != nil {
|
|
return localErr
|
|
}
|
|
if remoteErr != nil {
|
|
// Local succeeded, replica failed --degrade but don't fail the client.
|
|
vol.degradeReplica(remoteErr)
|
|
return nil
|
|
}
|
|
return nil
|
|
}
|
|
}
|