test: resolve an unknown revocation ACK by its exact recorded witness

This commit is contained in:
pingqiu committed 2026-11-22 01:26:45 -08:00
1 parent a86f07d71a
commit b1e973761a
1 file changed
+28 -4
@@ -15,13 +15,27 @@ import (
"github.com/seaweedfs/seaweed-block/core/lifecycle"
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"
)
type workspaceRPCView struct{ p frontend.Projection }
func (v workspaceRPCView) Projection() frontend.Projection { return v.p }
// lostAckReply returns an unknown outcome only after the real master has
// committed the ACK. The caller must resolve it from a recorded witness.
type lostAckReply struct{ control.WorkspaceServiceClient }
func (c lostAckReply) AckWorkspaceRevoked(ctx context.Context, q *control.WorkspaceRevocationAck, opts ...grpc.CallOption) (*control.WorkspaceEmpty, error) {
reply, err := c.WorkspaceServiceClient.AckWorkspaceRevoked(ctx, q, opts...)
if err != nil {
return reply, err
}
return nil, status.Error(codes.DeadlineExceeded, "injected ACK reply loss after commit")
}
func TestWorkspaceRPCCleanMovePreservesReplicaIdentity(t *testing.T) {
var detached atomic.Bool
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
@@ -70,11 +84,11 @@ func TestWorkspaceRPCCleanMovePreservesReplicaIdentity(t *testing.T) {
}
defer conn.Close()
client := control.NewWorkspaceServiceClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "vol-a", ReplicaId: "r2", Epoch: 1}
stops := 0
g, err := volume.NewWorkspaceLeaseGuard(workspaceRPCView{frontend.Projection{VolumeID: "vol-a", ReplicaID: "r2", Epoch: 1, Healthy: true}}, client, id,
g, err := volume.NewWorkspaceLeaseGuard(workspaceRPCView{frontend.Projection{VolumeID: "vol-a", ReplicaID: "r2", Epoch: 1, Healthy: true}}, lostAckReply{client}, id,
func(context.Context) (uint64, error) { stops++; return 9, nil }, nil)
if err != nil {
t.Fatal(err)
@@ -90,8 +104,18 @@ func TestWorkspaceRPCCleanMovePreservesReplicaIdentity(t *testing.T) {
if _, err := client.RevokeWorkspace(ctx, id); err != nil {
t.Fatal(err)
}
if err := g.Refresh(ctx); err != nil {
t.Fatal(err)
// The stop/ACK path keeps its production timeout. Resolve a lost reply
// from the master's exact ACK, never from elapsed time or the stop alone.
if err := g.Refresh(ctx); status.Code(err) != codes.DeadlineExceeded {
t.Fatalf("expected unknown ACK reply, got %v", err)
}
recorded, err := client.QueryWorkspace(ctx, &control.WorkspaceVolume{VolumeId: "vol-a"})
if err != nil {
t.Fatal("ACK witness unreadable", err)
}
ack := recorded.GetRevocationAck()
if ack.GetIdentity().GetVolumeId() != "vol-a" || ack.GetIdentity().GetReplicaId() != "r2" || ack.GetIdentity().GetEpoch() != 1 || ack.GetHeadGen() != 9 {
t.Fatalf("unknown ACK has no exact recorded witness: %+v", ack)
}
if g.Projection().Healthy || stops != 1 {
t.Fatal("revoked frontend remained admitted")