mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
test: pin final refusal and single exit after recorded revocation
This commit is contained in:
1 parent
5fa69f529c
commit
02de64b69e
5 files changed
+123
-4
No files matched your search
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRestartedRecordedRevocationExitsFinalOnce(t *testing.T) {
|
||||
if os.Getenv("SWB_RECORDED_REVOKE_CHILD") == "1" {
|
||||
refusal, e := status.New(codes.FailedPrecondition, "volume was moved or revoked; inspect workspace state and complete the intended move; leave this unit stopped").WithDetails(&control.WorkspaceLeaseRefusal{Kind: control.WorkspaceLeaseRefusal_FINAL})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
h, send := exitAuthorityHost(t, func(s *exitAssignmentStream) { s.refuse = refusal.Err() })
|
||||
send("r", 1)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
startWorkspaceLease(ctx, h) // the restarted holder receives FINAL on renewal
|
||||
for {
|
||||
if _, final := h.MasterWaitState(); final != "" {
|
||||
break
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Fatal("typed final renewal never ended the startup wait")
|
||||
case <-time.After(time.Millisecond):
|
||||
}
|
||||
}
|
||||
code := superviseProcess(ctx, func(e *processExit) int {
|
||||
if !chooseChunkStartupExit(e, flags{workspaceLease: true, durableImpl: "walstore-chunk", volumeID: "v"}, h, &exitStartupOutcome{expired: true}) {
|
||||
t.Fatal("no final decision")
|
||||
}
|
||||
e.choose(workspaceExit{code: 75, reason: "later retry must lose"})
|
||||
return 0
|
||||
})
|
||||
os.Exit(code)
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
cmd := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestRestartedRecordedRevocationExitsFinalOnce$", "-test.count=1")
|
||||
cmd.Env = append(os.Environ(), "SWB_RECORDED_REVOKE_CHILD=1")
|
||||
out, e := cmd.CombinedOutput()
|
||||
exit, ok := e.(*exec.ExitError)
|
||||
if !ok || exit.ExitCode() != 79 || strings.Count(string(out), "exiting status=79 reason=revoked") != 1 {
|
||||
t.Fatalf("restarted revoked holder: %v output=%s; want one final exit 79", e, out)
|
||||
}
|
||||
if strings.Contains(string(out), "exiting status=75") {
|
||||
t.Fatalf("restart loop outcome: %s", out)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package authority
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRevokingRenewalIsFinalOnlyAfterRecordedAck(t *testing.T) {
|
||||
for _, recorded := range []bool{false, true} {
|
||||
clock := newTestClock()
|
||||
p := newLeasePublisher(t, &failingStore{}, time.Second, clock)
|
||||
bindAndGrant(t, p, "v", "r")
|
||||
ctx := context.Background()
|
||||
if e := p.BeginWorkspaceRevocation(ctx, "v", "r", 1); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if recorded {
|
||||
if e := p.AckWorkspaceRevocation(ctx, "v", WorkspaceRevokeAck{ReplicaID: "r", Epoch: 1, Holder: "host/r", HeadGen: 7}, WorkspaceHead{Detached: true, Epoch: 1, Holder: "host/r", RemoteLSN: 42}); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
}
|
||||
for _, at := range []float64{0, 100} {
|
||||
clock.at(at)
|
||||
l, e := p.RenewWorkspaceLease(ctx, "v", "r", 1)
|
||||
if recorded && e == nil {
|
||||
t.Fatalf("recorded ACK got another revoking grant at %.0f: %+v", at, l)
|
||||
}
|
||||
if !recorded && (e != nil || !l.Revoking) {
|
||||
t.Fatalf("unrecorded revoke changed its retryable drain answer: %+v %v", l, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ const (
|
||||
WorkspaceLeaseRefusal_MOVED WorkspaceLeaseRefusal_Kind = 2
|
||||
WorkspaceLeaseRefusal_DELETED WorkspaceLeaseRefusal_Kind = 3
|
||||
WorkspaceLeaseRefusal_IDENTITY WorkspaceLeaseRefusal_Kind = 4
|
||||
WorkspaceLeaseRefusal_FINAL WorkspaceLeaseRefusal_Kind = 5
|
||||
)
|
||||
|
||||
// Enum value maps for WorkspaceLeaseRefusal_Kind.
|
||||
@@ -39,6 +40,7 @@ var (
|
||||
2: "MOVED",
|
||||
3: "DELETED",
|
||||
4: "IDENTITY",
|
||||
5: "FINAL",
|
||||
}
|
||||
WorkspaceLeaseRefusal_Kind_value = map[string]int32{
|
||||
"OTHER": 0,
|
||||
@@ -46,6 +48,7 @@ var (
|
||||
"MOVED": 2,
|
||||
"DELETED": 3,
|
||||
"IDENTITY": 4,
|
||||
"FINAL": 5,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -315,6 +318,8 @@ func (x *WorkspaceLeaseFact) GetRevoking() bool {
|
||||
// IDENTITY (also on a SubscribeAssignments refusal): the caller's server id is
|
||||
// not registered, or it calls from another host than the registered one;
|
||||
// identity names which ("unregistered" or "wrong_host").
|
||||
// FINAL: this holder's revocation ACK is recorded; restarting it cannot
|
||||
// restore its lease. The holder stops without automatic restart.
|
||||
type WorkspaceLeaseRefusal struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
Kind WorkspaceLeaseRefusal_Kind `protobuf:"varint,1,opt,name=kind,proto3,enum=seaweedfs.block.control.WorkspaceLeaseRefusal_Kind" json:"kind,omitempty"`
|
||||
@@ -1279,17 +1284,18 @@ const file_workspace_proto_rawDesc = "" +
|
||||
"\rexpires_at_ns\x18\x04 \x01(\x03R\vexpiresAtNs\x12 \n" +
|
||||
"\fvalid_for_ns\x18\x05 \x01(\x03R\n" +
|
||||
"validForNs\x12\x1a\n" +
|
||||
"\brevoking\x18\x06 \x01(\bR\brevoking\"\xe8\x01\n" +
|
||||
"\brevoking\x18\x06 \x01(\bR\brevoking\"\xf3\x01\n" +
|
||||
"\x15WorkspaceLeaseRefusal\x12G\n" +
|
||||
"\x04kind\x18\x01 \x01(\x0e23.seaweedfs.block.control.WorkspaceLeaseRefusal.KindR\x04kind\x12$\n" +
|
||||
"\x0eretry_after_ns\x18\x02 \x01(\x03R\fretryAfterNs\x12\x1a\n" +
|
||||
"\bidentity\x18\x03 \x01(\tR\bidentity\"D\n" +
|
||||
"\bidentity\x18\x03 \x01(\tR\bidentity\"O\n" +
|
||||
"\x04Kind\x12\t\n" +
|
||||
"\x05OTHER\x10\x00\x12\v\n" +
|
||||
"\aBARRIER\x10\x01\x12\t\n" +
|
||||
"\x05MOVED\x10\x02\x12\v\n" +
|
||||
"\aDELETED\x10\x03\x12\f\n" +
|
||||
"\bIDENTITY\x10\x04\"{\n" +
|
||||
"\bIDENTITY\x10\x04\x12\t\n" +
|
||||
"\x05FINAL\x10\x05\"{\n" +
|
||||
"\x16WorkspaceRevocationAck\x12F\n" +
|
||||
"\bidentity\x18\x01 \x01(\v2*.seaweedfs.block.control.WorkspaceIdentityR\bidentity\x12\x19\n" +
|
||||
"\bhead_gen\x18\x02 \x01(\x04R\aheadGen\"\xf6\x02\n" +
|
||||
|
||||
@@ -35,8 +35,10 @@ message WorkspaceLeaseFact {
|
||||
// IDENTITY (also on a SubscribeAssignments refusal): the caller's server id is
|
||||
// not registered, or it calls from another host than the registered one;
|
||||
// identity names which ("unregistered" or "wrong_host").
|
||||
// FINAL: this holder's revocation ACK is recorded; restarting it cannot
|
||||
// restore its lease. The holder stops without automatic restart.
|
||||
message WorkspaceLeaseRefusal {
|
||||
enum Kind { OTHER = 0; BARRIER = 1; MOVED = 2; DELETED = 3; IDENTITY = 4; }
|
||||
enum Kind { OTHER = 0; BARRIER = 1; MOVED = 2; DELETED = 3; IDENTITY = 4; FINAL = 5; }
|
||||
Kind kind = 1;
|
||||
int64 retry_after_ns = 2;
|
||||
string identity = 3;
|
||||
|
||||
@@ -39,3 +39,23 @@ func TestBlockvolumeUnitsBoundStartupRetries(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockvolumeUnitsPreventRestartAfterRecordedRevocation(t *testing.T) {
|
||||
for _, name := range []string{"sw-blockvolume.service", "sw-blockvolume@.service", "sw-blockvolume-ublk.service"} {
|
||||
body := readRepoFile(t, "deploy", "systemd", name)
|
||||
found := false
|
||||
for _, line := range strings.Split(body, "\n") {
|
||||
key, value, ok := strings.Cut(strings.TrimSpace(line), "=")
|
||||
if ok && key == "RestartPreventExitStatus" {
|
||||
for _, code := range strings.Fields(value) {
|
||||
if code == "79" {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Errorf("%s: recorded revocation exit 79 must prevent restart", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user