mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-19 10:52:04 +00:00
1afc7fa8aa
* fix: retry a recovery relaunch that lost a race with a starting dependency A guest drain-stopped by a coordinated cluster shutdown could be lost for good. The relaunch ran before JetStream was serving, the volume lease claim timed out, and the failure was recorded as permanent. The backoff this needed already existed. relaunchWithRetry retries five times, but only on ErrMountRetryable, and mountErrRetryable recognised exactly two viperblock state-load sentinels. A lease claim returning context deadline exceeded matched neither, so the mount was reported as permanently failed and the backoff never engaged once. - Classify a lease store that cannot answer as ErrLeaseStoreUnavailable, and include it in mountErrRetryable. A lease held by another node is deliberately excluded: that is an answer, not an outage. - Probe readiness rather than connectedness. checkViperblockReady tested natsConn.IsConnected(), which is true against a server whose JetStream is still starting; it now calls AccountInfo with a timeout. - Reconsider a latched failure. RetryRecoveryFailed relaunches instances parked in error by a dependency-unavailable reason, once the backing store is confirmed ready, for a bounded number of passes, then leaves them alone. Only mount-state and launch failures qualify; a failed reconnect or pre-relaunch hook can mean the guest itself needs looking at. Closes the e2e gap that made this feel covered. The node-failure tests stop the service units directly so guests keep running and recovery is a QMP re-attach to a live process. Nothing stopped a guest, so nothing relaunched one from a sealed volume against dependencies that were still starting. TestMultinodeClusterRestartResumesGuests does, including the wait for every spx process to exit that makes it a real restart rather than a stop that returned early. Beads mulga-v7kp4, mulga-kyb1d. * fix: stop every spx process by unit in the cluster-restart helper The first CI run of TestMultinodeClusterRestartResumesGuests failed at the process wait with "node1 still has 2 spx process(es)", and the same thing happened by hand on a prod node. Every service is the same binary, and the stop was driven from a hard-coded list. StopNode names seven units and omits spinifex-northstar and spinifex-qmp-collector, which is exactly the two survivors. The unit name now comes from the surviving process's cgroup, so the set that stops is whoever is still running the binary and the list cannot go stale when a service is added. StopNode itself is left alone: its list is deliberate for the hard outage it simulates, where the target's drain must not fire. Also marks recovery_retry_test.go as //test:in-package — the retry policy is unexported and the tests drive it through the seams restore_test.go uses. * fix: stop spinifex.target in the cluster-restart helper, not the units The second CI run reformed NATS to 2 peers of 3: node3's NATS was stopped and never started again. StopNode stops the service units directly and leaves spinifex.target active. That is right for the hard outage it simulates and wrong for a real shutdown — the target then reads as satisfied while its units are dead, and the later start raced a stop job that was still queued. The helper now runs what the operator procedure and update-nodes.sh run: stop spinifex.target, wait for every spx process to exit, and additionally wait for systemd to have no spinifex job left queued before starting. That last wait is the one that closes this race. * fix: wait for the right NATS peer count in the cluster-restart helper WaitNATSPeers counts remote peers, so a healthy three-node cluster reports two. Asking for three could never be satisfied, and the run that hit it had in fact restarted all three NATS correctly.
112 lines
3.8 KiB
Go
112 lines
3.8 KiB
Go
//go:build e2e
|
|
|
|
package multinode
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
|
"github.com/mulgadc/spinifex/tests/e2e/harness"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
// runClusterRestartResumesGuests is the software-update path: a coordinated
|
|
// shutdown drains every guest to stopped and seals its volumes, then the
|
|
// cluster comes back and each guest has to relaunch from that sealed state
|
|
// while its dependencies are themselves still starting.
|
|
//
|
|
// NodeFailure/NodeRecovery do not cover this. They stop the service units
|
|
// directly so guests keep running and the target's drain never fires, which
|
|
// makes recovery a QMP re-attach to a live process. Here the process is gone
|
|
// and the volume has to be re-opened, which is where a guest was lost: the
|
|
// relaunch raced a JetStream that had not finished starting, the lease claim
|
|
// timed out, and the failure was recorded as permanent.
|
|
func runClusterRestartResumesGuests(t *testing.T, fix *Fixture) {
|
|
harness.Phase(t, "Multinode — Cluster Restart Resumes Guests")
|
|
|
|
require.GreaterOrEqualf(t, len(fix.Cluster.Nodes), 2,
|
|
"a cluster restart needs a multi-node cluster, have %d", len(fix.Cluster.Nodes))
|
|
|
|
trio := needInstanceTrio(t, fix)
|
|
require.NotEmpty(t, trio, "the restart is only meaningful with guests to resume")
|
|
|
|
harness.Step(t, "confirm all %d guests are running before the shutdown", len(trio))
|
|
for _, id := range trio {
|
|
harness.WaitForInstanceState(t, fix.AWS, id, "running")
|
|
}
|
|
|
|
// If an assertion below fails mid-restart the cluster must not be left
|
|
// down for every later test in the package.
|
|
t.Cleanup(func() {
|
|
for _, n := range fix.Cluster.Nodes {
|
|
harness.StartNode(t, n)
|
|
}
|
|
})
|
|
|
|
harness.ClusterShutdownAndRestart(t, fix.Cluster, fix.Env)
|
|
|
|
harness.Step(t, "every guest resumes to running without operator action")
|
|
var failures []string
|
|
for _, id := range trio {
|
|
if err := waitInstanceRunningNotErrored(t, fix, id, 5*time.Minute); err != nil {
|
|
failures = append(failures, err.Error())
|
|
}
|
|
}
|
|
require.Emptyf(t, failures,
|
|
"guests must resume after a coordinated restart; an instance left in error is a guest an operator has to recover by hand:\n%s",
|
|
strings.Join(failures, "\n"))
|
|
}
|
|
|
|
// waitInstanceRunningNotErrored polls until id is running, failing early and
|
|
// with the recorded reason if it lands in error instead. Waiting out the full
|
|
// timeout on an instance already parked in error would hide why.
|
|
func waitInstanceRunningNotErrored(t *testing.T, fix *Fixture, id string, timeout time.Duration) error {
|
|
t.Helper()
|
|
|
|
deadline := time.Now().Add(timeout)
|
|
var last string
|
|
for time.Now().Before(deadline) {
|
|
out, err := fix.AWS.EC2.DescribeInstances(&ec2.DescribeInstancesInput{
|
|
InstanceIds: []*string{aws.String(id)},
|
|
})
|
|
if err != nil {
|
|
// The gateway can still be settling immediately after the restart.
|
|
last = err.Error()
|
|
time.Sleep(5 * time.Second)
|
|
continue
|
|
}
|
|
if len(out.Reservations) == 0 || len(out.Reservations[0].Instances) == 0 {
|
|
last = "not returned by DescribeInstances"
|
|
time.Sleep(5 * time.Second)
|
|
continue
|
|
}
|
|
|
|
inst := out.Reservations[0].Instances[0]
|
|
state := aws.StringValue(inst.State.Name)
|
|
last = state
|
|
switch state {
|
|
case "running":
|
|
return nil
|
|
case "error", "terminated":
|
|
return fmt.Errorf("%s reached %q after the restart instead of running: %s",
|
|
id, state, stateReason(inst))
|
|
}
|
|
time.Sleep(5 * time.Second)
|
|
}
|
|
return fmt.Errorf("%s did not resume within %s, last state %q", id, timeout, last)
|
|
}
|
|
|
|
// stateReason renders an instance's StateReason, which carries the recovery
|
|
// failure that explains a guest parked in error.
|
|
func stateReason(inst *ec2.Instance) string {
|
|
if inst.StateReason == nil {
|
|
return "no state reason recorded"
|
|
}
|
|
return fmt.Sprintf("%s: %s",
|
|
aws.StringValue(inst.StateReason.Code), aws.StringValue(inst.StateReason.Message))
|
|
}
|