test: pin agreed-leader filer census authority

This commit is contained in:
pingqiu committed 2026-11-29 15:53:54 -08:00
1 parent 0ae0c519b4
commit 654b9561f0
4 files changed
+220 -26

No files matched your search

@@ -13,7 +13,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.36.6
// protoc v3.12.4
// protoc v7.34.1
// source: master_subset.proto
package masterpb
@@ -33,6 +33,86 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type GetMasterConfigurationRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetMasterConfigurationRequest) Reset() {
*x = GetMasterConfigurationRequest{}
mi := &file_master_subset_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetMasterConfigurationRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetMasterConfigurationRequest) ProtoMessage() {}
func (x *GetMasterConfigurationRequest) ProtoReflect() protoreflect.Message {
mi := &file_master_subset_proto_msgTypes[0]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetMasterConfigurationRequest.ProtoReflect.Descriptor instead.
func (*GetMasterConfigurationRequest) Descriptor() ([]byte, []int) {
return file_master_subset_proto_rawDescGZIP(), []int{0}
}
type GetMasterConfigurationResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Leader string `protobuf:"bytes,5,opt,name=leader,proto3" json:"leader,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
func (x *GetMasterConfigurationResponse) Reset() {
*x = GetMasterConfigurationResponse{}
mi := &file_master_subset_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
func (x *GetMasterConfigurationResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*GetMasterConfigurationResponse) ProtoMessage() {}
func (x *GetMasterConfigurationResponse) ProtoReflect() protoreflect.Message {
mi := &file_master_subset_proto_msgTypes[1]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use GetMasterConfigurationResponse.ProtoReflect.Descriptor instead.
func (*GetMasterConfigurationResponse) Descriptor() ([]byte, []int) {
return file_master_subset_proto_rawDescGZIP(), []int{1}
}
func (x *GetMasterConfigurationResponse) GetLeader() string {
if x != nil {
return x.Leader
}
return ""
}
type ListClusterNodesRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
ClientType string `protobuf:"bytes,1,opt,name=client_type,json=clientType,proto3" json:"client_type,omitempty"`
@@ -44,7 +124,7 @@ type ListClusterNodesRequest struct {
func (x *ListClusterNodesRequest) Reset() {
*x = ListClusterNodesRequest{}
mi := &file_master_subset_proto_msgTypes[0]
mi := &file_master_subset_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -56,7 +136,7 @@ func (x *ListClusterNodesRequest) String() string {
func (*ListClusterNodesRequest) ProtoMessage() {}
func (x *ListClusterNodesRequest) ProtoReflect() protoreflect.Message {
mi := &file_master_subset_proto_msgTypes[0]
mi := &file_master_subset_proto_msgTypes[2]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -69,7 +149,7 @@ func (x *ListClusterNodesRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use ListClusterNodesRequest.ProtoReflect.Descriptor instead.
func (*ListClusterNodesRequest) Descriptor() ([]byte, []int) {
return file_master_subset_proto_rawDescGZIP(), []int{0}
return file_master_subset_proto_rawDescGZIP(), []int{2}
}
func (x *ListClusterNodesRequest) GetClientType() string {
@@ -102,7 +182,7 @@ type ListClusterNodesResponse struct {
func (x *ListClusterNodesResponse) Reset() {
*x = ListClusterNodesResponse{}
mi := &file_master_subset_proto_msgTypes[1]
mi := &file_master_subset_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -114,7 +194,7 @@ func (x *ListClusterNodesResponse) String() string {
func (*ListClusterNodesResponse) ProtoMessage() {}
func (x *ListClusterNodesResponse) ProtoReflect() protoreflect.Message {
mi := &file_master_subset_proto_msgTypes[1]
mi := &file_master_subset_proto_msgTypes[3]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -127,7 +207,7 @@ func (x *ListClusterNodesResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use ListClusterNodesResponse.ProtoReflect.Descriptor instead.
func (*ListClusterNodesResponse) Descriptor() ([]byte, []int) {
return file_master_subset_proto_rawDescGZIP(), []int{1}
return file_master_subset_proto_rawDescGZIP(), []int{3}
}
func (x *ListClusterNodesResponse) GetClusterNodes() []*ListClusterNodesResponse_ClusterNode {
@@ -146,7 +226,7 @@ type ListClusterNodesResponse_ClusterNode struct {
func (x *ListClusterNodesResponse_ClusterNode) Reset() {
*x = ListClusterNodesResponse_ClusterNode{}
mi := &file_master_subset_proto_msgTypes[2]
mi := &file_master_subset_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -158,7 +238,7 @@ func (x *ListClusterNodesResponse_ClusterNode) String() string {
func (*ListClusterNodesResponse_ClusterNode) ProtoMessage() {}
func (x *ListClusterNodesResponse_ClusterNode) ProtoReflect() protoreflect.Message {
mi := &file_master_subset_proto_msgTypes[2]
mi := &file_master_subset_proto_msgTypes[4]
if x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -171,7 +251,7 @@ func (x *ListClusterNodesResponse_ClusterNode) ProtoReflect() protoreflect.Messa
// Deprecated: Use ListClusterNodesResponse_ClusterNode.ProtoReflect.Descriptor instead.
func (*ListClusterNodesResponse_ClusterNode) Descriptor() ([]byte, []int) {
return file_master_subset_proto_rawDescGZIP(), []int{1, 0}
return file_master_subset_proto_rawDescGZIP(), []int{3, 0}
}
func (x *ListClusterNodesResponse_ClusterNode) GetAddress() string {
@@ -185,7 +265,10 @@ var File_master_subset_proto protoreflect.FileDescriptor
const file_master_subset_proto_rawDesc = "" +
"\n" +
"\x13master_subset.proto\x12\tmaster_pb\"q\n" +
"\x13master_subset.proto\x12\tmaster_pb\"\x1f\n" +
"\x1dGetMasterConfigurationRequest\"8\n" +
"\x1eGetMasterConfigurationResponse\x12\x16\n" +
"\x06leader\x18\x05 \x01(\tR\x06leader\"q\n" +
"\x17ListClusterNodesRequest\x12\x1f\n" +
"\vclient_type\x18\x01 \x01(\tR\n" +
"clientType\x12\x1f\n" +
@@ -195,8 +278,9 @@ const file_master_subset_proto_rawDesc = "" +
"\x18ListClusterNodesResponse\x12T\n" +
"\rcluster_nodes\x18\x01 \x03(\v2/.master_pb.ListClusterNodesResponse.ClusterNodeR\fclusterNodes\x1a'\n" +
"\vClusterNode\x12\x18\n" +
"\aaddress\x18\x01 \x01(\tR\aaddress2h\n" +
"\aSeaweed\x12]\n" +
"\aaddress\x18\x01 \x01(\tR\aaddress2\xd9\x01\n" +
"\aSeaweed\x12o\n" +
"\x16GetMasterConfiguration\x12(.master_pb.GetMasterConfigurationRequest\x1a).master_pb.GetMasterConfigurationResponse\"\x00\x12]\n" +
"\x10ListClusterNodes\x12\".master_pb.ListClusterNodesRequest\x1a#.master_pb.ListClusterNodesResponse\"\x00BFZDgithub.com/seaweedfs/seaweed-block/core/frontend/chunkstore/masterpbb\x06proto3"
var (
@@ -211,18 +295,22 @@ func file_master_subset_proto_rawDescGZIP() []byte {
return file_master_subset_proto_rawDescData
}
var file_master_subset_proto_msgTypes = make([]protoimpl.MessageInfo, 3)
var file_master_subset_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_master_subset_proto_goTypes = []any{
(*ListClusterNodesRequest)(nil), // 0: master_pb.ListClusterNodesRequest
(*ListClusterNodesResponse)(nil), // 1: master_pb.ListClusterNodesResponse
(*ListClusterNodesResponse_ClusterNode)(nil), // 2: master_pb.ListClusterNodesResponse.ClusterNode
(*GetMasterConfigurationRequest)(nil), // 0: master_pb.GetMasterConfigurationRequest
(*GetMasterConfigurationResponse)(nil), // 1: master_pb.GetMasterConfigurationResponse
(*ListClusterNodesRequest)(nil), // 2: master_pb.ListClusterNodesRequest
(*ListClusterNodesResponse)(nil), // 3: master_pb.ListClusterNodesResponse
(*ListClusterNodesResponse_ClusterNode)(nil), // 4: master_pb.ListClusterNodesResponse.ClusterNode
}
var file_master_subset_proto_depIdxs = []int32{
2, // 0: master_pb.ListClusterNodesResponse.cluster_nodes:type_name -> master_pb.ListClusterNodesResponse.ClusterNode
0, // 1: master_pb.Seaweed.ListClusterNodes:input_type -> master_pb.ListClusterNodesRequest
1, // 2: master_pb.Seaweed.ListClusterNodes:output_type -> master_pb.ListClusterNodesResponse
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
4, // 0: master_pb.ListClusterNodesResponse.cluster_nodes:type_name -> master_pb.ListClusterNodesResponse.ClusterNode
0, // 1: master_pb.Seaweed.GetMasterConfiguration:input_type -> master_pb.GetMasterConfigurationRequest
2, // 2: master_pb.Seaweed.ListClusterNodes:input_type -> master_pb.ListClusterNodesRequest
1, // 3: master_pb.Seaweed.GetMasterConfiguration:output_type -> master_pb.GetMasterConfigurationResponse
3, // 4: master_pb.Seaweed.ListClusterNodes:output_type -> master_pb.ListClusterNodesResponse
3, // [3:5] is the sub-list for method output_type
1, // [1:3] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
@@ -239,7 +327,7 @@ func file_master_subset_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: unsafe.Slice(unsafe.StringData(file_master_subset_proto_rawDesc), len(file_master_subset_proto_rawDesc)),
NumEnums: 0,
NumMessages: 3,
NumMessages: 5,
NumExtensions: 0,
NumServices: 1,
},
@@ -16,9 +16,16 @@ package master_pb;
option go_package = "github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/masterpb";
service Seaweed {
rpc GetMasterConfiguration (GetMasterConfigurationRequest) returns (GetMasterConfigurationResponse) {}
rpc ListClusterNodes (ListClusterNodesRequest) returns (ListClusterNodesResponse) {}
}
message GetMasterConfigurationRequest {}
message GetMasterConfigurationResponse {
string leader = 5;
}
message ListClusterNodesRequest {
string client_type = 1;
string filer_group = 2;
@@ -13,7 +13,7 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.6.2
// - protoc v3.12.4
// - protoc v7.34.1
// source: master_subset.proto
package masterpb
@@ -31,13 +31,15 @@ import (
const _ = grpc.SupportPackageIsVersion9
const (
Seaweed_ListClusterNodes_FullMethodName = "/master_pb.Seaweed/ListClusterNodes"
Seaweed_GetMasterConfiguration_FullMethodName = "/master_pb.Seaweed/GetMasterConfiguration"
Seaweed_ListClusterNodes_FullMethodName = "/master_pb.Seaweed/ListClusterNodes"
)
// SeaweedClient is the client API for Seaweed service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type SeaweedClient interface {
GetMasterConfiguration(ctx context.Context, in *GetMasterConfigurationRequest, opts ...grpc.CallOption) (*GetMasterConfigurationResponse, error)
ListClusterNodes(ctx context.Context, in *ListClusterNodesRequest, opts ...grpc.CallOption) (*ListClusterNodesResponse, error)
}
@@ -49,6 +51,16 @@ func NewSeaweedClient(cc grpc.ClientConnInterface) SeaweedClient {
return &seaweedClient{cc}
}
func (c *seaweedClient) GetMasterConfiguration(ctx context.Context, in *GetMasterConfigurationRequest, opts ...grpc.CallOption) (*GetMasterConfigurationResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetMasterConfigurationResponse)
err := c.cc.Invoke(ctx, Seaweed_GetMasterConfiguration_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *seaweedClient) ListClusterNodes(ctx context.Context, in *ListClusterNodesRequest, opts ...grpc.CallOption) (*ListClusterNodesResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ListClusterNodesResponse)
@@ -63,6 +75,7 @@ func (c *seaweedClient) ListClusterNodes(ctx context.Context, in *ListClusterNod
// All implementations must embed UnimplementedSeaweedServer
// for forward compatibility.
type SeaweedServer interface {
GetMasterConfiguration(context.Context, *GetMasterConfigurationRequest) (*GetMasterConfigurationResponse, error)
ListClusterNodes(context.Context, *ListClusterNodesRequest) (*ListClusterNodesResponse, error)
mustEmbedUnimplementedSeaweedServer()
}
@@ -74,6 +87,9 @@ type SeaweedServer interface {
// pointer dereference when methods are called.
type UnimplementedSeaweedServer struct{}
func (UnimplementedSeaweedServer) GetMasterConfiguration(context.Context, *GetMasterConfigurationRequest) (*GetMasterConfigurationResponse, error) {
return nil, status.Error(codes.Unimplemented, "method GetMasterConfiguration not implemented")
}
func (UnimplementedSeaweedServer) ListClusterNodes(context.Context, *ListClusterNodesRequest) (*ListClusterNodesResponse, error) {
return nil, status.Error(codes.Unimplemented, "method ListClusterNodes not implemented")
}
@@ -98,6 +114,24 @@ func RegisterSeaweedServer(s grpc.ServiceRegistrar, srv SeaweedServer) {
s.RegisterService(&Seaweed_ServiceDesc, srv)
}
func _Seaweed_GetMasterConfiguration_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetMasterConfigurationRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(SeaweedServer).GetMasterConfiguration(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Seaweed_GetMasterConfiguration_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(SeaweedServer).GetMasterConfiguration(ctx, req.(*GetMasterConfigurationRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Seaweed_ListClusterNodes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListClusterNodesRequest)
if err := dec(in); err != nil {
@@ -123,6 +157,10 @@ var Seaweed_ServiceDesc = grpc.ServiceDesc{
ServiceName: "master_pb.Seaweed",
HandlerType: (*SeaweedServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "GetMasterConfiguration",
Handler: _Seaweed_GetMasterConfiguration_Handler,
},
{
MethodName: "ListClusterNodes",
Handler: _Seaweed_ListClusterNodes_Handler,
@@ -47,6 +47,18 @@ type nodesMaster struct {
early time.Duration
calls int
got *masterpb.ListClusterNodesRequest
leader string
}
func (m *nodesMaster) GetMasterConfiguration(ctx context.Context, _ *masterpb.GetMasterConfigurationRequest) (*masterpb.GetMasterConfigurationResponse, error) {
m.mu.Lock()
leader, stall := m.leader, m.stall
m.mu.Unlock()
if stall {
<-ctx.Done()
return nil, ctx.Err()
}
return &masterpb.GetMasterConfigurationResponse{Leader: leader}, nil
}
func (m *nodesMaster) ListClusterNodes(ctx context.Context, r *masterpb.ListClusterNodesRequest) (*masterpb.ListClusterNodesResponse, error) {
@@ -96,7 +108,11 @@ func startMaster(t *testing.T, m *nodesMaster) string {
go func() { _ = srv.Serve(lis) }()
t.Cleanup(srv.Stop)
_, port, _ := net.SplitHostPort(lis.Addr().String())
return "127.0.0.1:9333." + port
addr := "127.0.0.1:9333." + port
m.mu.Lock()
m.leader = addr
m.mu.Unlock()
return addr
}
// deadAddress is a gRPC port nothing listens on.
@@ -145,6 +161,11 @@ func cluster(t *testing.T, group string, masters ...func(self string) *nodesMast
ms = append(ms, m)
addrs = append(addrs, startMaster(t, m))
}
for _, m := range ms {
m.mu.Lock()
m.leader = addrs[0]
m.mu.Unlock()
}
f.mu.Lock()
f.masters = addrs
f.mu.Unlock()
@@ -358,3 +379,43 @@ func TestGRPCAddress(t *testing.T) {
}
}
}
// Followers keep no authoritative filer list; their reported leader decides.
func TestSingleFilerCensusUsesTheAgreedLeader(t *testing.T) {
shortBounds(t)
t.Run("leader-two-followers-empty", func(t *testing.T) {
c, _ := cluster(t, "", lists("self", "10.0.0.2:8888"), lists(), lists())
refusedAtOnce(t, "leader lists two", c, "10.0.0.2:8888")
})
t.Run("follower-list-is-not-authority", func(t *testing.T) {
c, ms := cluster(t, "", lists("self"), lists("10.0.0.2:8888"))
if err := c.CheckSingleFiler(context.Background()); err != nil {
t.Fatal(err)
}
if ms[1].callCount() != 0 {
t.Fatal("queried follower's non-authoritative list")
}
})
t.Run("empty-leader-favourable-follower", func(t *testing.T) {
c, _ := cluster(t, "", lists(), lists("self"))
refusedAtBound(t, "leader has no filer", c)
})
t.Run("disagreement", func(t *testing.T) {
c, ms := cluster(t, "", lists("self"), lists())
ms[1].mu.Lock()
ms[1].leader = "127.0.0.1:9333.19999"
ms[1].mu.Unlock()
refusedAtBound(t, "masters disagree", c)
})
t.Run("missing-report", func(t *testing.T) {
c, ms := cluster(t, "", lists("self"), lists())
ms[1].mu.Lock()
ms[1].leader = ""
ms[1].mu.Unlock()
refusedAtBound(t, "missing leader", c)
})
t.Run("unreachable-follower", func(t *testing.T) {
c, _ := cluster(t, "", lists("self"), func(string) *nodesMaster { return &nodesMaster{stall: true} })
refusedAtBound(t, "master never answers", c)
})
}