mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
G9A: wire replication ACK profile flag
This commit is contained in:
1 parent
5c454d1716
commit
30ffa197ea
2 files changed
+104
-2
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
|
||||
"github.com/seaweedfs/seaweed-block/core/replication"
|
||||
)
|
||||
|
||||
func TestG9A_ParseReplicationAckProfile(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
profile string
|
||||
wantMode replication.DurabilityMode
|
||||
wantWrite durable.WriteAckPolicy
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "best effort default",
|
||||
profile: "best-effort",
|
||||
wantMode: replication.DurabilityBestEffort,
|
||||
wantWrite: durable.WriteAckBestEffort,
|
||||
},
|
||||
{
|
||||
name: "sync quorum gates foreground writes",
|
||||
profile: "sync-quorum",
|
||||
wantMode: replication.DurabilitySyncQuorum,
|
||||
wantWrite: durable.WriteAckRequireObserverAck,
|
||||
},
|
||||
{
|
||||
name: "sync all gates foreground writes",
|
||||
profile: "sync-all",
|
||||
wantMode: replication.DurabilitySyncAll,
|
||||
wantWrite: durable.WriteAckRequireObserverAck,
|
||||
},
|
||||
{
|
||||
name: "unknown profile rejected",
|
||||
profile: "full-sync-ish",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotMode, gotWrite, err := parseReplicationAckProfile(tt.profile)
|
||||
if tt.wantErr {
|
||||
if err == nil {
|
||||
t.Fatalf("parseReplicationAckProfile(%q): expected error", tt.profile)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("parseReplicationAckProfile(%q): %v", tt.profile, err)
|
||||
}
|
||||
if gotMode != tt.wantMode {
|
||||
t.Fatalf("mode=%v want %v", gotMode, tt.wantMode)
|
||||
}
|
||||
if gotWrite != tt.wantWrite {
|
||||
t.Fatalf("writeAck=%v want %v", gotWrite, tt.wantWrite)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -68,9 +68,9 @@ type flags struct {
|
||||
// T2 NVMe/TCP frontend flags. Symmetric with iSCSI flags
|
||||
// per QA note: same loopback-only safe-default rule, same
|
||||
// auto-enable of --t1-readiness so the symmetry stays clean.
|
||||
nvmeListen string
|
||||
nvmeListen string
|
||||
nvmeSubsysNQN string
|
||||
nvmeNS uint
|
||||
nvmeNS uint
|
||||
|
||||
// T3b durable-backend flags. When --durable-root is set, the
|
||||
// iSCSI and NVMe providers use DurableProvider instead of
|
||||
@@ -113,6 +113,11 @@ type flags struct {
|
||||
// after one milestone of dual-lane GREEN observed in CI / hardware
|
||||
// (architect §11 Resolution 3).
|
||||
recoveryMode string
|
||||
|
||||
// G9A: user-visible replication acknowledgement profile.
|
||||
// best-effort is the beta default. sync-quorum / sync-all opt into
|
||||
// foreground write ACK gating through the durable WriteObserver seam.
|
||||
replicationAck string
|
||||
}
|
||||
|
||||
func parseFlags(args []string) (flags, error) {
|
||||
@@ -166,6 +171,9 @@ func parseFlags(args []string) (flags, error) {
|
||||
"core/transport rebuild. \"dual-lane\" = core/recovery PrimaryBridge "+
|
||||
"with separate listener at data-addr port+1. Default flip is a "+
|
||||
"separate ops PR after dual-lane GREEN milestone.")
|
||||
fs.StringVar(&f.replicationAck, "replication-ack", "best-effort",
|
||||
"G9A replication acknowledgement profile: \"best-effort\" (default), \"sync-quorum\", or \"sync-all\". "+
|
||||
"sync-* modes fail foreground writes when required replica acknowledgement is unavailable.")
|
||||
fs.SetOutput(os.Stderr)
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return flags{}, err
|
||||
@@ -173,6 +181,9 @@ func parseFlags(args []string) (flags, error) {
|
||||
if f.recoveryMode != "legacy" && f.recoveryMode != "dual-lane" {
|
||||
return flags{}, fmt.Errorf("--recovery-mode=%q invalid; want \"legacy\" or \"dual-lane\"", f.recoveryMode)
|
||||
}
|
||||
if _, _, err := parseReplicationAckProfile(f.replicationAck); err != nil {
|
||||
return flags{}, err
|
||||
}
|
||||
missing := []string{}
|
||||
for name, val := range map[string]string{
|
||||
"master": f.masterAddr, "server-id": f.serverID,
|
||||
@@ -223,6 +234,20 @@ func parseFlags(args []string) (flags, error) {
|
||||
return f, nil
|
||||
}
|
||||
|
||||
func parseReplicationAckProfile(profile string) (replication.DurabilityMode, durable.WriteAckPolicy, error) {
|
||||
switch profile {
|
||||
case "best-effort":
|
||||
return replication.DurabilityBestEffort, durable.WriteAckBestEffort, nil
|
||||
case "sync-quorum":
|
||||
return replication.DurabilitySyncQuorum, durable.WriteAckRequireObserverAck, nil
|
||||
case "sync-all":
|
||||
return replication.DurabilitySyncAll, durable.WriteAckRequireObserverAck, nil
|
||||
default:
|
||||
return replication.DurabilityBestEffort, durable.WriteAckBestEffort,
|
||||
fmt.Errorf("--replication-ack=%q invalid; want \"best-effort\", \"sync-quorum\", or \"sync-all\"", profile)
|
||||
}
|
||||
}
|
||||
|
||||
// computeFrontendVolumeSize returns the byte capacity an iSCSI/NVMe
|
||||
// target should advertise: durableBlocks × blockSize.
|
||||
//
|
||||
@@ -472,6 +497,19 @@ func run(f flags) int {
|
||||
return 1
|
||||
}
|
||||
replVolume = replication.NewReplicationVolume(f.volumeID, store)
|
||||
repMode, writeAck, err := parseReplicationAckProfile(f.replicationAck)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "blockvolume:", err)
|
||||
_ = durableProv.Close()
|
||||
if status != nil {
|
||||
shutCtx, shutCancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
_ = status.Close(shutCtx)
|
||||
shutCancel()
|
||||
}
|
||||
_ = h.Close()
|
||||
return 1
|
||||
}
|
||||
replVolume.SetDurabilityMode(repMode)
|
||||
h.SetReplicationVolume(replVolume)
|
||||
|
||||
// G7-redo: when --recovery-mode=dual-lane, inject the dual-lane
|
||||
@@ -592,6 +630,7 @@ func run(f flags) int {
|
||||
// primary writes would land locally but never ship to peers.
|
||||
if sb := durableProv.Backend(f.volumeID); sb != nil {
|
||||
sb.SetWriteObserver(replVolume)
|
||||
sb.SetWriteAckPolicy(writeAck)
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, "blockvolume: write-observer wire: Backend(", f.volumeID, ") returned nil; replication fan-out disabled")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user