diff --git a/seaweed-block/cmd/blockcsi/g15d_manifest_test.go b/seaweed-block/cmd/blockcsi/g15d_manifest_test.go index 27a76a4c3f..5dfb390539 100644 --- a/seaweed-block/cmd/blockcsi/g15d_manifest_test.go +++ b/seaweed-block/cmd/blockcsi/g15d_manifest_test.go @@ -821,3 +821,25 @@ func g15dReadFile(t *testing.T, parts ...string) string { } return string(raw) } + +// The node-loss gate checks what this release claims: no automatic promotion +// while the primary's node is lost, then the same primary serves again. +func TestNodeLossGateExpectsNoAutomaticPromotion(t *testing.T) { + gate := g15dReadFile(t, "testops", "scenarios", "node-loss-survival-rf3-reattach-chain.yaml") + demo := g15dReadFile(t, "scripts", "run-alpha-app-demo.sh") + for _, want := range []string{"SW_BLOCK_DEMO_EXPECT_NO_AUTO_PROMOTION=1", "failover_status: recovered_same_primary", "auto_promotion_while_node_lost=none"} { + if !strings.Contains(gate, want) { + t.Fatalf("node-loss gate missing %q", want) + } + } + for _, gone := range []string{"failover_status: promoted\"", "SW_BLOCK_LAUNCHER_EXTERNAL_STATUS", "result=promoted"} { + if strings.Contains(gate, gone) { + t.Fatalf("node-loss gate still expects %q", gone) + } + } + for _, want := range []string{"SW_BLOCK_DEMO_EXPECT_NO_AUTO_PROMOTION", "failover_status: unexpected_auto_promotion", "failover_status: no_auto_promotion_unproven", "failover_status: recovered_same_primary", "primary frontend_primary_ready=false", "kubectl uncordon"} { + if !strings.Contains(demo, want) { + t.Fatalf("run-alpha-app-demo.sh missing %q", want) + } + } +} diff --git a/seaweed-block/scripts/run-alpha-app-demo.sh b/seaweed-block/scripts/run-alpha-app-demo.sh index 7c34edd006..ee8d21936d 100755 --- a/seaweed-block/scripts/run-alpha-app-demo.sh +++ b/seaweed-block/scripts/run-alpha-app-demo.sh @@ -33,6 +33,8 @@ BREAK_AFTER_BLOCKVOLUME_READY="${SW_BLOCK_DEMO_BREAK_AFTER_BLOCKVOLUME_READY:-}" BREAK_AFTER_BLOCKVOLUME_RESTART="${SW_BLOCK_DEMO_BREAK_AFTER_BLOCKVOLUME_RESTART:-}" FAIL_PRIMARY_BEFORE_READER="${SW_BLOCK_DEMO_FAIL_PRIMARY_BEFORE_READER:-}" REQUIRE_PROMOTION_READY_BEFORE_FAILURE="${SW_BLOCK_DEMO_REQUIRE_PROMOTION_READY_BEFORE_FAILURE:-0}" +EXPECT_NO_AUTO_PROMOTION="${SW_BLOCK_DEMO_EXPECT_NO_AUTO_PROMOTION:-0}" +NO_PROMOTION_HOLD_SECONDS="${SW_BLOCK_DEMO_NO_PROMOTION_HOLD_SECONDS:-30}" WRITER_TIMEOUT="${SW_BLOCK_DEMO_WRITER_TIMEOUT:-240}" DELETE_ALL_BLOCKVOLUMES="${SW_BLOCK_UNINSTALL_DELETE_ALL_BLOCKVOLUMES:-0}" PIN_APP_NODE="${SW_BLOCK_DEMO_PIN_APP_NODE:-1}" @@ -1004,6 +1006,72 @@ fail_primary_before_reader() { echo "old_primary_stale_io_success_count=0" >>"$recovery_marker" echo "stale_primary_fence_evidence=target_ready_replicas=${ready:-0}" >>"$recovery_marker" + if [[ "$EXPECT_NO_AUTO_PROMOTION" == "1" || "$EXPECT_NO_AUTO_PROMOTION" == "true" ]]; then + # This release claims no automatic promotion on node loss: a primary + # that cannot be read is unknown, not failed. Hold, then return the + # node and require the SAME primary to serve again. + log "hold ${NO_PROMOTION_HOLD_SECONDS}s: no automatic promotion while ${primary} is lost" + local hold_rounds=$((NO_PROMOTION_HOLD_SECONDS / 2)) + local hold_reads=0 + for _ in $(seq 1 "$hold_rounds"); do + # A round counts only when the inventory was actually read: an + # unreadable inventory shows no promotion and must not pass the hold. + if collect_ops_inventory_bundle "$after_dir" && grep -q '^replica: ' "$after_summary" 2>/dev/null; then + hold_reads=$((hold_reads + 1)) + fi + after_primary="$(inventory_primary_replica "$after_summary" 2>/dev/null || true)" + if [[ -n "$after_primary" && "$after_primary" != "$primary" ]]; then + echo "failover_status: unexpected_auto_promotion" >>"$recovery_marker" + echo "automatic promotion to ${after_primary} while the primary node was lost" >&2 + exit 1 + fi + sleep 2 + done + if (( hold_reads * 2 < hold_rounds )); then + echo "failover_status: no_auto_promotion_unproven" >>"$recovery_marker" + echo "no-promotion hold unproven: ${hold_reads} of ${hold_rounds} inventory reads succeeded" >&2 + exit 1 + fi + echo "auto_promotion_while_node_lost=none" >>"$recovery_marker" + echo "no_promotion_hold_reads=${hold_reads}/${hold_rounds}" >>"$recovery_marker" + write_control_plane_timeline_event "$timeline" "no_auto_promotion" "replica=${primary}" "hold_seconds=${NO_PROMOTION_HOLD_SECONDS}" + if [[ "$node_loss_mode" == "1" ]]; then + kubectl uncordon "$before_primary_node" | tee "$ARTIFACT_DIR/uncordon-primary-node.log" + fi + kubectl -n "$BLOCKVOLUME_NAMESPACE" scale "$deploy" --replicas=1 | tee "$ARTIFACT_DIR/scale-primary-one.log" + log "wait for the same primary ${primary} to serve again" + for _ in $(seq 1 120); do + collect_ops_inventory_bundle "$after_dir" || true + after_primary="$(inventory_primary_replica "$after_summary" 2>/dev/null || true)" + after_primary_count="$(grep -c '^replica: .* role=primary ' "$after_summary" 2>/dev/null || true)" + promoted_line="$(inventory_replica_line "$after_summary" "$primary" 2>/dev/null || true)" + # In the inventory summary 'frontend_primary_ready=true' appears only in + # the issue "non-primary ... frontend_primary_ready=true" (a replica that + # is not primary claims the frontend), so 0 means no such claim; the + # recovered primary must itself report ready: no + # "primary frontend_primary_ready=false" issue. + frontend_ready_issue_count="$(grep -c 'frontend_primary_ready=true' "$after_summary" 2>/dev/null || true)" + primary_not_ready_count="$(grep -c 'primary frontend_primary_ready=false' "$after_summary" 2>/dev/null || true)" + if [[ "$after_primary" == "$primary" && "$after_primary_count" == "1" && "$frontend_ready_issue_count" == "0" && "$primary_not_ready_count" == "0" ]]; then + { + echo "failover_status: recovered_same_primary" + echo "post_failure_primary_count=${after_primary_count}" + echo "recovered_replica=${primary}" + echo "promoted_replica=${primary}" + echo "promoted_replica_node=${before_primary_node:-unavailable}" + echo "after_publish_target_evidence=${promoted_line}" + echo "after_publish_target_frontend=$(promotion_evidence_field "$promoted_line" "frontend")" + } >>"$recovery_marker" + write_control_plane_timeline_event "$timeline" "primary_recovered" "replica=${primary}" "primary_count=${after_primary_count}" "evidence=${promoted_line}" + return 0 + fi + sleep 2 + done + echo "failover_status: recovery_timeout" >>"$recovery_marker" + echo "the primary ${primary} did not serve again after its node returned" >&2 + exit 1 + fi + log "wait for promoted primary ${candidate_replica} after controlled failure" for _ in $(seq 1 120); do if [[ -n "$required_frontier_arg" ]]; then diff --git a/seaweed-block/testops/README.md b/seaweed-block/testops/README.md index 2bab6216a4..47638a232c 100644 --- a/seaweed-block/testops/README.md +++ b/seaweed-block/testops/README.md @@ -74,6 +74,16 @@ Use the smallest gate that can prove the contract you changed. | Kernel initiator, k3s, mounted filesystem, failover, or stale-session behavior | The matching child chain, for example `nvme-p5-csi-protocol-chain` or `csi-rf1-durable-restart-chain` | These require real Linux/K8s/initiator behavior. | | Milestone readiness or cross-protocol release confidence | `swblock suite testops/suites/beta-hardening-gate.yaml` plus `swblock validate-bundle --profile beta-hardening` | Slow, evidence-heavy gate. Use for release/milestone claims, not first debugging. | +**Node loss (`node-loss-survival-rf3-reattach-chain`).** This release claims no automatic promotion on node loss: +the gate cordons the primary's node and stops it, requires that no other replica is promoted during the hold +(`auto_promotion_while_node_lost=none`), then returns the node and requires the same primary to serve the same +data. Manual failover (a `SwBlockReplicaFailback` handled by the failback executor, which calls blockmaster's admin +`ExecuteFailback`) is covered by the existing tests: `TestFailbackExecutorGRPCRuntimeUsesRealMasterService`, +`TestFailbackServiceEnabledUsesHostRuntime`, `TestHostFailbackAuthorityRuntimeUsesLivePublisher` +(`core/host/master/failback_runtime_test.go`), `TestFailbackAuthorityRuntimeAdapterRejectsStaleExpectedCurrent` +(`core/ops/failback_authority_runtime_adapter_test.go`) and `TestFailbackExecutorInvokesRuntimeWhenExplicitlyEnabled` +(`core/ops/failback_executor_controller_test.go`). + Default ownership: - Developers run unit/component tests, fast runner-native component gates, and diff --git a/seaweed-block/testops/scenarios/node-loss-survival-rf3-reattach-chain.yaml b/seaweed-block/testops/scenarios/node-loss-survival-rf3-reattach-chain.yaml index 9be7b67a93..be14ce5b4e 100644 --- a/seaweed-block/testops/scenarios/node-loss-survival-rf3-reattach-chain.yaml +++ b/seaweed-block/testops/scenarios/node-loss-survival-rf3-reattach-chain.yaml @@ -153,7 +153,7 @@ phases: timeout: 20m cmd: | cd {{ product_root }} - bash -c 'set -a; source /mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/pin_build/alpha-images.env; source /mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/node-specs.env; set +a; set +e; SW_BLOCK_ARTIFACT_DIR=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo SW_BLOCK_DEMO_APP_MANIFEST=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/demo-app-rf3.yaml SW_BLOCK_DEMO_APP_NODE_NAME="$APP_NODE" SW_BLOCK_DEMO_READER_NODE_NAME="$SURVIVOR_APP_NODE" SW_BLOCK_ALPHA_NODE_SPECS="$NODE_SPECS" SW_BLOCK_ALPHA_LOGICAL_SERVERS=3 SW_BLOCK_ALPHA_EXPECTED_SLOTS_PER_VOLUME=3 SW_BLOCK_ALPHA_REPLICATION_ACK=sync-quorum SW_BLOCK_LAUNCHER_EXTERNAL_ISCSI=1 SW_BLOCK_LAUNCHER_EXTERNAL_STATUS=1 SW_BLOCK_REJECT_LOOPBACK_PUBLISH_TARGETS=1 SW_BLOCK_ISCSI_CHAP_SECRET_NAME=sw-block-node-loss-chap SW_BLOCK_ISCSI_CHAP_USERNAME=testops-node-loss SW_BLOCK_ISCSI_CHAP_SECRET=testops-node-loss-{{ run_id }} SW_BLOCK_LAUNCHER_STATE_HOSTPATH=/var/lib/sw-block/testops-{{ run_id }}-node-loss-survival SW_BLOCK_DEMO_REQUIRE_PROMOTION_READY_BEFORE_FAILURE=1 SW_BLOCK_DEMO_FAIL_PRIMARY_BEFORE_READER=cordon-node-scale-primary-to-zero SW_BLOCK_DEMO_STOP_AFTER=reader-verified SW_BLOCK_DEMO_KEEP_ON_STOP=1 bash scripts/run-k8s-demo.sh {{ product_root }}; rc=$?; echo $rc > /mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/exit_code.txt; test "$rc" -eq 44' + bash -c 'set -a; source /mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/pin_build/alpha-images.env; source /mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/node-specs.env; set +a; set +e; SW_BLOCK_ARTIFACT_DIR=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo SW_BLOCK_DEMO_APP_MANIFEST=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/demo-app-rf3.yaml SW_BLOCK_DEMO_APP_NODE_NAME="$APP_NODE" SW_BLOCK_DEMO_READER_NODE_NAME="$SURVIVOR_APP_NODE" SW_BLOCK_ALPHA_NODE_SPECS="$NODE_SPECS" SW_BLOCK_ALPHA_LOGICAL_SERVERS=3 SW_BLOCK_ALPHA_EXPECTED_SLOTS_PER_VOLUME=3 SW_BLOCK_ALPHA_REPLICATION_ACK=sync-quorum SW_BLOCK_LAUNCHER_EXTERNAL_ISCSI=1 SW_BLOCK_DEMO_EXPECT_NO_AUTO_PROMOTION=1 SW_BLOCK_REJECT_LOOPBACK_PUBLISH_TARGETS=1 SW_BLOCK_ISCSI_CHAP_SECRET_NAME=sw-block-node-loss-chap SW_BLOCK_ISCSI_CHAP_USERNAME=testops-node-loss SW_BLOCK_ISCSI_CHAP_SECRET=testops-node-loss-{{ run_id }} SW_BLOCK_LAUNCHER_STATE_HOSTPATH=/var/lib/sw-block/testops-{{ run_id }}-node-loss-survival SW_BLOCK_DEMO_REQUIRE_PROMOTION_READY_BEFORE_FAILURE=1 SW_BLOCK_DEMO_FAIL_PRIMARY_BEFORE_READER=cordon-node-scale-primary-to-zero SW_BLOCK_DEMO_STOP_AFTER=reader-verified SW_BLOCK_DEMO_KEEP_ON_STOP=1 bash scripts/run-k8s-demo.sh {{ product_root }}; rc=$?; echo $rc > /mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/exit_code.txt; test "$rc" -eq 44' - action: grep_log node: m02 path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/run.log" @@ -238,14 +238,14 @@ phases: - action: grep_log node: m02 path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/primary-failure-recovery.txt" - pattern: "failover_status: promoted" + pattern: "failover_status: recovered_same_primary" save_as: failover_promoted_count - action: assert_greater actual: "{{ failover_promoted_count }}" threshold: "0" - action: exec node: m02 - cmd: "M=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/primary-failure-recovery.txt; promoted=$(sed -n 's/^promoted_replica=//p' \"$M\" | tail -1); failed=$(sed -n 's/^failed_replica=//p' \"$M\" | head -1); promoted_node=$(sed -n 's/^promoted_replica_node=//p' \"$M\" | tail -1); failed_node=$(sed -n 's/^failed_node=//p' \"$M\" | head -1); test -n \"$promoted\" && test \"$promoted\" != \"$failed\" && test -n \"$promoted_node\" && test \"$promoted_node\" != \"$failed_node\"" + cmd: "M=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/primary-failure-recovery.txt; recovered=$(sed -n 's/^recovered_replica=//p' \"$M\" | tail -1); failed=$(sed -n 's/^failed_replica=//p' \"$M\" | head -1); test -n \"$recovered\" && test \"$recovered\" = \"$failed\" && grep -q '^auto_promotion_while_node_lost=none$' \"$M\"" - action: grep_log node: m02 path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/primary-failure-recovery.txt" @@ -328,13 +328,13 @@ phases: threshold: "0" - action: exec node: m02 - cmd: "M=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/primary-failure-recovery.txt; before=$(sed -n 's/^before_publish_target_frontend=//p' \"$M\" | head -1); portal=$(sed -n 's/^after_publish_target_frontend=//p' \"$M\" | tail -1); test -n \"$portal\" && test \"$portal\" != \"$before\" && ! printf '%s\n' \"$portal\" | grep -q '^127\\.0\\.0\\.1:' && grep -q \"NodeStageVolume: .* staged transport=iscsi portal=${portal}\" /mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/blockcsi-node.log" + cmd: "M=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/primary-failure-recovery.txt; before=$(sed -n 's/^before_publish_target_frontend=//p' \"$M\" | head -1); portal=$(sed -n 's/^after_publish_target_frontend=//p' \"$M\" | tail -1); test -n \"$portal\" && test \"$portal\" = \"$before\" && ! printf '%s\n' \"$portal\" | grep -q '^127\\.0\\.0\\.1:' && grep -q \"NodeStageVolume: .* staged transport=iscsi portal=${portal}\" /mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/blockcsi-node.log" - action: exec node: m02 cmd: "test -s /mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/node-loss-recovery-boundary.txt && grep -q 'node_loss_recovery_claimed=true' /mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/node-loss-recovery-boundary.txt" - action: exec node: m02 - cmd: "S=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/node-loss-recovery-summary.txt; test -s \"$S\" && grep -q '^node_loss_recovery_summary_version=1$' \"$S\" && grep -q '^result=promoted$' \"$S\" && grep -q '^data_check_after_node_loss=reader_checksum_passed$' \"$S\"" + cmd: "S=/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/node-loss-recovery-summary.txt; test -s \"$S\" && grep -q '^node_loss_recovery_summary_version=1$' \"$S\" && grep -q '^result=recovered_same_primary$' \"$S\" && grep -q '^data_check_after_node_loss=reader_checksum_passed$' \"$S\"" - action: grep_log node: m02 path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/control-plane-timeline.txt" @@ -359,14 +359,6 @@ phases: - action: assert_greater actual: "{{ product_event_candidate_count }}" threshold: "0" - - action: grep_log - node: m02 - path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/product-observation/cluster-evidence.json" - pattern: "\"event_type\": \"authority_published\"" - save_as: product_event_authority_count - - action: assert_greater - actual: "{{ product_event_authority_count }}" - threshold: "0" - action: grep_log node: m02 path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-node-loss-survival/demo/product-observation/cluster-evidence.json"