From 30bff413cdef05c03295f62084c769cb8095cde1 Mon Sep 17 00:00:00 2001 From: francoposa Date: Mon, 13 Jan 2025 11:07:01 -0800 Subject: [PATCH 01/22] update protoc, protoc-gen-go, protoc-gen-go-grpc, and protoc-gen-gogoslick --- Makefile | 13 +- go.mod | 2 +- httpgrpc/httpgrpc.pb.go | 73 +++------ kv/memberlist/kv.pb.go | 68 +++----- middleware/middleware_test/echo_server.pb.go | 63 ++------ ring/partition_ring_desc.pb.go | 77 +++------- ring/ring.pb.go | 70 +++------ server/fake_server.pb.go | 154 ++++++++----------- 8 files changed, 164 insertions(+), 356 deletions(-) diff --git a/Makefile b/Makefile index bda2b2452..3cdf6bf03 100644 --- a/Makefile +++ b/Makefile @@ -8,12 +8,12 @@ PROTO_GOS := $(patsubst %.proto,%.pb.go,$(PROTO_DEFS)) # Download the proper protoc version for Darwin (osx) and Linux. # If you need windows for some reason it's at https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protoc-3.6.1-win32.zip UNAME_S := $(shell uname -s) -PROTO_PATH := https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/ +PROTO_PATH := https://github.com/protocolbuffers/protobuf/releases/download/v29.3/ ifeq ($(UNAME_S), Linux) - PROTO_ZIP=protoc-3.6.1-linux-x86_64.zip + PROTO_ZIP=protoc-29.3-linux-x86_64.zip endif ifeq ($(UNAME_S), Darwin) - PROTO_ZIP=protoc-3.6.1-osx-x86_64.zip + PROTO_ZIP=protoc-v29.3-osx-x86_64.zip endif GO_MODS=$(shell find . $(DONT_FIND) -type f -name 'go.mod' -print) @@ -92,7 +92,10 @@ ifeq ("$(wildcard .tools/protoc/bin/protoc)","") endif .tools/bin/protoc-gen-gogoslick: .tools - GOPATH=$(CURDIR)/.tools go install github.com/gogo/protobuf/protoc-gen-gogoslick@v1.3.0 + GOPATH=$(CURDIR)/.tools go install github.com/gogo/protobuf/protoc-gen-gogoslick@v1.3.2 .tools/bin/protoc-gen-go: .tools - GOPATH=$(CURDIR)/.tools go install github.com/golang/protobuf/protoc-gen-go@v1.3.1 + GOPATH=$(CURDIR)/.tools go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.2 + +.tools/bin/protoc-gen-go-grpc: .tools + GOPATH=$(CURDIR)/.tools go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1 diff --git a/go.mod b/go.mod index 771fc1e18..9b3630035 100644 --- a/go.mod +++ b/go.mod @@ -52,6 +52,7 @@ require ( golang.org/x/sync v0.7.0 golang.org/x/time v0.1.0 google.golang.org/grpc v1.65.0 + google.golang.org/protobuf v1.34.1 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -99,7 +100,6 @@ require ( golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect - google.golang.org/protobuf v1.34.1 // indirect ) replace k8s.io/client-go v12.0.0+incompatible => k8s.io/client-go v0.21.4 diff --git a/httpgrpc/httpgrpc.pb.go b/httpgrpc/httpgrpc.pb.go index bab0efd53..7ebebecff 100644 --- a/httpgrpc/httpgrpc.pb.go +++ b/httpgrpc/httpgrpc.pb.go @@ -924,10 +924,7 @@ func (m *HTTPRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthHttpgrpc - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthHttpgrpc } if (iNdEx + skippy) > l { @@ -1064,10 +1061,7 @@ func (m *HTTPResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthHttpgrpc - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthHttpgrpc } if (iNdEx + skippy) > l { @@ -1181,10 +1175,7 @@ func (m *Header) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthHttpgrpc - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthHttpgrpc } if (iNdEx + skippy) > l { @@ -1202,6 +1193,7 @@ func (m *Header) Unmarshal(dAtA []byte) error { func skipHttpgrpc(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -1233,10 +1225,8 @@ func skipHttpgrpc(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -1257,55 +1247,30 @@ func skipHttpgrpc(dAtA []byte) (n int, err error) { return 0, ErrInvalidLengthHttpgrpc } iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthHttpgrpc - } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowHttpgrpc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipHttpgrpc(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthHttpgrpc - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupHttpgrpc + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthHttpgrpc + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthHttpgrpc = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowHttpgrpc = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthHttpgrpc = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowHttpgrpc = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupHttpgrpc = fmt.Errorf("proto: unexpected end of group") ) diff --git a/kv/memberlist/kv.pb.go b/kv/memberlist/kv.pb.go index 4c2eb9265..a7096f4d0 100644 --- a/kv/memberlist/kv.pb.go +++ b/kv/memberlist/kv.pb.go @@ -486,10 +486,7 @@ func (m *KeyValueStore) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthKv - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthKv } if (iNdEx + skippy) > l { @@ -637,10 +634,7 @@ func (m *KeyValuePair) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthKv - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthKv } if (iNdEx + skippy) > l { @@ -658,6 +652,7 @@ func (m *KeyValuePair) Unmarshal(dAtA []byte) error { func skipKv(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -689,10 +684,8 @@ func skipKv(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -713,55 +706,30 @@ func skipKv(dAtA []byte) (n int, err error) { return 0, ErrInvalidLengthKv } iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthKv - } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipKv(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthKv - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupKv + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthKv + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthKv = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowKv = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthKv = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowKv = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupKv = fmt.Errorf("proto: unexpected end of group") ) diff --git a/middleware/middleware_test/echo_server.pb.go b/middleware/middleware_test/echo_server.pb.go index ff6509352..fc9ae74aa 100644 --- a/middleware/middleware_test/echo_server.pb.go +++ b/middleware/middleware_test/echo_server.pb.go @@ -396,10 +396,7 @@ func (m *Msg) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthEchoServer - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthEchoServer } if (iNdEx + skippy) > l { @@ -417,6 +414,7 @@ func (m *Msg) Unmarshal(dAtA []byte) error { func skipEchoServer(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -448,10 +446,8 @@ func skipEchoServer(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -472,55 +468,30 @@ func skipEchoServer(dAtA []byte) (n int, err error) { return 0, ErrInvalidLengthEchoServer } iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthEchoServer - } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowEchoServer - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipEchoServer(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthEchoServer - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupEchoServer + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthEchoServer + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthEchoServer = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowEchoServer = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthEchoServer = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEchoServer = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupEchoServer = fmt.Errorf("proto: unexpected end of group") ) diff --git a/ring/partition_ring_desc.pb.go b/ring/partition_ring_desc.pb.go index 8f47b1c56..d699c6db3 100644 --- a/ring/partition_ring_desc.pb.go +++ b/ring/partition_ring_desc.pb.go @@ -973,7 +973,7 @@ func (m *PartitionRingDesc) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPartitionRingDesc } if (iNdEx + skippy) > postIndex { @@ -1102,7 +1102,7 @@ func (m *PartitionRingDesc) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPartitionRingDesc } if (iNdEx + skippy) > postIndex { @@ -1119,10 +1119,7 @@ func (m *PartitionRingDesc) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPartitionRingDesc } if (iNdEx + skippy) > l { @@ -1305,10 +1302,7 @@ func (m *PartitionDesc) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPartitionRingDesc } if (iNdEx + skippy) > l { @@ -1415,10 +1409,7 @@ func (m *OwnerDesc) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthPartitionRingDesc } if (iNdEx + skippy) > l { @@ -1436,6 +1427,7 @@ func (m *OwnerDesc) Unmarshal(dAtA []byte) error { func skipPartitionRingDesc(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -1467,10 +1459,8 @@ func skipPartitionRingDesc(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -1491,55 +1481,30 @@ func skipPartitionRingDesc(dAtA []byte) (n int, err error) { return 0, ErrInvalidLengthPartitionRingDesc } iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthPartitionRingDesc - } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipPartitionRingDesc(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthPartitionRingDesc - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPartitionRingDesc + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthPartitionRingDesc + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthPartitionRingDesc = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowPartitionRingDesc = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthPartitionRingDesc = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPartitionRingDesc = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPartitionRingDesc = fmt.Errorf("proto: unexpected end of group") ) diff --git a/ring/ring.pb.go b/ring/ring.pb.go index f976b7e99..3fcff0822 100644 --- a/ring/ring.pb.go +++ b/ring/ring.pb.go @@ -826,7 +826,7 @@ func (m *Desc) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRing } if (iNdEx + skippy) > postIndex { @@ -843,10 +843,7 @@ func (m *Desc) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthRing - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRing } if (iNdEx + skippy) > l { @@ -1164,10 +1161,7 @@ func (m *InstanceDesc) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthRing - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthRing } if (iNdEx + skippy) > l { @@ -1185,6 +1179,7 @@ func (m *InstanceDesc) Unmarshal(dAtA []byte) error { func skipRing(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -1216,10 +1211,8 @@ func skipRing(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -1240,55 +1233,30 @@ func skipRing(dAtA []byte) (n int, err error) { return 0, ErrInvalidLengthRing } iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthRing - } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRing - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipRing(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthRing - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupRing + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthRing + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthRing = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRing = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthRing = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowRing = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupRing = fmt.Errorf("proto: unexpected end of group") ) diff --git a/server/fake_server.pb.go b/server/fake_server.pb.go index 4bb2d5a1f..75091c7dd 100644 --- a/server/fake_server.pb.go +++ b/server/fake_server.pb.go @@ -7,10 +7,10 @@ import ( context "context" fmt "fmt" proto "github.com/gogo/protobuf/proto" - empty "github.com/golang/protobuf/ptypes/empty" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" io "io" math "math" math_bits "math/bits" @@ -236,12 +236,12 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type FakeServerClient interface { - Succeed(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*empty.Empty, error) - FailWithError(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*empty.Empty, error) - FailWithHTTPError(ctx context.Context, in *FailWithHTTPErrorRequest, opts ...grpc.CallOption) (*empty.Empty, error) - Sleep(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*empty.Empty, error) - StreamSleep(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (FakeServer_StreamSleepClient, error) - ReturnProxyProtoCallerIP(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*ProxyProtoIPResponse, error) + Succeed(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) + FailWithError(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) + FailWithHTTPError(ctx context.Context, in *FailWithHTTPErrorRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) + Sleep(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) + StreamSleep(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (FakeServer_StreamSleepClient, error) + ReturnProxyProtoCallerIP(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*ProxyProtoIPResponse, error) } type fakeServerClient struct { @@ -252,8 +252,8 @@ func NewFakeServerClient(cc *grpc.ClientConn) FakeServerClient { return &fakeServerClient{cc} } -func (c *fakeServerClient) Succeed(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*empty.Empty, error) { - out := new(empty.Empty) +func (c *fakeServerClient) Succeed(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) err := c.cc.Invoke(ctx, "/server.FakeServer/Succeed", in, out, opts...) if err != nil { return nil, err @@ -261,8 +261,8 @@ func (c *fakeServerClient) Succeed(ctx context.Context, in *empty.Empty, opts .. return out, nil } -func (c *fakeServerClient) FailWithError(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*empty.Empty, error) { - out := new(empty.Empty) +func (c *fakeServerClient) FailWithError(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) err := c.cc.Invoke(ctx, "/server.FakeServer/FailWithError", in, out, opts...) if err != nil { return nil, err @@ -270,8 +270,8 @@ func (c *fakeServerClient) FailWithError(ctx context.Context, in *empty.Empty, o return out, nil } -func (c *fakeServerClient) FailWithHTTPError(ctx context.Context, in *FailWithHTTPErrorRequest, opts ...grpc.CallOption) (*empty.Empty, error) { - out := new(empty.Empty) +func (c *fakeServerClient) FailWithHTTPError(ctx context.Context, in *FailWithHTTPErrorRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) err := c.cc.Invoke(ctx, "/server.FakeServer/FailWithHTTPError", in, out, opts...) if err != nil { return nil, err @@ -279,8 +279,8 @@ func (c *fakeServerClient) FailWithHTTPError(ctx context.Context, in *FailWithHT return out, nil } -func (c *fakeServerClient) Sleep(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*empty.Empty, error) { - out := new(empty.Empty) +func (c *fakeServerClient) Sleep(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) err := c.cc.Invoke(ctx, "/server.FakeServer/Sleep", in, out, opts...) if err != nil { return nil, err @@ -288,7 +288,7 @@ func (c *fakeServerClient) Sleep(ctx context.Context, in *empty.Empty, opts ...g return out, nil } -func (c *fakeServerClient) StreamSleep(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (FakeServer_StreamSleepClient, error) { +func (c *fakeServerClient) StreamSleep(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (FakeServer_StreamSleepClient, error) { stream, err := c.cc.NewStream(ctx, &_FakeServer_serviceDesc.Streams[0], "/server.FakeServer/StreamSleep", opts...) if err != nil { return nil, err @@ -304,7 +304,7 @@ func (c *fakeServerClient) StreamSleep(ctx context.Context, in *empty.Empty, opt } type FakeServer_StreamSleepClient interface { - Recv() (*empty.Empty, error) + Recv() (*emptypb.Empty, error) grpc.ClientStream } @@ -312,15 +312,15 @@ type fakeServerStreamSleepClient struct { grpc.ClientStream } -func (x *fakeServerStreamSleepClient) Recv() (*empty.Empty, error) { - m := new(empty.Empty) +func (x *fakeServerStreamSleepClient) Recv() (*emptypb.Empty, error) { + m := new(emptypb.Empty) if err := x.ClientStream.RecvMsg(m); err != nil { return nil, err } return m, nil } -func (c *fakeServerClient) ReturnProxyProtoCallerIP(ctx context.Context, in *empty.Empty, opts ...grpc.CallOption) (*ProxyProtoIPResponse, error) { +func (c *fakeServerClient) ReturnProxyProtoCallerIP(ctx context.Context, in *emptypb.Empty, opts ...grpc.CallOption) (*ProxyProtoIPResponse, error) { out := new(ProxyProtoIPResponse) err := c.cc.Invoke(ctx, "/server.FakeServer/ReturnProxyProtoCallerIP", in, out, opts...) if err != nil { @@ -331,34 +331,34 @@ func (c *fakeServerClient) ReturnProxyProtoCallerIP(ctx context.Context, in *emp // FakeServerServer is the server API for FakeServer service. type FakeServerServer interface { - Succeed(context.Context, *empty.Empty) (*empty.Empty, error) - FailWithError(context.Context, *empty.Empty) (*empty.Empty, error) - FailWithHTTPError(context.Context, *FailWithHTTPErrorRequest) (*empty.Empty, error) - Sleep(context.Context, *empty.Empty) (*empty.Empty, error) - StreamSleep(*empty.Empty, FakeServer_StreamSleepServer) error - ReturnProxyProtoCallerIP(context.Context, *empty.Empty) (*ProxyProtoIPResponse, error) + Succeed(context.Context, *emptypb.Empty) (*emptypb.Empty, error) + FailWithError(context.Context, *emptypb.Empty) (*emptypb.Empty, error) + FailWithHTTPError(context.Context, *FailWithHTTPErrorRequest) (*emptypb.Empty, error) + Sleep(context.Context, *emptypb.Empty) (*emptypb.Empty, error) + StreamSleep(*emptypb.Empty, FakeServer_StreamSleepServer) error + ReturnProxyProtoCallerIP(context.Context, *emptypb.Empty) (*ProxyProtoIPResponse, error) } // UnimplementedFakeServerServer can be embedded to have forward compatible implementations. type UnimplementedFakeServerServer struct { } -func (*UnimplementedFakeServerServer) Succeed(ctx context.Context, req *empty.Empty) (*empty.Empty, error) { +func (*UnimplementedFakeServerServer) Succeed(ctx context.Context, req *emptypb.Empty) (*emptypb.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method Succeed not implemented") } -func (*UnimplementedFakeServerServer) FailWithError(ctx context.Context, req *empty.Empty) (*empty.Empty, error) { +func (*UnimplementedFakeServerServer) FailWithError(ctx context.Context, req *emptypb.Empty) (*emptypb.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method FailWithError not implemented") } -func (*UnimplementedFakeServerServer) FailWithHTTPError(ctx context.Context, req *FailWithHTTPErrorRequest) (*empty.Empty, error) { +func (*UnimplementedFakeServerServer) FailWithHTTPError(ctx context.Context, req *FailWithHTTPErrorRequest) (*emptypb.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method FailWithHTTPError not implemented") } -func (*UnimplementedFakeServerServer) Sleep(ctx context.Context, req *empty.Empty) (*empty.Empty, error) { +func (*UnimplementedFakeServerServer) Sleep(ctx context.Context, req *emptypb.Empty) (*emptypb.Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method Sleep not implemented") } -func (*UnimplementedFakeServerServer) StreamSleep(req *empty.Empty, srv FakeServer_StreamSleepServer) error { +func (*UnimplementedFakeServerServer) StreamSleep(req *emptypb.Empty, srv FakeServer_StreamSleepServer) error { return status.Errorf(codes.Unimplemented, "method StreamSleep not implemented") } -func (*UnimplementedFakeServerServer) ReturnProxyProtoCallerIP(ctx context.Context, req *empty.Empty) (*ProxyProtoIPResponse, error) { +func (*UnimplementedFakeServerServer) ReturnProxyProtoCallerIP(ctx context.Context, req *emptypb.Empty) (*ProxyProtoIPResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ReturnProxyProtoCallerIP not implemented") } @@ -367,7 +367,7 @@ func RegisterFakeServerServer(s *grpc.Server, srv FakeServerServer) { } func _FakeServer_Succeed_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(empty.Empty) + in := new(emptypb.Empty) if err := dec(in); err != nil { return nil, err } @@ -379,13 +379,13 @@ func _FakeServer_Succeed_Handler(srv interface{}, ctx context.Context, dec func( FullMethod: "/server.FakeServer/Succeed", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(FakeServerServer).Succeed(ctx, req.(*empty.Empty)) + return srv.(FakeServerServer).Succeed(ctx, req.(*emptypb.Empty)) } return interceptor(ctx, in, info, handler) } func _FakeServer_FailWithError_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(empty.Empty) + in := new(emptypb.Empty) if err := dec(in); err != nil { return nil, err } @@ -397,7 +397,7 @@ func _FakeServer_FailWithError_Handler(srv interface{}, ctx context.Context, dec FullMethod: "/server.FakeServer/FailWithError", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(FakeServerServer).FailWithError(ctx, req.(*empty.Empty)) + return srv.(FakeServerServer).FailWithError(ctx, req.(*emptypb.Empty)) } return interceptor(ctx, in, info, handler) } @@ -421,7 +421,7 @@ func _FakeServer_FailWithHTTPError_Handler(srv interface{}, ctx context.Context, } func _FakeServer_Sleep_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(empty.Empty) + in := new(emptypb.Empty) if err := dec(in); err != nil { return nil, err } @@ -433,13 +433,13 @@ func _FakeServer_Sleep_Handler(srv interface{}, ctx context.Context, dec func(in FullMethod: "/server.FakeServer/Sleep", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(FakeServerServer).Sleep(ctx, req.(*empty.Empty)) + return srv.(FakeServerServer).Sleep(ctx, req.(*emptypb.Empty)) } return interceptor(ctx, in, info, handler) } func _FakeServer_StreamSleep_Handler(srv interface{}, stream grpc.ServerStream) error { - m := new(empty.Empty) + m := new(emptypb.Empty) if err := stream.RecvMsg(m); err != nil { return err } @@ -447,7 +447,7 @@ func _FakeServer_StreamSleep_Handler(srv interface{}, stream grpc.ServerStream) } type FakeServer_StreamSleepServer interface { - Send(*empty.Empty) error + Send(*emptypb.Empty) error grpc.ServerStream } @@ -455,12 +455,12 @@ type fakeServerStreamSleepServer struct { grpc.ServerStream } -func (x *fakeServerStreamSleepServer) Send(m *empty.Empty) error { +func (x *fakeServerStreamSleepServer) Send(m *emptypb.Empty) error { return x.ServerStream.SendMsg(m) } func _FakeServer_ReturnProxyProtoCallerIP_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(empty.Empty) + in := new(emptypb.Empty) if err := dec(in); err != nil { return nil, err } @@ -472,7 +472,7 @@ func _FakeServer_ReturnProxyProtoCallerIP_Handler(srv interface{}, ctx context.C FullMethod: "/server.FakeServer/ReturnProxyProtoCallerIP", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(FakeServerServer).ReturnProxyProtoCallerIP(ctx, req.(*empty.Empty)) + return srv.(FakeServerServer).ReturnProxyProtoCallerIP(ctx, req.(*emptypb.Empty)) } return interceptor(ctx, in, info, handler) } @@ -707,10 +707,7 @@ func (m *ProxyProtoIPResponse) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthFakeServer - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthFakeServer } if (iNdEx + skippy) > l { @@ -779,10 +776,7 @@ func (m *FailWithHTTPErrorRequest) Unmarshal(dAtA []byte) error { if err != nil { return err } - if skippy < 0 { - return ErrInvalidLengthFakeServer - } - if (iNdEx + skippy) < 0 { + if (skippy < 0) || (iNdEx+skippy) < 0 { return ErrInvalidLengthFakeServer } if (iNdEx + skippy) > l { @@ -800,6 +794,7 @@ func (m *FailWithHTTPErrorRequest) Unmarshal(dAtA []byte) error { func skipFakeServer(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 + depth := 0 for iNdEx < l { var wire uint64 for shift := uint(0); ; shift += 7 { @@ -831,10 +826,8 @@ func skipFakeServer(dAtA []byte) (n int, err error) { break } } - return iNdEx, nil case 1: iNdEx += 8 - return iNdEx, nil case 2: var length int for shift := uint(0); ; shift += 7 { @@ -855,55 +848,30 @@ func skipFakeServer(dAtA []byte) (n int, err error) { return 0, ErrInvalidLengthFakeServer } iNdEx += length - if iNdEx < 0 { - return 0, ErrInvalidLengthFakeServer - } - return iNdEx, nil case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowFakeServer - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipFakeServer(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - if iNdEx < 0 { - return 0, ErrInvalidLengthFakeServer - } - } - return iNdEx, nil + depth++ case 4: - return iNdEx, nil + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupFakeServer + } + depth-- case 5: iNdEx += 4 - return iNdEx, nil default: return 0, fmt.Errorf("proto: illegal wireType %d", wireType) } + if iNdEx < 0 { + return 0, ErrInvalidLengthFakeServer + } + if depth == 0 { + return iNdEx, nil + } } - panic("unreachable") + return 0, io.ErrUnexpectedEOF } var ( - ErrInvalidLengthFakeServer = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowFakeServer = fmt.Errorf("proto: integer overflow") + ErrInvalidLengthFakeServer = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowFakeServer = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupFakeServer = fmt.Errorf("proto: unexpected end of group") ) From dfe29e510796fb73708a38a6e299ffae95209060 Mon Sep 17 00:00:00 2001 From: francoposa Date: Mon, 13 Jan 2025 11:14:21 -0800 Subject: [PATCH 02/22] csproto gen in Makefile; update & gen ring.proto; go mod tidy and vendor csproto gen in Makefile; update & gen ring.proto; go mod tidy and vendor --- Makefile | 15 + go.mod | 15 +- go.sum | 33 +- ring/ring.pb.fm.go | 412 +++++++++++++ ring/ring.pb.go | 1385 ++++++++------------------------------------ ring/ring.proto | 7 +- 6 files changed, 693 insertions(+), 1174 deletions(-) create mode 100644 ring/ring.pb.fm.go diff --git a/Makefile b/Makefile index 3cdf6bf03..cf31515ee 100644 --- a/Makefile +++ b/Makefile @@ -65,6 +65,18 @@ clean-protos: ## Removes the proto files .PHONY: protos protos: .tools/bin/protoc .tools/bin/protoc-gen-gogoslick .tools/bin/protoc-gen-go $(PROTO_GOS) ## Creates proto files +PROTO_DEFS_CSPROTO := ./ring/ring.proto +.PHONY: protos-csproto +protos-csproto: + @for name in $(PROTO_DEFS_CSPROTO); do \ + .tools/protoc/bin/protoc \ + -I . \ + --go_out=paths=source_relative:. \ + --fastmarshal_out=apiversion=v2,paths=source_relative:. \ + --go-grpc_out=require_unimplemented_servers=false,paths=source_relative:. \ + $${name}; \ + done + %.pb.go: .tools/protoc/bin/protoc -I $(GOPATH):./vendor/github.com/gogo/protobuf:./vendor:./$(@D) --gogoslick_out=plugins=grpc,Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,:./$(@D) ./$(patsubst %.pb.go,%.proto,$@) @@ -99,3 +111,6 @@ endif .tools/bin/protoc-gen-go-grpc: .tools GOPATH=$(CURDIR)/.tools go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1 + +.tools/bin/protoc-gen-fastmarshal: .tools + GOPATH=$(CURDIR)/.tools go install github.com/CrowdStrike/csproto/cmd/protoc-gen-fastmarshal@v0.33.0 \ No newline at end of file diff --git a/go.mod b/go.mod index 9b3630035..690aefe21 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/grafana/dskit go 1.21 require ( + github.com/CrowdStrike/csproto v0.33.0 github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 github.com/alicebob/miniredis v2.5.0+incompatible github.com/armon/go-metrics v0.3.10 @@ -39,7 +40,7 @@ require ( github.com/prometheus/common v0.44.0 github.com/prometheus/exporter-toolkit v0.10.1-0.20230714054209-2f4150c63f97 github.com/sercand/kuberesolver/v5 v5.1.1 - github.com/stretchr/testify v1.8.1 + github.com/stretchr/testify v1.10.0 github.com/uber/jaeger-client-go v2.28.0+incompatible github.com/uber/jaeger-lib v2.2.0+incompatible go.etcd.io/etcd/api/v3 v3.5.0 @@ -49,10 +50,10 @@ require ( go.uber.org/goleak v1.2.0 golang.org/x/exp v0.0.0-20230321023759-10a507213a29 golang.org/x/net v0.26.0 - golang.org/x/sync v0.7.0 + golang.org/x/sync v0.8.0 golang.org/x/time v0.1.0 google.golang.org/grpc v1.65.0 - google.golang.org/protobuf v1.34.1 + google.golang.org/protobuf v1.35.1 gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -88,15 +89,15 @@ require ( github.com/onsi/gomega v1.24.0 // indirect github.com/prometheus/procfs v0.9.0 // indirect github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect - github.com/stretchr/objx v0.5.0 // indirect + github.com/stretchr/objx v0.5.2 // indirect github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.17.0 // indirect - golang.org/x/crypto v0.24.0 // indirect + golang.org/x/crypto v0.26.0 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/sys v0.23.0 // indirect + golang.org/x/text v0.17.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect diff --git a/go.sum b/go.sum index 4a1cb572c..d44494327 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/CrowdStrike/csproto v0.33.0 h1:xdGHWB/WFcAwV1OmxCSOkoUcRrQRc3fDDKcKRCN0Zlg= +github.com/CrowdStrike/csproto v0.33.0/go.mod h1:quhKDsPpKaXwLWgG5xvW47QCtlmV41of4gRmMZrSxEs= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -318,18 +320,15 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/uber/jaeger-client-go v2.28.0+incompatible h1:G4QSBfvPKvg5ZM2j9MrJFdfI5iSljY/WnJqOGFao6HI= github.com/uber/jaeger-client-go v2.28.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= @@ -362,8 +361,8 @@ golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= @@ -418,8 +417,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -457,8 +456,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -469,8 +468,8 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.1.0 h1:xYY+Bajn2a7VBmTM5GikTmnK8ZuX8YgnQCqZpbBNtmA= golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -525,8 +524,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/ring/ring.pb.fm.go b/ring/ring.pb.fm.go new file mode 100644 index 000000000..e23425ff3 --- /dev/null +++ b/ring/ring.pb.fm.go @@ -0,0 +1,412 @@ +// GENERATED CODE - DO NOT EDIT +// This file was generated by protoc-gen-fastmarshal + +package ring + +import ( + "fmt" + "sync/atomic" + "github.com/CrowdStrike/csproto" +) + +//------------------------------------------------------------------------------ +// Custom Protobuf size/marshal/unmarshal code for Desc + +// Size calculates and returns the size, in bytes, required to hold the contents of m using the Protobuf +// binary encoding. +func (m *Desc) Size() int { + // nil message is always 0 bytes + if m == nil { + return 0 + } + // return cached size, if present + if csz := int(atomic.LoadInt32(&m.sizeCache)); csz > 0 { + return csz + } + // calculate and cache + var sz, l int + _ = l // avoid unused variable + + // Ingesters (message,repeated) + for k, v := range m.Ingesters { + // size of key (always has an internal tag of 1) + l = len(k) + keySize := 1 + csproto.SizeOfVarint(uint64(l)) + l + // size of value (always has an internal tag of 2) + if v != nil { + l = csproto.Size(v) + valueSize := 1 + csproto.SizeOfVarint(uint64(l)) + l + sz += csproto.SizeOfTagKey(1) + csproto.SizeOfVarint(uint64(keySize+valueSize)) + keySize + valueSize + } + } + + // cache the size so it can be re-used in Marshal()/MarshalTo() + atomic.StoreInt32(&m.sizeCache, int32(sz)) + return sz +} + +// Marshal converts the contents of m to the Protobuf binary encoding and returns the result or an error. +func (m *Desc) Marshal() ([]byte, error) { + siz := m.Size() + if siz == 0 { + return []byte{}, nil + } + buf := make([]byte, siz) + err := m.MarshalTo(buf) + return buf, err +} + +// MarshalTo converts the contents of m to the Protobuf binary encoding and writes the result to dest. +func (m *Desc) MarshalTo(dest []byte) error { + // nil message == no-op + if m == nil { + return nil + } + var ( + enc = csproto.NewEncoder(dest) + buf []byte + err error + extVal interface{} + ) + // ensure no unused variables + _ = enc + _ = buf + _ = err + _ = extVal + + // Ingesters (1,map) + for k, v := range m.Ingesters { + if v == nil { + continue + } + valueSize := csproto.Size(v) + itemSize := 1 + csproto.SizeOfVarint(uint64(valueSize)) + valueSize + keySize := len(k) + itemSize += 1 + csproto.SizeOfVarint(uint64(keySize)) + keySize + enc.EncodeMapEntryHeader(1, itemSize) + enc.EncodeString(1, k) + enc.EncodeNested(2, v) + } + + return nil +} + +// Unmarshal decodes a binary encoded Protobuf message from p and populates m with the result. +func (m *Desc) Unmarshal(p []byte) error { + m.Reset() + if len(p) == 0 { + return nil + } + dec := csproto.NewDecoder(p) + for dec.More() { + tag, wt, err := dec.DecodeTag() + if err != nil { + return err + } + switch tag { + case 1: // Ingesters (map) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for map field 'ingesters' (tag=1), expected 2 (length-delimited)", wt) + } + + if m.Ingesters == nil { + m.Ingesters = make(map[string]*InstanceDesc) + } + // consume the map entry size + // TODO - should we validate this? + if _, err = dec.DecodeInt32(); err != nil { + return err + } + // always 2 values + var ( + entryKey string + entryValue *InstanceDesc + ) + for i := 0; i < 2; i++ { + etag, ewt, err := dec.DecodeTag() + if err != nil { + return err + } + switch etag { + case 1: // key + if ewt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for map key for field 'ingesters' (tag=1), expected 2 (length-delimited)", ewt) + } + if entryKey, err = dec.DecodeString(); err != nil { + return err + } + case 2: // value + if ewt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for map value for field 'ingesters' (tag=1), expected 2 (length-delimited)", ewt) + } + var v InstanceDesc + if err = dec.DecodeNested(&v); err != nil { + return err + } else { + entryValue = &v + } + default: + return fmt.Errorf("invalid map entry field tag %d, expected 1 or 2", etag) + } + } + m.Ingesters[entryKey] = entryValue + + default: + if skipped, err := dec.Skip(tag, wt); err != nil { + return fmt.Errorf("invalid operation skipping tag %v: %w", tag, err) + } else { + m.unknownFields = append(m.unknownFields, skipped...) + } + } + } + return nil +} + +//------------------------------------------------------------------------------ +// Custom Protobuf size/marshal/unmarshal code for InstanceDesc + +// Size calculates and returns the size, in bytes, required to hold the contents of m using the Protobuf +// binary encoding. +func (m *InstanceDesc) Size() int { + // nil message is always 0 bytes + if m == nil { + return 0 + } + // return cached size, if present + if csz := int(atomic.LoadInt32(&m.sizeCache)); csz > 0 { + return csz + } + // calculate and cache + var sz, l int + _ = l // avoid unused variable + + // Addr (string,optional) + if l = len(m.Addr); l > 0 { + sz += csproto.SizeOfTagKey(1) + csproto.SizeOfVarint(uint64(l)) + l + } + // Timestamp (int64,optional) + if m.Timestamp != 0 { + sz += csproto.SizeOfTagKey(2) + csproto.SizeOfVarint(uint64(m.Timestamp)) + } + // State (enum,optional) + if m.State != 0 { + sz += csproto.SizeOfTagKey(3) + csproto.SizeOfVarint(uint64(m.State)) + } + // Tokens (uint32,repeated,packed) + if len(m.Tokens) > 0 { + sz += csproto.SizeOfTagKey(6) + l = 0 + for _, iv := range m.Tokens { + l += csproto.SizeOfVarint(uint64(iv)) + } + sz += csproto.SizeOfVarint(uint64(l)) + l + } + // Zone (string,optional) + if l = len(m.Zone); l > 0 { + sz += csproto.SizeOfTagKey(7) + csproto.SizeOfVarint(uint64(l)) + l + } + // RegisteredTimestamp (int64,optional) + if m.RegisteredTimestamp != 0 { + sz += csproto.SizeOfTagKey(8) + csproto.SizeOfVarint(uint64(m.RegisteredTimestamp)) + } + // Id (string,optional) + if l = len(m.Id); l > 0 { + sz += csproto.SizeOfTagKey(9) + csproto.SizeOfVarint(uint64(l)) + l + } + // ReadOnlyUpdatedTimestamp (int64,optional) + if m.ReadOnlyUpdatedTimestamp != 0 { + sz += csproto.SizeOfTagKey(10) + csproto.SizeOfVarint(uint64(m.ReadOnlyUpdatedTimestamp)) + } + // ReadOnly (bool,optional) + if m.ReadOnly { + sz += csproto.SizeOfTagKey(11) + 1 + } + // cache the size so it can be re-used in Marshal()/MarshalTo() + atomic.StoreInt32(&m.sizeCache, int32(sz)) + return sz +} + +// Marshal converts the contents of m to the Protobuf binary encoding and returns the result or an error. +func (m *InstanceDesc) Marshal() ([]byte, error) { + siz := m.Size() + if siz == 0 { + return []byte{}, nil + } + buf := make([]byte, siz) + err := m.MarshalTo(buf) + return buf, err +} + +// MarshalTo converts the contents of m to the Protobuf binary encoding and writes the result to dest. +func (m *InstanceDesc) MarshalTo(dest []byte) error { + // nil message == no-op + if m == nil { + return nil + } + var ( + enc = csproto.NewEncoder(dest) + buf []byte + err error + extVal interface{} + ) + // ensure no unused variables + _ = enc + _ = buf + _ = err + _ = extVal + + // Addr (1,string,optional) + if len(m.Addr) > 0 { + enc.EncodeString(1, m.Addr) + } + // Timestamp (2,int64,optional) + if m.Timestamp != 0 { + enc.EncodeInt64(2, m.Timestamp) + } + // State (3,enum,optional) + if m.State != 0 { + enc.EncodeInt32(3, int32(m.State)) + } + // Tokens (6,uint32,repeated,packed) + if len(m.Tokens) > 0 { + enc.EncodePackedUInt32(6, m.Tokens) + } + // Zone (7,string,optional) + if len(m.Zone) > 0 { + enc.EncodeString(7, m.Zone) + } + // RegisteredTimestamp (8,int64,optional) + if m.RegisteredTimestamp != 0 { + enc.EncodeInt64(8, m.RegisteredTimestamp) + } + // Id (9,string,optional) + if len(m.Id) > 0 { + enc.EncodeString(9, m.Id) + } + // ReadOnlyUpdatedTimestamp (10,int64,optional) + if m.ReadOnlyUpdatedTimestamp != 0 { + enc.EncodeInt64(10, m.ReadOnlyUpdatedTimestamp) + } + // ReadOnly (11,bool,optional) + if m.ReadOnly { + enc.EncodeBool(11, m.ReadOnly) + } + return nil +} + +// Unmarshal decodes a binary encoded Protobuf message from p and populates m with the result. +func (m *InstanceDesc) Unmarshal(p []byte) error { + m.Reset() + if len(p) == 0 { + return nil + } + dec := csproto.NewDecoder(p) + for dec.More() { + tag, wt, err := dec.DecodeTag() + if err != nil { + return err + } + switch tag { + case 1: // Addr (string,optional) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'addr' (tag=1), expected 2 (length-delimited)", wt) + } + if s, err := dec.DecodeString(); err != nil { + return fmt.Errorf("unable to decode string value for field 'addr' (tag=1): %w", err) + } else { + m.Addr = s + } + + case 2: // Timestamp (int64,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'timestamp' (tag=2), expected 0 (varint)", wt) + } + if v, err := dec.DecodeInt64(); err != nil { + return fmt.Errorf("unable to decode int64 value for field 'timestamp' (tag=2): %w", err) + } else { + m.Timestamp = v + } + case 3: // State (enum,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'state' (tag=3), expected 0 (varint)", wt) + } + if v, err := dec.DecodeInt32(); err != nil { + return fmt.Errorf("unable to decode int32 enum value for field 'state' (tag=3): %w", err) + } else { + m.State = InstanceState(v) + } + case 6: // Tokens (uint32,repeated,packed) + switch wt { + case csproto.WireTypeVarint: + if v, err := dec.DecodeUInt32(); err != nil { + return fmt.Errorf("unable to decode uint32 value for field 'tokens' (tag=6): %w", err) + } else { + m.Tokens = append(m.Tokens, v) + } + case csproto.WireTypeLengthDelimited: + if v, err := dec.DecodePackedUint32(); err != nil { + return fmt.Errorf("unable to decode packed uint32 values for field 'tokens' (tag=6): %w", err) + } else { + m.Tokens = append(m.Tokens, v...) + } + default: + return fmt.Errorf("incorrect wire type %v for repeated field 'tokens' (tag=6), expected 0 (varint) or 1 (length-delimited)", wt) + } + case 7: // Zone (string,optional) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'zone' (tag=7), expected 2 (length-delimited)", wt) + } + if s, err := dec.DecodeString(); err != nil { + return fmt.Errorf("unable to decode string value for field 'zone' (tag=7): %w", err) + } else { + m.Zone = s + } + + case 8: // RegisteredTimestamp (int64,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'registered_timestamp' (tag=8), expected 0 (varint)", wt) + } + if v, err := dec.DecodeInt64(); err != nil { + return fmt.Errorf("unable to decode int64 value for field 'registered_timestamp' (tag=8): %w", err) + } else { + m.RegisteredTimestamp = v + } + case 9: // Id (string,optional) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'id' (tag=9), expected 2 (length-delimited)", wt) + } + if s, err := dec.DecodeString(); err != nil { + return fmt.Errorf("unable to decode string value for field 'id' (tag=9): %w", err) + } else { + m.Id = s + } + + case 10: // ReadOnlyUpdatedTimestamp (int64,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'read_only_updated_timestamp' (tag=10), expected 0 (varint)", wt) + } + if v, err := dec.DecodeInt64(); err != nil { + return fmt.Errorf("unable to decode int64 value for field 'read_only_updated_timestamp' (tag=10): %w", err) + } else { + m.ReadOnlyUpdatedTimestamp = v + } + case 11: // ReadOnly (bool,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'read_only' (tag=11), expected 0 (varint)", wt) + } + if v, err := dec.DecodeBool(); err != nil { + return fmt.Errorf("unable to decode boolean value for field 'read_only' (tag=11): %w", err) + } else { + m.ReadOnly = v + } + + default: + if skipped, err := dec.Skip(tag, wt); err != nil { + return fmt.Errorf("invalid operation skipping tag %v: %w", tag, err) + } else { + m.unknownFields = append(m.unknownFields, skipped...) + } + } + } + return nil +} diff --git a/ring/ring.pb.go b/ring/ring.pb.go index 3fcff0822..1c5007820 100644 --- a/ring/ring.pb.go +++ b/ring/ring.pb.go @@ -1,111 +1,131 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: ring.proto +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.2 +// protoc v5.29.3 +// source: ring/ring.proto package ring import ( - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" - io "io" - math "math" - math_bits "math/bits" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" - strconv "strconv" - strings "strings" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) type InstanceState int32 const ( - ACTIVE InstanceState = 0 - LEAVING InstanceState = 1 - PENDING InstanceState = 2 - JOINING InstanceState = 3 + InstanceState_ACTIVE InstanceState = 0 + InstanceState_LEAVING InstanceState = 1 + InstanceState_PENDING InstanceState = 2 + InstanceState_JOINING InstanceState = 3 // This state is only used by gossiping code to distribute information about // instances that have been removed from the ring. Ring users should not use it directly. - LEFT InstanceState = 4 + InstanceState_LEFT InstanceState = 4 ) -var InstanceState_name = map[int32]string{ - 0: "ACTIVE", - 1: "LEAVING", - 2: "PENDING", - 3: "JOINING", - 4: "LEFT", +// Enum value maps for InstanceState. +var ( + InstanceState_name = map[int32]string{ + 0: "ACTIVE", + 1: "LEAVING", + 2: "PENDING", + 3: "JOINING", + 4: "LEFT", + } + InstanceState_value = map[string]int32{ + "ACTIVE": 0, + "LEAVING": 1, + "PENDING": 2, + "JOINING": 3, + "LEFT": 4, + } +) + +func (x InstanceState) Enum() *InstanceState { + p := new(InstanceState) + *p = x + return p } -var InstanceState_value = map[string]int32{ - "ACTIVE": 0, - "LEAVING": 1, - "PENDING": 2, - "JOINING": 3, - "LEFT": 4, +func (x InstanceState) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) } +func (InstanceState) Descriptor() protoreflect.EnumDescriptor { + return file_ring_ring_proto_enumTypes[0].Descriptor() +} + +func (InstanceState) Type() protoreflect.EnumType { + return &file_ring_ring_proto_enumTypes[0] +} + +func (x InstanceState) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use InstanceState.Descriptor instead. func (InstanceState) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_26381ed67e202a6e, []int{0} + return file_ring_ring_proto_rawDescGZIP(), []int{0} } // Desc is the top-level type used to model a ring, containing information for individual instances. type Desc struct { - Ingesters map[string]InstanceDesc `protobuf:"bytes,1,rep,name=ingesters,proto3" json:"ingesters" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + state protoimpl.MessageState `protogen:"open.v1"` + Ingesters map[string]*InstanceDesc `protobuf:"bytes,1,rep,name=ingesters,proto3" json:"ingesters,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } -func (m *Desc) Reset() { *m = Desc{} } -func (*Desc) ProtoMessage() {} -func (*Desc) Descriptor() ([]byte, []int) { - return fileDescriptor_26381ed67e202a6e, []int{0} +func (x *Desc) Reset() { + *x = Desc{} + mi := &file_ring_ring_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } -func (m *Desc) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + +func (x *Desc) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *Desc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Desc.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err + +func (*Desc) ProtoMessage() {} + +func (x *Desc) ProtoReflect() protoreflect.Message { + mi := &file_ring_ring_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) } - return b[:n], nil + return ms } -} -func (m *Desc) XXX_Merge(src proto.Message) { - xxx_messageInfo_Desc.Merge(m, src) -} -func (m *Desc) XXX_Size() int { - return m.Size() -} -func (m *Desc) XXX_DiscardUnknown() { - xxx_messageInfo_Desc.DiscardUnknown(m) + return mi.MessageOf(x) } -var xxx_messageInfo_Desc proto.InternalMessageInfo +// Deprecated: Use Desc.ProtoReflect.Descriptor instead. +func (*Desc) Descriptor() ([]byte, []int) { + return file_ring_ring_proto_rawDescGZIP(), []int{0} +} -func (m *Desc) GetIngesters() map[string]InstanceDesc { - if m != nil { - return m.Ingesters +func (x *Desc) GetIngesters() map[string]*InstanceDesc { + if x != nil { + return x.Ingesters } return nil } // InstanceDesc is the top-level type used to model per-instance information in a ring. type InstanceDesc struct { - Addr string `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + Addr string `protobuf:"bytes,1,opt,name=addr,proto3" json:"addr,omitempty"` // Unix timestamp (with seconds precision) of the last heartbeat sent // by this instance. Timestamp int64 `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"` @@ -136,1127 +156,202 @@ type InstanceDesc struct { // Indicates whether this instance is read only. // Read-only instances go through standard state changes, and special handling is applied to them // during shuffle shards. - ReadOnly bool `protobuf:"varint,11,opt,name=read_only,json=readOnly,proto3" json:"read_only,omitempty"` + ReadOnly bool `protobuf:"varint,11,opt,name=read_only,json=readOnly,proto3" json:"read_only,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } -func (m *InstanceDesc) Reset() { *m = InstanceDesc{} } -func (*InstanceDesc) ProtoMessage() {} -func (*InstanceDesc) Descriptor() ([]byte, []int) { - return fileDescriptor_26381ed67e202a6e, []int{1} +func (x *InstanceDesc) Reset() { + *x = InstanceDesc{} + mi := &file_ring_ring_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } -func (m *InstanceDesc) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + +func (x *InstanceDesc) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *InstanceDesc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_InstanceDesc.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err + +func (*InstanceDesc) ProtoMessage() {} + +func (x *InstanceDesc) ProtoReflect() protoreflect.Message { + mi := &file_ring_ring_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) } - return b[:n], nil + return ms } -} -func (m *InstanceDesc) XXX_Merge(src proto.Message) { - xxx_messageInfo_InstanceDesc.Merge(m, src) -} -func (m *InstanceDesc) XXX_Size() int { - return m.Size() -} -func (m *InstanceDesc) XXX_DiscardUnknown() { - xxx_messageInfo_InstanceDesc.DiscardUnknown(m) + return mi.MessageOf(x) } -var xxx_messageInfo_InstanceDesc proto.InternalMessageInfo +// Deprecated: Use InstanceDesc.ProtoReflect.Descriptor instead. +func (*InstanceDesc) Descriptor() ([]byte, []int) { + return file_ring_ring_proto_rawDescGZIP(), []int{1} +} -func (m *InstanceDesc) GetAddr() string { - if m != nil { - return m.Addr +func (x *InstanceDesc) GetAddr() string { + if x != nil { + return x.Addr } return "" } -func (m *InstanceDesc) GetTimestamp() int64 { - if m != nil { - return m.Timestamp +func (x *InstanceDesc) GetTimestamp() int64 { + if x != nil { + return x.Timestamp } return 0 } -func (m *InstanceDesc) GetState() InstanceState { - if m != nil { - return m.State +func (x *InstanceDesc) GetState() InstanceState { + if x != nil { + return x.State } - return ACTIVE + return InstanceState_ACTIVE } -func (m *InstanceDesc) GetTokens() []uint32 { - if m != nil { - return m.Tokens +func (x *InstanceDesc) GetTokens() []uint32 { + if x != nil { + return x.Tokens } return nil } -func (m *InstanceDesc) GetZone() string { - if m != nil { - return m.Zone +func (x *InstanceDesc) GetZone() string { + if x != nil { + return x.Zone } return "" } -func (m *InstanceDesc) GetRegisteredTimestamp() int64 { - if m != nil { - return m.RegisteredTimestamp +func (x *InstanceDesc) GetRegisteredTimestamp() int64 { + if x != nil { + return x.RegisteredTimestamp } return 0 } -func (m *InstanceDesc) GetId() string { - if m != nil { - return m.Id +func (x *InstanceDesc) GetId() string { + if x != nil { + return x.Id } return "" } -func (m *InstanceDesc) GetReadOnlyUpdatedTimestamp() int64 { - if m != nil { - return m.ReadOnlyUpdatedTimestamp +func (x *InstanceDesc) GetReadOnlyUpdatedTimestamp() int64 { + if x != nil { + return x.ReadOnlyUpdatedTimestamp } return 0 } -func (m *InstanceDesc) GetReadOnly() bool { - if m != nil { - return m.ReadOnly +func (x *InstanceDesc) GetReadOnly() bool { + if x != nil { + return x.ReadOnly } return false } -func init() { - proto.RegisterEnum("ring.InstanceState", InstanceState_name, InstanceState_value) - proto.RegisterType((*Desc)(nil), "ring.Desc") - proto.RegisterMapType((map[string]InstanceDesc)(nil), "ring.Desc.IngestersEntry") - proto.RegisterType((*InstanceDesc)(nil), "ring.InstanceDesc") -} - -func init() { proto.RegisterFile("ring.proto", fileDescriptor_26381ed67e202a6e) } - -var fileDescriptor_26381ed67e202a6e = []byte{ - // 478 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x92, 0x31, 0x6f, 0xd3, 0x40, - 0x1c, 0xc5, 0x7d, 0xf6, 0xc5, 0xb5, 0xff, 0xa1, 0x91, 0x75, 0x45, 0xc8, 0xb4, 0xe8, 0xb0, 0x3a, - 0x19, 0x24, 0x52, 0x11, 0x18, 0x10, 0x52, 0x87, 0x96, 0x1a, 0xe4, 0x28, 0x4a, 0x2b, 0x13, 0xba, - 0x46, 0x4e, 0x7c, 0x18, 0xab, 0x89, 0x1d, 0xd9, 0x17, 0xa4, 0x30, 0xf1, 0x11, 0xf8, 0x02, 0xec, - 0x7c, 0x0e, 0xa6, 0x8e, 0x19, 0x3b, 0x21, 0xe2, 0x2c, 0x8c, 0xfd, 0x08, 0xe8, 0xce, 0x6d, 0xdd, - 0x6c, 0xef, 0xe5, 0xbd, 0xff, 0xef, 0xe5, 0x24, 0x03, 0xe4, 0x49, 0x1a, 0xb7, 0x67, 0x79, 0xc6, - 0x33, 0x82, 0x85, 0xde, 0x7d, 0x11, 0x27, 0xfc, 0xcb, 0x7c, 0xd4, 0x1e, 0x67, 0xd3, 0x83, 0x38, - 0x8b, 0xb3, 0x03, 0x19, 0x8e, 0xe6, 0x9f, 0xa5, 0x93, 0x46, 0xaa, 0xea, 0x68, 0xff, 0x27, 0x02, - 0x7c, 0xc2, 0x8a, 0x31, 0x39, 0x04, 0x33, 0x49, 0x63, 0x56, 0x70, 0x96, 0x17, 0x36, 0x72, 0x34, - 0xb7, 0xd9, 0x79, 0xdc, 0x96, 0x74, 0x11, 0xb7, 0xfd, 0xdb, 0xcc, 0x4b, 0x79, 0xbe, 0x38, 0xc6, - 0x97, 0x7f, 0x9e, 0x2a, 0x41, 0x7d, 0xb1, 0x7b, 0x06, 0xad, 0xcd, 0x0a, 0xb1, 0x40, 0xbb, 0x60, - 0x0b, 0x1b, 0x39, 0xc8, 0x35, 0x03, 0x21, 0x89, 0x0b, 0x8d, 0xaf, 0xe1, 0x64, 0xce, 0x6c, 0xd5, - 0x41, 0x6e, 0xb3, 0x43, 0x2a, 0xbc, 0x9f, 0x16, 0x3c, 0x4c, 0xc7, 0x4c, 0xcc, 0x04, 0x55, 0xe1, - 0xad, 0xfa, 0x06, 0x75, 0xb1, 0xa1, 0x5a, 0xda, 0xfe, 0x6f, 0x15, 0x1e, 0xdc, 0x6f, 0x10, 0x02, - 0x38, 0x8c, 0xa2, 0xfc, 0x86, 0x2b, 0x35, 0x79, 0x02, 0x26, 0x4f, 0xa6, 0xac, 0xe0, 0xe1, 0x74, - 0x26, 0xe1, 0x5a, 0x50, 0xff, 0x40, 0x9e, 0x41, 0xa3, 0xe0, 0x21, 0x67, 0xb6, 0xe6, 0x20, 0xb7, - 0xd5, 0xd9, 0xd9, 0x9c, 0xfd, 0x28, 0xa2, 0xa0, 0x6a, 0x90, 0x47, 0xa0, 0xf3, 0xec, 0x82, 0xa5, - 0x85, 0xad, 0x3b, 0x9a, 0xbb, 0x1d, 0xdc, 0x38, 0x31, 0xfa, 0x2d, 0x4b, 0x99, 0xbd, 0x55, 0x8d, - 0x0a, 0x4d, 0x5e, 0xc2, 0xc3, 0x9c, 0xc5, 0x89, 0x78, 0x31, 0x8b, 0x86, 0xf5, 0xbe, 0x21, 0xf7, - 0x77, 0xea, 0x6c, 0x70, 0xf7, 0x4f, 0x5a, 0xa0, 0x26, 0x91, 0x6d, 0x4a, 0x88, 0x9a, 0x44, 0xe4, - 0x10, 0xf6, 0x72, 0x16, 0x46, 0xc3, 0x2c, 0x9d, 0x2c, 0x86, 0xf3, 0x59, 0x14, 0xf2, 0x0d, 0x12, - 0x48, 0x92, 0x2d, 0x2a, 0xa7, 0xe9, 0x64, 0xf1, 0xa9, 0x2a, 0xd4, 0xb8, 0x3d, 0x30, 0xef, 0xce, - 0xed, 0xa6, 0x83, 0x5c, 0x23, 0x30, 0x6e, 0xcb, 0x5d, 0x6c, 0x60, 0xab, 0xd1, 0xc5, 0x46, 0xc3, - 0xd2, 0x9f, 0xf7, 0x60, 0x7b, 0xe3, 0xb9, 0x04, 0x40, 0x3f, 0x7a, 0x37, 0xf0, 0xcf, 0x3d, 0x4b, - 0x21, 0x4d, 0xd8, 0xea, 0x79, 0x47, 0xe7, 0x7e, 0xff, 0x83, 0x85, 0x84, 0x39, 0xf3, 0xfa, 0x27, - 0xc2, 0xa8, 0xc2, 0x74, 0x4f, 0xfd, 0xbe, 0x30, 0x1a, 0x31, 0x00, 0xf7, 0xbc, 0xf7, 0x03, 0x0b, - 0x1f, 0xbf, 0x5e, 0xae, 0xa8, 0x72, 0xb5, 0xa2, 0xca, 0xf5, 0x8a, 0xa2, 0xef, 0x25, 0x45, 0xbf, - 0x4a, 0x8a, 0x2e, 0x4b, 0x8a, 0x96, 0x25, 0x45, 0x7f, 0x4b, 0x8a, 0xfe, 0x95, 0x54, 0xb9, 0x2e, - 0x29, 0xfa, 0xb1, 0xa6, 0xca, 0x72, 0x4d, 0x95, 0xab, 0x35, 0x55, 0x46, 0xba, 0xfc, 0xde, 0x5e, - 0xfd, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x6a, 0x5b, 0x75, 0x81, 0xb2, 0x02, 0x00, 0x00, -} - -func (x InstanceState) String() string { - s, ok := InstanceState_name[int32(x)] - if ok { - return s - } - return strconv.Itoa(int(x)) -} -func (this *Desc) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Desc) - if !ok { - that2, ok := that.(Desc) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.Ingesters) != len(that1.Ingesters) { - return false - } - for i := range this.Ingesters { - a := this.Ingesters[i] - b := that1.Ingesters[i] - if !(&a).Equal(&b) { - return false - } - } - return true -} -func (this *InstanceDesc) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*InstanceDesc) - if !ok { - that2, ok := that.(InstanceDesc) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Addr != that1.Addr { - return false - } - if this.Timestamp != that1.Timestamp { - return false - } - if this.State != that1.State { - return false - } - if len(this.Tokens) != len(that1.Tokens) { - return false - } - for i := range this.Tokens { - if this.Tokens[i] != that1.Tokens[i] { - return false - } - } - if this.Zone != that1.Zone { - return false - } - if this.RegisteredTimestamp != that1.RegisteredTimestamp { - return false - } - if this.Id != that1.Id { - return false - } - if this.ReadOnlyUpdatedTimestamp != that1.ReadOnlyUpdatedTimestamp { - return false - } - if this.ReadOnly != that1.ReadOnly { - return false - } - return true -} -func (this *Desc) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 5) - s = append(s, "&ring.Desc{") - keysForIngesters := make([]string, 0, len(this.Ingesters)) - for k, _ := range this.Ingesters { - keysForIngesters = append(keysForIngesters, k) - } - github_com_gogo_protobuf_sortkeys.Strings(keysForIngesters) - mapStringForIngesters := "map[string]InstanceDesc{" - for _, k := range keysForIngesters { - mapStringForIngesters += fmt.Sprintf("%#v: %#v,", k, this.Ingesters[k]) - } - mapStringForIngesters += "}" - if this.Ingesters != nil { - s = append(s, "Ingesters: "+mapStringForIngesters+",\n") - } - s = append(s, "}") - return strings.Join(s, "") -} -func (this *InstanceDesc) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 13) - s = append(s, "&ring.InstanceDesc{") - s = append(s, "Addr: "+fmt.Sprintf("%#v", this.Addr)+",\n") - s = append(s, "Timestamp: "+fmt.Sprintf("%#v", this.Timestamp)+",\n") - s = append(s, "State: "+fmt.Sprintf("%#v", this.State)+",\n") - s = append(s, "Tokens: "+fmt.Sprintf("%#v", this.Tokens)+",\n") - s = append(s, "Zone: "+fmt.Sprintf("%#v", this.Zone)+",\n") - s = append(s, "RegisteredTimestamp: "+fmt.Sprintf("%#v", this.RegisteredTimestamp)+",\n") - s = append(s, "Id: "+fmt.Sprintf("%#v", this.Id)+",\n") - s = append(s, "ReadOnlyUpdatedTimestamp: "+fmt.Sprintf("%#v", this.ReadOnlyUpdatedTimestamp)+",\n") - s = append(s, "ReadOnly: "+fmt.Sprintf("%#v", this.ReadOnly)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringRing(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} -func (m *Desc) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Desc) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *Desc) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Ingesters) > 0 { - for k := range m.Ingesters { - v := m.Ingesters[k] - baseI := i - { - size, err := (&v).MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintRing(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - i -= len(k) - copy(dAtA[i:], k) - i = encodeVarintRing(dAtA, i, uint64(len(k))) - i-- - dAtA[i] = 0xa - i = encodeVarintRing(dAtA, i, uint64(baseI-i)) - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *InstanceDesc) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *InstanceDesc) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *InstanceDesc) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.ReadOnly { - i-- - if m.ReadOnly { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i-- - dAtA[i] = 0x58 - } - if m.ReadOnlyUpdatedTimestamp != 0 { - i = encodeVarintRing(dAtA, i, uint64(m.ReadOnlyUpdatedTimestamp)) - i-- - dAtA[i] = 0x50 - } - if len(m.Id) > 0 { - i -= len(m.Id) - copy(dAtA[i:], m.Id) - i = encodeVarintRing(dAtA, i, uint64(len(m.Id))) - i-- - dAtA[i] = 0x4a - } - if m.RegisteredTimestamp != 0 { - i = encodeVarintRing(dAtA, i, uint64(m.RegisteredTimestamp)) - i-- - dAtA[i] = 0x40 - } - if len(m.Zone) > 0 { - i -= len(m.Zone) - copy(dAtA[i:], m.Zone) - i = encodeVarintRing(dAtA, i, uint64(len(m.Zone))) - i-- - dAtA[i] = 0x3a - } - if len(m.Tokens) > 0 { - dAtA3 := make([]byte, len(m.Tokens)*10) - var j2 int - for _, num := range m.Tokens { - for num >= 1<<7 { - dAtA3[j2] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j2++ - } - dAtA3[j2] = uint8(num) - j2++ - } - i -= j2 - copy(dAtA[i:], dAtA3[:j2]) - i = encodeVarintRing(dAtA, i, uint64(j2)) - i-- - dAtA[i] = 0x32 - } - if m.State != 0 { - i = encodeVarintRing(dAtA, i, uint64(m.State)) - i-- - dAtA[i] = 0x18 - } - if m.Timestamp != 0 { - i = encodeVarintRing(dAtA, i, uint64(m.Timestamp)) - i-- - dAtA[i] = 0x10 - } - if len(m.Addr) > 0 { - i -= len(m.Addr) - copy(dAtA[i:], m.Addr) - i = encodeVarintRing(dAtA, i, uint64(len(m.Addr))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func encodeVarintRing(dAtA []byte, offset int, v uint64) int { - offset -= sovRing(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *Desc) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Ingesters) > 0 { - for k, v := range m.Ingesters { - _ = k - _ = v - l = v.Size() - mapEntrySize := 1 + len(k) + sovRing(uint64(len(k))) + 1 + l + sovRing(uint64(l)) - n += mapEntrySize + 1 + sovRing(uint64(mapEntrySize)) - } - } - return n -} - -func (m *InstanceDesc) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = len(m.Addr) - if l > 0 { - n += 1 + l + sovRing(uint64(l)) - } - if m.Timestamp != 0 { - n += 1 + sovRing(uint64(m.Timestamp)) - } - if m.State != 0 { - n += 1 + sovRing(uint64(m.State)) - } - if len(m.Tokens) > 0 { - l = 0 - for _, e := range m.Tokens { - l += sovRing(uint64(e)) - } - n += 1 + sovRing(uint64(l)) + l - } - l = len(m.Zone) - if l > 0 { - n += 1 + l + sovRing(uint64(l)) - } - if m.RegisteredTimestamp != 0 { - n += 1 + sovRing(uint64(m.RegisteredTimestamp)) - } - l = len(m.Id) - if l > 0 { - n += 1 + l + sovRing(uint64(l)) - } - if m.ReadOnlyUpdatedTimestamp != 0 { - n += 1 + sovRing(uint64(m.ReadOnlyUpdatedTimestamp)) - } - if m.ReadOnly { - n += 2 - } - return n -} - -func sovRing(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozRing(x uint64) (n int) { - return sovRing(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *Desc) String() string { - if this == nil { - return "nil" - } - keysForIngesters := make([]string, 0, len(this.Ingesters)) - for k, _ := range this.Ingesters { - keysForIngesters = append(keysForIngesters, k) - } - github_com_gogo_protobuf_sortkeys.Strings(keysForIngesters) - mapStringForIngesters := "map[string]InstanceDesc{" - for _, k := range keysForIngesters { - mapStringForIngesters += fmt.Sprintf("%v: %v,", k, this.Ingesters[k]) - } - mapStringForIngesters += "}" - s := strings.Join([]string{`&Desc{`, - `Ingesters:` + mapStringForIngesters + `,`, - `}`, - }, "") - return s -} -func (this *InstanceDesc) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&InstanceDesc{`, - `Addr:` + fmt.Sprintf("%v", this.Addr) + `,`, - `Timestamp:` + fmt.Sprintf("%v", this.Timestamp) + `,`, - `State:` + fmt.Sprintf("%v", this.State) + `,`, - `Tokens:` + fmt.Sprintf("%v", this.Tokens) + `,`, - `Zone:` + fmt.Sprintf("%v", this.Zone) + `,`, - `RegisteredTimestamp:` + fmt.Sprintf("%v", this.RegisteredTimestamp) + `,`, - `Id:` + fmt.Sprintf("%v", this.Id) + `,`, - `ReadOnlyUpdatedTimestamp:` + fmt.Sprintf("%v", this.ReadOnlyUpdatedTimestamp) + `,`, - `ReadOnly:` + fmt.Sprintf("%v", this.ReadOnly) + `,`, - `}`, - }, "") - return s -} -func valueToStringRing(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *Desc) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Desc: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Desc: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Ingesters", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthRing - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthRing - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Ingesters == nil { - m.Ingesters = make(map[string]InstanceDesc) - } - var mapkey string - mapvalue := &InstanceDesc{} - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return ErrInvalidLengthRing - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey < 0 { - return ErrInvalidLengthRing - } - if postStringIndexmapkey > l { - return io.ErrUnexpectedEOF - } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - var mapmsglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapmsglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if mapmsglen < 0 { - return ErrInvalidLengthRing - } - postmsgIndex := iNdEx + mapmsglen - if postmsgIndex < 0 { - return ErrInvalidLengthRing - } - if postmsgIndex > l { - return io.ErrUnexpectedEOF - } - mapvalue = &InstanceDesc{} - if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { - return err - } - iNdEx = postmsgIndex - } else { - iNdEx = entryPreIndex - skippy, err := skipRing(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRing - } - if (iNdEx + skippy) > postIndex { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - m.Ingesters[mapkey] = *mapvalue - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipRing(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRing - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *InstanceDesc) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: InstanceDesc: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: InstanceDesc: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Addr", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRing - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthRing - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Addr = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Timestamp", wireType) - } - m.Timestamp = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Timestamp |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) - } - m.State = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.State |= InstanceState(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType == 0 { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Tokens = append(m.Tokens, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthRing - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthRing - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.Tokens) == 0 { - m.Tokens = make([]uint32, 0, elementCount) - } - for iNdEx < postIndex { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Tokens = append(m.Tokens, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Tokens", wireType) - } - case 7: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Zone", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRing - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthRing - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Zone = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RegisteredTimestamp", wireType) - } - m.RegisteredTimestamp = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.RegisteredTimestamp |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 9: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthRing - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthRing - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Id = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ReadOnlyUpdatedTimestamp", wireType) - } - m.ReadOnlyUpdatedTimestamp = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.ReadOnlyUpdatedTimestamp |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 11: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field ReadOnly", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowRing - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.ReadOnly = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipRing(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthRing - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipRing(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRing - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRing - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowRing - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthRing - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupRing - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthRing - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF +var File_ring_ring_proto protoreflect.FileDescriptor + +var file_ring_ring_proto_rawDesc = []byte{ + 0x0a, 0x0f, 0x72, 0x69, 0x6e, 0x67, 0x2f, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x04, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x97, 0x01, 0x0a, 0x04, 0x44, 0x65, 0x73, 0x63, + 0x12, 0x37, 0x0a, 0x09, 0x69, 0x6e, 0x67, 0x65, 0x73, 0x74, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x44, 0x65, 0x73, 0x63, 0x2e, + 0x49, 0x6e, 0x67, 0x65, 0x73, 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x09, + 0x69, 0x6e, 0x67, 0x65, 0x73, 0x74, 0x65, 0x72, 0x73, 0x1a, 0x50, 0x0a, 0x0e, 0x49, 0x6e, 0x67, + 0x65, 0x73, 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, + 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x28, 0x0a, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x72, + 0x69, 0x6e, 0x67, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x44, 0x65, 0x73, 0x63, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x4a, 0x04, 0x08, 0x02, 0x10, + 0x03, 0x22, 0xc2, 0x02, 0x0a, 0x0c, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x44, 0x65, + 0x73, 0x63, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, + 0x74, 0x61, 0x6d, 0x70, 0x12, 0x29, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x0e, 0x32, 0x13, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x49, 0x6e, 0x73, 0x74, 0x61, + 0x6e, 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, + 0x16, 0x0a, 0x06, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0d, 0x52, + 0x06, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x7a, 0x6f, 0x6e, 0x65, 0x18, + 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x7a, 0x6f, 0x6e, 0x65, 0x12, 0x31, 0x0a, 0x14, 0x72, + 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, + 0x61, 0x6d, 0x70, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x13, 0x72, 0x65, 0x67, 0x69, 0x73, + 0x74, 0x65, 0x72, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x0e, + 0x0a, 0x02, 0x69, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x3d, + 0x0a, 0x1b, 0x72, 0x65, 0x61, 0x64, 0x5f, 0x6f, 0x6e, 0x6c, 0x79, 0x5f, 0x75, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x64, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x0a, 0x20, + 0x01, 0x28, 0x03, 0x52, 0x18, 0x72, 0x65, 0x61, 0x64, 0x4f, 0x6e, 0x6c, 0x79, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x1b, 0x0a, + 0x09, 0x72, 0x65, 0x61, 0x64, 0x5f, 0x6f, 0x6e, 0x6c, 0x79, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x08, 0x72, 0x65, 0x61, 0x64, 0x4f, 0x6e, 0x6c, 0x79, 0x4a, 0x04, 0x08, 0x04, 0x10, 0x05, + 0x4a, 0x04, 0x08, 0x05, 0x10, 0x06, 0x2a, 0x4c, 0x0a, 0x0d, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, + 0x63, 0x65, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x0a, 0x0a, 0x06, 0x41, 0x43, 0x54, 0x49, 0x56, + 0x45, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x4c, 0x45, 0x41, 0x56, 0x49, 0x4e, 0x47, 0x10, 0x01, + 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x45, 0x4e, 0x44, 0x49, 0x4e, 0x47, 0x10, 0x02, 0x12, 0x0b, 0x0a, + 0x07, 0x4a, 0x4f, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x4c, 0x45, + 0x46, 0x54, 0x10, 0x04, 0x42, 0x29, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x61, 0x66, 0x61, 0x6e, 0x61, 0x2f, 0x63, 0x6f, 0x72, 0x74, 0x65, + 0x78, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x72, 0x69, 0x6e, 0x67, 0x3b, 0x72, 0x69, 0x6e, 0x67, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - ErrInvalidLengthRing = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowRing = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupRing = fmt.Errorf("proto: unexpected end of group") + file_ring_ring_proto_rawDescOnce sync.Once + file_ring_ring_proto_rawDescData = file_ring_ring_proto_rawDesc ) + +func file_ring_ring_proto_rawDescGZIP() []byte { + file_ring_ring_proto_rawDescOnce.Do(func() { + file_ring_ring_proto_rawDescData = protoimpl.X.CompressGZIP(file_ring_ring_proto_rawDescData) + }) + return file_ring_ring_proto_rawDescData +} + +var file_ring_ring_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_ring_ring_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_ring_ring_proto_goTypes = []any{ + (InstanceState)(0), // 0: ring.InstanceState + (*Desc)(nil), // 1: ring.Desc + (*InstanceDesc)(nil), // 2: ring.InstanceDesc + nil, // 3: ring.Desc.IngestersEntry +} +var file_ring_ring_proto_depIdxs = []int32{ + 3, // 0: ring.Desc.ingesters:type_name -> ring.Desc.IngestersEntry + 0, // 1: ring.InstanceDesc.state:type_name -> ring.InstanceState + 2, // 2: ring.Desc.IngestersEntry.value:type_name -> ring.InstanceDesc + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_ring_ring_proto_init() } +func file_ring_ring_proto_init() { + if File_ring_ring_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_ring_ring_proto_rawDesc, + NumEnums: 1, + NumMessages: 3, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_ring_ring_proto_goTypes, + DependencyIndexes: file_ring_ring_proto_depIdxs, + EnumInfos: file_ring_ring_proto_enumTypes, + MessageInfos: file_ring_ring_proto_msgTypes, + }.Build() + File_ring_ring_proto = out.File + file_ring_ring_proto_rawDesc = nil + file_ring_ring_proto_goTypes = nil + file_ring_ring_proto_depIdxs = nil +} diff --git a/ring/ring.proto b/ring/ring.proto index 7795e8493..13a62fb3a 100644 --- a/ring/ring.proto +++ b/ring/ring.proto @@ -2,14 +2,11 @@ syntax = "proto3"; package ring; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; - -option (gogoproto.marshaler_all) = true; -option (gogoproto.unmarshaler_all) = true; +option go_package = "github.com/grafana/cortex/pkg/ring;ring"; // Desc is the top-level type used to model a ring, containing information for individual instances. message Desc { - map ingesters = 1 [(gogoproto.nullable) = false]; + map ingesters = 1; reserved 2; } From 6876e3a7efccf962455e995e2bc1210a54d25f1f Mon Sep 17 00:00:00 2001 From: francoposa Date: Mon, 13 Jan 2025 11:21:06 -0800 Subject: [PATCH 03/22] replace enum value references with new prefixed enums --- ring/basic_lifecycler.go | 4 +- ring/basic_lifecycler_delegates.go | 4 +- ring/basic_lifecycler_delegates_test.go | 56 ++--- ring/basic_lifecycler_test.go | 68 ++--- ring/bench/ring_memberlist_test.go | 2 +- ring/example/local/local.go | 2 +- ring/flush.go | 2 +- ring/lifecycler.go | 68 ++--- ring/lifecycler_test.go | 102 ++++---- ring/merge_test.go | 156 ++++++------ ring/model.go | 38 +-- ring/model_test.go | 28 +-- ring/partition_instance_lifecycler.go | 4 +- ring/partition_instance_ring_test.go | 44 ++-- ring/partition_ring.go | 16 +- ring/partition_ring_desc.proto | 2 +- ring/partition_ring_test.go | 10 +- ring/partition_ring_watcher_test.go | 4 +- ring/replication_set.go | 4 +- ring/replication_set_test.go | 2 +- ring/ring.go | 26 +- ring/ring.proto | 10 +- ring/ring_http_test.go | 8 +- ring/ring_test.go | 236 +++++++++--------- .../spread_minimizing_token_generator_test.go | 6 +- ring/token_range_test.go | 2 +- ring/util.go | 2 +- ring/util_test.go | 28 +-- servicediscovery/ring.go | 2 +- servicediscovery/ring_test.go | 30 +-- 30 files changed, 483 insertions(+), 483 deletions(-) diff --git a/ring/basic_lifecycler.go b/ring/basic_lifecycler.go index 1a2e10380..214939d99 100644 --- a/ring/basic_lifecycler.go +++ b/ring/basic_lifecycler.go @@ -147,7 +147,7 @@ func (l *BasicLifecycler) GetState() InstanceState { defer l.currState.RUnlock() if l.currInstanceDesc == nil { - return PENDING + return InstanceState_PENDING } return l.currInstanceDesc.GetState() @@ -250,7 +250,7 @@ func (l *BasicLifecycler) stopping(runningError error) error { return nil } - // Let the delegate change the instance state (ie. to LEAVING) and handling any + // Let the delegate change the instance state (ie. to InstanceState_LEAVING) and handling any // state transferring / flushing while we continue to heartbeat. done := make(chan struct{}) go func() { diff --git a/ring/basic_lifecycler_delegates.go b/ring/basic_lifecycler_delegates.go index 34cc0d92a..4f77ac43b 100644 --- a/ring/basic_lifecycler_delegates.go +++ b/ring/basic_lifecycler_delegates.go @@ -30,8 +30,8 @@ func (d *LeaveOnStoppingDelegate) OnRingInstanceTokens(lifecycler *BasicLifecycl } func (d *LeaveOnStoppingDelegate) OnRingInstanceStopping(lifecycler *BasicLifecycler) { - if err := lifecycler.changeState(context.Background(), LEAVING); err != nil { - level.Error(d.logger).Log("msg", "failed to change instance state to LEAVING in the ring", "err", err) + if err := lifecycler.changeState(context.Background(), InstanceState_LEAVING); err != nil { + level.Error(d.logger).Log("msg", "failed to change instance state to InstanceState_LEAVING in the ring", "err", err) } d.next.OnRingInstanceStopping(lifecycler) diff --git a/ring/basic_lifecycler_delegates_test.go b/ring/basic_lifecycler_delegates_test.go index 6fa0980b5..a525573b5 100644 --- a/ring/basic_lifecycler_delegates_test.go +++ b/ring/basic_lifecycler_delegates_test.go @@ -24,7 +24,7 @@ func TestLeaveOnStoppingDelegate(t *testing.T) { testDelegate := &mockDelegate{ onStopping: func(l *BasicLifecycler) { - assert.Equal(t, LEAVING, l.GetState()) + assert.Equal(t, InstanceState_LEAVING, l.GetState()) onStoppingCalled = true }, } @@ -47,13 +47,13 @@ func TestTokensPersistencyDelegate_ShouldSkipTokensLoadingIfFileDoesNotExist(t * testDelegate := &mockDelegate{ onRegister: func(_ *BasicLifecycler, _ Desc, instanceExists bool, _ string, _ InstanceDesc) (InstanceState, Tokens) { assert.False(t, instanceExists) - return JOINING, Tokens{1, 2, 3, 4, 5} + return InstanceState_JOINING, Tokens{1, 2, 3, 4, 5} }, } logs := &concurrency.SyncBuffer{} logger := log.NewLogfmtLogger(logs) - persistencyDelegate := NewTokensPersistencyDelegate(tokensFile.Name(), ACTIVE, testDelegate, logger) + persistencyDelegate := NewTokensPersistencyDelegate(tokensFile.Name(), InstanceState_ACTIVE, testDelegate, logger) ctx := context.Background() cfg := prepareBasicLifecyclerConfig() @@ -62,7 +62,7 @@ func TestTokensPersistencyDelegate_ShouldSkipTokensLoadingIfFileDoesNotExist(t * defer services.StopAndAwaitTerminated(ctx, lifecycler) //nolint:errcheck require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) - assert.Equal(t, JOINING, lifecycler.GetState()) + assert.Equal(t, InstanceState_JOINING, lifecycler.GetState()) assert.Equal(t, Tokens{1, 2, 3, 4, 5}, lifecycler.GetTokens()) assert.True(t, lifecycler.IsRegistered()) @@ -89,7 +89,7 @@ func TestTokensPersistencyDelegate_ShouldLoadTokensFromFileIfFileExist(t *testin testDelegate := &mockDelegate{ onRegister: func(_ *BasicLifecycler, _ Desc, instanceExists bool, _ string, instanceDesc InstanceDesc) (InstanceState, Tokens) { assert.True(t, instanceExists) - assert.Equal(t, ACTIVE, instanceDesc.GetState()) + assert.Equal(t, InstanceState_ACTIVE, instanceDesc.GetState()) assert.Equal(t, storedTokens, Tokens(instanceDesc.GetTokens())) assert.True(t, instanceDesc.GetRegisteredAt().IsZero()) @@ -97,7 +97,7 @@ func TestTokensPersistencyDelegate_ShouldLoadTokensFromFileIfFileExist(t *testin }, } - persistencyDelegate := NewTokensPersistencyDelegate(tokensFile.Name(), ACTIVE, testDelegate, log.NewNopLogger()) + persistencyDelegate := NewTokensPersistencyDelegate(tokensFile.Name(), InstanceState_ACTIVE, testDelegate, log.NewNopLogger()) ctx := context.Background() cfg := prepareBasicLifecyclerConfig() @@ -105,7 +105,7 @@ func TestTokensPersistencyDelegate_ShouldLoadTokensFromFileIfFileExist(t *testin require.NoError(t, err) require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) - assert.Equal(t, ACTIVE, lifecycler.GetState()) + assert.Equal(t, InstanceState_ACTIVE, lifecycler.GetState()) assert.Equal(t, storedTokens, lifecycler.GetTokens()) assert.True(t, lifecycler.IsRegistered()) assert.InDelta(t, time.Now().Unix(), lifecycler.GetRegisteredAt().Unix(), 2) @@ -130,15 +130,15 @@ func TestTokensPersistencyDelegate_ShouldHandleTheCaseTheInstanceIsAlreadyInTheR expectedTokens Tokens }{ "instance already registered in the ring without tokens": { - initialState: PENDING, + initialState: InstanceState_PENDING, initialTokens: nil, - expectedState: ACTIVE, + expectedState: InstanceState_ACTIVE, expectedTokens: storedTokens, }, "instance already registered in the ring with tokens": { - initialState: JOINING, + initialState: InstanceState_JOINING, initialTokens: differentTokens, - expectedState: JOINING, + expectedState: InstanceState_JOINING, expectedTokens: differentTokens, }, } @@ -161,7 +161,7 @@ func TestTokensPersistencyDelegate_ShouldHandleTheCaseTheInstanceIsAlreadyInTheR }, } - persistencyDelegate := NewTokensPersistencyDelegate(tokensFile.Name(), ACTIVE, testDelegate, log.NewNopLogger()) + persistencyDelegate := NewTokensPersistencyDelegate(tokensFile.Name(), InstanceState_ACTIVE, testDelegate, log.NewNopLogger()) ctx := context.Background() cfg := prepareBasicLifecyclerConfig() @@ -199,15 +199,15 @@ func TestDelegatesChain(t *testing.T) { chain = &mockDelegate{ onRegister: func(_ *BasicLifecycler, _ Desc, instanceExists bool, _ string, _ InstanceDesc) (InstanceState, Tokens) { assert.False(t, instanceExists) - return JOINING, Tokens{1, 2, 3, 4, 5} + return InstanceState_JOINING, Tokens{1, 2, 3, 4, 5} }, onStopping: func(l *BasicLifecycler) { - assert.Equal(t, LEAVING, l.GetState()) + assert.Equal(t, InstanceState_LEAVING, l.GetState()) onStoppingCalled = true }, } - chain = NewTokensPersistencyDelegate(tokensFile.Name(), ACTIVE, chain, log.NewNopLogger()) + chain = NewTokensPersistencyDelegate(tokensFile.Name(), InstanceState_ACTIVE, chain, log.NewNopLogger()) chain = NewLeaveOnStoppingDelegate(chain, log.NewNopLogger()) chain = NewAutoForgetDelegate(time.Minute, chain, log.NewNopLogger()) @@ -218,7 +218,7 @@ func TestDelegatesChain(t *testing.T) { defer services.StopAndAwaitTerminated(ctx, lifecycler) //nolint:errcheck require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) - assert.Equal(t, JOINING, lifecycler.GetState()) + assert.Equal(t, InstanceState_JOINING, lifecycler.GetState()) assert.Equal(t, Tokens{1, 2, 3, 4, 5}, lifecycler.GetTokens()) assert.True(t, lifecycler.IsRegistered()) @@ -242,13 +242,13 @@ func TestAutoForgetDelegate(t *testing.T) { }{ "no unhealthy instance in the ring": { setup: func(ringDesc *Desc) { - ringDesc.AddIngester("instance-1", "1.1.1.1", "", nil, ACTIVE, registeredAt, false, readOnlyUpdated) + ringDesc.AddIngester("instance-1", "1.1.1.1", "", nil, InstanceState_ACTIVE, registeredAt, false, readOnlyUpdated) }, expectedInstances: []string{testInstanceID, "instance-1"}, }, "unhealthy instance in the ring that has NOTreached the forget period yet": { setup: func(ringDesc *Desc) { - i := ringDesc.AddIngester("instance-1", "1.1.1.1", "", nil, ACTIVE, registeredAt, false, readOnlyUpdated) + i := ringDesc.AddIngester("instance-1", "1.1.1.1", "", nil, InstanceState_ACTIVE, registeredAt, false, readOnlyUpdated) i.Timestamp = time.Now().Add(-forgetPeriod).Add(5 * time.Second).Unix() ringDesc.Ingesters["instance-1"] = i }, @@ -256,7 +256,7 @@ func TestAutoForgetDelegate(t *testing.T) { }, "unhealthy instance in the ring that has reached the forget period": { setup: func(ringDesc *Desc) { - i := ringDesc.AddIngester("instance-1", "1.1.1.1", "", nil, ACTIVE, registeredAt, false, readOnlyUpdated) + i := ringDesc.AddIngester("instance-1", "1.1.1.1", "", nil, InstanceState_ACTIVE, registeredAt, false, readOnlyUpdated) i.Timestamp = time.Now().Add(-forgetPeriod).Add(-5 * time.Second).Unix() ringDesc.Ingesters["instance-1"] = i }, @@ -310,8 +310,8 @@ func TestAutoForgetDelegate(t *testing.T) { func TestInstanceRegisterDelegate_OnRingInstanceRegister(t *testing.T) { const tokenCount = 128 - t.Run("no previous tokens, JOINING state", func(t *testing.T) { - delegate := NewInstanceRegisterDelegate(JOINING, 128) + t.Run("no previous tokens, InstanceState_JOINING state", func(t *testing.T) { + delegate := NewInstanceRegisterDelegate(InstanceState_JOINING, 128) cfg := prepareBasicLifecyclerConfig() cfg.HeartbeatPeriod = 100 * time.Millisecond @@ -321,18 +321,18 @@ func TestInstanceRegisterDelegate_OnRingInstanceRegister(t *testing.T) { otherIngesterTokens := []uint32{100, 200, 300, 400, 500} desc := NewDesc() - desc.AddIngester("other-instance", "addr", "zone", otherIngesterTokens, ACTIVE, time.Now(), false, time.Time{}) + desc.AddIngester("other-instance", "addr", "zone", otherIngesterTokens, InstanceState_ACTIVE, time.Now(), false, time.Time{}) state, tokens := delegate.OnRingInstanceRegister(lifecycler, *desc, false, "test-instance", InstanceDesc{}) - require.Equal(t, JOINING, state) + require.Equal(t, InstanceState_JOINING, state) require.Equal(t, tokenCount, len(tokens)) for _, tok := range otherIngesterTokens { require.NotContains(t, tokens, tok) } }) - t.Run("with previous tokens, ACTIVE state", func(t *testing.T) { - delegate := NewInstanceRegisterDelegate(ACTIVE, 128) + t.Run("with previous tokens, InstanceState_ACTIVE state", func(t *testing.T) { + delegate := NewInstanceRegisterDelegate(InstanceState_ACTIVE, 128) cfg := prepareBasicLifecyclerConfig() cfg.HeartbeatPeriod = 100 * time.Millisecond @@ -342,13 +342,13 @@ func TestInstanceRegisterDelegate_OnRingInstanceRegister(t *testing.T) { otherIngesterTokens := []uint32{100, 200, 300, 400, 500} desc := NewDesc() - desc.AddIngester("other-instance", "addr", "zone", otherIngesterTokens, ACTIVE, time.Now(), false, time.Time{}) + desc.AddIngester("other-instance", "addr", "zone", otherIngesterTokens, InstanceState_ACTIVE, time.Now(), false, time.Time{}) prevTokens := []uint32{10, 20, 30} - desc.AddIngester("test-instance", "test-addr", "zone", prevTokens, JOINING, time.Now(), false, time.Time{}) + desc.AddIngester("test-instance", "test-addr", "zone", prevTokens, InstanceState_JOINING, time.Now(), false, time.Time{}) state, tokens := delegate.OnRingInstanceRegister(lifecycler, *desc, true, "test-instance", desc.GetIngesters()["test-instance"]) - require.Equal(t, ACTIVE, state) + require.Equal(t, InstanceState_ACTIVE, state) require.Equal(t, tokenCount, len(tokens)) for _, tok := range prevTokens { diff --git a/ring/basic_lifecycler_test.go b/ring/basic_lifecycler_test.go index df12bce6f..6d1330203 100644 --- a/ring/basic_lifecycler_test.go +++ b/ring/basic_lifecycler_test.go @@ -55,64 +55,64 @@ func TestBasicLifecycler_RegisterOnStart(t *testing.T) { registerTokens Tokens }{ "initial ring is empty": { - registerState: ACTIVE, + registerState: InstanceState_ACTIVE, registerTokens: Tokens{1, 2, 3, 4, 5}, }, "initial ring non empty (containing another instance)": { initialInstanceID: "instance-1", initialInstanceDesc: &InstanceDesc{ Addr: "1.1.1.1", - State: ACTIVE, + State: InstanceState_ACTIVE, Tokens: Tokens{6, 7, 8, 9, 10}, RegisteredTimestamp: time.Now().Add(-time.Hour).Unix(), }, - registerState: ACTIVE, + registerState: InstanceState_ACTIVE, registerTokens: Tokens{1, 2, 3, 4, 5}, }, "initial ring contains the same instance with different state, tokens and address (new one is 127.0.0.1)": { initialInstanceID: testInstanceID, initialInstanceDesc: &InstanceDesc{ Addr: "1.1.1.1", - State: ACTIVE, + State: InstanceState_ACTIVE, Tokens: Tokens{6, 7, 8, 9, 10}, RegisteredTimestamp: time.Now().Add(-time.Hour).Unix(), }, - registerState: JOINING, + registerState: InstanceState_JOINING, registerTokens: Tokens{1, 2, 3, 4, 5}, }, "initial ring contains the same instance with different address (new one is 127.0.0.1)": { initialInstanceID: testInstanceID, initialInstanceDesc: &InstanceDesc{ Addr: "1.1.1.1", - State: ACTIVE, + State: InstanceState_ACTIVE, Tokens: Tokens{1, 2, 3, 4, 5}, RegisteredTimestamp: time.Now().Add(-time.Hour).Unix(), }, - registerState: ACTIVE, + registerState: InstanceState_ACTIVE, registerTokens: Tokens{1, 2, 3, 4, 5}, }, "initial ring contains the same instance with registered timestamp == 0": { initialInstanceID: testInstanceID, initialInstanceDesc: &InstanceDesc{ Addr: "1.1.1.1", - State: ACTIVE, + State: InstanceState_ACTIVE, Tokens: Tokens{1, 2, 3, 4, 5}, RegisteredTimestamp: 0, }, - registerState: ACTIVE, + registerState: InstanceState_ACTIVE, registerTokens: Tokens{1, 2, 3, 4, 5}, }, "initial ring contains read only instance": { initialInstanceID: testInstanceID, initialInstanceDesc: &InstanceDesc{ Addr: "1.1.1.1", - State: ACTIVE, + State: InstanceState_ACTIVE, Tokens: Tokens{1, 2, 3, 4, 5}, RegisteredTimestamp: time.Now().Add(-time.Hour).Unix(), ReadOnly: true, ReadOnlyUpdatedTimestamp: time.Now().Unix(), }, - registerState: ACTIVE, + registerState: InstanceState_ACTIVE, registerTokens: Tokens{1, 2, 3, 4, 5}, }, } @@ -162,7 +162,7 @@ func TestBasicLifecycler_RegisterOnStart(t *testing.T) { assert.Equal(t, testInstanceID, lifecycler.GetInstanceID()) assert.Equal(t, services.New, lifecycler.State()) - assert.Equal(t, PENDING, lifecycler.GetState()) + assert.Equal(t, InstanceState_PENDING, lifecycler.GetState()) assert.Empty(t, lifecycler.GetTokens()) assert.False(t, lifecycler.IsRegistered()) assert.Equal(t, float64(0), testutil.ToFloat64(lifecycler.metrics.tokensOwned)) @@ -205,14 +205,14 @@ func TestBasicLifecycler_UnregisterOnStop(t *testing.T) { require.NoError(t, err) delegate.onRegister = func(_ *BasicLifecycler, _ Desc, _ bool, _ string, _ InstanceDesc) (InstanceState, Tokens) { - return ACTIVE, Tokens{1, 2, 3, 4, 5} + return InstanceState_ACTIVE, Tokens{1, 2, 3, 4, 5} } delegate.onStopping = func(_ *BasicLifecycler) { assert.Equal(t, services.Stopping, lifecycler.State()) } require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) - assert.Equal(t, ACTIVE, lifecycler.GetState()) + assert.Equal(t, InstanceState_ACTIVE, lifecycler.GetState()) assert.Equal(t, Tokens{1, 2, 3, 4, 5}, lifecycler.GetTokens()) assert.True(t, lifecycler.IsRegistered()) assert.NotZero(t, lifecycler.GetRegisteredAt()) @@ -220,7 +220,7 @@ func TestBasicLifecycler_UnregisterOnStop(t *testing.T) { assert.Equal(t, float64(cfg.NumTokens), testutil.ToFloat64(lifecycler.metrics.tokensToOwn)) require.NoError(t, services.StopAndAwaitTerminated(ctx, lifecycler)) - assert.Equal(t, PENDING, lifecycler.GetState()) + assert.Equal(t, InstanceState_PENDING, lifecycler.GetState()) assert.Equal(t, Tokens{}, lifecycler.GetTokens()) assert.False(t, lifecycler.IsRegistered()) assert.Zero(t, lifecycler.GetRegisteredAt()) @@ -242,14 +242,14 @@ func TestBasicLifecycler_KeepInTheRingOnStop(t *testing.T) { require.Equal(t, cfg.KeepInstanceInTheRingOnShutdown, lifecycler.ShouldKeepInstanceInTheRingOnShutdown()) delegate.onRegister = func(_ *BasicLifecycler, _ Desc, _ bool, _ string, _ InstanceDesc) (InstanceState, Tokens) { - return ACTIVE, Tokens{1, 2, 3, 4, 5} + return InstanceState_ACTIVE, Tokens{1, 2, 3, 4, 5} } delegate.onStopping = func(lifecycler *BasicLifecycler) { - require.NoError(t, lifecycler.changeState(context.Background(), LEAVING)) + require.NoError(t, lifecycler.changeState(context.Background(), InstanceState_LEAVING)) } require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) - assert.Equal(t, ACTIVE, lifecycler.GetState()) + assert.Equal(t, InstanceState_ACTIVE, lifecycler.GetState()) assert.Equal(t, Tokens{1, 2, 3, 4, 5}, lifecycler.GetTokens()) assert.True(t, lifecycler.IsRegistered()) assert.NotZero(t, lifecycler.GetRegisteredAt()) @@ -257,7 +257,7 @@ func TestBasicLifecycler_KeepInTheRingOnStop(t *testing.T) { assert.Equal(t, float64(cfg.NumTokens), testutil.ToFloat64(lifecycler.metrics.tokensToOwn)) require.NoError(t, services.StopAndAwaitTerminated(ctx, lifecycler)) - assert.Equal(t, LEAVING, lifecycler.GetState()) + assert.Equal(t, InstanceState_LEAVING, lifecycler.GetState()) assert.Equal(t, Tokens{1, 2, 3, 4, 5}, lifecycler.GetTokens()) assert.True(t, lifecycler.IsRegistered()) assert.NotZero(t, lifecycler.GetRegisteredAt()) @@ -269,7 +269,7 @@ func TestBasicLifecycler_KeepInTheRingOnStop(t *testing.T) { assert.True(t, ok) assert.Equal(t, cfg.ID, inst.GetId()) assert.Equal(t, cfg.Addr, inst.GetAddr()) - assert.Equal(t, LEAVING, inst.GetState()) + assert.Equal(t, InstanceState_LEAVING, inst.GetState()) assert.Equal(t, Tokens{1, 2, 3, 4, 5}, Tokens(inst.GetTokens())) assert.Equal(t, cfg.Zone, inst.GetZone()) } @@ -284,15 +284,15 @@ func TestBasicLifecycler_UnregisterFromTheRingOnStop(t *testing.T) { require.Equal(t, cfg.KeepInstanceInTheRingOnShutdown, lifecycler.ShouldKeepInstanceInTheRingOnShutdown()) delegate.onRegister = func(_ *BasicLifecycler, _ Desc, _ bool, _ string, _ InstanceDesc) (InstanceState, Tokens) { - return ACTIVE, Tokens{1, 2, 3, 4, 5} + return InstanceState_ACTIVE, Tokens{1, 2, 3, 4, 5} } delegate.onStopping = func(lifecycler *BasicLifecycler) { - require.NoError(t, lifecycler.changeState(context.Background(), LEAVING)) + require.NoError(t, lifecycler.changeState(context.Background(), InstanceState_LEAVING)) } // check that after StartAndAwaitRunning the instance is up and running require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) - assert.Equal(t, ACTIVE, lifecycler.GetState()) + assert.Equal(t, InstanceState_ACTIVE, lifecycler.GetState()) assert.Equal(t, Tokens{1, 2, 3, 4, 5}, lifecycler.GetTokens()) assert.True(t, lifecycler.IsRegistered()) assert.NotZero(t, lifecycler.GetRegisteredAt()) @@ -304,8 +304,8 @@ func TestBasicLifecycler_UnregisterFromTheRingOnStop(t *testing.T) { // check that after StopAndAwaitTerminated the instance is unregistered require.NoError(t, services.StopAndAwaitTerminated(ctx, lifecycler)) - assert.NotEqual(t, ACTIVE, lifecycler.GetState()) - assert.NotEqual(t, LEAVING, lifecycler.GetState()) + assert.NotEqual(t, InstanceState_ACTIVE, lifecycler.GetState()) + assert.NotEqual(t, InstanceState_LEAVING, lifecycler.GetState()) assert.Equal(t, Tokens{}, lifecycler.GetTokens()) assert.False(t, lifecycler.IsRegistered()) assert.Zero(t, lifecycler.GetRegisteredAt()) @@ -388,7 +388,7 @@ func TestBasicLifecycler_HeartbeatAfterBackendReset(t *testing.T) { registerTokens := Tokens{1, 2, 3, 4, 5} delegate.onRegister = func(_ *BasicLifecycler, _ Desc, _ bool, _ string, _ InstanceDesc) (state InstanceState, tokens Tokens) { - return ACTIVE, registerTokens + return InstanceState_ACTIVE, registerTokens } require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) @@ -410,7 +410,7 @@ func TestBasicLifecycler_HeartbeatAfterBackendReset(t *testing.T) { desc, ok := getInstanceFromStore(t, store, testInstanceID) return ok && desc.GetTimestamp() > 0 && - desc.GetState() == ACTIVE && + desc.GetState() == InstanceState_ACTIVE && Tokens(desc.GetTokens()).Equals(registerTokens) && desc.GetAddr() == cfg.Addr && desc.GetId() == cfg.ID @@ -430,13 +430,13 @@ func TestBasicLifecycler_ChangeState(t *testing.T) { defer services.StopAndAwaitTerminated(ctx, lifecycler) //nolint:errcheck delegate.onRegister = func(_ *BasicLifecycler, _ Desc, _ bool, _ string, _ InstanceDesc) (InstanceState, Tokens) { - return JOINING, Tokens{1, 2, 3, 4, 5} + return InstanceState_JOINING, Tokens{1, 2, 3, 4, 5} } require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) - assert.Equal(t, JOINING, lifecycler.GetState()) + assert.Equal(t, InstanceState_JOINING, lifecycler.GetState()) - for _, state := range []InstanceState{ACTIVE, LEAVING} { + for _, state := range []InstanceState{InstanceState_ACTIVE, InstanceState_LEAVING} { assert.NoError(t, lifecycler.ChangeState(ctx, state)) assert.Equal(t, state, lifecycler.GetState()) @@ -458,7 +458,7 @@ func TestBasicLifecycler_TokensObservePeriod(t *testing.T) { defer services.StopAndAwaitTerminated(ctx, lifecycler) //nolint:errcheck delegate.onRegister = func(_ *BasicLifecycler, _ Desc, _ bool, _ string, _ InstanceDesc) (InstanceState, Tokens) { - return ACTIVE, Tokens{1, 2, 3, 4, 5} + return InstanceState_ACTIVE, Tokens{1, 2, 3, 4, 5} } require.NoError(t, lifecycler.StartAsync(ctx)) @@ -499,7 +499,7 @@ func TestBasicLifecycler_updateInstance_ShouldAddInstanceToTheRingIfDoesNotExist registerTokens := Tokens{1, 2, 3, 4, 5} delegate.onRegister = func(_ *BasicLifecycler, _ Desc, _ bool, _ string, _ InstanceDesc) (state InstanceState, tokens Tokens) { - return ACTIVE, registerTokens + return InstanceState_ACTIVE, registerTokens } require.NoError(t, services.StartAndAwaitRunning(ctx, lifecycler)) @@ -521,7 +521,7 @@ func TestBasicLifecycler_updateInstance_ShouldAddInstanceToTheRingIfDoesNotExist desc, ok := getInstanceFromStore(t, store, testInstanceID) require.True(t, ok) assert.Equal(t, cfg.ID, desc.GetId()) - assert.Equal(t, ACTIVE, desc.GetState()) + assert.Equal(t, InstanceState_ACTIVE, desc.GetState()) assert.Equal(t, registerTokens, Tokens(desc.GetTokens())) assert.Equal(t, cfg.Addr, desc.GetAddr()) assert.Equal(t, expectedRegisteredAt.Unix(), desc.RegisteredTimestamp) @@ -564,7 +564,7 @@ type mockDelegate struct { func (m *mockDelegate) OnRingInstanceRegister(lifecycler *BasicLifecycler, ringDesc Desc, instanceExists bool, instanceID string, instanceDesc InstanceDesc) (InstanceState, Tokens) { if m.onRegister == nil { - return PENDING, Tokens{} + return InstanceState_PENDING, Tokens{} } return m.onRegister(lifecycler, ringDesc, instanceExists, instanceID, instanceDesc) diff --git a/ring/bench/ring_memberlist_test.go b/ring/bench/ring_memberlist_test.go index 161f08711..340103758 100644 --- a/ring/bench/ring_memberlist_test.go +++ b/ring/bench/ring_memberlist_test.go @@ -81,7 +81,7 @@ func BenchmarkMemberlistReceiveWithRingDesc(b *testing.B) { { for i := 0; i < numInstances; i++ { tokens := generateUniqueTokens(i, numTokens) - initialDesc.AddIngester(fmt.Sprintf("instance-%d", i), "127.0.0.1", "zone", tokens, ring.ACTIVE, time.Now(), false, time.Time{}) + initialDesc.AddIngester(fmt.Sprintf("instance-%d", i), "127.0.0.1", "zone", tokens, ring.InstanceState_ACTIVE, time.Now(), false, time.Time{}) } // Send a single update to populate the store. msg := encodeMessage(b, "ring", initialDesc) diff --git a/ring/example/local/local.go b/ring/example/local/local.go index 4a0089140..040fca56e 100644 --- a/ring/example/local/local.go +++ b/ring/example/local/local.go @@ -216,7 +216,7 @@ func SimpleRingLifecycler(store kv.Client, bindaddr string, bindport int) (*ring var delegate ring.BasicLifecyclerDelegate - delegate = ring.NewInstanceRegisterDelegate(ring.ACTIVE, 128) + delegate = ring.NewInstanceRegisterDelegate(ring.InstanceState_ACTIVE, 128) delegate = ring.NewLeaveOnStoppingDelegate(delegate, logger) delegate = ring.NewAutoForgetDelegate(1*time.Minute, delegate, logger) diff --git a/ring/flush.go b/ring/flush.go index 798169b2e..7d8c08fb8 100644 --- a/ring/flush.go +++ b/ring/flush.go @@ -11,7 +11,7 @@ var ErrTransferDisabled = errors.New("transfers disabled") // FlushTransferer controls the shutdown of an instance in the ring. // Methods on this interface are called when lifecycler is stopping. // At that point, it no longer runs the "actor loop", but it keeps updating heartbeat in the ring. -// Ring entry is in LEAVING state. +// Ring entry is in InstanceState_LEAVING state. // After calling TransferOut and then Flush, lifecycler stops. type FlushTransferer interface { Flush() diff --git a/ring/lifecycler.go b/ring/lifecycler.go index bb9f1e8f3..1703b45f1 100644 --- a/ring/lifecycler.go +++ b/ring/lifecycler.go @@ -101,7 +101,7 @@ func (cfg *LifecyclerConfig) RegisterFlagsWithPrefix(prefix string, f *flag.Flag f.StringVar(&cfg.ID, prefix+"lifecycler.ID", hostname, "ID to register in the ring.") f.StringVar(&cfg.Zone, prefix+"availability-zone", "", "The availability zone where this instance is running.") f.BoolVar(&cfg.UnregisterOnShutdown, prefix+"unregister-on-shutdown", true, "Unregister from the ring upon clean shutdown. It can be useful to disable for rolling restarts with consistent naming in conjunction with -distributor.extend-writes=false.") - f.BoolVar(&cfg.ReadinessCheckRingHealth, prefix+"readiness-check-ring-health", true, "When enabled the readiness probe succeeds only after all instances are ACTIVE and healthy in the ring, otherwise only the instance itself is checked. This option should be disabled if in your cluster multiple instances can be rolled out simultaneously, otherwise rolling updates may be slowed down.") + f.BoolVar(&cfg.ReadinessCheckRingHealth, prefix+"readiness-check-ring-health", true, "When enabled the readiness probe succeeds only after all instances are InstanceState_ACTIVE and healthy in the ring, otherwise only the instance itself is checked. This option should be disabled if in your cluster multiple instances can be rolled out simultaneously, otherwise rolling updates may be slowed down.") f.BoolVar(&cfg.EnableInet6, prefix+"enable-inet6", false, "Enable IPv6 support. Required to make use of IP addresses from IPv6 interfaces.") } @@ -121,9 +121,9 @@ func (cfg *LifecyclerConfig) Validate() error { /* Lifecycler is a Service that is responsible for publishing changes to a ring for a single instance. - - When a Lifecycler first starts, it will be in a [PENDING] state. - - After the configured [ring.LifecyclerConfig.JoinAfter] period, it selects some random tokens and enters the [JOINING] state, creating or updating the ring as needed. - - The lifecycler will then periodically, based on the [ring.LifecyclerConfig.ObservePeriod], attempt to verify that its tokens have been added to the ring, after which it will transition to the [ACTIVE] state. + - When a Lifecycler first starts, it will be in a [InstanceState_PENDING] state. + - After the configured [ring.LifecyclerConfig.JoinAfter] period, it selects some random tokens and enters the [InstanceState_JOINING] state, creating or updating the ring as needed. + - The lifecycler will then periodically, based on the [ring.LifecyclerConfig.ObservePeriod], attempt to verify that its tokens have been added to the ring, after which it will transition to the [InstanceState_ACTIVE] state. - The lifecycler will update the key/value store with heartbeats, state changes, and token changes, based on the [ring.LifecyclerConfig.HeartbeatPeriod]. */ type Lifecycler struct { @@ -228,7 +228,7 @@ func NewLifecycler(cfg LifecyclerConfig, flushTransferer FlushTransferer, ringNa clearTokensOnShutdown: atomic.NewBool(false), Zone: cfg.Zone, actorChan: make(chan func()), - state: PENDING, + state: InstanceState_PENDING, tokenGenerator: tokenGenerator, canJoinTimeout: 5 * time.Minute, lifecyclerMetrics: NewLifecyclerMetrics(ringName, reg), @@ -279,7 +279,7 @@ func (i *Lifecycler) checkRingHealthForReadiness(ctx context.Context) error { return fmt.Errorf("this instance owns no tokens") } - // If ring health checking is enabled we make sure all instances in the ring are ACTIVE and healthy, + // If ring health checking is enabled we make sure all instances in the ring are InstanceState_ACTIVE and healthy, // otherwise we just check this instance. desc, err := i.KVStore.Get(ctx, i.RingKey) if err != nil { @@ -427,7 +427,7 @@ func (i *Lifecycler) setReadOnlyState(readOnly bool, readOnlyLastUpdated time.Ti // ClaimTokensFor takes all the tokens for the supplied ingester and assigns them to this ingester. // // For this method to work correctly (especially when using gossiping), source ingester (specified by -// ingesterID) must be in the LEAVING state, otherwise ring's merge function may detect token conflict and +// ingesterID) must be in the InstanceState_LEAVING state, otherwise ring's merge function may detect token conflict and // assign token to the wrong ingester. While we could check for that state here, when this method is called, // transfers have already finished -- it's better to check for this *before* transfers start. func (i *Lifecycler) ClaimTokensFor(ctx context.Context, ingesterID string) error { @@ -540,22 +540,22 @@ func (i *Lifecycler) loop(ctx context.Context) error { select { case <-autoJoinAfter: level.Debug(i.logger).Log("msg", "JoinAfter expired", "ring", i.RingName) - // Will only fire once, after auto join timeout. If we haven't entered "JOINING" state, - // then pick some tokens and enter ACTIVE state. - if i.GetState() == PENDING { + // Will only fire once, after auto join timeout. If we haven't entered "InstanceState_JOINING" state, + // then pick some tokens and enter InstanceState_ACTIVE state. + if i.GetState() == InstanceState_PENDING { level.Info(i.logger).Log("msg", "auto-joining cluster after timeout", "ring", i.RingName) if i.cfg.ObservePeriod > 0 { - // let's observe the ring. By using JOINING state, this ingester will be ignored by LEAVING + // let's observe the ring. By using InstanceState_JOINING state, this ingester will be ignored by InstanceState_LEAVING // ingesters, but we also signal that it is not fully functional yet. - if err := i.autoJoin(context.Background(), JOINING); err != nil { + if err := i.autoJoin(context.Background(), InstanceState_JOINING); err != nil { return errors.Wrapf(err, "failed to pick tokens in the KV store, ring: %s", i.RingName) } - level.Info(i.logger).Log("msg", "observing tokens before going ACTIVE", "ring", i.RingName) + level.Info(i.logger).Log("msg", "observing tokens before going InstanceState_ACTIVE", "ring", i.RingName) observeChan = time.After(i.cfg.ObservePeriod) } else { - if err := i.autoJoin(context.Background(), ACTIVE); err != nil { + if err := i.autoJoin(context.Background(), InstanceState_ACTIVE); err != nil { return errors.Wrapf(err, "failed to pick tokens in the KV store, ring: %s", i.RingName) } } @@ -566,16 +566,16 @@ func (i *Lifecycler) loop(ctx context.Context) error { // When observing is done, observeChan is set to nil. observeChan = nil - if s := i.GetState(); s != JOINING { + if s := i.GetState(); s != InstanceState_JOINING { level.Error(i.logger).Log("msg", "unexpected state while observing tokens", "state", s, "ring", i.RingName) } if i.verifyTokens(context.Background()) { level.Info(i.logger).Log("msg", "token verification successful", "ring", i.RingName) - err := i.changeState(context.Background(), ACTIVE) + err := i.changeState(context.Background(), InstanceState_ACTIVE) if err != nil { - level.Error(i.logger).Log("msg", "failed to set state to ACTIVE", "ring", i.RingName, "err", err) + level.Error(i.logger).Log("msg", "failed to set state to InstanceState_ACTIVE", "ring", i.RingName, "err", err) } } else { level.Info(i.logger).Log("msg", "token verification failed, observing", "ring", i.RingName) @@ -614,9 +614,9 @@ func (i *Lifecycler) stopping(runningError error) error { defer heartbeatTickerStop() // Mark ourselved as Leaving so no more samples are send to us. - err := i.changeState(context.Background(), LEAVING) + err := i.changeState(context.Background(), InstanceState_LEAVING) if err != nil { - level.Error(i.logger).Log("msg", "failed to set state to LEAVING", "ring", i.RingName, "err", err) + level.Error(i.logger).Log("msg", "failed to set state to InstanceState_LEAVING", "ring", i.RingName, "err", err) } // Do the transferring / flushing on a background goroutine so we can continue @@ -692,7 +692,7 @@ func (i *Lifecycler) initRing(ctx context.Context) error { if len(tokensFromFile) > 0 { level.Info(i.logger).Log("msg", "adding tokens from file", "num_tokens", len(tokensFromFile)) if len(tokensFromFile) >= i.cfg.NumTokens { - i.setState(ACTIVE) + i.setState(InstanceState_ACTIVE) } ro, rots := i.GetReadOnlyState() ringDesc.AddIngester(i.ID, i.Addr, i.Zone, tokensFromFile, i.GetState(), i.getRegisteredAt(), ro, rots) @@ -714,14 +714,14 @@ func (i *Lifecycler) initRing(ctx context.Context) error { // Set lifecycler read-only state from ring entry. We will not modify ring entry's read-only state. i.setReadOnlyState(instanceDesc.GetReadOnlyState()) - // If the ingester is in the JOINING state this means it crashed due to + // If the ingester is in the InstanceState_JOINING state this means it crashed due to // a failed token transfer or some other reason during startup. We want - // to set it back to PENDING in order to start the lifecycle from the + // to set it back to InstanceState_PENDING in order to start the lifecycle from the // beginning. - if instanceDesc.State == JOINING { - level.Warn(i.logger).Log("msg", "instance found in ring as JOINING, setting to PENDING", + if instanceDesc.State == InstanceState_JOINING { + level.Warn(i.logger).Log("msg", "instance found in ring as InstanceState_JOINING, setting to InstanceState_PENDING", "ring", i.RingName) - instanceDesc.State = PENDING + instanceDesc.State = InstanceState_PENDING return ringDesc, true, nil } @@ -730,8 +730,8 @@ func (i *Lifecycler) initRing(ctx context.Context) error { level.Info(i.logger).Log("msg", "existing instance found in ring", "state", instanceDesc.State, "tokens", len(tokens), "ring", i.RingName, "readOnly", ro, "readOnlyStateUpdate", rots) // If the ingester fails to clean its ring entry up or unregister_on_shutdown=false, it can leave behind its - // ring state as LEAVING. Make sure to switch to the ACTIVE state. - if instanceDesc.State == LEAVING { + // ring state as InstanceState_LEAVING. Make sure to switch to the InstanceState_ACTIVE state. + if instanceDesc.State == InstanceState_LEAVING { delta := i.cfg.NumTokens - len(tokens) if delta > 0 { // We need more tokens @@ -750,7 +750,7 @@ func (i *Lifecycler) initRing(ctx context.Context) error { sort.Sort(tokens) } - instanceDesc.State = ACTIVE + instanceDesc.State = InstanceState_ACTIVE instanceDesc.Tokens = tokens } @@ -902,7 +902,7 @@ func (i *Lifecycler) autoJoin(ctx context.Context, targetState InstanceState) er err = i.KVStore.CAS(ctx, i.RingKey, func(in interface{}) (out interface{}, retry bool, err error) { ringDesc = GetOrCreateRingDesc(in) - // At this point, we should not have any tokens, and we should be in PENDING state. + // At this point, we should not have any tokens, and we should be in InstanceState_PENDING state. myTokens, takenTokens := ringDesc.TokensFor(i.ID) if len(myTokens) > 0 { level.Error(i.logger).Log("msg", "tokens already exist for this instance - wasn't expecting any!", "num_tokens", len(myTokens), "ring", i.RingName) @@ -968,11 +968,11 @@ func (i *Lifecycler) updateConsul(ctx context.Context) error { func (i *Lifecycler) changeState(ctx context.Context, state InstanceState) error { currState := i.GetState() // Only the following state transitions can be triggered externally - if !((currState == PENDING && state == JOINING) || // triggered by TransferChunks at the beginning - (currState == JOINING && state == PENDING) || // triggered by TransferChunks on failure - (currState == JOINING && state == ACTIVE) || // triggered by TransferChunks on success - (currState == PENDING && state == ACTIVE) || // triggered by autoJoin - (currState == ACTIVE && state == LEAVING)) { // triggered by shutdown + if !((currState == InstanceState_PENDING && state == InstanceState_JOINING) || // triggered by TransferChunks at the beginning + (currState == InstanceState_JOINING && state == InstanceState_PENDING) || // triggered by TransferChunks on failure + (currState == InstanceState_JOINING && state == InstanceState_ACTIVE) || // triggered by TransferChunks on success + (currState == InstanceState_PENDING && state == InstanceState_ACTIVE) || // triggered by autoJoin + (currState == InstanceState_ACTIVE && state == InstanceState_LEAVING)) { // triggered by shutdown return fmt.Errorf("Changing instance state from %v -> %v is disallowed", currState, state) } diff --git a/ring/lifecycler_test.go b/ring/lifecycler_test.go index 634d22495..a1a147f2c 100644 --- a/ring/lifecycler_test.go +++ b/ring/lifecycler_test.go @@ -53,7 +53,7 @@ func checkNormalised(d interface{}, id string) bool { desc, ok := d.(*Desc) return ok && len(desc.Ingesters) == 1 && - desc.Ingesters[id].State == ACTIVE && + desc.Ingesters[id].State == InstanceState_ACTIVE && len(desc.Ingesters[id].Tokens) == 1 } @@ -617,7 +617,7 @@ func TestLifecycler_HeartbeatAfterBackendReset(t *testing.T) { // Ensure other information has been preserved. assert.Greater(t, desc.GetTimestamp(), int64(0)) assert.Equal(t, testInstanceID, desc.GetId()) - assert.Equal(t, ACTIVE, desc.GetState()) + assert.Equal(t, InstanceState_ACTIVE, desc.GetState()) assert.Equal(t, net.JoinHostPort(lifecyclerCfg.Addr, strconv.Itoa(lifecyclerCfg.Port)), desc.GetAddr()) assert.Equal(t, lifecyclerCfg.Zone, desc.Zone) assert.Equal(t, prevTokens, Tokens(desc.GetTokens())) @@ -647,7 +647,7 @@ func TestLifecycler_IncreasingTokensLeavingInstanceInTheRing(t *testing.T) { lifecyclerConfig.HeartbeatPeriod = 0 lifecyclerConfig.NumTokens = numTokens - // Simulate ingester with 64 tokens left the ring in LEAVING state + // Simulate ingester with 64 tokens left the ring in InstanceState_LEAVING state origTokens := initTokenGenerator(t).GenerateTokens(64, nil) err = r.KVClient.CAS(ctx, ringKey, func(interface{}) (out interface{}, retry bool, err error) { ringDesc := NewDesc() @@ -656,7 +656,7 @@ func TestLifecycler_IncreasingTokensLeavingInstanceInTheRing(t *testing.T) { return nil, false, err } - ringDesc.AddIngester("ing1", addr, lifecyclerConfig.Zone, origTokens, LEAVING, time.Now(), false, time.Time{}) + ringDesc.AddIngester("ing1", addr, lifecyclerConfig.Zone, origTokens, InstanceState_LEAVING, time.Now(), false, time.Time{}) return ringDesc, false, nil }) require.NoError(t, err) @@ -680,7 +680,7 @@ func TestLifecycler_IncreasingTokensLeavingInstanceInTheRing(t *testing.T) { ingDesc = desc.Ingesters["ing1"] t.Log(fmt.Sprintf("Polling for new ingester to have become active with %d tokens", numTokens), "state", ingDesc.State, "tokens", len(ingDesc.Tokens)) - return ingDesc.State == ACTIVE && len(ingDesc.Tokens) == numTokens + return ingDesc.State == InstanceState_ACTIVE && len(ingDesc.Tokens) == numTokens }) origSeen := 0 @@ -825,7 +825,7 @@ func TestLifecycler_DecreasingTokensLeavingInstanceInTheRing(t *testing.T) { lifecyclerConfig.HeartbeatPeriod = 0 lifecyclerConfig.NumTokens = numTokens - // Simulate ingester with 128 tokens left the ring in LEAVING state + // Simulate ingester with 128 tokens left the ring in InstanceState_LEAVING state origTokens := initTokenGenerator(t).GenerateTokens(128, nil) err = r.KVClient.CAS(ctx, ringKey, func(interface{}) (out interface{}, retry bool, err error) { ringDesc := NewDesc() @@ -834,7 +834,7 @@ func TestLifecycler_DecreasingTokensLeavingInstanceInTheRing(t *testing.T) { return nil, false, err } - ringDesc.AddIngester("ing1", addr, lifecyclerConfig.Zone, origTokens, LEAVING, time.Now(), false, time.Time{}) + ringDesc.AddIngester("ing1", addr, lifecyclerConfig.Zone, origTokens, InstanceState_LEAVING, time.Now(), false, time.Time{}) return ringDesc, false, nil }) require.NoError(t, err) @@ -858,7 +858,7 @@ func TestLifecycler_DecreasingTokensLeavingInstanceInTheRing(t *testing.T) { ingDesc = desc.Ingesters["ing1"] t.Log(fmt.Sprintf("Polling for new ingester to have become active with %d tokens", numTokens), "state", ingDesc.State, "tokens", len(ingDesc.Tokens)) - return ingDesc.Id == "ing1" && ingDesc.State == ACTIVE && len(ingDesc.Tokens) == numTokens + return ingDesc.Id == "ing1" && ingDesc.State == InstanceState_ACTIVE && len(ingDesc.Tokens) == numTokens }) seen := map[uint32]struct{}{} @@ -973,11 +973,11 @@ func TestCheckReady_MinReadyDuration(t *testing.T) { minReadyDuration time.Duration expectedMinDelay time.Duration }{ - "should immediately pass the check if the instance is ACTIVE and healthy and min ready duration is disabled": { + "should immediately pass the check if the instance is InstanceState_ACTIVE and healthy and min ready duration is disabled": { minReadyDuration: 0, expectedMinDelay: 0, }, - "should wait min ready duration before passing the check after the instance is ACTIVE and healthy": { + "should wait min ready duration before passing the check after the instance is InstanceState_ACTIVE and healthy": { minReadyDuration: time.Second, expectedMinDelay: time.Second, }, @@ -1007,7 +1007,7 @@ func TestCheckReady_MinReadyDuration(t *testing.T) { startTime := time.Now() - // Wait until the instance is ACTIVE and healthy in the ring. + // Wait until the instance is InstanceState_ACTIVE and healthy in the ring. waitRingInstance(t, 3*time.Second, l, func(instance InstanceDesc) error { return instance.IsReady(time.Now(), cfg.RingConfig.HeartbeatTimeout) }) @@ -1035,14 +1035,14 @@ func TestCheckReady_CheckRingHealth(t *testing.T) { expectedFirstMinReady time.Duration expectedFirstMaxReady time.Duration }{ - "should wait until the self instance is ACTIVE and healthy in the ring when 'check ring health' is disabled": { + "should wait until the self instance is InstanceState_ACTIVE and healthy in the ring when 'check ring health' is disabled": { checkRingHealthEnabled: false, firstJoinAfter: time.Second, secondJoinAfter: 3 * time.Second, expectedFirstMinReady: time.Second, expectedFirstMaxReady: 2 * time.Second, }, - "should wait until all instances are ACTIVE and healthy in the ring when 'check ring health' is enabled": { + "should wait until all instances are InstanceState_ACTIVE and healthy in the ring when 'check ring health' is enabled": { checkRingHealthEnabled: true, firstJoinAfter: time.Second, secondJoinAfter: 3 * time.Second, @@ -1095,7 +1095,7 @@ func TestCheckReady_CheckRingHealth(t *testing.T) { startTime := time.Now() // Wait until both instances are registered in the ring. We expect them to be registered - // immediately and then switch to ACTIVE after the configured auto join delay. + // immediately and then switch to InstanceState_ACTIVE after the configured auto join delay. waitRingInstance(t, 3*time.Second, l1, func(InstanceDesc) error { return nil }) waitRingInstance(t, 3*time.Second, l2, func(InstanceDesc) error { return nil }) @@ -1157,46 +1157,46 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi require.NoError(t, err) require.NoError(t, services.StartAndAwaitRunning(context.Background(), lifecycler)) poll(func(desc *Desc) bool { - return desc.Ingesters[ingId].State == ACTIVE + return desc.Ingesters[ingId].State == InstanceState_ACTIVE }) return lifecycler } // We are going to create 2 fake ingester with disabled heart beat and `unregister_on_shutdown=false` then // test if the ingester 2 became active after: - // * Clean Shutdown (LEAVING after shutdown) - // * Crashes while in the PENDING or JOINING state + // * Clean Shutdown (InstanceState_LEAVING after shutdown) + // * Crashes while in the InstanceState_PENDING or InstanceState_JOINING state l1 := startIngesterAndWaitActive("ing1") defer services.StopAndAwaitTerminated(context.Background(), l1) //nolint:errcheck l2 := startIngesterAndWaitActive("ing2") ingesters := poll(func(desc *Desc) bool { - return len(desc.Ingesters) == 2 && desc.Ingesters["ing1"].State == ACTIVE && desc.Ingesters["ing2"].State == ACTIVE + return len(desc.Ingesters) == 2 && desc.Ingesters["ing1"].State == InstanceState_ACTIVE && desc.Ingesters["ing2"].State == InstanceState_ACTIVE }) // Both Ingester should be active and running - assert.Equal(t, ACTIVE, ingesters["ing1"].State) - assert.Equal(t, ACTIVE, ingesters["ing2"].State) + assert.Equal(t, InstanceState_ACTIVE, ingesters["ing1"].State) + assert.Equal(t, InstanceState_ACTIVE, ingesters["ing2"].State) - // Stop One ingester gracefully should leave it on LEAVING STATE on the ring + // Stop One ingester gracefully should leave it on InstanceState_LEAVING STATE on the ring require.NoError(t, services.StopAndAwaitTerminated(context.Background(), l2)) ingesters = poll(func(desc *Desc) bool { - return len(desc.Ingesters) == 2 && desc.Ingesters["ing2"].State == LEAVING + return len(desc.Ingesters) == 2 && desc.Ingesters["ing2"].State == InstanceState_LEAVING }) - assert.Equal(t, LEAVING, ingesters["ing2"].State) + assert.Equal(t, InstanceState_LEAVING, ingesters["ing2"].State) - // Start Ingester2 again - Should flip back to ACTIVE in the ring + // Start Ingester2 again - Should flip back to InstanceState_ACTIVE in the ring l2 = startIngesterAndWaitActive("ing2") require.NoError(t, services.StopAndAwaitTerminated(context.Background(), l2)) - // Simulate ingester2 crash on startup and left the ring with JOINING state + // Simulate ingester2 crash on startup and left the ring with InstanceState_JOINING state err = r.KVClient.CAS(context.Background(), ringKey, func(in interface{}) (out interface{}, retry bool, err error) { desc, ok := in.(*Desc) require.True(t, ok) ingester2Desc := desc.Ingesters["ing2"] - ingester2Desc.State = JOINING + ingester2Desc.State = InstanceState_JOINING desc.Ingesters["ing2"] = ingester2Desc return desc, true, nil }) @@ -1205,12 +1205,12 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi l2 = startIngesterAndWaitActive("ing2") require.NoError(t, services.StopAndAwaitTerminated(context.Background(), l2)) - // Simulate ingester2 crash on startup and left the ring with PENDING state + // Simulate ingester2 crash on startup and left the ring with InstanceState_PENDING state err = r.KVClient.CAS(context.Background(), ringKey, func(in interface{}) (out interface{}, retry bool, err error) { desc, ok := in.(*Desc) require.True(t, ok) ingester2Desc := desc.Ingesters["ing2"] - ingester2Desc.State = PENDING + ingester2Desc.State = InstanceState_PENDING desc.Ingesters["ing2"] = ingester2Desc return desc, true, nil }) @@ -1230,9 +1230,9 @@ func TestRestartIngester_NoUnregister_LongHeartbeat(t *testing.T) { registeredAt := time.Now().Add(-1 * time.Hour) err := ringStore.CAS(context.Background(), ringKey, func(in interface{}) (out interface{}, retry bool, err error) { - // Create ring with LEAVING entry with some tokens + // Create ring with InstanceState_LEAVING entry with some tokens r := GetOrCreateRingDesc(in) - r.AddIngester(id, "3.3.3.3:333", "old", origTokens, LEAVING, registeredAt, false, time.Time{}) + r.AddIngester(id, "3.3.3.3:333", "old", origTokens, InstanceState_LEAVING, registeredAt, false, time.Time{}) return r, true, err }) require.NoError(t, err) @@ -1259,8 +1259,8 @@ func TestRestartIngester_NoUnregister_LongHeartbeat(t *testing.T) { return l.CheckReady(context.Background()) }) - // Lifecycler should be in ACTIVE state, using tokens from the ring. - require.Equal(t, ACTIVE, l.GetState()) + // Lifecycler should be in InstanceState_ACTIVE state, using tokens from the ring. + require.Equal(t, InstanceState_ACTIVE, l.GetState()) require.Equal(t, origTokens, l.getTokens()) require.Equal(t, registeredAt.Truncate(time.Second), l.getRegisteredAt()) @@ -1270,7 +1270,7 @@ func TestRestartIngester_NoUnregister_LongHeartbeat(t *testing.T) { r := GetOrCreateRingDesc(desc) require.Equal(t, lifecyclerConfig.ID, r.Ingesters[id].Id) - require.Equal(t, ACTIVE, r.Ingesters[id].State) + require.Equal(t, InstanceState_ACTIVE, r.Ingesters[id].State) require.Equal(t, "1.1.1.1:111", r.Ingesters[id].Addr) require.Equal(t, "new", r.Ingesters[id].Zone) require.Equal(t, registeredAt.Unix(), r.Ingesters[id].RegisteredTimestamp) @@ -1312,7 +1312,7 @@ func TestTokensOnDisk(t *testing.T) { } return ok && len(desc.Ingesters) == 1 && - desc.Ingesters["ing1"].State == ACTIVE && + desc.Ingesters["ing1"].State == InstanceState_ACTIVE && len(desc.Ingesters["ing1"].Tokens) == 512 }) @@ -1336,7 +1336,7 @@ func TestTokensOnDisk(t *testing.T) { } return ok && len(desc.Ingesters) == 1 && - desc.Ingesters["ing2"].State == ACTIVE && + desc.Ingesters["ing2"].State == InstanceState_ACTIVE && len(desc.Ingesters["ing2"].Tokens) == 512 }) @@ -1382,7 +1382,7 @@ func TestDeletePersistedTokensOnShutdown(t *testing.T) { desc, ok := d.(*Desc) return ok && len(desc.Ingesters) == 1 && - desc.Ingesters["ing1"].State == ACTIVE && + desc.Ingesters["ing1"].State == InstanceState_ACTIVE && len(desc.Ingesters["ing1"].Tokens) == 512 }) @@ -1395,7 +1395,7 @@ func TestDeletePersistedTokensOnShutdown(t *testing.T) { require.True(t, os.IsNotExist(err)) } -// JoinInLeavingState ensures that if the lifecycler starts up and the ring already has it in a LEAVING state that it still is able to auto join +// JoinInLeavingState ensures that if the lifecycler starts up and the ring already has it in a InstanceState_LEAVING state that it still is able to auto join func TestJoinInLeavingState(t *testing.T) { ringStore, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil) t.Cleanup(func() { assert.NoError(t, closer.Close()) }) @@ -1413,12 +1413,12 @@ func TestJoinInLeavingState(t *testing.T) { cfg.NumTokens = 2 cfg.MinReadyDuration = 1 * time.Nanosecond - // Set state as LEAVING + // Set state as InstanceState_LEAVING err = r.KVClient.CAS(context.Background(), ringKey, func(interface{}) (interface{}, bool, error) { r := &Desc{ Ingesters: map[string]InstanceDesc{ "ing1": { - State: LEAVING, + State: InstanceState_LEAVING, Tokens: []uint32{1, 4}, }, "ing2": { @@ -1436,7 +1436,7 @@ func TestJoinInLeavingState(t *testing.T) { require.NoError(t, services.StartAndAwaitRunning(context.Background(), l1)) defer services.StopAndAwaitTerminated(context.Background(), l1) //nolint:errcheck - // Check that the lifecycler was able to join after coming up in LEAVING + // Check that the lifecycler was able to join after coming up in InstanceState_LEAVING test.Poll(t, 1000*time.Millisecond, true, func() interface{} { d, err := r.KVClient.Get(context.Background(), ringKey) require.NoError(t, err) @@ -1444,13 +1444,13 @@ func TestJoinInLeavingState(t *testing.T) { desc, ok := d.(*Desc) return ok && len(desc.Ingesters) == 2 && - desc.Ingesters["ing1"].State == ACTIVE && + desc.Ingesters["ing1"].State == InstanceState_ACTIVE && len(desc.Ingesters["ing1"].Tokens) == cfg.NumTokens && len(desc.Ingesters["ing2"].Tokens) == 2 }) } -// JoinInJoiningState ensures that if the lifecycler starts up and the ring already has it in a JOINING state that it still is able to auto join +// JoinInJoiningState ensures that if the lifecycler starts up and the ring already has it in a InstanceState_JOINING state that it still is able to auto join func TestJoinInJoiningState(t *testing.T) { ringStore, closer := consul.NewInMemoryClient(GetCodec(), log.NewNopLogger(), nil) t.Cleanup(func() { assert.NoError(t, closer.Close()) }) @@ -1470,12 +1470,12 @@ func TestJoinInJoiningState(t *testing.T) { instance1RegisteredAt := time.Now().Add(-1 * time.Hour) instance2RegisteredAt := time.Now().Add(-2 * time.Hour) - // Set state as JOINING + // Set state as InstanceState_JOINING err = r.KVClient.CAS(context.Background(), ringKey, func(interface{}) (interface{}, bool, error) { r := &Desc{ Ingesters: map[string]InstanceDesc{ "ing1": { - State: JOINING, + State: InstanceState_JOINING, Tokens: []uint32{1, 4}, RegisteredTimestamp: instance1RegisteredAt.Unix(), }, @@ -1495,7 +1495,7 @@ func TestJoinInJoiningState(t *testing.T) { require.NoError(t, services.StartAndAwaitRunning(context.Background(), l1)) defer services.StopAndAwaitTerminated(context.Background(), l1) //nolint:errcheck - // Check that the lifecycler was able to join after coming up in JOINING + // Check that the lifecycler was able to join after coming up in InstanceState_JOINING test.Poll(t, 1000*time.Millisecond, true, func() interface{} { d, err := r.KVClient.Get(context.Background(), ringKey) require.NoError(t, err) @@ -1503,7 +1503,7 @@ func TestJoinInJoiningState(t *testing.T) { desc, ok := d.(*Desc) return ok && len(desc.Ingesters) == 2 && - desc.Ingesters["ing1"].State == ACTIVE && + desc.Ingesters["ing1"].State == InstanceState_ACTIVE && len(desc.Ingesters["ing1"].Tokens) == cfg.NumTokens && len(desc.Ingesters["ing2"].Tokens) == 2 && desc.Ingesters["ing1"].RegisteredTimestamp == instance1RegisteredAt.Unix() && @@ -1530,11 +1530,11 @@ func TestWaitBeforeJoining(t *testing.T) { r := &Desc{ Ingesters: map[string]InstanceDesc{ instanceName(0, 1): { - State: ACTIVE, + State: InstanceState_ACTIVE, Tokens: []uint32{1, 2, 3}, }, instanceName(1, 1): { - State: ACTIVE, + State: InstanceState_ACTIVE, Tokens: []uint32{4, 5, 6}, }, }, @@ -1658,14 +1658,14 @@ func TestAutoJoinWithSpreadMinimizingTokenGenerator(t *testing.T) { } firstInstanceDesc, ok := desc.Ingesters[firstInstanceID] - if ok && firstInstanceDesc.State == ACTIVE && len(firstInstanceDesc.Tokens) != 0 { + if ok && firstInstanceDesc.State == InstanceState_ACTIVE && len(firstInstanceDesc.Tokens) != 0 { if firstInstanceRegistered.CompareAndSwap(false, true) { firstInstanceRegistrationTimestamp = time.Now() } } secondInstanceDesc, ok := desc.Ingesters[secondInstanceID] - if ok && secondInstanceDesc.State == ACTIVE && len(secondInstanceDesc.Tokens) != 0 { + if ok && secondInstanceDesc.State == InstanceState_ACTIVE && len(secondInstanceDesc.Tokens) != 0 { if secondInstanceRegistered.CompareAndSwap(false, true) { secondInstanceRegistrationTimestamp = time.Now() } @@ -1740,7 +1740,7 @@ func TestRestoreOfZoneWhenOverwritten(t *testing.T) { r := &Desc{ Ingesters: map[string]InstanceDesc{ "ing1": { - State: ACTIVE, + State: InstanceState_ACTIVE, Addr: "0.0.0.0", Tokens: []uint32{1, 4}, }, diff --git a/ring/merge_test.go b/ring/merge_test.go index f9f745dd5..60f7c5c04 100644 --- a/ring/merge_test.go +++ b/ring/merge_test.go @@ -12,10 +12,10 @@ func TestNormalizationAndConflictResolution(t *testing.T) { first := &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{50, 40, 40, 30}}, - "Ing 2": {Addr: "addr2", Timestamp: 123456, State: LEAVING, Tokens: []uint32{100, 5, 5, 100, 100, 200, 20, 10}}, - "Ing 3": {Addr: "addr3", Timestamp: now, State: LEFT, Tokens: []uint32{100, 200, 300}}, - "Ing 4": {Addr: "addr4", Timestamp: now, State: LEAVING, Tokens: []uint32{30, 40, 50}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{50, 40, 40, 30}}, + "Ing 2": {Addr: "addr2", Timestamp: 123456, State: InstanceState_LEAVING, Tokens: []uint32{100, 5, 5, 100, 100, 200, 20, 10}}, + "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEFT, Tokens: []uint32{100, 200, 300}}, + "Ing 4": {Addr: "addr4", Timestamp: now, State: InstanceState_LEAVING, Tokens: []uint32{30, 40, 50}}, "Unknown": {Tokens: []uint32{100}}, }, } @@ -40,10 +40,10 @@ func TestNormalizationAndConflictResolution(t *testing.T) { assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: 123456, State: LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}}, - "Ing 3": {Addr: "addr3", Timestamp: now, State: LEFT}, - "Ing 4": {Addr: "addr4", Timestamp: now, State: LEAVING}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: 123456, State: InstanceState_LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEFT}, + "Ing 4": {Addr: "addr4", Timestamp: now, State: InstanceState_LEAVING}, "Unknown": {Timestamp: now + 10, Tokens: []uint32{1000, 2000}}, }, }, first) @@ -76,8 +76,8 @@ func TestMerge(t *testing.T) { firstRing := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now, State: JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, }, } } @@ -85,8 +85,8 @@ func TestMerge(t *testing.T) { secondRing := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{150, 250, 350}}, - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{150, 250, 350}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, }, } } @@ -94,8 +94,8 @@ func TestMerge(t *testing.T) { thirdRing := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: LEAVING, Tokens: []uint32{30, 40, 50}}, - "Ing 3": {Addr: "addr3", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{150, 250, 350}}, + "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEAVING, Tokens: []uint32{30, 40, 50}}, + "Ing 3": {Addr: "addr3", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{150, 250, 350}}, }, } } @@ -103,9 +103,9 @@ func TestMerge(t *testing.T) { expectedFirstSecondMerge := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, - "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{150, 250, 350}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{150, 250, 350}}, }, } } @@ -113,9 +113,9 @@ func TestMerge(t *testing.T) { expectedFirstSecondThirdMerge := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: LEAVING, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, - "Ing 3": {Addr: "addr3", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{150, 250, 350}}, + "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEAVING, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 3": {Addr: "addr3", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{150, 250, 350}}, }, } } @@ -123,7 +123,7 @@ func TestMerge(t *testing.T) { fourthRing := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: LEFT, Tokens: []uint32{30, 40, 50}}, + "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEFT, Tokens: []uint32{30, 40, 50}}, }, } } @@ -131,9 +131,9 @@ func TestMerge(t *testing.T) { expectedFirstSecondThirdFourthMerge := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: LEFT, Tokens: nil}, - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, - "Ing 3": {Addr: "addr3", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{150, 250, 350}}, + "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEFT, Tokens: nil}, + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 3": {Addr: "addr3", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{150, 250, 350}}, }, } } @@ -156,7 +156,7 @@ func TestMerge(t *testing.T) { // when merging first into second ring, only "Ing 1" is new assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, }, }, ch) } @@ -177,7 +177,7 @@ func TestMerge(t *testing.T) { // entire fourth ring is the update -- but without tokens assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: LEFT, Tokens: nil}, + "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEFT, Tokens: nil}, }, }, ch) } @@ -189,8 +189,8 @@ func TestTokensTakeover(t *testing.T) { first := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now, State: JOINING, Tokens: []uint32{5, 10, 20}}, // partially migrated from Ing 3 + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{5, 10, 20}}, // partially migrated from Ing 3 }, } } @@ -198,8 +198,8 @@ func TestTokensTakeover(t *testing.T) { second := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20}}, - "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20}}, + "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: InstanceState_LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}}, }, } } @@ -207,9 +207,9 @@ func TestTokensTakeover(t *testing.T) { merged := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20}}, - "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: LEAVING, Tokens: []uint32{100, 200}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20}}, + "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: InstanceState_LEAVING, Tokens: []uint32{100, 200}}, }, } } @@ -219,8 +219,8 @@ func TestTokensTakeover(t *testing.T) { assert.Equal(t, merged(), our) assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20}}, - "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: LEAVING, Tokens: []uint32{100, 200}}, // change doesn't contain conflicted tokens + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20}}, + "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: InstanceState_LEAVING, Tokens: []uint32{100, 200}}, // change doesn't contain conflicted tokens }, }, ch) } @@ -238,7 +238,7 @@ func TestTokensTakeover(t *testing.T) { // change is different though assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, }, }, ch) } @@ -250,8 +250,8 @@ func TestMergeLeft(t *testing.T) { firstRing := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now, State: JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, }, } } @@ -260,8 +260,8 @@ func TestMergeLeft(t *testing.T) { firstRingNotNormalised := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now, State: JOINING, Tokens: []uint32{20, 10, 5, 10, 20, 100, 200, 100}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{20, 10, 5, 10, 20, 100, 200, 100}}, }, } } @@ -269,16 +269,16 @@ func TestMergeLeft(t *testing.T) { secondRing := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 2": {Addr: "addr2", Timestamp: now, State: LEFT}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT}, }, } } - // Not normalised because it contains a LEFT ingester with tokens. + // Not normalised because it contains a InstanceState_LEFT ingester with tokens. secondRingNotNormalised := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 2": {Addr: "addr2", Timestamp: now, State: LEFT, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT, Tokens: []uint32{5, 10, 20, 100, 200}}, }, } } @@ -286,8 +286,8 @@ func TestMergeLeft(t *testing.T) { expectedFirstSecondMerge := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now, State: LEFT}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT}, }, } } @@ -295,8 +295,8 @@ func TestMergeLeft(t *testing.T) { thirdRing := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: LEAVING, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now, State: JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, // from firstRing + "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEAVING, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, // from firstRing }, } } @@ -304,8 +304,8 @@ func TestMergeLeft(t *testing.T) { expectedFirstSecondThirdMerge := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: LEAVING, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now, State: LEFT}, + "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEAVING, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT}, }, } } @@ -315,7 +315,7 @@ func TestMergeLeft(t *testing.T) { assert.Equal(t, expectedFirstSecondMerge(), our) assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 2": {Addr: "addr2", Timestamp: now, State: LEFT}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT}, }, }, ch) } @@ -325,7 +325,7 @@ func TestMergeLeft(t *testing.T) { assert.Equal(t, expectedFirstSecondMerge(), our) assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 2": {Addr: "addr2", Timestamp: now, State: LEFT}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT}, }, }, ch) @@ -343,7 +343,7 @@ func TestMergeLeft(t *testing.T) { // when merging first into second ring, only "Ing 1" is new assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, }, }, ch) } @@ -354,7 +354,7 @@ func TestMergeLeft(t *testing.T) { // when merging first into second ring, only "Ing 1" is new assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, }, }, ch) @@ -377,9 +377,9 @@ func TestMergeRemoveMissing(t *testing.T) { firstRing := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now, State: JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, - "Ing 3": {Addr: "addr3", Timestamp: now, State: LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}}, }, } } @@ -387,8 +387,8 @@ func TestMergeRemoveMissing(t *testing.T) { secondRing := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, }, } } @@ -396,9 +396,9 @@ func TestMergeRemoveMissing(t *testing.T) { expectedFirstSecondMerge := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, - "Ing 3": {Addr: "addr3", Timestamp: now + 3, State: LEFT}, // When deleting, time depends on value passed to merge function. + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 3": {Addr: "addr3", Timestamp: now + 3, State: InstanceState_LEFT}, // When deleting, time depends on value passed to merge function. }, } } @@ -408,8 +408,8 @@ func TestMergeRemoveMissing(t *testing.T) { assert.Equal(t, expectedFirstSecondMerge(), our) assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, - "Ing 3": {Addr: "addr3", Timestamp: now + 3, State: LEFT}, // When deleting, time depends on value passed to merge function. + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 3": {Addr: "addr3", Timestamp: now + 3, State: InstanceState_LEFT}, // When deleting, time depends on value passed to merge function. }, }, ch) // entire second ring is new } @@ -424,15 +424,15 @@ func TestMergeRemoveMissing(t *testing.T) { our, ch := mergeLocalCAS(secondRing(), firstRing(), now+3) assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, - "Ing 3": {Addr: "addr3", Timestamp: now, State: LEAVING}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEAVING}, }, }, our) assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 3": {Addr: "addr3", Timestamp: now, State: LEAVING}, + "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEAVING}, }, }, ch) } @@ -444,9 +444,9 @@ func TestMergeMissingIntoLeft(t *testing.T) { ring1 := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, - "Ing 3": {Addr: "addr3", Timestamp: now, State: LEFT}, + "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEFT}, }, } } @@ -454,8 +454,8 @@ func TestMergeMissingIntoLeft(t *testing.T) { ring2 := func() *Desc { return &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, }, } } @@ -464,17 +464,17 @@ func TestMergeMissingIntoLeft(t *testing.T) { our, ch := mergeLocalCAS(ring1(), ring2(), now+10) assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, - "Ing 3": {Addr: "addr3", Timestamp: now, State: LEFT}, + "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEFT}, }, }, our) assert.Equal(t, &Desc{ Ingesters: map[string]InstanceDesc{ - "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{30, 40, 50}}, - "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, - // Ing 3 is not changed, it was already LEFT + "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, + "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, + // Ing 3 is not changed, it was already InstanceState_LEFT }, }, ch) } diff --git a/ring/model.go b/ring/model.go index 32529b6ba..9c590dd92 100644 --- a/ring/model.go +++ b/ring/model.go @@ -111,7 +111,7 @@ func (d *Desc) FindIngestersByState(state InstanceState) []InstanceDesc { return result } -// IsReady returns no error when all instance are ACTIVE and healthy, +// IsReady returns no error when all instance are InstanceState_ACTIVE and healthy, // and the ring has some tokens. func (d *Desc) IsReady(now time.Time, heartbeatTimeout time.Duration) error { numTokens := 0 @@ -185,12 +185,12 @@ func (i *InstanceDesc) IsHeartbeatHealthy(heartbeatTimeout time.Duration, now ti return now.Sub(time.Unix(i.Timestamp, 0)) <= heartbeatTimeout } -// IsReady returns no error if the instance is ACTIVE and healthy. +// IsReady returns no error if the instance is InstanceState_ACTIVE and healthy. func (i *InstanceDesc) IsReady(now time.Time, heartbeatTimeout time.Duration) error { if !i.IsHeartbeatHealthy(heartbeatTimeout, now) { return fmt.Errorf("instance %s past heartbeat timeout", i.Addr) } - if i.State != ACTIVE { + if i.State != InstanceState_ACTIVE { return fmt.Errorf("instance %s in state %v", i.Addr, i.State) } return nil @@ -201,11 +201,11 @@ func (i *InstanceDesc) IsReady(now time.Time, heartbeatTimeout time.Duration) er // // This merge function depends on the timestamp of the ingester. For each ingester, // it will choose more recent state from the two rings, and put that into this ring. -// There is one exception: we accept LEFT state even if Timestamp hasn't changed. +// There is one exception: we accept InstanceState_LEFT state even if Timestamp hasn't changed. // // localCAS flag tells the merge that it can use incoming ring as a full state, and detect // missing ingesters based on it. Ingesters from incoming ring will cause ingester -// to be marked as LEFT and gossiped about. +// to be marked as InstanceState_LEFT and gossiped about. // // If multiple ingesters end up owning the same tokens, Merge will do token conflict resolution // (see resolveConflicts). @@ -255,8 +255,8 @@ func (d *Desc) mergeWithTime(mergeable memberlist.Mergeable, localCAS bool, now oing.Tokens = append([]uint32(nil), oing.Tokens...) // make a copy of tokens thisIngesterMap[name] = oing updated = append(updated, name) - } else if oing.Timestamp == ting.Timestamp && ting.State != LEFT && oing.State == LEFT { - // we accept LEFT even if timestamp hasn't changed + } else if oing.Timestamp == ting.Timestamp && ting.State != InstanceState_LEFT && oing.State == InstanceState_LEFT { + // we accept InstanceState_LEFT even if timestamp hasn't changed thisIngesterMap[name] = oing // has no tokens already updated = append(updated, name) } @@ -265,9 +265,9 @@ func (d *Desc) mergeWithTime(mergeable memberlist.Mergeable, localCAS bool, now if localCAS { // This breaks commutativity! But we only do it locally, not when gossiping with others. for name, ting := range thisIngesterMap { - if _, ok := otherIngesterMap[name]; !ok && ting.State != LEFT { - // missing, let's mark our ingester as LEFT - ting.State = LEFT + if _, ok := otherIngesterMap[name]; !ok && ting.State != InstanceState_LEFT { + // missing, let's mark our ingester as InstanceState_LEFT + ting.State = InstanceState_LEFT ting.Tokens = nil // We are deleting entry "now", and should not keep old timestamp, because there may already be pending // message in the gossip network with newer timestamp (but still older than "now"). @@ -316,9 +316,9 @@ func (d *Desc) MergeContent() []string { // - sorts tokens and removes duplicates (only within single ingester) // - modifies the input ring func normalizeIngestersMap(inputRing *Desc) { - // Make sure LEFT ingesters have no tokens + // Make sure InstanceState_LEFT ingesters have no tokens for n, ing := range inputRing.Ingesters { - if ing.State == LEFT { + if ing.State == InstanceState_LEFT { ing.Tokens = nil inputRing.Ingesters[n] = ing } @@ -385,7 +385,7 @@ func conflictingTokensExist(normalizedIngesters map[string]InstanceDesc) bool { // This function resolves token conflicts, if there are any. // // We deal with two possibilities: -// 1) if one node is LEAVING or LEFT and the other node is not, LEVING/LEFT one loses the token +// 1) if one node is InstanceState_LEAVING or InstanceState_LEFT and the other node is not, LEVING/InstanceState_LEFT one loses the token // 2) otherwise node names are compared, and node with "lower" name wins the token // // Modifies ingesters map with updated tokens. @@ -398,8 +398,8 @@ func resolveConflicts(normalizedIngesters map[string]InstanceDesc) { tokenToIngester := make(map[uint32]string, size) for ingKey, ing := range normalizedIngesters { - if ing.State == LEFT { - // LEFT ingesters don't use tokens anymore + if ing.State == InstanceState_LEFT { + // InstanceState_LEFT ingesters don't use tokens anymore continue } @@ -414,9 +414,9 @@ func resolveConflicts(normalizedIngesters map[string]InstanceDesc) { winnerKey := ingKey switch { - case ing.State == LEAVING && prevIng.State != LEAVING: + case ing.State == InstanceState_LEAVING && prevIng.State != InstanceState_LEAVING: winnerKey = prevKey - case prevIng.State == LEAVING && ing.State != LEAVING: + case prevIng.State == InstanceState_LEAVING && ing.State != InstanceState_LEAVING: winnerKey = ingKey case ingKey < prevKey: winnerKey = ingKey @@ -453,10 +453,10 @@ func resolveConflicts(normalizedIngesters map[string]InstanceDesc) { } } -// RemoveTombstones removes LEFT ingesters older than given time limit. If time limit is zero, remove all LEFT ingesters. +// RemoveTombstones removes InstanceState_LEFT ingesters older than given time limit. If time limit is zero, remove all InstanceState_LEFT ingesters. func (d *Desc) RemoveTombstones(limit time.Time) (total, removed int) { for n, ing := range d.Ingesters { - if ing.State == LEFT { + if ing.State == InstanceState_LEFT { if limit.IsZero() || time.Unix(ing.Timestamp, 0).Before(limit) { // remove it delete(d.Ingesters, n) diff --git a/ring/model_test.go b/ring/model_test.go index be8ed343f..758f3e84f 100644 --- a/ring/model_test.go +++ b/ring/model_test.go @@ -17,29 +17,29 @@ func TestInstanceDesc_IsHealthy_ForIngesterOperations(t *testing.T) { readExpected bool reportExpected bool }{ - "ACTIVE ingester with last keepalive newer than timeout": { - ingester: &InstanceDesc{State: ACTIVE, Timestamp: time.Now().Add(-30 * time.Second).Unix()}, + "InstanceState_ACTIVE ingester with last keepalive newer than timeout": { + ingester: &InstanceDesc{State: InstanceState_ACTIVE, Timestamp: time.Now().Add(-30 * time.Second).Unix()}, timeout: time.Minute, writeExpected: true, readExpected: true, reportExpected: true, }, - "ACTIVE ingester with last keepalive older than timeout": { - ingester: &InstanceDesc{State: ACTIVE, Timestamp: time.Now().Add(-90 * time.Second).Unix()}, + "InstanceState_ACTIVE ingester with last keepalive older than timeout": { + ingester: &InstanceDesc{State: InstanceState_ACTIVE, Timestamp: time.Now().Add(-90 * time.Second).Unix()}, timeout: time.Minute, writeExpected: false, readExpected: false, reportExpected: false, }, - "JOINING ingester with last keepalive newer than timeout": { - ingester: &InstanceDesc{State: JOINING, Timestamp: time.Now().Add(-30 * time.Second).Unix()}, + "InstanceState_JOINING ingester with last keepalive newer than timeout": { + ingester: &InstanceDesc{State: InstanceState_JOINING, Timestamp: time.Now().Add(-30 * time.Second).Unix()}, timeout: time.Minute, writeExpected: false, readExpected: false, reportExpected: true, }, - "LEAVING ingester with last keepalive newer than timeout": { - ingester: &InstanceDesc{State: LEAVING, Timestamp: time.Now().Add(-30 * time.Second).Unix()}, + "InstanceState_LEAVING ingester with last keepalive newer than timeout": { + ingester: &InstanceDesc{State: InstanceState_LEAVING, Timestamp: time.Now().Add(-30 * time.Second).Unix()}, timeout: time.Minute, writeExpected: false, readExpected: true, @@ -156,7 +156,7 @@ func TestDesc_Ready(t *testing.T) { Ingesters: map[string]InstanceDesc{ "ing1": { Tokens: []uint32{100, 200, 300}, - State: ACTIVE, + State: InstanceState_ACTIVE, Timestamp: now.Unix(), }, }, @@ -181,7 +181,7 @@ func TestDesc_Ready(t *testing.T) { r = &Desc{ Ingesters: map[string]InstanceDesc{ "ing1": { - State: ACTIVE, + State: InstanceState_ACTIVE, Timestamp: now.Unix(), }, }, @@ -311,13 +311,13 @@ func TestDesc_RingsCompare(t *testing.T) { expected: EqualButStatesAndTimestamps, }, "same single instance, different state": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: ACTIVE}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: JOINING}}}, + r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_ACTIVE}}}, + r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_JOINING}}}, expected: EqualButStatesAndTimestamps, }, "same single instance, different registered timestamp": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: ACTIVE, RegisteredTimestamp: 1}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: ACTIVE, RegisteredTimestamp: 2}}}, + r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_ACTIVE, RegisteredTimestamp: 1}}}, + r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_ACTIVE, RegisteredTimestamp: 2}}}, expected: Different, }, "same single instance, different read only flag": { diff --git a/ring/partition_instance_lifecycler.go b/ring/partition_instance_lifecycler.go index 09fef7223..29e68211a 100644 --- a/ring/partition_instance_lifecycler.go +++ b/ring/partition_instance_lifecycler.go @@ -35,7 +35,7 @@ type PartitionInstanceLifecyclerConfig struct { InstanceID string // WaitOwnersCountOnPending is the minimum number of owners to wait before switching a - // PENDING partition to ACTIVE. + // InstanceState_PENDING partition to InstanceState_ACTIVE. WaitOwnersCountOnPending int // WaitOwnersDurationOnPending is how long each owner should have been added to the @@ -275,7 +275,7 @@ func (l *PartitionInstanceLifecycler) createPartitionAndRegisterOwner(ctx contex if !exists { // The partition doesn't exist, so we create a new one. A new partition should always be created - // in PENDING state. + // in InstanceState_PENDING state. ring.AddPartition(l.cfg.PartitionID, PartitionPending, now) changed = true } diff --git a/ring/partition_instance_ring_test.go b/ring/partition_instance_ring_test.go index ef29bcb0c..2d0fce2c3 100644 --- a/ring/partition_instance_ring_test.go +++ b/ring/partition_instance_ring_test.go @@ -12,7 +12,7 @@ import ( func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { now := time.Now() - op := NewOp([]InstanceState{ACTIVE}, nil) + op := NewOp([]InstanceState{InstanceState_ACTIVE}, nil) heartbeatTimeout := time.Minute type comparableReplicationSet struct { @@ -29,8 +29,8 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { "should return error on empty partitions ring": { partitionsRing: PartitionRingDesc{}, instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ - "instance-1": {Id: "instance-1", State: ACTIVE, Timestamp: now.Unix()}, - "instance-2": {Id: "instance-2", State: ACTIVE, Timestamp: now.Unix()}, + "instance-1": {Id: "instance-1", State: InstanceState_ACTIVE, Timestamp: now.Unix()}, + "instance-2": {Id: "instance-2", State: InstanceState_ACTIVE, Timestamp: now.Unix()}, }}, expectedErr: ErrEmptyRing, }, @@ -61,9 +61,9 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }, }, instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ - "instance-zone-a-1": {Id: "instance-zone-a-1", State: ACTIVE, Zone: "a", Timestamp: now.Unix()}, - "instance-zone-a-2": {Id: "instance-zone-a-2", State: ACTIVE, Zone: "a", Timestamp: now.Unix()}, - "instance-zone-b-2": {Id: "instance-zone-b-2", State: ACTIVE, Zone: "b", Timestamp: now.Unix()}, + "instance-zone-a-1": {Id: "instance-zone-a-1", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, + "instance-zone-a-2": {Id: "instance-zone-a-2", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, + "instance-zone-b-2": {Id: "instance-zone-b-2", State: InstanceState_ACTIVE, Zone: "b", Timestamp: now.Unix()}, }}, expectedSets: []comparableReplicationSet{ {instances: []string{"instance-zone-a-1"}, maxUnavailableZones: 0}, @@ -83,8 +83,8 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }, }, instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ - "instance-zone-a-1": {Id: "instance-zone-a-1", State: ACTIVE, Zone: "a", Timestamp: now.Unix()}, - "instance-zone-a-2": {Id: "instance-zone-a-2", State: ACTIVE, Zone: "a", Timestamp: now.Add(-2 * time.Minute).Unix()}, // Unhealthy. + "instance-zone-a-1": {Id: "instance-zone-a-1", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, + "instance-zone-a-2": {Id: "instance-zone-a-2", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Add(-2 * time.Minute).Unix()}, // Unhealthy. }}, expectedErr: ErrTooManyUnhealthyInstances, }, @@ -102,10 +102,10 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }, }, instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ - "instance-zone-a-1": {Id: "instance-zone-a-1", State: ACTIVE, Zone: "a", Timestamp: now.Unix()}, - "instance-zone-b-1": {Id: "instance-zone-a-1", State: LEAVING, Zone: "a", Timestamp: now.Unix()}, // Unhealthy because of the state. - "instance-zone-a-2": {Id: "instance-zone-a-2", State: ACTIVE, Zone: "a", Timestamp: now.Unix()}, - "instance-zone-b-2": {Id: "instance-zone-b-2", State: ACTIVE, Zone: "b", Timestamp: now.Add(-2 * time.Minute).Unix()}, // Unhealthy because of the heartbeat. + "instance-zone-a-1": {Id: "instance-zone-a-1", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, + "instance-zone-b-1": {Id: "instance-zone-a-1", State: InstanceState_LEAVING, Zone: "a", Timestamp: now.Unix()}, // Unhealthy because of the state. + "instance-zone-a-2": {Id: "instance-zone-a-2", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, + "instance-zone-b-2": {Id: "instance-zone-b-2", State: InstanceState_ACTIVE, Zone: "b", Timestamp: now.Add(-2 * time.Minute).Unix()}, // Unhealthy because of the heartbeat. }}, expectedSets: []comparableReplicationSet{ {instances: []string{"instance-zone-a-1"}, maxUnavailableZones: 0}, @@ -126,8 +126,8 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }, }, instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ - "instance-zone-a-1": {Id: "instance-zone-a-1", State: ACTIVE, Zone: "a", Timestamp: now.Unix()}, - "instance-zone-b-2": {Id: "instance-zone-b-2", State: ACTIVE, Zone: "b", Timestamp: now.Unix()}, + "instance-zone-a-1": {Id: "instance-zone-a-1", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, + "instance-zone-b-2": {Id: "instance-zone-b-2", State: InstanceState_ACTIVE, Zone: "b", Timestamp: now.Unix()}, }}, expectedSets: []comparableReplicationSet{ {instances: []string{"instance-zone-a-1"}, maxUnavailableZones: 0}, @@ -148,10 +148,10 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }, }, instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ - "instance-zone-a-1": {Id: "instance-zone-a-1", State: ACTIVE, Zone: "fixed", Timestamp: now.Unix()}, - "instance-zone-b-1": {Id: "instance-zone-b-1", State: ACTIVE, Zone: "fixed", Timestamp: now.Unix()}, - "instance-zone-a-2": {Id: "instance-zone-a-2", State: ACTIVE, Zone: "fixed", Timestamp: now.Unix()}, - "instance-zone-b-2": {Id: "instance-zone-b-2", State: ACTIVE, Zone: "fixed", Timestamp: now.Unix()}, + "instance-zone-a-1": {Id: "instance-zone-a-1", State: InstanceState_ACTIVE, Zone: "fixed", Timestamp: now.Unix()}, + "instance-zone-b-1": {Id: "instance-zone-b-1", State: InstanceState_ACTIVE, Zone: "fixed", Timestamp: now.Unix()}, + "instance-zone-a-2": {Id: "instance-zone-a-2", State: InstanceState_ACTIVE, Zone: "fixed", Timestamp: now.Unix()}, + "instance-zone-b-2": {Id: "instance-zone-b-2", State: InstanceState_ACTIVE, Zone: "fixed", Timestamp: now.Unix()}, }}, expectedSets: []comparableReplicationSet{ {instances: []string{"instance-zone-a-1", "instance-zone-b-1"}, maxUnavailableZones: 0}, @@ -199,7 +199,7 @@ func BenchmarkPartitionInstanceRing_GetReplicationSetsForOperation(b *testing.B) for _, zone := range zones { instanceID := fmt.Sprintf("instance-zone-%s-%d", zone, partitionID) - instancesRing.ringDesc.AddIngester(instanceID, instanceID, zone, nil, ACTIVE, now, false, readOnlyUpdated) + instancesRing.ringDesc.AddIngester(instanceID, instanceID, zone, nil, InstanceState_ACTIVE, now, false, readOnlyUpdated) partitionsRing.AddOrUpdateOwner(instanceID, OwnerActive, int32(partitionID), now) } } @@ -231,9 +231,9 @@ func TestPartitionInstanceRing_ShuffleShard(t *testing.T) { partitionsRing.AddOrUpdateOwner("instance-3", OwnerActive, 3, now.Add(-30*time.Minute)) instancesRing := &Desc{Ingesters: map[string]InstanceDesc{ - "instance-1": {Id: "instance-1", State: ACTIVE, Timestamp: time.Now().Unix()}, - "instance-2": {Id: "instance-2", State: ACTIVE, Timestamp: time.Now().Unix()}, - "instance-3": {Id: "instance-3", State: ACTIVE, Timestamp: time.Now().Unix()}, + "instance-1": {Id: "instance-1", State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()}, + "instance-2": {Id: "instance-2", State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()}, + "instance-3": {Id: "instance-3", State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()}, }} r := NewPartitionInstanceRing(newStaticPartitionRingReader(NewPartitionRing(*partitionsRing)), &Ring{ringDesc: instancesRing}, 0) diff --git a/ring/partition_ring.go b/ring/partition_ring.go index 21ef2d7fd..ec433027c 100644 --- a/ring/partition_ring.go +++ b/ring/partition_ring.go @@ -110,7 +110,7 @@ func (r *PartitionRing) ShuffleShardSize(size int) int { // predictable numbers. The random generator is initialised with a seed based on the // provided identifier. // -// This function returns a subring containing ONLY ACTIVE partitions. +// This function returns a subring containing ONLY InstanceState_ACTIVE partitions. // // This function supports caching. // @@ -141,8 +141,8 @@ func (r *PartitionRing) ShuffleShard(identifier string, size int) (*PartitionRin // ShuffleShardWithLookback is like ShuffleShard() but the returned subring includes all instances // that have been part of the identifier's shard in [now - lookbackPeriod, now] time window. // -// This function can return a mix of ACTIVE and INACTIVE partitions. INACTIVE partitions are only -// included if they were part of the identifier's shard within the lookbackPeriod. PENDING partitions +// This function can return a mix of InstanceState_ACTIVE and INACTIVE partitions. INACTIVE partitions are only +// included if they were part of the identifier's shard within the lookbackPeriod. InstanceState_PENDING partitions // are never returned. // // This function supports caching, but the cache will only be effective if successive calls for the @@ -216,7 +216,7 @@ func (r *PartitionRing) shuffleShard(identifier string, size int, lookbackPeriod return nil, ErrInconsistentTokensInfo } - // PENDING partitions should be skipped because they're not ready for read or write yet, + // InstanceState_PENDING partitions should be skipped because they're not ready for read or write yet, // and they don't need to be looked back. if p.IsPending() { exclude[pid] = struct{}{} @@ -292,7 +292,7 @@ func (r *PartitionRing) PartitionIDs() []int32 { return ids } -// PendingPartitionIDs returns a sorted list of all PENDING partition IDs in the ring. +// PendingPartitionIDs returns a sorted list of all InstanceState_PENDING partition IDs in the ring. // The returned slice is a copy, so the caller can freely manipulate it. func (r *PartitionRing) PendingPartitionIDs() []int32 { ids := make([]int32, 0, len(r.desc.Partitions)) @@ -307,7 +307,7 @@ func (r *PartitionRing) PendingPartitionIDs() []int32 { return ids } -// ActivePartitionIDs returns a sorted list of all ACTIVE partition IDs in the ring. +// ActivePartitionIDs returns a sorted list of all InstanceState_ACTIVE partition IDs in the ring. // The returned slice is a copy, so the caller can freely manipulate it. func (r *PartitionRing) ActivePartitionIDs() []int32 { ids := make([]int32, 0, len(r.desc.Partitions)) @@ -428,7 +428,7 @@ func (r *PartitionRing) GetTokenRangesForPartition(partitionID int32) (TokenRang return ranges, nil } -// ActivePartitionBatchRing wraps PartitionRing and implements DoBatchRing to lookup ACTIVE partitions. +// ActivePartitionBatchRing wraps PartitionRing and implements DoBatchRing to lookup InstanceState_ACTIVE partitions. type ActivePartitionBatchRing struct { ring *PartitionRing } @@ -473,7 +473,7 @@ func (r *ActivePartitionBatchRing) Get(key uint32, _ Operation, bufInstances []I bufInstances[0] = InstanceDesc{ Addr: partitionIDString, Timestamp: 0, - State: ACTIVE, + State: InstanceState_ACTIVE, Id: partitionIDString, } diff --git a/ring/partition_ring_desc.proto b/ring/partition_ring_desc.proto index d8fb9316f..312d7193d 100644 --- a/ring/partition_ring_desc.proto +++ b/ring/partition_ring_desc.proto @@ -35,7 +35,7 @@ message PartitionDesc { enum PartitionState { PartitionUnknown = 0; - // Pending partition is a partition that is about to be switched to ACTIVE. This state is used + // Pending partition is a partition that is about to be switched to InstanceState_ACTIVE. This state is used // to let owners to attach to the partition and get ready to handle the partition. // // When a partition is in this state, it must not be used for writing or reading. diff --git a/ring/partition_ring_test.go b/ring/partition_ring_test.go index db75396f8..145274cc2 100644 --- a/ring/partition_ring_test.go +++ b/ring/partition_ring_test.go @@ -190,7 +190,7 @@ func TestPartitionRing_ShuffleShard(t *testing.T) { assert.Equal(t, subring.PartitionsCount(), ring.ShuffleShardSize(numActivePartitions+1)) }) - t.Run("should never return INACTIVE or PENDING partitions", func(t *testing.T) { + t.Run("should never return INACTIVE or InstanceState_PENDING partitions", func(t *testing.T) { const ( numActivePartitions = 5 numInactivePartitions = 5 @@ -1169,7 +1169,7 @@ func TestActivePartitionBatchRing(t *testing.T) { } func TestActivePartitionBatchRing_InstancesCount(t *testing.T) { - t.Run("should return the number of ACTIVE partitions", func(t *testing.T) { + t.Run("should return the number of InstanceState_ACTIVE partitions", func(t *testing.T) { activeRing := NewActivePartitionBatchRing(createPartitionRingWithPartitions(10, 3, 2)) assert.Equal(t, 10, activeRing.InstancesCount()) }) @@ -1230,13 +1230,13 @@ func BenchmarkActivePartitionBatchRing_Get(b *testing.B) { benchCases := map[string]struct { ring *ActivePartitionBatchRing }{ - "ACTIVE partitions only": { + "InstanceState_ACTIVE partitions only": { ring: NewActivePartitionBatchRing(createPartitionRingWithPartitions(100, 0, 0)), }, - "ACTIVE and INACTIVE partitions": { + "InstanceState_ACTIVE and INACTIVE partitions": { ring: NewActivePartitionBatchRing(createPartitionRingWithPartitions(100, 10, 0)), }, - "ACTIVE, INACTIVE and PENDING partitions": { + "InstanceState_ACTIVE, INACTIVE and InstanceState_PENDING partitions": { ring: NewActivePartitionBatchRing(createPartitionRingWithPartitions(100, 10, 10)), }, } diff --git a/ring/partition_ring_watcher_test.go b/ring/partition_ring_watcher_test.go index 540626643..2e0c292bb 100644 --- a/ring/partition_ring_watcher_test.go +++ b/ring/partition_ring_watcher_test.go @@ -46,7 +46,7 @@ func TestPartitionRingWatcher_ShouldWatchUpdates(t *testing.T) { partition_ring_partitions{name="test",state="Inactive"} 0 `))) - // Add an ACTIVE partition to the ring. + // Add an InstanceState_ACTIVE partition to the ring. require.NoError(t, store.CAS(ctx, ringKey, func(in interface{}) (out interface{}, retry bool, err error) { desc := GetOrCreatePartitionRingDesc(in) desc.AddPartition(1, PartitionActive, time.Now()) @@ -84,7 +84,7 @@ func TestPartitionRingWatcher_ShouldWatchUpdates(t *testing.T) { partition_ring_partitions{name="test",state="Inactive"} 1 `))) - // Add a PENDING partition to the ring. + // Add a InstanceState_PENDING partition to the ring. require.NoError(t, store.CAS(ctx, ringKey, func(in interface{}) (out interface{}, retry bool, err error) { desc := GetOrCreatePartitionRingDesc(in) desc.AddPartition(3, PartitionPending, time.Now()) diff --git a/ring/replication_set.go b/ring/replication_set.go index ae3782020..ede46e9c1 100644 --- a/ring/replication_set.go +++ b/ring/replication_set.go @@ -580,7 +580,7 @@ func HasReplicationSetChanged(before, after ReplicationSet) bool { func HasReplicationSetChangedWithoutState(before, after ReplicationSet) bool { return hasReplicationSetChangedExcluding(before, after, func(i *InstanceDesc) { i.Timestamp = 0 - i.State = PENDING + i.State = InstanceState_PENDING }) } @@ -590,7 +590,7 @@ func HasReplicationSetChangedWithoutState(before, after ReplicationSet) bool { func HasReplicationSetChangedWithoutStateOrAddr(before, after ReplicationSet) bool { return hasReplicationSetChangedExcluding(before, after, func(i *InstanceDesc) { i.Timestamp = 0 - i.State = PENDING + i.State = InstanceState_PENDING i.Addr = "" }) } diff --git a/ring/replication_set_test.go b/ring/replication_set_test.go index 4b8ac021d..7f627d4e2 100644 --- a/ring/replication_set_test.go +++ b/ring/replication_set_test.go @@ -1935,7 +1935,7 @@ var ( "state changed": { ReplicationSet{ Instances: []InstanceDesc{ - {Id: "ingester-0", State: PENDING}, + {Id: "ingester-0", State: InstanceState_PENDING}, {Id: "ingester-1"}, {Id: "ingester-2"}, }, diff --git a/ring/ring.go b/ring/ring.go index 62a49a6d8..0123d38c2 100644 --- a/ring/ring.go +++ b/ring/ring.go @@ -30,7 +30,7 @@ const ( unhealthy = "Unhealthy" // GetBufferSize is the suggested size of buffers passed to Ring.Get(). It's based on - // a typical replication factor 3, plus extra room for a JOINING + LEAVING instance. + // a typical replication factor 3, plus extra room for a InstanceState_JOINING + InstanceState_LEAVING instance. GetBufferSize = 5 ) @@ -99,23 +99,23 @@ type ReadRing interface { } var ( - // Write operation that also extends replica set, if instance state is not ACTIVE. - Write = NewOp([]InstanceState{ACTIVE}, func(s InstanceState) bool { - // We do not want to Write to instances that are not ACTIVE, but we do want + // Write operation that also extends replica set, if instance state is not InstanceState_ACTIVE. + Write = NewOp([]InstanceState{InstanceState_ACTIVE}, func(s InstanceState) bool { + // We do not want to Write to instances that are not InstanceState_ACTIVE, but we do want // to write the extra replica somewhere. So we increase the size of the set // of replicas for the key. // NB unhealthy instances will be filtered later by defaultReplicationStrategy.Filter(). - return s != ACTIVE + return s != InstanceState_ACTIVE }) // WriteNoExtend is like Write, but with no replicaset extension. - WriteNoExtend = NewOp([]InstanceState{ACTIVE}, nil) + WriteNoExtend = NewOp([]InstanceState{InstanceState_ACTIVE}, nil) - // Read operation that extends the replica set if an instance is not ACTIVE or LEAVING - Read = NewOp([]InstanceState{ACTIVE, PENDING, LEAVING}, func(s InstanceState) bool { + // Read operation that extends the replica set if an instance is not InstanceState_ACTIVE or InstanceState_LEAVING + Read = NewOp([]InstanceState{InstanceState_ACTIVE, InstanceState_PENDING, InstanceState_LEAVING}, func(s InstanceState) bool { // To match Write with extended replica set we have to also increase the - // size of the replica set for Read, but we can read from LEAVING ingesters. - return s != ACTIVE && s != LEAVING + // size of the replica set for Read, but we can read from InstanceState_LEAVING ingesters. + return s != InstanceState_ACTIVE && s != InstanceState_LEAVING }) // Reporting is a special value for inquiring about health. @@ -665,7 +665,7 @@ func (r *Ring) updateRingMetrics() { oldestTimestampByState := map[string]int64{} // Initialized to zero so we emit zero-metrics (instead of not emitting anything) - for _, s := range []string{unhealthy, ACTIVE.String(), LEAVING.String(), PENDING.String(), JOINING.String()} { + for _, s := range []string{unhealthy, InstanceState_ACTIVE.String(), InstanceState_LEAVING.String(), InstanceState_PENDING.String(), InstanceState_JOINING.String()} { numByState[s] = 0 oldestTimestampByState[s] = 0 } @@ -1040,7 +1040,7 @@ func (r *Ring) GetInstance(instanceID string) (doNotModify InstanceDesc, _ error func (r *Ring) GetInstanceState(instanceID string) (InstanceState, error) { instance, err := r.GetInstance(instanceID) if err != nil { - return PENDING, err + return InstanceState_PENDING, err } return instance.GetState(), nil @@ -1311,7 +1311,7 @@ func NewOp(healthyStates []InstanceState, shouldExtendReplicaSet func(s Instance } if shouldExtendReplicaSet != nil { - for _, s := range []InstanceState{ACTIVE, LEAVING, PENDING, JOINING, LEFT} { + for _, s := range []InstanceState{InstanceState_ACTIVE, InstanceState_LEAVING, InstanceState_PENDING, InstanceState_JOINING, InstanceState_LEFT} { if shouldExtendReplicaSet(s) { op |= (0x10000 << s) } diff --git a/ring/ring.proto b/ring/ring.proto index 13a62fb3a..f55515f78 100644 --- a/ring/ring.proto +++ b/ring/ring.proto @@ -55,13 +55,13 @@ message InstanceDesc { } enum InstanceState { - ACTIVE = 0; - LEAVING = 1; + InstanceState_ACTIVE = 0; + InstanceState_LEAVING = 1; - PENDING = 2; - JOINING = 3; + InstanceState_PENDING = 2; + InstanceState_JOINING = 3; // This state is only used by gossiping code to distribute information about // instances that have been removed from the ring. Ring users should not use it directly. - LEFT = 4; + InstanceState_LEFT = 4; } diff --git a/ring/ring_http_test.go b/ring/ring_http_test.go index 8c27016f7..e3548a4e8 100644 --- a/ring/ring_http_test.go +++ b/ring/ring_http_test.go @@ -20,14 +20,14 @@ func TestRingPageHandler_handle(t *testing.T) { Ingesters: map[string]InstanceDesc{ "1": { Zone: "zone-a", - State: ACTIVE, + State: InstanceState_ACTIVE, Addr: "addr-a", Timestamp: now.Unix(), Tokens: []uint32{1000000, 3000000, 6000000}, }, "2": { Zone: "zone-b", - State: ACTIVE, + State: InstanceState_ACTIVE, Addr: "addr-b", Timestamp: now.Unix(), Tokens: []uint32{2000000, 4000000, 5000000, 7000000}, @@ -47,7 +47,7 @@ func TestRingPageHandler_handle(t *testing.T) { assert.Regexp(t, regexp.MustCompile(fmt.Sprintf("(?m)%s", strings.Join([]string{ "", "1", "", "", "zone-a", "", - "", "ACTIVE", "", + "", "InstanceState_ACTIVE", "", "", "addr-a", "", }, `\s*`))), recorder.Body.String()) @@ -59,7 +59,7 @@ func TestRingPageHandler_handle(t *testing.T) { assert.Regexp(t, regexp.MustCompile(fmt.Sprintf("(?m)%s", strings.Join([]string{ "", "2", "", "", "zone-b", "", - "", "ACTIVE", "", + "", "InstanceState_ACTIVE", "", "", "addr-b", "", }, `\s*`))), recorder.Body.String()) diff --git a/ring/ring_test.go b/ring/ring_test.go index 909c5d019..3b86c8db5 100644 --- a/ring/ring_test.go +++ b/ring/ring_test.go @@ -69,7 +69,7 @@ func benchmarkBatch(b *testing.B, numInstances, numKeys int) { for i := 0; i < numInstances; i++ { tokens := gen.GenerateTokens(numTokens, takenTokens) takenTokens = append(takenTokens, tokens...) - desc.AddIngester(fmt.Sprintf("%d", i), fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, ACTIVE, time.Now(), false, time.Time{}) + desc.AddIngester(fmt.Sprintf("%d", i), fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, InstanceState_ACTIVE, time.Now(), false, time.Time{}) } cfg := Config{} @@ -162,13 +162,13 @@ func benchmarkUpdateRingState(b *testing.B, numInstances, numTokens int, updateT now := time.Now() zeroTime := time.Time{} id := fmt.Sprintf("%d", i) - desc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, ACTIVE, now, false, zeroTime) + desc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, InstanceState_ACTIVE, now, false, zeroTime) if updateTokens { otherTokens := gen.GenerateTokens(numTokens, otherTakenTokens) otherTakenTokens = append(otherTakenTokens, otherTokens...) - otherDesc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), otherTokens, ACTIVE, now, false, zeroTime) + otherDesc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), otherTokens, InstanceState_ACTIVE, now, false, zeroTime) } else { - otherDesc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, JOINING, now, false, zeroTime) + otherDesc.AddIngester(id, fmt.Sprintf("instance-%d", i), strconv.Itoa(i), tokens, InstanceState_JOINING, now, false, zeroTime) } } @@ -353,7 +353,7 @@ func TestDoBatch_QuorumError(t *testing.T) { for address := 0; address < replicationFactor; address++ { instTokens := gen.GenerateTokens(128, nil) instanceID := fmt.Sprintf("%d", address) - desc.AddIngester(instanceID, instanceID, "", instTokens, ACTIVE, time.Now(), false, time.Time{}) + desc.AddIngester(instanceID, instanceID, "", instTokens, InstanceState_ACTIVE, time.Now(), false, time.Time{}) } ringConfig := Config{ HeartbeatTimeout: time.Hour, @@ -490,7 +490,7 @@ func TestDoBatch_QuorumError(t *testing.T) { for testName, testData := range testCases { t.Run(testName, func(t *testing.T) { - updateState(testData.unavailableInstances, LEFT) + updateState(testData.unavailableInstances, InstanceState_LEFT) for i := 0; i < numberOfOperations; i++ { err := runDoBatch(testData.errors, testData.isClientError) if testData.acceptableOutcomes == nil { @@ -500,7 +500,7 @@ func TestDoBatch_QuorumError(t *testing.T) { } } unfinishedDoBatchCalls.Wait() - updateState(testData.unavailableInstances, ACTIVE) + updateState(testData.unavailableInstances, InstanceState_ACTIVE) }) } } @@ -513,7 +513,7 @@ func TestAddIngester(t *testing.T) { now := time.Now() ing1Tokens := initTokenGenerator(t).GenerateTokens(128, nil) - r.AddIngester(ingName, "addr", "1", ing1Tokens, ACTIVE, now, false, time.Time{}) + r.AddIngester(ingName, "addr", "1", ing1Tokens, InstanceState_ACTIVE, now, false, time.Time{}) assert.Equal(t, "addr", r.Ingesters[ingName].Addr) assert.Equal(t, ing1Tokens, Tokens(r.Ingesters[ingName].Tokens)) @@ -535,7 +535,7 @@ func TestAddIngesterReplacesExistingTokens(t *testing.T) { newTokens := initTokenGenerator(t).GenerateTokens(128, nil) - r.AddIngester(ing1Name, "addr", "1", newTokens, ACTIVE, time.Now(), false, time.Time{}) + r.AddIngester(ing1Name, "addr", "1", newTokens, InstanceState_ACTIVE, time.Now(), false, time.Time{}) require.Equal(t, newTokens, Tokens(r.Ingesters[ing1Name].Tokens)) } @@ -566,12 +566,12 @@ func TestRing_Get_ZoneAwarenessWithIngesterLeaving(t *testing.T) { r := NewDesc() instances := map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE}, - "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE}, - "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: ACTIVE}, - "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: ACTIVE}, - "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: LEAVING}, - "instance-6": {Addr: "127.0.0.6", Zone: "zone-c", State: ACTIVE}, + "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE}, + "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_ACTIVE}, + "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: InstanceState_ACTIVE}, + "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: InstanceState_ACTIVE}, + "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: InstanceState_LEAVING}, + "instance-6": {Addr: "127.0.0.6", Zone: "zone-c", State: InstanceState_ACTIVE}, } var prevTokens []uint32 for id, instance := range instances { @@ -665,7 +665,7 @@ func TestRing_Get_ZoneAwareness(t *testing.T) { name := fmt.Sprintf("ing%v", i) ingTokens := gen.GenerateTokens(128, prevTokens) - r.AddIngester(name, fmt.Sprintf("127.0.0.%d", i), fmt.Sprintf("zone-%v", i%testData.numZones), ingTokens, ACTIVE, time.Now(), false, time.Time{}) + r.AddIngester(name, fmt.Sprintf("127.0.0.%d", i), fmt.Sprintf("zone-%v", i%testData.numZones), ingTokens, InstanceState_ACTIVE, time.Now(), false, time.Time{}) prevTokens = append(prevTokens, ingTokens...) } @@ -742,11 +742,11 @@ func TestRing_GetAllHealthy(t *testing.T) { }, "should return all healthy instances for the given operation": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", State: ACTIVE, Timestamp: now.Unix()}, - "instance-2": {Addr: "127.0.0.2", State: PENDING, Timestamp: now.Add(-10 * time.Second).Unix()}, - "instance-3": {Addr: "127.0.0.3", State: JOINING, Timestamp: now.Add(-20 * time.Second).Unix()}, - "instance-4": {Addr: "127.0.0.4", State: LEAVING, Timestamp: now.Add(-30 * time.Second).Unix()}, - "instance-5": {Addr: "127.0.0.5", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix()}, + "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Unix()}, + "instance-2": {Addr: "127.0.0.2", State: InstanceState_PENDING, Timestamp: now.Add(-10 * time.Second).Unix()}, + "instance-3": {Addr: "127.0.0.3", State: InstanceState_JOINING, Timestamp: now.Add(-20 * time.Second).Unix()}, + "instance-4": {Addr: "127.0.0.4", State: InstanceState_LEAVING, Timestamp: now.Add(-30 * time.Second).Unix()}, + "instance-5": {Addr: "127.0.0.5", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix()}, }, expectedSetForRead: []string{"127.0.0.1", "127.0.0.2", "127.0.0.4"}, expectedSetForWrite: []string{"127.0.0.1"}, @@ -805,11 +805,11 @@ func TestRing_GetReplicationSetForOperation(t *testing.T) { }, "should succeed on all healthy instances and RF=1": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", State: ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-2": {Addr: "127.0.0.2", State: ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-3": {Addr: "127.0.0.3", State: ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-4": {Addr: "127.0.0.4", State: ACTIVE, Timestamp: now.Add(-30 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-5": {Addr: "127.0.0.5", State: ACTIVE, Timestamp: now.Add(-40 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-2": {Addr: "127.0.0.2", State: InstanceState_ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-3": {Addr: "127.0.0.3", State: InstanceState_ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-4": {Addr: "127.0.0.4", State: InstanceState_ACTIVE, Timestamp: now.Add(-30 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-5": {Addr: "127.0.0.5", State: InstanceState_ACTIVE, Timestamp: now.Add(-40 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, }, ringHeartbeatTimeout: time.Minute, ringReplicationFactor: 1, @@ -819,11 +819,11 @@ func TestRing_GetReplicationSetForOperation(t *testing.T) { }, "should succeed on instances with old timestamps but heartbeat timeout disabled": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-2": {Addr: "127.0.0.2", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-3": {Addr: "127.0.0.3", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-4": {Addr: "127.0.0.4", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-5": {Addr: "127.0.0.5", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-2": {Addr: "127.0.0.2", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-3": {Addr: "127.0.0.3", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-4": {Addr: "127.0.0.4", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-5": {Addr: "127.0.0.5", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, }, ringHeartbeatTimeout: 0, ringReplicationFactor: 1, @@ -833,11 +833,11 @@ func TestRing_GetReplicationSetForOperation(t *testing.T) { }, "should fail on 1 unhealthy instance and RF=1": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", State: ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-2": {Addr: "127.0.0.2", State: ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-3": {Addr: "127.0.0.3", State: ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-4": {Addr: "127.0.0.4", State: ACTIVE, Timestamp: now.Add(-30 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-5": {Addr: "127.0.0.5", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-2": {Addr: "127.0.0.2", State: InstanceState_ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-3": {Addr: "127.0.0.3", State: InstanceState_ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-4": {Addr: "127.0.0.4", State: InstanceState_ACTIVE, Timestamp: now.Add(-30 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-5": {Addr: "127.0.0.5", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, }, ringHeartbeatTimeout: time.Minute, ringReplicationFactor: 1, @@ -847,11 +847,11 @@ func TestRing_GetReplicationSetForOperation(t *testing.T) { }, "should succeed on 1 unhealthy instances and RF=3": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", State: ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-2": {Addr: "127.0.0.2", State: ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-3": {Addr: "127.0.0.3", State: ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-4": {Addr: "127.0.0.4", State: ACTIVE, Timestamp: now.Add(-30 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-5": {Addr: "127.0.0.5", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-2": {Addr: "127.0.0.2", State: InstanceState_ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-3": {Addr: "127.0.0.3", State: InstanceState_ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-4": {Addr: "127.0.0.4", State: InstanceState_ACTIVE, Timestamp: now.Add(-30 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-5": {Addr: "127.0.0.5", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, }, ringHeartbeatTimeout: time.Minute, ringReplicationFactor: 3, @@ -861,11 +861,11 @@ func TestRing_GetReplicationSetForOperation(t *testing.T) { }, "should fail on 2 unhealthy instances and RF=3": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", State: ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-2": {Addr: "127.0.0.2", State: ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-3": {Addr: "127.0.0.3", State: ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-4": {Addr: "127.0.0.4", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, - "instance-5": {Addr: "127.0.0.5", State: ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-2": {Addr: "127.0.0.2", State: InstanceState_ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-3": {Addr: "127.0.0.3", State: InstanceState_ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-4": {Addr: "127.0.0.4", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, + "instance-5": {Addr: "127.0.0.5", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, }, ringHeartbeatTimeout: time.Minute, ringReplicationFactor: 3, @@ -1188,7 +1188,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. ringDesc := &Desc{Ingesters: testData.ringInstances} for id, instance := range ringDesc.Ingesters { instance.Timestamp = time.Now().Unix() - instance.State = ACTIVE + instance.State = InstanceState_ACTIVE for _, instanceName := range testData.unhealthyInstances { if instanceName == id { instance.Timestamp = time.Now().Add(-time.Hour).Unix() @@ -1244,38 +1244,38 @@ func TestRing_GetInstancesWithTokensCounts(t *testing.T) { }, "single zone, no tokens": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Tokens: []uint32{}}, - "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: LEAVING, Tokens: []uint32{}}, - "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: PENDING, Tokens: []uint32{}}, - "instance-4": {Addr: "127.0.0.4", Zone: "zone-a", State: JOINING, Tokens: []uint32{}}, + "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}}, + "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_LEAVING, Tokens: []uint32{}}, + "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: InstanceState_PENDING, Tokens: []uint32{}}, + "instance-4": {Addr: "127.0.0.4", Zone: "zone-a", State: InstanceState_JOINING, Tokens: []uint32{}}, }, expectedInstancesWithTokensCount: 0, expectedInstancesWithTokensInZoneCount: map[string]int{"zone-a": 0}, }, "single zone, some tokens": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, - "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE, Tokens: []uint32{}}, - "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: LEAVING, Tokens: gen.GenerateTokens(128, nil)}, - "instance-4": {Addr: "127.0.0.4", Zone: "zone-a", State: LEAVING, Tokens: []uint32{}}, - "instance-5": {Addr: "127.0.0.5", Zone: "zone-a", State: PENDING, Tokens: gen.GenerateTokens(128, nil)}, - "instance-6": {Addr: "127.0.0.6", Zone: "zone-a", State: PENDING, Tokens: []uint32{}}, - "instance-7": {Addr: "127.0.0.7", Zone: "zone-a", State: JOINING, Tokens: gen.GenerateTokens(128, nil)}, - "instance-8": {Addr: "127.0.0.8", Zone: "zone-a", State: JOINING, Tokens: []uint32{}}, + "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, + "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}}, + "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: InstanceState_LEAVING, Tokens: gen.GenerateTokens(128, nil)}, + "instance-4": {Addr: "127.0.0.4", Zone: "zone-a", State: InstanceState_LEAVING, Tokens: []uint32{}}, + "instance-5": {Addr: "127.0.0.5", Zone: "zone-a", State: InstanceState_PENDING, Tokens: gen.GenerateTokens(128, nil)}, + "instance-6": {Addr: "127.0.0.6", Zone: "zone-a", State: InstanceState_PENDING, Tokens: []uint32{}}, + "instance-7": {Addr: "127.0.0.7", Zone: "zone-a", State: InstanceState_JOINING, Tokens: gen.GenerateTokens(128, nil)}, + "instance-8": {Addr: "127.0.0.8", Zone: "zone-a", State: InstanceState_JOINING, Tokens: []uint32{}}, }, expectedInstancesWithTokensCount: 4, expectedInstancesWithTokensInZoneCount: map[string]int{"zone-a": 4}, }, "multiple zones": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, - "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE, Tokens: []uint32{}}, - "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: LEAVING, Tokens: gen.GenerateTokens(128, nil)}, - "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: LEAVING, Tokens: []uint32{}}, - "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: PENDING, Tokens: gen.GenerateTokens(128, nil)}, - "instance-6": {Addr: "127.0.0.6", Zone: "zone-d", State: PENDING, Tokens: []uint32{}}, - "instance-7": {Addr: "127.0.0.7", Zone: "zone-c", State: JOINING, Tokens: gen.GenerateTokens(128, nil)}, - "instance-8": {Addr: "127.0.0.8", Zone: "zone-d", State: JOINING, Tokens: []uint32{}}, + "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, + "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}}, + "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: InstanceState_LEAVING, Tokens: gen.GenerateTokens(128, nil)}, + "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: InstanceState_LEAVING, Tokens: []uint32{}}, + "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: InstanceState_PENDING, Tokens: gen.GenerateTokens(128, nil)}, + "instance-6": {Addr: "127.0.0.6", Zone: "zone-d", State: InstanceState_PENDING, Tokens: []uint32{}}, + "instance-7": {Addr: "127.0.0.7", Zone: "zone-c", State: InstanceState_JOINING, Tokens: gen.GenerateTokens(128, nil)}, + "instance-8": {Addr: "127.0.0.8", Zone: "zone-d", State: InstanceState_JOINING, Tokens: []uint32{}}, }, expectedInstancesWithTokensCount: 4, expectedInstancesWithTokensInZoneCount: map[string]int{"zone-a": 1, "zone-b": 1, "zone-c": 2, "zone-d": 0}, @@ -1320,38 +1320,38 @@ func TestRing_GetWritableInstancesWithTokensCounts(t *testing.T) { }, "single zone, no tokens": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Tokens: []uint32{}}, - "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: LEAVING, Tokens: []uint32{}, ReadOnly: true}, - "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: PENDING, Tokens: []uint32{}}, - "instance-4": {Addr: "127.0.0.4", Zone: "zone-a", State: JOINING, Tokens: []uint32{}}, + "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}}, + "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_LEAVING, Tokens: []uint32{}, ReadOnly: true}, + "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: InstanceState_PENDING, Tokens: []uint32{}}, + "instance-4": {Addr: "127.0.0.4", Zone: "zone-a", State: InstanceState_JOINING, Tokens: []uint32{}}, }, expectedWritableInstancesWithTokensCount: 0, expectedWritableInstancesWithTokensCountPerZone: map[string]int{"zone-a": 0}, }, "single zone, some tokens": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, - "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE, Tokens: []uint32{}}, - "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: LEAVING, Tokens: gen.GenerateTokens(128, nil)}, - "instance-4": {Addr: "127.0.0.4", Zone: "zone-a", State: LEAVING, Tokens: []uint32{}}, - "instance-5": {Addr: "127.0.0.5", Zone: "zone-a", State: PENDING, Tokens: gen.GenerateTokens(128, nil)}, - "instance-6": {Addr: "127.0.0.6", Zone: "zone-a", State: PENDING, Tokens: []uint32{}, ReadOnly: true}, - "instance-7": {Addr: "127.0.0.7", Zone: "zone-a", State: JOINING, Tokens: gen.GenerateTokens(128, nil), ReadOnly: true}, - "instance-8": {Addr: "127.0.0.8", Zone: "zone-a", State: JOINING, Tokens: []uint32{}, ReadOnly: true}, + "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, + "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}}, + "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: InstanceState_LEAVING, Tokens: gen.GenerateTokens(128, nil)}, + "instance-4": {Addr: "127.0.0.4", Zone: "zone-a", State: InstanceState_LEAVING, Tokens: []uint32{}}, + "instance-5": {Addr: "127.0.0.5", Zone: "zone-a", State: InstanceState_PENDING, Tokens: gen.GenerateTokens(128, nil)}, + "instance-6": {Addr: "127.0.0.6", Zone: "zone-a", State: InstanceState_PENDING, Tokens: []uint32{}, ReadOnly: true}, + "instance-7": {Addr: "127.0.0.7", Zone: "zone-a", State: InstanceState_JOINING, Tokens: gen.GenerateTokens(128, nil), ReadOnly: true}, + "instance-8": {Addr: "127.0.0.8", Zone: "zone-a", State: InstanceState_JOINING, Tokens: []uint32{}, ReadOnly: true}, }, expectedWritableInstancesWithTokensCount: 3, expectedWritableInstancesWithTokensCountPerZone: map[string]int{"zone-a": 3}, }, "multiple zones": { ringInstances: map[string]InstanceDesc{ - "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, - "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: ACTIVE, Tokens: []uint32{}, ReadOnly: true}, - "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: LEAVING, Tokens: gen.GenerateTokens(128, nil), ReadOnly: true}, - "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: LEAVING, Tokens: []uint32{}}, - "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: PENDING, Tokens: gen.GenerateTokens(128, nil)}, - "instance-6": {Addr: "127.0.0.6", Zone: "zone-d", State: PENDING, Tokens: []uint32{}}, - "instance-7": {Addr: "127.0.0.7", Zone: "zone-c", State: JOINING, Tokens: gen.GenerateTokens(128, nil)}, - "instance-8": {Addr: "127.0.0.8", Zone: "zone-d", State: JOINING, Tokens: []uint32{}, ReadOnly: true}, + "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, + "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}, ReadOnly: true}, + "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: InstanceState_LEAVING, Tokens: gen.GenerateTokens(128, nil), ReadOnly: true}, + "instance-4": {Addr: "127.0.0.4", Zone: "zone-b", State: InstanceState_LEAVING, Tokens: []uint32{}}, + "instance-5": {Addr: "127.0.0.5", Zone: "zone-c", State: InstanceState_PENDING, Tokens: gen.GenerateTokens(128, nil)}, + "instance-6": {Addr: "127.0.0.6", Zone: "zone-d", State: InstanceState_PENDING, Tokens: []uint32{}}, + "instance-7": {Addr: "127.0.0.7", Zone: "zone-c", State: InstanceState_JOINING, Tokens: gen.GenerateTokens(128, nil)}, + "instance-8": {Addr: "127.0.0.8", Zone: "zone-d", State: InstanceState_JOINING, Tokens: []uint32{}, ReadOnly: true}, }, expectedWritableInstancesWithTokensCount: 3, expectedWritableInstancesWithTokensCountPerZone: map[string]int{"zone-a": 1, "zone-b": 0, "zone-c": 2, "zone-d": 0}, @@ -1643,7 +1643,7 @@ func TestRing_ShuffleShard(t *testing.T) { ringDesc := &Desc{Ingesters: testData.ringInstances} for id, instance := range ringDesc.Ingesters { instance.Timestamp = time.Now().Unix() - instance.State = ACTIVE + instance.State = InstanceState_ACTIVE ringDesc.Ingesters[id] = instance } @@ -1758,7 +1758,7 @@ func TestRing_ShuffleShard_Shuffling(t *testing.T) { Addr: fmt.Sprintf("127.0.0.%d", i), Timestamp: time.Now().Unix(), RegisteredTimestamp: time.Now().Unix(), - State: ACTIVE, + State: InstanceState_ACTIVE, Tokens: generateTokensLinear(i, numInstances, 128), Zone: fmt.Sprintf("zone-%d", i%numZones), } @@ -3265,7 +3265,7 @@ func TestRing_ShuffleShardWithLookback_CachingAfterHeartbeatOrStateChange(t *tes // Simulate an instance reporting that it's about to leave the ring. updatedInstance3 := generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)) updatedInstance3.Timestamp = initialInstances["instance-3"].Timestamp - updatedInstance3.State = LEAVING + updatedInstance3.State = InstanceState_LEAVING updatedInstances := map[string]InstanceDesc{ "instance-1": updatedInstance1, @@ -3292,7 +3292,7 @@ func TestRing_ShuffleShardWithLookback_CachingAfterHeartbeatOrStateChange(t *tes case "instance-1": require.Equal(t, updatedInstance1Timestamp, instance.Timestamp) case "instance-3": - require.Equal(t, LEAVING, instance.State) + require.Equal(t, InstanceState_LEAVING, instance.State) } } } @@ -3547,7 +3547,7 @@ func generateRingInstanceWithInfo(addr, zone string, tokens []uint32, registered Addr: addr, Timestamp: time.Now().Unix(), RegisteredTimestamp: regts, - State: ACTIVE, + State: InstanceState_ACTIVE, Tokens: tokens, Zone: zone, } @@ -3737,12 +3737,12 @@ func TestRing_ShuffleShard_Caching(t *testing.T) { lcs = append(lcs, lc) } - // Wait until all instances in the ring are ACTIVE. + // Wait until all instances in the ring are InstanceState_ACTIVE. test.Poll(t, 5*time.Second, numLifecyclers, func() interface{} { active := 0 rs, _ := ring.GetReplicationSetForOperation(Read) for _, ing := range rs.Instances { - if ing.State == ACTIVE { + if ing.State == InstanceState_ACTIVE { active++ } } @@ -3873,17 +3873,17 @@ func TestUpdateMetrics(t *testing.T) { err = testutil.GatherAndCompare(registry, bytes.NewBufferString(` # HELP ring_members Number of members in the ring # TYPE ring_members gauge - ring_members{name="test",state="ACTIVE"} 2 - ring_members{name="test",state="JOINING"} 0 - ring_members{name="test",state="LEAVING"} 0 - ring_members{name="test",state="PENDING"} 0 + ring_members{name="test",state="InstanceState_ACTIVE"} 2 + ring_members{name="test",state="InstanceState_JOINING"} 0 + ring_members{name="test",state="InstanceState_LEAVING"} 0 + ring_members{name="test",state="InstanceState_PENDING"} 0 ring_members{name="test",state="Unhealthy"} 0 # HELP ring_oldest_member_timestamp Timestamp of the oldest member in the ring. # TYPE ring_oldest_member_timestamp gauge - ring_oldest_member_timestamp{name="test",state="ACTIVE"} 11 - ring_oldest_member_timestamp{name="test",state="JOINING"} 0 - ring_oldest_member_timestamp{name="test",state="LEAVING"} 0 - ring_oldest_member_timestamp{name="test",state="PENDING"} 0 + ring_oldest_member_timestamp{name="test",state="InstanceState_ACTIVE"} 11 + ring_oldest_member_timestamp{name="test",state="InstanceState_JOINING"} 0 + ring_oldest_member_timestamp{name="test",state="InstanceState_LEAVING"} 0 + ring_oldest_member_timestamp{name="test",state="InstanceState_PENDING"} 0 ring_oldest_member_timestamp{name="test",state="Unhealthy"} 0 # HELP ring_tokens_total Number of tokens in the ring # TYPE ring_tokens_total gauge @@ -3917,17 +3917,17 @@ func TestUpdateMetricsWithRemoval(t *testing.T) { err = testutil.GatherAndCompare(registry, bytes.NewBufferString(` # HELP ring_members Number of members in the ring # TYPE ring_members gauge - ring_members{name="test",state="ACTIVE"} 2 - ring_members{name="test",state="JOINING"} 0 - ring_members{name="test",state="LEAVING"} 0 - ring_members{name="test",state="PENDING"} 0 + ring_members{name="test",state="InstanceState_ACTIVE"} 2 + ring_members{name="test",state="InstanceState_JOINING"} 0 + ring_members{name="test",state="InstanceState_LEAVING"} 0 + ring_members{name="test",state="InstanceState_PENDING"} 0 ring_members{name="test",state="Unhealthy"} 0 # HELP ring_oldest_member_timestamp Timestamp of the oldest member in the ring. # TYPE ring_oldest_member_timestamp gauge - ring_oldest_member_timestamp{name="test",state="ACTIVE"} 11 - ring_oldest_member_timestamp{name="test",state="JOINING"} 0 - ring_oldest_member_timestamp{name="test",state="LEAVING"} 0 - ring_oldest_member_timestamp{name="test",state="PENDING"} 0 + ring_oldest_member_timestamp{name="test",state="InstanceState_ACTIVE"} 11 + ring_oldest_member_timestamp{name="test",state="InstanceState_JOINING"} 0 + ring_oldest_member_timestamp{name="test",state="InstanceState_LEAVING"} 0 + ring_oldest_member_timestamp{name="test",state="InstanceState_PENDING"} 0 ring_oldest_member_timestamp{name="test",state="Unhealthy"} 0 # HELP ring_tokens_total Number of tokens in the ring # TYPE ring_tokens_total gauge @@ -3945,17 +3945,17 @@ func TestUpdateMetricsWithRemoval(t *testing.T) { err = testutil.GatherAndCompare(registry, bytes.NewBufferString(` # HELP ring_members Number of members in the ring # TYPE ring_members gauge - ring_members{name="test",state="ACTIVE"} 1 - ring_members{name="test",state="JOINING"} 0 - ring_members{name="test",state="LEAVING"} 0 - ring_members{name="test",state="PENDING"} 0 + ring_members{name="test",state="InstanceState_ACTIVE"} 1 + ring_members{name="test",state="InstanceState_JOINING"} 0 + ring_members{name="test",state="InstanceState_LEAVING"} 0 + ring_members{name="test",state="InstanceState_PENDING"} 0 ring_members{name="test",state="Unhealthy"} 0 # HELP ring_oldest_member_timestamp Timestamp of the oldest member in the ring. # TYPE ring_oldest_member_timestamp gauge - ring_oldest_member_timestamp{name="test",state="ACTIVE"} 22 - ring_oldest_member_timestamp{name="test",state="JOINING"} 0 - ring_oldest_member_timestamp{name="test",state="LEAVING"} 0 - ring_oldest_member_timestamp{name="test",state="PENDING"} 0 + ring_oldest_member_timestamp{name="test",state="InstanceState_ACTIVE"} 22 + ring_oldest_member_timestamp{name="test",state="InstanceState_JOINING"} 0 + ring_oldest_member_timestamp{name="test",state="InstanceState_LEAVING"} 0 + ring_oldest_member_timestamp{name="test",state="InstanceState_PENDING"} 0 ring_oldest_member_timestamp{name="test",state="Unhealthy"} 0 # HELP ring_tokens_total Number of tokens in the ring # TYPE ring_tokens_total gauge diff --git a/ring/spread_minimizing_token_generator_test.go b/ring/spread_minimizing_token_generator_test.go index 912df1bfd..cd4674bef 100644 --- a/ring/spread_minimizing_token_generator_test.go +++ b/ring/spread_minimizing_token_generator_test.go @@ -478,10 +478,10 @@ func TestSpreadMinimizingTokenGenerator_CanJoin(t *testing.T) { tokens Tokens ) if i <= instanceID-2 { - state = ACTIVE + state = InstanceState_ACTIVE tokens = allTokens[i] } else { - state = PENDING + state = InstanceState_PENDING tokens = nil } ringDesc.AddIngester(instance, instance, zone, tokens, state, time.Now(), false, time.Time{}) @@ -507,7 +507,7 @@ func TestSpreadMinimizingTokenGenerator_CanJoin(t *testing.T) { // if canJoinEnabled is true, the check returns nil all instances have tokens tokenGenerator.canJoinEnabled = true - pendingInstanceDesc.State = ACTIVE + pendingInstanceDesc.State = InstanceState_ACTIVE pendingInstanceDesc.Tokens = allTokens[pendingInstanceID] ringDesc.Ingesters[pendingInstance] = pendingInstanceDesc err = tokenGenerator.CanJoin(ringDesc.GetIngesters()) diff --git a/ring/token_range_test.go b/ring/token_range_test.go index db6fef28f..9015bf785 100644 --- a/ring/token_range_test.go +++ b/ring/token_range_test.go @@ -221,7 +221,7 @@ func testCheckingOfKeyOwnership(t *testing.T, randomizeInstanceStates bool) { if randomizeInstanceStates { for ins, ing := range ringDesc.Ingesters { - ing.State = InstanceState(stateRand.Int31n(int32(LEFT))) // LEFT is not state that clients can see, so we don't test it. + ing.State = InstanceState(stateRand.Int31n(int32(InstanceState_LEFT))) // InstanceState_LEFT is not state that clients can see, so we don't test it. ringDesc.Ingesters[ins] = ing } } diff --git a/ring/util.go b/ring/util.go index 910860cc8..21a7be591 100644 --- a/ring/util.go +++ b/ring/util.go @@ -66,7 +66,7 @@ func WaitRingStability(ctx context.Context, r ReadRing, op Operation, minStabili // WaitRingTokensStability waits for the Ring to be unchanged at // least for minStability time period, excluding transitioning between -// allowed states (e.g. JOINING->ACTIVE if allowed by op). +// allowed states (e.g. InstanceState_JOINING->InstanceState_ACTIVE if allowed by op). // This can be used to avoid wasting resources on moving data around // due to multiple changes in the Ring. func WaitRingTokensStability(ctx context.Context, r ReadRing, op Operation, minStability, maxWaiting time.Duration) error { diff --git a/ring/util_test.go b/ring/util_test.go index ec52c5077..744196773 100644 --- a/ring/util_test.go +++ b/ring/util_test.go @@ -98,11 +98,11 @@ func (r *RingMock) ZonesCount() int { func createStartingRing() *Ring { // Init the ring. ringDesc := &Desc{Ingesters: map[string]InstanceDesc{ - "instance-1": {Id: "instance-1", Addr: "127.0.0.1", State: ACTIVE, Timestamp: time.Now().Unix()}, - "instance-2": {Id: "instance-2", Addr: "127.0.0.2", State: PENDING, Timestamp: time.Now().Unix()}, - "instance-3": {Id: "instance-3", Addr: "127.0.0.3", State: JOINING, Timestamp: time.Now().Unix()}, - "instance-4": {Id: "instance-4", Addr: "127.0.0.4", State: LEAVING, Timestamp: time.Now().Unix()}, - "instance-5": {Id: "instance-5", Addr: "127.0.0.5", State: ACTIVE, Timestamp: time.Now().Unix()}, + "instance-1": {Id: "instance-1", Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()}, + "instance-2": {Id: "instance-2", Addr: "127.0.0.2", State: InstanceState_PENDING, Timestamp: time.Now().Unix()}, + "instance-3": {Id: "instance-3", Addr: "127.0.0.3", State: InstanceState_JOINING, Timestamp: time.Now().Unix()}, + "instance-4": {Id: "instance-4", Addr: "127.0.0.4", State: InstanceState_LEAVING, Timestamp: time.Now().Unix()}, + "instance-5": {Id: "instance-5", Addr: "127.0.0.5", State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()}, }} ring := &Ring{ @@ -162,7 +162,7 @@ func addInstanceAfterSomeTime(ring *Ring, addInstanceAfter time.Duration) { defer ring.mtx.Unlock() ringDesc := ring.ringDesc instanceID := fmt.Sprintf("127.0.0.%d", len(ringDesc.Ingesters)+1) - ringDesc.Ingesters[instanceID] = InstanceDesc{Addr: instanceID, State: ACTIVE, Timestamp: time.Now().Unix()} + ringDesc.Ingesters[instanceID] = InstanceDesc{Addr: instanceID, State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()} ring.ringDesc = ringDesc ring.ringTokens = ringDesc.GetTokens() ring.ringTokensByZone = ringDesc.getTokensByZone() @@ -228,7 +228,7 @@ func addInstancesPeriodically(ring *Ring) chan struct{} { ring.mtx.Lock() ringDesc := ring.ringDesc instanceID := fmt.Sprintf("127.0.0.%d", len(ringDesc.Ingesters)+1) - ringDesc.Ingesters[instanceID] = InstanceDesc{Id: instanceID, Addr: instanceID, State: ACTIVE, Timestamp: time.Now().Unix()} + ringDesc.Ingesters[instanceID] = InstanceDesc{Id: instanceID, Addr: instanceID, State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()} ring.ringDesc = ringDesc ring.ringTokens = ringDesc.GetTokens() ring.ringTokensByZone = ringDesc.getTokensByZone() @@ -287,7 +287,7 @@ func changeStatePeriodically(ring *Ring) chan struct{} { done := make(chan struct{}) go func() { instanceToMutate := "instance-1" - states := []InstanceState{PENDING, JOINING, ACTIVE, LEAVING} + states := []InstanceState{InstanceState_PENDING, InstanceState_JOINING, InstanceState_ACTIVE, InstanceState_LEAVING} stateIdx := 0 for states[stateIdx] != ring.ringDesc.Ingesters[instanceToMutate].State { @@ -369,9 +369,9 @@ func TestWaitInstanceState_Timeout(t *testing.T) { defer cancel() ring := &RingMock{} - ring.On("GetInstanceState", mock.Anything, mock.Anything).Return(ACTIVE, nil) + ring.On("GetInstanceState", mock.Anything, mock.Anything).Return(InstanceState_ACTIVE, nil) - err := WaitInstanceState(ctx, ring, instanceID, PENDING) + err := WaitInstanceState(ctx, ring, instanceID, InstanceState_PENDING) assert.Equal(t, context.DeadlineExceeded, err) ring.AssertCalled(t, "GetInstanceState", instanceID) @@ -389,9 +389,9 @@ func TestWaitInstanceState_TimeoutOnError(t *testing.T) { defer cancel() ring := &RingMock{} - ring.On("GetInstanceState", mock.Anything, mock.Anything).Return(PENDING, errors.New("instance not found in the ring")) + ring.On("GetInstanceState", mock.Anything, mock.Anything).Return(InstanceState_PENDING, errors.New("instance not found in the ring")) - err := WaitInstanceState(ctx, ring, instanceID, ACTIVE) + err := WaitInstanceState(ctx, ring, instanceID, InstanceState_ACTIVE) assert.Equal(t, context.DeadlineExceeded, err) ring.AssertCalled(t, "GetInstanceState", instanceID) @@ -409,9 +409,9 @@ func TestWaitInstanceState_ExitsAfterActualStateEqualsState(t *testing.T) { defer cancel() ring := &RingMock{} - ring.On("GetInstanceState", mock.Anything, mock.Anything).Return(ACTIVE, nil) + ring.On("GetInstanceState", mock.Anything, mock.Anything).Return(InstanceState_ACTIVE, nil) - err := WaitInstanceState(ctx, ring, instanceID, ACTIVE) + err := WaitInstanceState(ctx, ring, instanceID, InstanceState_ACTIVE) assert.Nil(t, err) ring.AssertNumberOfCalls(t, "GetInstanceState", 1) diff --git a/servicediscovery/ring.go b/servicediscovery/ring.go index c1c7affac..ec3456432 100644 --- a/servicediscovery/ring.go +++ b/servicediscovery/ring.go @@ -13,7 +13,7 @@ import ( var ( // Ring operation used to get healthy active instances in the ring. - activeRingOp = ring.NewOp([]ring.InstanceState{ring.ACTIVE}, nil) + activeRingOp = ring.NewOp([]ring.InstanceState{ring.InstanceState_ACTIVE}, nil) ) type ringServiceDiscovery struct { diff --git a/servicediscovery/ring_test.go b/servicediscovery/ring_test.go index dfa8f90a6..02a693ea4 100644 --- a/servicediscovery/ring_test.go +++ b/servicediscovery/ring_test.go @@ -56,10 +56,10 @@ func TestRingServiceDiscovery_WithoutMaxUsedInstances(t *testing.T) { // Register some instances. require.NoError(t, inmem.CAS(ctx, ringKey, func(in interface{}) (out interface{}, retry bool, err error) { desc := in.(*ring.Desc) - desc.AddIngester("instance-1", "127.0.0.1", "", nil, ring.ACTIVE, time.Now(), false, time.Time{}) - desc.AddIngester("instance-2", "127.0.0.2", "", nil, ring.PENDING, time.Now(), false, time.Time{}) - desc.AddIngester("instance-3", "127.0.0.3", "", nil, ring.JOINING, time.Now(), false, time.Time{}) - desc.AddIngester("instance-4", "127.0.0.4", "", nil, ring.LEAVING, time.Now(), false, time.Time{}) + desc.AddIngester("instance-1", "127.0.0.1", "", nil, ring.InstanceState_ACTIVE, time.Now(), false, time.Time{}) + desc.AddIngester("instance-2", "127.0.0.2", "", nil, ring.InstanceState_PENDING, time.Now(), false, time.Time{}) + desc.AddIngester("instance-3", "127.0.0.3", "", nil, ring.InstanceState_JOINING, time.Now(), false, time.Time{}) + desc.AddIngester("instance-4", "127.0.0.4", "", nil, ring.InstanceState_LEAVING, time.Now(), false, time.Time{}) return desc, true, nil })) @@ -70,8 +70,8 @@ func TestRingServiceDiscovery_WithoutMaxUsedInstances(t *testing.T) { // Register more instances. require.NoError(t, inmem.CAS(ctx, ringKey, func(in interface{}) (out interface{}, retry bool, err error) { desc := in.(*ring.Desc) - desc.AddIngester("instance-5", "127.0.0.5", "", nil, ring.ACTIVE, time.Now(), false, time.Time{}) - desc.AddIngester("instance-6", "127.0.0.6", "", nil, ring.ACTIVE, time.Now(), false, time.Time{}) + desc.AddIngester("instance-5", "127.0.0.5", "", nil, ring.InstanceState_ACTIVE, time.Now(), false, time.Time{}) + desc.AddIngester("instance-6", "127.0.0.6", "", nil, ring.InstanceState_ACTIVE, time.Now(), false, time.Time{}) return desc, true, nil })) @@ -95,7 +95,7 @@ func TestRingServiceDiscovery_WithoutMaxUsedInstances(t *testing.T) { require.NoError(t, inmem.CAS(ctx, ringKey, func(in interface{}) (out interface{}, retry bool, err error) { desc := in.(*ring.Desc) instance := desc.Ingesters["instance-2"] - instance.State = ring.ACTIVE + instance.State = ring.InstanceState_ACTIVE desc.Ingesters["instance-2"] = instance return desc, true, nil })) @@ -158,10 +158,10 @@ func TestRingServiceDiscovery_WithMaxUsedInstances(t *testing.T) { // Register some instances. require.NoError(t, inmem.CAS(ctx, ringKey, func(in interface{}) (out interface{}, retry bool, err error) { desc := in.(*ring.Desc) - desc.AddIngester("instance-1", "127.0.0.1", "", nil, ring.ACTIVE, time.Now(), false, time.Time{}) - desc.AddIngester("instance-2", "127.0.0.2", "", nil, ring.PENDING, time.Now(), false, time.Time{}) - desc.AddIngester("instance-3", "127.0.0.3", "", nil, ring.JOINING, time.Now(), false, time.Time{}) - desc.AddIngester("instance-4", "127.0.0.4", "", nil, ring.LEAVING, time.Now(), false, time.Time{}) + desc.AddIngester("instance-1", "127.0.0.1", "", nil, ring.InstanceState_ACTIVE, time.Now(), false, time.Time{}) + desc.AddIngester("instance-2", "127.0.0.2", "", nil, ring.InstanceState_PENDING, time.Now(), false, time.Time{}) + desc.AddIngester("instance-3", "127.0.0.3", "", nil, ring.InstanceState_JOINING, time.Now(), false, time.Time{}) + desc.AddIngester("instance-4", "127.0.0.4", "", nil, ring.InstanceState_LEAVING, time.Now(), false, time.Time{}) return desc, true, nil })) @@ -172,8 +172,8 @@ func TestRingServiceDiscovery_WithMaxUsedInstances(t *testing.T) { // Register more instances. require.NoError(t, inmem.CAS(ctx, ringKey, func(in interface{}) (out interface{}, retry bool, err error) { desc := in.(*ring.Desc) - desc.AddIngester("instance-5", "127.0.0.5", "", nil, ring.ACTIVE, time.Now(), false, time.Time{}) - desc.AddIngester("instance-6", "127.0.0.6", "", nil, ring.ACTIVE, time.Now(), false, time.Time{}) + desc.AddIngester("instance-5", "127.0.0.5", "", nil, ring.InstanceState_ACTIVE, time.Now(), false, time.Time{}) + desc.AddIngester("instance-6", "127.0.0.6", "", nil, ring.InstanceState_ACTIVE, time.Now(), false, time.Time{}) return desc, true, nil })) @@ -197,11 +197,11 @@ func TestRingServiceDiscovery_WithMaxUsedInstances(t *testing.T) { require.NoError(t, inmem.CAS(ctx, ringKey, func(in interface{}) (out interface{}, retry bool, err error) { desc := in.(*ring.Desc) instance := desc.Ingesters["instance-2"] - instance.State = ring.ACTIVE + instance.State = ring.InstanceState_ACTIVE desc.Ingesters["instance-2"] = instance instance = desc.Ingesters["instance-3"] - instance.State = ring.ACTIVE + instance.State = ring.InstanceState_ACTIVE desc.Ingesters["instance-3"] = instance return desc, true, nil From 905028592088d4e17faf35bdac542ac277fb7492 Mon Sep 17 00:00:00 2001 From: francoposa Date: Mon, 13 Jan 2025 11:38:36 -0800 Subject: [PATCH 04/22] add compatibility methods; copy impl for InstanceDesc.Equal and helpers for getting & setting InstanceDesc map with values --- ring/model.go | 60 ++++++++++++++++++++++++++++++++++++++-------- ring/ring_extra.go | 55 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 ring/ring_extra.go diff --git a/ring/model.go b/ring/model.go index 9c590dd92..3fda56c4f 100644 --- a/ring/model.go +++ b/ring/model.go @@ -41,7 +41,7 @@ func GetCodec() codec.Codec { // NewDesc returns an empty ring.Desc func NewDesc() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{}, + Ingesters: map[string]*InstanceDesc{}, } } @@ -52,14 +52,57 @@ func timeToUnixSecons(t time.Time) int64 { return t.Unix() } +func (x *Desc) GetIngester(id string) *InstanceDesc { + if x != nil { + if x.Ingesters != nil { + return x.Ingesters[id] + } + } + return nil +} + +func (x *Desc) GetIngesterVal(id string) (InstanceDesc, bool) { + if x != nil { + if x.Ingesters != nil { + if ptr, ok := x.Ingesters[id]; ok { + return *ptr, true + } + } + } + return InstanceDesc{}, false +} + +func (x *Desc) GetIngesterVals() map[string]InstanceDesc { + if x != nil { + valMap := make(map[string]InstanceDesc, len(x.Ingesters)) + for k, v := range x.Ingesters { + if v != nil { + valMap[k] = *v + } else { + valMap[k] = InstanceDesc{} + } + } + return valMap + } + return nil +} + +func (d *Desc) SetIngesterVal(id string, ingester InstanceDesc) InstanceDesc { + if d.Ingesters == nil { + d.Ingesters = map[string]*InstanceDesc{} + } + d.Ingesters[id] = &ingester + return ingester +} + // AddIngester adds the given ingester to the ring. Ingester will only use supplied tokens, // any other tokens are removed. func (d *Desc) AddIngester(id, addr, zone string, tokens []uint32, state InstanceState, registeredAt time.Time, readOnly bool, readOnlyUpdated time.Time) InstanceDesc { if d.Ingesters == nil { - d.Ingesters = map[string]InstanceDesc{} + d.Ingesters = map[string]*InstanceDesc{} } - ingester := InstanceDesc{ + return d.SetIngesterVal(id, InstanceDesc{ Id: id, Addr: addr, Timestamp: time.Now().Unix(), @@ -69,10 +112,7 @@ func (d *Desc) AddIngester(id, addr, zone string, tokens []uint32, state Instanc RegisteredTimestamp: timeToUnixSecons(registeredAt), ReadOnly: readOnly, ReadOnlyUpdatedTimestamp: timeToUnixSecons(readOnlyUpdated), - } - - d.Ingesters[id] = ingester - return ingester + }) } // RemoveIngester removes the given ingester and all its tokens. @@ -103,7 +143,7 @@ func (d *Desc) ClaimTokens(from, to string) Tokens { // FindIngestersByState returns the list of ingesters in the given state func (d *Desc) FindIngestersByState(state InstanceState) []InstanceDesc { var result []InstanceDesc - for _, ing := range d.Ingesters { + for _, ing := range d.GetIngesterVals() { if ing.State == state { result = append(result, ing) } @@ -363,7 +403,7 @@ func tokensEqual(lhs, rhs []uint32) bool { var tokenMapPool = sync.Pool{New: func() interface{} { return make(map[uint32]struct{}) }} -func conflictingTokensExist(normalizedIngesters map[string]InstanceDesc) bool { +func conflictingTokensExist(normalizedIngesters map[string]*InstanceDesc) bool { tokensMap := tokenMapPool.Get().(map[uint32]struct{}) defer func() { for k := range tokensMap { @@ -389,7 +429,7 @@ func conflictingTokensExist(normalizedIngesters map[string]InstanceDesc) bool { // 2) otherwise node names are compared, and node with "lower" name wins the token // // Modifies ingesters map with updated tokens. -func resolveConflicts(normalizedIngesters map[string]InstanceDesc) { +func resolveConflicts(normalizedIngesters map[string]*InstanceDesc) { size := 0 for _, ing := range normalizedIngesters { size += len(ing.Tokens) diff --git a/ring/ring_extra.go b/ring/ring_extra.go new file mode 100644 index 000000000..a49a61c70 --- /dev/null +++ b/ring/ring_extra.go @@ -0,0 +1,55 @@ +package ring + +func (this *InstanceDesc) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*InstanceDesc) + if !ok { + that2, ok := that.(InstanceDesc) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Addr != that1.Addr { + return false + } + if this.Timestamp != that1.Timestamp { + return false + } + if this.State != that1.State { + return false + } + if len(this.Tokens) != len(that1.Tokens) { + return false + } + for i := range this.Tokens { + if this.Tokens[i] != that1.Tokens[i] { + return false + } + } + if this.Zone != that1.Zone { + return false + } + if this.RegisteredTimestamp != that1.RegisteredTimestamp { + return false + } + if this.Id != that1.Id { + return false + } + if this.ReadOnlyUpdatedTimestamp != that1.ReadOnlyUpdatedTimestamp { + return false + } + if this.ReadOnly != that1.ReadOnly { + return false + } + return true +} From 6199b62a9e57dcfbeef603bb296bab0bcb9b3895 Mon Sep 17 00:00:00 2001 From: francoposa Date: Mon, 13 Jan 2025 12:02:41 -0800 Subject: [PATCH 05/22] fix compilation errors in ring for non-test references to IngesterVals as pointers; opt to copy pointer to value when any external or public methods require value --- ring/basic_lifecycler.go | 6 +++--- ring/lifecycler.go | 2 +- ring/model.go | 2 -- ring/ring.go | 31 +++++++++++++------------------ 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/ring/basic_lifecycler.go b/ring/basic_lifecycler.go index 214939d99..f1acc8291 100644 --- a/ring/basic_lifecycler.go +++ b/ring/basic_lifecycler.go @@ -294,7 +294,7 @@ func (l *BasicLifecycler) registerInstance(ctx context.Context) error { ringDesc := GetOrCreateRingDesc(in) var exists bool - instanceDesc, exists = ringDesc.Ingesters[l.cfg.ID] + instanceDesc, exists = ringDesc.GetIngesterVal(l.cfg.ID) if exists { level.Info(l.logger).Log("msg", "instance found in the ring", "instance", l.cfg.ID, "ring", l.ringName, "state", instanceDesc.GetState(), "tokens", len(instanceDesc.GetTokens()), "registered_at", instanceDesc.GetRegisteredAt().String(), "last_heartbeat_at", instanceDesc.GetLastHeartbeatAt().String()) } else { @@ -436,7 +436,7 @@ func (l *BasicLifecycler) updateInstance(ctx context.Context, update func(*Desc, ringDesc := GetOrCreateRingDesc(in) var ok bool - instanceDesc, ok = ringDesc.Ingesters[l.cfg.ID] + instanceDesc, ok = ringDesc.GetIngesterVal(l.cfg.ID) // This could happen if the backend store restarted (and content deleted) // or the instance has been forgotten. In this case, we do re-insert it. @@ -462,7 +462,7 @@ func (l *BasicLifecycler) updateInstance(ctx context.Context, update func(*Desc, instanceDesc.Timestamp = time.Now().Unix() } - ringDesc.Ingesters[l.cfg.ID] = instanceDesc + ringDesc.SetIngesterVal(l.cfg.ID, instanceDesc) return ringDesc, true, nil }) diff --git a/ring/lifecycler.go b/ring/lifecycler.go index 1703b45f1..b4be2a1c5 100644 --- a/ring/lifecycler.go +++ b/ring/lifecycler.go @@ -874,7 +874,7 @@ func (i *Lifecycler) waitBeforeJoining(ctx context.Context) error { lastError = fmt.Errorf("no ring returned from the KV store") continue } - lastError = i.tokenGenerator.CanJoin(ringDesc.GetIngesters()) + lastError = i.tokenGenerator.CanJoin(ringDesc.GetIngesterVals()) if lastError == nil { level.Info(i.logger).Log("msg", "it is now possible to join the ring", "ring", i.RingName, "id", i.cfg.ID, "retries", retries.NumRetries()) return nil diff --git a/ring/model.go b/ring/model.go index 3fda56c4f..72d385a42 100644 --- a/ring/model.go +++ b/ring/model.go @@ -78,8 +78,6 @@ func (x *Desc) GetIngesterVals() map[string]InstanceDesc { for k, v := range x.Ingesters { if v != nil { valMap[k] = *v - } else { - valMap[k] = InstanceDesc{} } } return valMap diff --git a/ring/ring.go b/ring/ring.go index 0123d38c2..e4762c1e8 100644 --- a/ring/ring.go +++ b/ring/ring.go @@ -489,7 +489,7 @@ func (r *Ring) findInstancesForKey(key uint32, op Operation, bufDescs []Instance } distinctHosts = append(distinctHosts, info.InstanceID) - instance := r.ringDesc.Ingesters[info.InstanceID] + instance, _ := r.ringDesc.GetIngesterVal(info.InstanceID) // Check whether the replica set should be extended given we're including // this instance. @@ -526,7 +526,7 @@ func (r *Ring) GetAllHealthy(op Operation) (ReplicationSet, error) { now := time.Now() instances := make([]InstanceDesc, 0, len(r.ringDesc.Ingesters)) - for _, instance := range r.ringDesc.Ingesters { + for _, instance := range r.ringDesc.GetIngesterVals() { if r.IsHealthy(&instance, op, now) { instances = append(instances, instance) } @@ -552,7 +552,7 @@ func (r *Ring) GetReplicationSetForOperation(op Operation) (ReplicationSet, erro zoneFailures := make(map[string]struct{}) now := time.Now() - for _, instance := range r.ringDesc.Ingesters { + for _, instance := range r.ringDesc.GetIngesterVals() { if r.IsHealthy(&instance, op, now) { healthyInstances = append(healthyInstances, instance) } else { @@ -670,7 +670,7 @@ func (r *Ring) updateRingMetrics() { oldestTimestampByState[s] = 0 } - for _, instance := range r.ringDesc.Ingesters { + for _, instance := range r.ringDesc.GetIngesterVals() { s := instance.State.String() if !r.IsHealthy(&instance, Reporting, time.Now()) { s = unhealthy @@ -791,7 +791,7 @@ func (r *Ring) shuffleShard(identifier string, size int, lookbackPeriod time.Dur actualZones = []string{""} } - shard := make(map[string]InstanceDesc, min(len(r.ringDesc.Ingesters), size)) + shard := make(map[string]*InstanceDesc, min(len(r.ringDesc.Ingesters), size)) // We need to iterate zones always in the same order to guarantee stability. for _, zone := range actualZones { @@ -890,7 +890,7 @@ func (r *Ring) shuffleShard(identifier string, size int, lookbackPeriod time.Dur } // shouldIncludeReadonlyInstanceInTheShard returns true if instance is not read-only, or when it is read-only and should be included in the shuffle shard. -func shouldIncludeReadonlyInstanceInTheShard(instance InstanceDesc, lookbackPeriod time.Duration, lookbackUntil int64) bool { +func shouldIncludeReadonlyInstanceInTheShard(instance *InstanceDesc, lookbackPeriod time.Duration, lookbackUntil int64) bool { if !instance.ReadOnly { return true } @@ -923,7 +923,7 @@ func (r *Ring) filterOutReadOnlyInstances(lookbackPeriod time.Duration, now time return r } - shard := make(map[string]InstanceDesc, len(r.ringDesc.Ingesters)) + shard := make(map[string]*InstanceDesc, len(r.ringDesc.Ingesters)) for id, inst := range r.ringDesc.Ingesters { if shouldIncludeReadonlyInstanceInTheShard(inst, lookbackPeriod, lookbackUntil) { @@ -935,7 +935,7 @@ func (r *Ring) filterOutReadOnlyInstances(lookbackPeriod time.Duration, now time } // buildRingForTheShard builds read-only ring for the shard (this ring won't be updated in the future). -func (r *Ring) buildRingForTheShard(shard map[string]InstanceDesc) *Ring { +func (r *Ring) buildRingForTheShard(shard map[string]*InstanceDesc) *Ring { shardDesc := &Desc{Ingesters: shard} shardTokensByZone := shardDesc.getTokensByZone() shardTokens := mergeTokenGroups(shardTokensByZone) @@ -1022,17 +1022,12 @@ func (r *Ring) GetInstance(instanceID string) (doNotModify InstanceDesc, _ error r.mtx.RLock() defer r.mtx.RUnlock() - instances := r.ringDesc.GetIngesters() - if instances == nil { - return InstanceDesc{}, ErrInstanceNotFound - } - - instance, ok := instances[instanceID] + var err error + instance, ok := r.ringDesc.GetIngesterVal(instanceID) if !ok { - return InstanceDesc{}, ErrInstanceNotFound + err = ErrInstanceNotFound } - - return instance, nil + return instance, err } // GetInstanceState returns the current state of an instance or an error if the @@ -1288,7 +1283,7 @@ func (r *Ring) ZonesCount() int { func (r *Ring) readOnlyInstanceCount() int { r.mtx.RLock() c := 0 - for _, i := range r.ringDesc.Ingesters { + for _, i := range r.ringDesc.GetIngesterVals() { if i.ReadOnly { c++ } From 9d0f2a2cbb1bbe2078543e632b07d081dc0c5144 Mon Sep 17 00:00:00 2001 From: francoposa Date: Mon, 13 Jan 2025 14:29:09 -0800 Subject: [PATCH 06/22] fix compilation errors in ring for basic_lifecycler_delegates_test.go and basic_lifecycler_test.go; replaced direct map access with value getters & setters --- ring/basic_lifecycler_delegates_test.go | 6 +++--- ring/basic_lifecycler_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ring/basic_lifecycler_delegates_test.go b/ring/basic_lifecycler_delegates_test.go index a525573b5..0c8c1a7e3 100644 --- a/ring/basic_lifecycler_delegates_test.go +++ b/ring/basic_lifecycler_delegates_test.go @@ -250,7 +250,7 @@ func TestAutoForgetDelegate(t *testing.T) { setup: func(ringDesc *Desc) { i := ringDesc.AddIngester("instance-1", "1.1.1.1", "", nil, InstanceState_ACTIVE, registeredAt, false, readOnlyUpdated) i.Timestamp = time.Now().Add(-forgetPeriod).Add(5 * time.Second).Unix() - ringDesc.Ingesters["instance-1"] = i + ringDesc.SetIngesterVal("instance-1", i) }, expectedInstances: []string{testInstanceID, "instance-1"}, }, @@ -258,7 +258,7 @@ func TestAutoForgetDelegate(t *testing.T) { setup: func(ringDesc *Desc) { i := ringDesc.AddIngester("instance-1", "1.1.1.1", "", nil, InstanceState_ACTIVE, registeredAt, false, readOnlyUpdated) i.Timestamp = time.Now().Add(-forgetPeriod).Add(-5 * time.Second).Unix() - ringDesc.Ingesters["instance-1"] = i + ringDesc.SetIngesterVal("instance-1", i) }, expectedInstances: []string{testInstanceID}, }, @@ -347,7 +347,7 @@ func TestInstanceRegisterDelegate_OnRingInstanceRegister(t *testing.T) { prevTokens := []uint32{10, 20, 30} desc.AddIngester("test-instance", "test-addr", "zone", prevTokens, InstanceState_JOINING, time.Now(), false, time.Time{}) - state, tokens := delegate.OnRingInstanceRegister(lifecycler, *desc, true, "test-instance", desc.GetIngesters()["test-instance"]) + state, tokens := delegate.OnRingInstanceRegister(lifecycler, *desc, true, "test-instance", desc.GetIngesterVals()["test-instance"]) require.Equal(t, InstanceState_ACTIVE, state) require.Equal(t, tokenCount, len(tokens)) diff --git a/ring/basic_lifecycler_test.go b/ring/basic_lifecycler_test.go index 6d1330203..10480bbf9 100644 --- a/ring/basic_lifecycler_test.go +++ b/ring/basic_lifecycler_test.go @@ -597,7 +597,7 @@ func getInstanceFromStore(t *testing.T, store kv.Client, instanceID string) (Ins } ringDesc := out.(*Desc) - instanceDesc, ok := ringDesc.GetIngesters()[instanceID] + instanceDesc, ok := ringDesc.GetIngesterVal(instanceID) return instanceDesc, ok } From a05aa999983863caa79b4f3522040d13cbd392d2 Mon Sep 17 00:00:00 2001 From: francoposa Date: Mon, 13 Jan 2025 15:38:33 -0800 Subject: [PATCH 07/22] fix logic in ring lifecycler.go initRing and model.go mergeWithTime for pointer usage, fix compilation errors in lifecycler_test.go and merge_test.go; pass changed basic_lifecycler_test.go to use pointers; opt for all pointer access; pass all mentioned tests with race check --- ring/basic_lifecycler_test.go | 8 ++-- ring/lifecycler.go | 7 +++- ring/lifecycler_test.go | 33 ++++++++------- ring/merge_test.go | 78 +++++++++++++++++------------------ ring/model.go | 4 ++ 5 files changed, 72 insertions(+), 58 deletions(-) diff --git a/ring/basic_lifecycler_test.go b/ring/basic_lifecycler_test.go index 10480bbf9..369704640 100644 --- a/ring/basic_lifecycler_test.go +++ b/ring/basic_lifecycler_test.go @@ -588,16 +588,16 @@ func (m *mockDelegate) OnRingInstanceHeartbeat(lifecycler *BasicLifecycler, ring } } -func getInstanceFromStore(t *testing.T, store kv.Client, instanceID string) (InstanceDesc, bool) { +func getInstanceFromStore(t *testing.T, store kv.Client, instanceID string) (*InstanceDesc, bool) { out, err := store.Get(context.Background(), testRingKey) require.NoError(t, err) if out == nil { - return InstanceDesc{}, false + return nil, false } ringDesc := out.(*Desc) - instanceDesc, ok := ringDesc.GetIngesterVal(instanceID) + instanceDesc := ringDesc.GetIngester(instanceID) - return instanceDesc, ok + return instanceDesc, instanceDesc != nil } diff --git a/ring/lifecycler.go b/ring/lifecycler.go index b4be2a1c5..521d483fe 100644 --- a/ring/lifecycler.go +++ b/ring/lifecycler.go @@ -707,6 +707,11 @@ func (i *Lifecycler) initRing(ctx context.Context) error { return ringDesc, true, nil } + // instanceDesc is a pointer to the value in the ringDesc.Ingesters map, + // so updates to it will be reflected in ringDesc.Ingesters[i.ID]; + // hold a copy of the original state so we can determine if we need to update the ring's backing store + originalInstanceDesc := *instanceDesc + // The instance already exists in the ring, so we can't change the registered timestamp (even if it's zero) // but we need to update the local state accordingly. i.setRegisteredAt(instanceDesc.GetRegisteredAt()) @@ -765,7 +770,7 @@ func (i *Lifecycler) initRing(ctx context.Context) error { // Update the ring if the instance has been changed. We don't want to rely on heartbeat update, as heartbeat // can be configured to long time, and until then lifecycler would not report this instance as ready in CheckReady. - if !instanceDesc.Equal(ringDesc.Ingesters[i.ID]) { + if !instanceDesc.Equal(originalInstanceDesc) { // Update timestamp to give gossiping client a chance register ring change. instanceDesc.Timestamp = time.Now().Unix() ringDesc.Ingesters[i.ID] = instanceDesc diff --git a/ring/lifecycler_test.go b/ring/lifecycler_test.go index a1a147f2c..9e1e286cd 100644 --- a/ring/lifecycler_test.go +++ b/ring/lifecycler_test.go @@ -670,7 +670,7 @@ func TestLifecycler_IncreasingTokensLeavingInstanceInTheRing(t *testing.T) { }) // Verify ingester joined, is active, and has 128 tokens - var ingDesc InstanceDesc + var ingDesc *InstanceDesc test.Poll(t, time.Second, true, func() interface{} { d, err := r.KVClient.Get(ctx, ringKey) require.NoError(t, err) @@ -848,7 +848,7 @@ func TestLifecycler_DecreasingTokensLeavingInstanceInTheRing(t *testing.T) { }) // Verify ingester joined, is active, and has 64 tokens - var ingDesc InstanceDesc + var ingDesc *InstanceDesc test.Poll(t, time.Second, true, func() interface{} { d, err := r.KVClient.Get(ctx, ringKey) require.NoError(t, err) @@ -1008,7 +1008,7 @@ func TestCheckReady_MinReadyDuration(t *testing.T) { startTime := time.Now() // Wait until the instance is InstanceState_ACTIVE and healthy in the ring. - waitRingInstance(t, 3*time.Second, l, func(instance InstanceDesc) error { + waitRingInstance(t, 3*time.Second, l, func(instance *InstanceDesc) error { return instance.IsReady(time.Now(), cfg.RingConfig.HeartbeatTimeout) }) @@ -1096,8 +1096,8 @@ func TestCheckReady_CheckRingHealth(t *testing.T) { // Wait until both instances are registered in the ring. We expect them to be registered // immediately and then switch to InstanceState_ACTIVE after the configured auto join delay. - waitRingInstance(t, 3*time.Second, l1, func(InstanceDesc) error { return nil }) - waitRingInstance(t, 3*time.Second, l2, func(InstanceDesc) error { return nil }) + waitRingInstance(t, 3*time.Second, l1, func(*InstanceDesc) error { return nil }) + waitRingInstance(t, 3*time.Second, l2, func(*InstanceDesc) error { return nil }) // Poll the readiness check until ready and measure how much time it takes. test.Poll(t, 5*time.Second, nil, func() interface{} { @@ -1130,8 +1130,8 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi defer services.StopAndAwaitTerminated(context.Background(), r) //nolint:errcheck // poll function waits for a condition and returning actual state of the ingesters after the condition succeed. - poll := func(condition func(*Desc) bool) map[string]InstanceDesc { - var ingesters map[string]InstanceDesc + poll := func(condition func(*Desc) bool) map[string]*InstanceDesc { + var ingesters map[string]*InstanceDesc test.Poll(t, 5*time.Second, true, func() interface{} { d, err := r.KVClient.Get(context.Background(), ringKey) require.NoError(t, err) @@ -1157,7 +1157,10 @@ func TestRestartIngester_DisabledHeartbeat_unregister_on_shutdown_false(t *testi require.NoError(t, err) require.NoError(t, services.StartAndAwaitRunning(context.Background(), lifecycler)) poll(func(desc *Desc) bool { - return desc.Ingesters[ingId].State == InstanceState_ACTIVE + if ing := desc.GetIngester(ingId); ing != nil { + return ing.State == InstanceState_ACTIVE + } + return false }) return lifecycler } @@ -1332,7 +1335,9 @@ func TestTokensOnDisk(t *testing.T) { require.NoError(t, err) desc, ok := d.(*Desc) if ok { - actTokens = desc.Ingesters["ing2"].Tokens + if ing := desc.GetIngester("ing2"); ing != nil { + actTokens = ing.Tokens + } } return ok && len(desc.Ingesters) == 1 && @@ -1416,7 +1421,7 @@ func TestJoinInLeavingState(t *testing.T) { // Set state as InstanceState_LEAVING err = r.KVClient.CAS(context.Background(), ringKey, func(interface{}) (interface{}, bool, error) { r := &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "ing1": { State: InstanceState_LEAVING, Tokens: []uint32{1, 4}, @@ -1473,7 +1478,7 @@ func TestJoinInJoiningState(t *testing.T) { // Set state as InstanceState_JOINING err = r.KVClient.CAS(context.Background(), ringKey, func(interface{}) (interface{}, bool, error) { r := &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "ing1": { State: InstanceState_JOINING, Tokens: []uint32{1, 4}, @@ -1528,7 +1533,7 @@ func TestWaitBeforeJoining(t *testing.T) { err = r.KVClient.CAS(context.Background(), ringKey, func(interface{}) (interface{}, bool, error) { r := &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ instanceName(0, 1): { State: InstanceState_ACTIVE, Tokens: []uint32{1, 2, 3}, @@ -1738,7 +1743,7 @@ func TestRestoreOfZoneWhenOverwritten(t *testing.T) { // Set ing1 to not have a zone err = r.KVClient.CAS(context.Background(), ringKey, func(interface{}) (interface{}, bool, error) { r := &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "ing1": { State: InstanceState_ACTIVE, Addr: "0.0.0.0", @@ -1772,7 +1777,7 @@ func TestRestoreOfZoneWhenOverwritten(t *testing.T) { }) } -func waitRingInstance(t *testing.T, timeout time.Duration, l *Lifecycler, check func(instance InstanceDesc) error) { +func waitRingInstance(t *testing.T, timeout time.Duration, l *Lifecycler, check func(instance *InstanceDesc) error) { test.Poll(t, timeout, nil, func() interface{} { desc, err := l.KVStore.Get(context.Background(), l.RingKey) if err != nil { diff --git a/ring/merge_test.go b/ring/merge_test.go index 60f7c5c04..7bc589ab5 100644 --- a/ring/merge_test.go +++ b/ring/merge_test.go @@ -11,7 +11,7 @@ func TestNormalizationAndConflictResolution(t *testing.T) { now := time.Now().Unix() first := &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{50, 40, 40, 30}}, "Ing 2": {Addr: "addr2", Timestamp: 123456, State: InstanceState_LEAVING, Tokens: []uint32{100, 5, 5, 100, 100, 200, 20, 10}}, "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEFT, Tokens: []uint32{100, 200, 300}}, @@ -21,7 +21,7 @@ func TestNormalizationAndConflictResolution(t *testing.T) { } second := &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Unknown": { Timestamp: now + 10, Tokens: []uint32{1000, 2000}, @@ -39,7 +39,7 @@ func TestNormalizationAndConflictResolution(t *testing.T) { } assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: 123456, State: InstanceState_LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}}, "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEFT}, @@ -50,7 +50,7 @@ func TestNormalizationAndConflictResolution(t *testing.T) { assert.Equal(t, &Desc{ // change ring is always normalized, "Unknown" ingester has lost two tokens: 100 from first ring (because of second ring), and 1000 (conflict resolution) - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Unknown": {Timestamp: now + 10, Tokens: []uint32{1000, 2000}}, }, }, changeRing) @@ -75,7 +75,7 @@ func TestMerge(t *testing.T) { firstRing := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, }, @@ -84,7 +84,7 @@ func TestMerge(t *testing.T) { secondRing := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{150, 250, 350}}, "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, }, @@ -93,7 +93,7 @@ func TestMerge(t *testing.T) { thirdRing := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEAVING, Tokens: []uint32{30, 40, 50}}, "Ing 3": {Addr: "addr3", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{150, 250, 350}}, }, @@ -102,7 +102,7 @@ func TestMerge(t *testing.T) { expectedFirstSecondMerge := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{150, 250, 350}}, @@ -112,7 +112,7 @@ func TestMerge(t *testing.T) { expectedFirstSecondThirdMerge := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEAVING, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, "Ing 3": {Addr: "addr3", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{150, 250, 350}}, @@ -122,7 +122,7 @@ func TestMerge(t *testing.T) { fourthRing := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEFT, Tokens: []uint32{30, 40, 50}}, }, } @@ -130,7 +130,7 @@ func TestMerge(t *testing.T) { expectedFirstSecondThirdFourthMerge := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEFT, Tokens: nil}, "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, "Ing 3": {Addr: "addr3", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{150, 250, 350}}, @@ -155,7 +155,7 @@ func TestMerge(t *testing.T) { assert.Equal(t, expectedFirstSecondMerge(), our) // when merging first into second ring, only "Ing 1" is new assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, }, }, ch) @@ -176,7 +176,7 @@ func TestMerge(t *testing.T) { assert.Equal(t, expectedFirstSecondThirdFourthMerge(), out) // entire fourth ring is the update -- but without tokens assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEFT, Tokens: nil}, }, }, ch) @@ -188,7 +188,7 @@ func TestTokensTakeover(t *testing.T) { first := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{5, 10, 20}}, // partially migrated from Ing 3 }, @@ -197,7 +197,7 @@ func TestTokensTakeover(t *testing.T) { second := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20}}, "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: InstanceState_LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}}, }, @@ -206,7 +206,7 @@ func TestTokensTakeover(t *testing.T) { merged := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20}}, "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: InstanceState_LEAVING, Tokens: []uint32{100, 200}}, @@ -218,7 +218,7 @@ func TestTokensTakeover(t *testing.T) { our, ch := merge(first(), second()) assert.Equal(t, merged(), our) assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20}}, "Ing 3": {Addr: "addr3", Timestamp: now + 5, State: InstanceState_LEAVING, Tokens: []uint32{100, 200}}, // change doesn't contain conflicted tokens }, @@ -237,7 +237,7 @@ func TestTokensTakeover(t *testing.T) { // change is different though assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, }, }, ch) @@ -249,7 +249,7 @@ func TestMergeLeft(t *testing.T) { firstRing := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, }, @@ -259,7 +259,7 @@ func TestMergeLeft(t *testing.T) { // Not normalised because it contains duplicate and unsorted tokens. firstRingNotNormalised := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{20, 10, 5, 10, 20, 100, 200, 100}}, }, @@ -268,7 +268,7 @@ func TestMergeLeft(t *testing.T) { secondRing := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT}, }, } @@ -277,7 +277,7 @@ func TestMergeLeft(t *testing.T) { // Not normalised because it contains a InstanceState_LEFT ingester with tokens. secondRingNotNormalised := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT, Tokens: []uint32{5, 10, 20, 100, 200}}, }, } @@ -285,7 +285,7 @@ func TestMergeLeft(t *testing.T) { expectedFirstSecondMerge := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT}, }, @@ -294,7 +294,7 @@ func TestMergeLeft(t *testing.T) { thirdRing := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEAVING, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, // from firstRing }, @@ -303,7 +303,7 @@ func TestMergeLeft(t *testing.T) { expectedFirstSecondThirdMerge := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_LEAVING, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT}, }, @@ -314,7 +314,7 @@ func TestMergeLeft(t *testing.T) { our, ch := merge(firstRing(), secondRing()) assert.Equal(t, expectedFirstSecondMerge(), our) assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT}, }, }, ch) @@ -324,7 +324,7 @@ func TestMergeLeft(t *testing.T) { our, ch := merge(firstRing(), secondRingNotNormalised()) assert.Equal(t, expectedFirstSecondMerge(), our) assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_LEFT}, }, }, ch) @@ -342,7 +342,7 @@ func TestMergeLeft(t *testing.T) { assert.Equal(t, expectedFirstSecondMerge(), our) // when merging first into second ring, only "Ing 1" is new assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, }, }, ch) @@ -353,7 +353,7 @@ func TestMergeLeft(t *testing.T) { assert.Equal(t, expectedFirstSecondMerge(), our) // when merging first into second ring, only "Ing 1" is new assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, }, }, ch) @@ -376,7 +376,7 @@ func TestMergeRemoveMissing(t *testing.T) { firstRing := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now, State: InstanceState_JOINING, Tokens: []uint32{5, 10, 20, 100, 200}}, "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEAVING, Tokens: []uint32{5, 10, 20, 100, 200}}, @@ -386,7 +386,7 @@ func TestMergeRemoveMissing(t *testing.T) { secondRing := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, }, @@ -395,7 +395,7 @@ func TestMergeRemoveMissing(t *testing.T) { expectedFirstSecondMerge := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, "Ing 3": {Addr: "addr3", Timestamp: now + 3, State: InstanceState_LEFT}, // When deleting, time depends on value passed to merge function. @@ -407,7 +407,7 @@ func TestMergeRemoveMissing(t *testing.T) { our, ch := mergeLocalCAS(firstRing(), secondRing(), now+3) assert.Equal(t, expectedFirstSecondMerge(), our) assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, "Ing 3": {Addr: "addr3", Timestamp: now + 3, State: InstanceState_LEFT}, // When deleting, time depends on value passed to merge function. }, @@ -423,7 +423,7 @@ func TestMergeRemoveMissing(t *testing.T) { { // commutativity is broken when deleting missing entries. But let's make sure we get reasonable results at least. our, ch := mergeLocalCAS(secondRing(), firstRing(), now+3) assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEAVING}, @@ -431,7 +431,7 @@ func TestMergeRemoveMissing(t *testing.T) { }, our) assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEAVING}, }, }, ch) @@ -443,7 +443,7 @@ func TestMergeMissingIntoLeft(t *testing.T) { ring1 := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now + 5, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEFT}, @@ -453,7 +453,7 @@ func TestMergeMissingIntoLeft(t *testing.T) { ring2 := func() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, }, @@ -463,7 +463,7 @@ func TestMergeMissingIntoLeft(t *testing.T) { { our, ch := mergeLocalCAS(ring1(), ring2(), now+10) assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, "Ing 3": {Addr: "addr3", Timestamp: now, State: InstanceState_LEFT}, @@ -471,7 +471,7 @@ func TestMergeMissingIntoLeft(t *testing.T) { }, our) assert.Equal(t, &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "Ing 1": {Addr: "addr1", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{30, 40, 50}}, "Ing 2": {Addr: "addr2", Timestamp: now + 10, State: InstanceState_ACTIVE, Tokens: []uint32{5, 10, 20, 100, 200}}, // Ing 3 is not changed, it was already InstanceState_LEFT diff --git a/ring/model.go b/ring/model.go index 72d385a42..6dddef1cd 100644 --- a/ring/model.go +++ b/ring/model.go @@ -285,6 +285,10 @@ func (d *Desc) mergeWithTime(mergeable memberlist.Mergeable, localCAS bool, now for name, oing := range otherIngesterMap { ting := thisIngesterMap[name] + if ting == nil { + ting = &InstanceDesc{} + } + // ting.Timestamp will be 0, if there was no such ingester in our version if oing.Timestamp > ting.Timestamp { if !tokensEqual(ting.Tokens, oing.Tokens) { From 7667afcf1d55ebc51dd6f5e14b338806c99a8f0f Mon Sep 17 00:00:00 2001 From: francoposa Date: Tue, 14 Jan 2025 11:32:30 -0800 Subject: [PATCH 08/22] fix compilation errors in model_test.go; set nil check guard in TokensFor in model.go; pass model_test.go with race check --- ring/model.go | 4 ++- ring/model_test.go | 74 +++++++++++++++++++++++----------------------- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/ring/model.go b/ring/model.go index 6dddef1cd..8a57f5216 100644 --- a/ring/model.go +++ b/ring/model.go @@ -170,7 +170,9 @@ func (d *Desc) IsReady(now time.Time, heartbeatTimeout time.Duration) error { // Returned tokens are guaranteed to be sorted. func (d *Desc) TokensFor(id string) (myTokens, allTokens Tokens) { allTokens = d.GetTokens() - myTokens = d.Ingesters[id].Tokens + if ing := d.GetIngester(id); ing != nil { + myTokens = ing.Tokens + } return } diff --git a/ring/model_test.go b/ring/model_test.go index 758f3e84f..0d9ae7954 100644 --- a/ring/model_test.go +++ b/ring/model_test.go @@ -125,16 +125,16 @@ func TestInstanceDesc_GetLastHeartbeatAt(t *testing.T) { func normalizedSource() *Desc { r := NewDesc() - r.Ingesters["first"] = InstanceDesc{ + r.Ingesters["first"] = &InstanceDesc{ Tokens: []uint32{100, 200, 300}, } - r.Ingesters["second"] = InstanceDesc{} + r.Ingesters["second"] = &InstanceDesc{} return r } func normalizedOutput() *Desc { return &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "first": {}, "second": {Tokens: []uint32{100, 200, 300}}, }, @@ -153,7 +153,7 @@ func TestDesc_Ready(t *testing.T) { now := time.Now() r := &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "ing1": { Tokens: []uint32{100, 200, 300}, State: InstanceState_ACTIVE, @@ -179,7 +179,7 @@ func TestDesc_Ready(t *testing.T) { } r = &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "ing1": { State: InstanceState_ACTIVE, Timestamp: now.Unix(), @@ -191,7 +191,7 @@ func TestDesc_Ready(t *testing.T) { t.Fatal("expected !ready (no tokens), but got no error") } - r.Ingesters["some ingester"] = InstanceDesc{ + r.Ingesters["some ingester"] = &InstanceDesc{ Tokens: []uint32{12345}, Timestamp: now.Unix(), } @@ -207,11 +207,11 @@ func TestDesc_getTokensByZone(t *testing.T) { expected map[string][]uint32 }{ "empty ring": { - desc: &Desc{Ingesters: map[string]InstanceDesc{}}, + desc: &Desc{Ingesters: map[string]*InstanceDesc{}}, expected: map[string][]uint32{}, }, "single zone": { - desc: &Desc{Ingesters: map[string]InstanceDesc{ + desc: &Desc{Ingesters: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Tokens: []uint32{1, 5}, Zone: ""}, "instance-2": {Addr: "127.0.0.1", Tokens: []uint32{2, 4}, Zone: ""}, "instance-3": {Addr: "127.0.0.1", Tokens: []uint32{3, 6}, Zone: ""}, @@ -221,7 +221,7 @@ func TestDesc_getTokensByZone(t *testing.T) { }, }, "multiple zones": { - desc: &Desc{Ingesters: map[string]InstanceDesc{ + desc: &Desc{Ingesters: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Tokens: []uint32{1, 5}, Zone: "zone-1"}, "instance-2": {Addr: "127.0.0.1", Tokens: []uint32{2, 4}, Zone: "zone-1"}, "instance-3": {Addr: "127.0.0.1", Tokens: []uint32{3, 6}, Zone: "zone-2"}, @@ -247,12 +247,12 @@ func TestDesc_TokensFor(t *testing.T) { expectedAll Tokens }{ "empty ring": { - desc: &Desc{Ingesters: map[string]InstanceDesc{}}, + desc: &Desc{Ingesters: map[string]*InstanceDesc{}}, expectedMine: Tokens(nil), expectedAll: Tokens{}, }, "single zone": { - desc: &Desc{Ingesters: map[string]InstanceDesc{ + desc: &Desc{Ingesters: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Tokens: []uint32{1, 5}, Zone: ""}, "instance-2": {Addr: "127.0.0.1", Tokens: []uint32{2, 4}, Zone: ""}, "instance-3": {Addr: "127.0.0.1", Tokens: []uint32{3, 6}, Zone: ""}, @@ -261,7 +261,7 @@ func TestDesc_TokensFor(t *testing.T) { expectedAll: Tokens{1, 2, 3, 4, 5, 6}, }, "multiple zones": { - desc: &Desc{Ingesters: map[string]InstanceDesc{ + desc: &Desc{Ingesters: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Tokens: []uint32{1, 5}, Zone: "zone-1"}, "instance-2": {Addr: "127.0.0.1", Tokens: []uint32{2, 4}, Zone: "zone-1"}, "instance-3": {Addr: "127.0.0.1", Tokens: []uint32{3, 6}, Zone: "zone-2"}, @@ -292,67 +292,67 @@ func TestDesc_RingsCompare(t *testing.T) { }, "one nil, one empty ring": { r1: nil, - r2: &Desc{Ingesters: map[string]InstanceDesc{}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{}}, expected: Equal, }, "two empty rings": { - r1: &Desc{Ingesters: map[string]InstanceDesc{}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{}}, expected: Equal, }, "same single instance": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1"}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1"}}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1"}}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1"}}}, expected: Equal, }, "same single instance, different timestamp": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", Timestamp: 123456}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", Timestamp: 789012}}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", Timestamp: 123456}}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", Timestamp: 789012}}}, expected: EqualButStatesAndTimestamps, }, "same single instance, different state": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_ACTIVE}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_JOINING}}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_ACTIVE}}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_JOINING}}}, expected: EqualButStatesAndTimestamps, }, "same single instance, different registered timestamp": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_ACTIVE, RegisteredTimestamp: 1}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_ACTIVE, RegisteredTimestamp: 2}}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_ACTIVE, RegisteredTimestamp: 1}}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", State: InstanceState_ACTIVE, RegisteredTimestamp: 2}}}, expected: Different, }, "same single instance, different read only flag": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1"}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", ReadOnly: true}}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1"}}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", ReadOnly: true}}}, expected: Different, }, "same single instance, different read only timestamp": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", ReadOnlyUpdatedTimestamp: time.Time{}.Unix()}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", ReadOnlyUpdatedTimestamp: time.Now().Unix()}}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", ReadOnlyUpdatedTimestamp: time.Time{}.Unix()}}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", ReadOnlyUpdatedTimestamp: time.Now().Unix()}}}, expected: Different, }, "instance in different zone": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", Zone: "one"}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", Zone: "two"}}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", Zone: "one"}}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", Zone: "two"}}}, expected: Different, }, "same instance, different address": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1"}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr2"}}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1"}}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr2"}}}, expected: Different, }, "more instances in one ring": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1"}, "ing2": {Addr: "ing2"}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1"}}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1"}, "ing2": {Addr: "ing2"}}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1"}}}, expected: Different, }, "different tokens": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", Tokens: []uint32{1, 2, 3}}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1"}}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", Tokens: []uint32{1, 2, 3}}}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1"}}}, expected: Different, }, "different tokens 2": { - r1: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", Tokens: []uint32{1, 2, 3}}}}, - r2: &Desc{Ingesters: map[string]InstanceDesc{"ing1": {Addr: "addr1", Tokens: []uint32{1, 2, 4}}}}, + r1: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", Tokens: []uint32{1, 2, 3}}}}, + r2: &Desc{Ingesters: map[string]*InstanceDesc{"ing1": {Addr: "addr1", Tokens: []uint32{1, 2, 4}}}}, expected: Different, }, } From 2c62aadee0f38e0135e50016b31a86bda2b4573f Mon Sep 17 00:00:00 2001 From: francoposa Date: Tue, 14 Jan 2025 12:05:58 -0800 Subject: [PATCH 09/22] fix compilation errors in ring_http_test.go and partition_instance_ring_test.go; pass all mentioned tests with race check --- ring/partition_instance_ring_test.go | 14 +++++++------- ring/ring_http_test.go | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ring/partition_instance_ring_test.go b/ring/partition_instance_ring_test.go index 2d0fce2c3..87dfcc1cc 100644 --- a/ring/partition_instance_ring_test.go +++ b/ring/partition_instance_ring_test.go @@ -28,7 +28,7 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }{ "should return error on empty partitions ring": { partitionsRing: PartitionRingDesc{}, - instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ + instancesRing: &Desc{Ingesters: map[string]*InstanceDesc{ "instance-1": {Id: "instance-1", State: InstanceState_ACTIVE, Timestamp: now.Unix()}, "instance-2": {Id: "instance-2", State: InstanceState_ACTIVE, Timestamp: now.Unix()}, }}, @@ -60,7 +60,7 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { "instance-zone-b-2": {OwnedPartition: 2}, }, }, - instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ + instancesRing: &Desc{Ingesters: map[string]*InstanceDesc{ "instance-zone-a-1": {Id: "instance-zone-a-1", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, "instance-zone-a-2": {Id: "instance-zone-a-2", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, "instance-zone-b-2": {Id: "instance-zone-b-2", State: InstanceState_ACTIVE, Zone: "b", Timestamp: now.Unix()}, @@ -82,7 +82,7 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { "instance-zone-b-2": {OwnedPartition: 2}, }, }, - instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ + instancesRing: &Desc{Ingesters: map[string]*InstanceDesc{ "instance-zone-a-1": {Id: "instance-zone-a-1", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, "instance-zone-a-2": {Id: "instance-zone-a-2", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Add(-2 * time.Minute).Unix()}, // Unhealthy. }}, @@ -101,7 +101,7 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { "instance-zone-b-2": {OwnedPartition: 2}, }, }, - instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ + instancesRing: &Desc{Ingesters: map[string]*InstanceDesc{ "instance-zone-a-1": {Id: "instance-zone-a-1", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, "instance-zone-b-1": {Id: "instance-zone-a-1", State: InstanceState_LEAVING, Zone: "a", Timestamp: now.Unix()}, // Unhealthy because of the state. "instance-zone-a-2": {Id: "instance-zone-a-2", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, @@ -125,7 +125,7 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { "instance-zone-b-2": {OwnedPartition: 2}, }, }, - instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ + instancesRing: &Desc{Ingesters: map[string]*InstanceDesc{ "instance-zone-a-1": {Id: "instance-zone-a-1", State: InstanceState_ACTIVE, Zone: "a", Timestamp: now.Unix()}, "instance-zone-b-2": {Id: "instance-zone-b-2", State: InstanceState_ACTIVE, Zone: "b", Timestamp: now.Unix()}, }}, @@ -147,7 +147,7 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { "instance-zone-b-2": {OwnedPartition: 2}, }, }, - instancesRing: &Desc{Ingesters: map[string]InstanceDesc{ + instancesRing: &Desc{Ingesters: map[string]*InstanceDesc{ "instance-zone-a-1": {Id: "instance-zone-a-1", State: InstanceState_ACTIVE, Zone: "fixed", Timestamp: now.Unix()}, "instance-zone-b-1": {Id: "instance-zone-b-1", State: InstanceState_ACTIVE, Zone: "fixed", Timestamp: now.Unix()}, "instance-zone-a-2": {Id: "instance-zone-a-2", State: InstanceState_ACTIVE, Zone: "fixed", Timestamp: now.Unix()}, @@ -230,7 +230,7 @@ func TestPartitionInstanceRing_ShuffleShard(t *testing.T) { partitionsRing.AddOrUpdateOwner("instance-2", OwnerActive, 2, now.Add(-30*time.Minute)) partitionsRing.AddOrUpdateOwner("instance-3", OwnerActive, 3, now.Add(-30*time.Minute)) - instancesRing := &Desc{Ingesters: map[string]InstanceDesc{ + instancesRing := &Desc{Ingesters: map[string]*InstanceDesc{ "instance-1": {Id: "instance-1", State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()}, "instance-2": {Id: "instance-2", State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()}, "instance-3": {Id: "instance-3", State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()}, diff --git a/ring/ring_http_test.go b/ring/ring_http_test.go index e3548a4e8..d133a5bd9 100644 --- a/ring/ring_http_test.go +++ b/ring/ring_http_test.go @@ -17,7 +17,7 @@ func TestRingPageHandler_handle(t *testing.T) { now := time.Now() ring := fakeRingAccess{ desc: &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "1": { Zone: "zone-a", State: InstanceState_ACTIVE, @@ -47,7 +47,7 @@ func TestRingPageHandler_handle(t *testing.T) { assert.Regexp(t, regexp.MustCompile(fmt.Sprintf("(?m)%s", strings.Join([]string{ "", "1", "", "", "zone-a", "", - "", "InstanceState_ACTIVE", "", + "", "ACTIVE", "", "", "addr-a", "", }, `\s*`))), recorder.Body.String()) @@ -59,7 +59,7 @@ func TestRingPageHandler_handle(t *testing.T) { assert.Regexp(t, regexp.MustCompile(fmt.Sprintf("(?m)%s", strings.Join([]string{ "", "2", "", "", "zone-b", "", - "", "InstanceState_ACTIVE", "", + "", "ACTIVE", "", "", "addr-b", "", }, `\s*`))), recorder.Body.String()) From 2f7d5095cc43795bac6d6392de502255d6afc719 Mon Sep 17 00:00:00 2001 From: francoposa Date: Tue, 14 Jan 2025 13:16:22 -0800 Subject: [PATCH 10/22] fix compilation errors in ring_test.go and update ring.go; replaced direct map access with value getters & setters in getCachedShuffledSubring and getCachedShuffledSubringWithLookback to eliminate race conditions and maintain spirit of original code; pass all mentioned tests with race check --- ring/ring.go | 12 +-- ring/ring_test.go | 250 +++++++++++++++++++++++----------------------- 2 files changed, 131 insertions(+), 131 deletions(-) diff --git a/ring/ring.go b/ring/ring.go index e4762c1e8..a481affaa 100644 --- a/ring/ring.go +++ b/ring/ring.go @@ -1075,11 +1075,11 @@ func (r *Ring) getCachedShuffledSubring(identifier string, size int) *Ring { // Update instance states and timestamps. We know that the topology is the same, // so zones and tokens are equal. - for name, cachedIng := range cached.ringDesc.Ingesters { - ing := r.ringDesc.Ingesters[name] + for name, cachedIng := range cached.ringDesc.GetIngesterVals() { + ing, _ := r.ringDesc.GetIngesterVal(name) cachedIng.State = ing.State cachedIng.Timestamp = ing.Timestamp - cached.ringDesc.Ingesters[name] = cachedIng + cached.ringDesc.SetIngesterVal(name, cachedIng) } return cached } @@ -1131,11 +1131,11 @@ func (r *Ring) getCachedShuffledSubringWithLookback(identifier string, size int, // Update instance states and timestamps. We know that the topology is the same, // so zones and tokens are equal. - for name, cachedIng := range cachedSubring.ringDesc.Ingesters { - ing := r.ringDesc.Ingesters[name] + for name, cachedIng := range cachedSubring.ringDesc.GetIngesterVals() { + ing, _ := r.ringDesc.GetIngesterVal(name) cachedIng.State = ing.State cachedIng.Timestamp = ing.Timestamp - cachedSubring.ringDesc.Ingesters[name] = cachedIng + cachedSubring.ringDesc.SetIngesterVal(name, cachedIng) } return cachedSubring diff --git a/ring/ring_test.go b/ring/ring_test.go index 3b86c8db5..e8eb04dbf 100644 --- a/ring/ring_test.go +++ b/ring/ring_test.go @@ -529,7 +529,7 @@ func TestAddIngesterReplacesExistingTokens(t *testing.T) { const ing1Name = "ing1" // old tokens will be replaced - r.Ingesters[ing1Name] = InstanceDesc{ + r.Ingesters[ing1Name] = &InstanceDesc{ Tokens: []uint32{11111, 22222, 33333}, } @@ -565,7 +565,7 @@ func TestRing_Get_ZoneAwarenessWithIngesterLeaving(t *testing.T) { gen := initTokenGenerator(t) r := NewDesc() - instances := map[string]InstanceDesc{ + instances := map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_ACTIVE}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: InstanceState_ACTIVE}, @@ -580,7 +580,7 @@ func TestRing_Get_ZoneAwarenessWithIngesterLeaving(t *testing.T) { prevTokens = append(prevTokens, ingTokens...) } instancesList := make([]InstanceDesc, 0, len(r.GetIngesters())) - for _, v := range r.GetIngesters() { + for _, v := range r.GetIngesterVals() { instancesList = append(instancesList, v) } @@ -679,7 +679,7 @@ func TestRing_Get_ZoneAwareness(t *testing.T) { ring.setRingStateFromDesc(r, false, false, false) instances := make([]InstanceDesc, 0, len(r.GetIngesters())) - for _, v := range r.GetIngesters() { + for _, v := range r.GetIngesterVals() { instances = append(instances, v) } @@ -726,7 +726,7 @@ func TestRing_GetAllHealthy(t *testing.T) { now := time.Now() tests := map[string]struct { - ringInstances map[string]InstanceDesc + ringInstances map[string]*InstanceDesc expectedErrForRead error expectedSetForRead []string expectedErrForWrite error @@ -741,7 +741,7 @@ func TestRing_GetAllHealthy(t *testing.T) { expectedErrForReporting: ErrEmptyRing, }, "should return all healthy instances for the given operation": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Unix()}, "instance-2": {Addr: "127.0.0.2", State: InstanceState_PENDING, Timestamp: now.Add(-10 * time.Second).Unix()}, "instance-3": {Addr: "127.0.0.3", State: InstanceState_JOINING, Timestamp: now.Add(-20 * time.Second).Unix()}, @@ -785,7 +785,7 @@ func TestRing_GetReplicationSetForOperation(t *testing.T) { gen := initTokenGenerator(t) tests := map[string]struct { - ringInstances map[string]InstanceDesc + ringInstances map[string]*InstanceDesc ringHeartbeatTimeout time.Duration ringReplicationFactor int expectedErrForRead error @@ -804,7 +804,7 @@ func TestRing_GetReplicationSetForOperation(t *testing.T) { expectedErrForReporting: ErrEmptyRing, }, "should succeed on all healthy instances and RF=1": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", State: InstanceState_ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", State: InstanceState_ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, @@ -818,7 +818,7 @@ func TestRing_GetReplicationSetForOperation(t *testing.T) { expectedSetForReporting: []string{"127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5"}, }, "should succeed on instances with old timestamps but heartbeat timeout disabled": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", State: InstanceState_ACTIVE, Timestamp: now.Add(-2 * time.Minute).Unix(), Tokens: gen.GenerateTokens(128, nil)}, @@ -832,7 +832,7 @@ func TestRing_GetReplicationSetForOperation(t *testing.T) { expectedSetForReporting: []string{"127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4", "127.0.0.5"}, }, "should fail on 1 unhealthy instance and RF=1": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", State: InstanceState_ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", State: InstanceState_ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, @@ -846,7 +846,7 @@ func TestRing_GetReplicationSetForOperation(t *testing.T) { expectedErrForReporting: ErrTooManyUnhealthyInstances, }, "should succeed on 1 unhealthy instances and RF=3": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", State: InstanceState_ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", State: InstanceState_ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, @@ -860,7 +860,7 @@ func TestRing_GetReplicationSetForOperation(t *testing.T) { expectedSetForReporting: []string{"127.0.0.1", "127.0.0.2", "127.0.0.3", "127.0.0.4"}, }, "should fail on 2 unhealthy instances and RF=3": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: now.Unix(), Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", State: InstanceState_ACTIVE, Timestamp: now.Add(-10 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", State: InstanceState_ACTIVE, Timestamp: now.Add(-20 * time.Second).Unix(), Tokens: gen.GenerateTokens(128, nil)}, @@ -908,7 +908,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. gen := initTokenGenerator(t) tests := map[string]struct { - ringInstances map[string]InstanceDesc + ringInstances map[string]*InstanceDesc unhealthyInstances []string expectedAddresses []string replicationFactor int @@ -921,7 +921,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedError: ErrEmptyRing, }, "RF=1, 1 zone": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, }, @@ -931,7 +931,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 0, }, "RF=1, 1 zone, one unhealthy instance": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, @@ -941,7 +941,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedError: ErrTooManyUnhealthyInstances, }, "RF=1, 3 zones, one unhealthy instance": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-c", Tokens: gen.GenerateTokens(128, nil)}, @@ -951,7 +951,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedError: ErrTooManyUnhealthyInstances, }, "RF=2, 2 zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, }, @@ -960,7 +960,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 1, }, "RF=2, 2 zones, one unhealthy instance": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, }, @@ -969,7 +969,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. replicationFactor: 2, }, "RF=3, 3 zones, one instance per zone": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-c", Tokens: gen.GenerateTokens(128, nil)}, @@ -980,7 +980,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 1, }, "RF=3, 3 zones, one instance per zone, one instance unhealthy": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-c", Tokens: gen.GenerateTokens(128, nil)}, @@ -992,7 +992,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 0, }, "RF=3, 3 zones, one instance per zone, two instances unhealthy in separate zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-c", Tokens: gen.GenerateTokens(128, nil)}, @@ -1002,7 +1002,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedError: ErrTooManyUnhealthyInstances, }, "RF=3, 3 zones, one instance per zone, all instances unhealthy": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-c", Tokens: gen.GenerateTokens(128, nil)}, @@ -1012,7 +1012,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedError: ErrTooManyUnhealthyInstances, }, "RF=3, 3 zones, two instances per zone": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, @@ -1026,7 +1026,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 1, }, "RF=3, 3 zones, two instances per zone, two instances unhealthy in same zone": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, @@ -1041,7 +1041,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 0, }, "RF=3, 3 zones, three instances per zone, two instances unhealthy in same zone": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, @@ -1059,7 +1059,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 0, }, "RF=3, only 2 zones, two instances per zone": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, @@ -1071,7 +1071,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 1, }, "RF=3, only 2 zones, two instances per zone, one instance unhealthy": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, @@ -1084,7 +1084,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 0, }, "RF=3, only 1 zone, two instances per zone": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, }, @@ -1094,7 +1094,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 0, }, "RF=3, only 1 zone, two instances per zone, one instance unhealthy": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, }, @@ -1103,7 +1103,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedError: ErrTooManyUnhealthyInstances, }, "RF=5, 5 zones, two instances per zone except for one zone which has three": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, @@ -1125,7 +1125,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 2, }, "RF=5, 5 zones, two instances per zone except for one zone which has three, 2 unhealthy nodes in same zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, @@ -1145,7 +1145,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 1, }, "RF=5, 5 zones, two instances per zone except for one zone which has three, 2 unhealthy nodes in separate zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, @@ -1165,7 +1165,7 @@ func TestRing_GetReplicationSetForOperation_WithZoneAwarenessEnabled(t *testing. expectedMaxUnavailableZones: 0, }, "RF=5, 5 zones, one instances per zone, three unhealthy instances": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-c", Tokens: gen.GenerateTokens(128, nil)}, @@ -1233,7 +1233,7 @@ func TestRing_GetInstancesWithTokensCounts(t *testing.T) { gen := initTokenGenerator(t) tests := map[string]struct { - ringInstances map[string]InstanceDesc + ringInstances map[string]*InstanceDesc expectedInstancesWithTokensCount int expectedInstancesWithTokensInZoneCount map[string]int }{ @@ -1243,7 +1243,7 @@ func TestRing_GetInstancesWithTokensCounts(t *testing.T) { expectedInstancesWithTokensInZoneCount: map[string]int{}, }, "single zone, no tokens": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_LEAVING, Tokens: []uint32{}}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: InstanceState_PENDING, Tokens: []uint32{}}, @@ -1253,7 +1253,7 @@ func TestRing_GetInstancesWithTokensCounts(t *testing.T) { expectedInstancesWithTokensInZoneCount: map[string]int{"zone-a": 0}, }, "single zone, some tokens": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: InstanceState_LEAVING, Tokens: gen.GenerateTokens(128, nil)}, @@ -1267,7 +1267,7 @@ func TestRing_GetInstancesWithTokensCounts(t *testing.T) { expectedInstancesWithTokensInZoneCount: map[string]int{"zone-a": 4}, }, "multiple zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: InstanceState_LEAVING, Tokens: gen.GenerateTokens(128, nil)}, @@ -1309,7 +1309,7 @@ func TestRing_GetWritableInstancesWithTokensCounts(t *testing.T) { gen := initTokenGenerator(t) tests := map[string]struct { - ringInstances map[string]InstanceDesc + ringInstances map[string]*InstanceDesc expectedWritableInstancesWithTokensCount int expectedWritableInstancesWithTokensCountPerZone map[string]int }{ @@ -1319,7 +1319,7 @@ func TestRing_GetWritableInstancesWithTokensCounts(t *testing.T) { expectedWritableInstancesWithTokensCountPerZone: map[string]int{}, }, "single zone, no tokens": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_LEAVING, Tokens: []uint32{}, ReadOnly: true}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: InstanceState_PENDING, Tokens: []uint32{}}, @@ -1329,7 +1329,7 @@ func TestRing_GetWritableInstancesWithTokensCounts(t *testing.T) { expectedWritableInstancesWithTokensCountPerZone: map[string]int{"zone-a": 0}, }, "single zone, some tokens": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", State: InstanceState_LEAVING, Tokens: gen.GenerateTokens(128, nil)}, @@ -1343,7 +1343,7 @@ func TestRing_GetWritableInstancesWithTokensCounts(t *testing.T) { expectedWritableInstancesWithTokensCountPerZone: map[string]int{"zone-a": 3}, }, "multiple zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", State: InstanceState_ACTIVE, Tokens: []uint32{}, ReadOnly: true}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", State: InstanceState_LEAVING, Tokens: gen.GenerateTokens(128, nil), ReadOnly: true}, @@ -1385,7 +1385,7 @@ func TestRing_ShuffleShard(t *testing.T) { gen := initTokenGenerator(t) tests := map[string]struct { - ringInstances map[string]InstanceDesc + ringInstances map[string]*InstanceDesc shardSize int zoneAwarenessEnabled bool expectedSize int @@ -1408,7 +1408,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedDistribution: []int{}, }, "single zone, shard size > num instances": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, }, @@ -1420,7 +1420,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 2}, }, "single zone, shard size == 0": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, }, @@ -1432,7 +1432,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 2}, }, "single zone, shard size < num instances": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, @@ -1445,7 +1445,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 2}, }, "single zone, with read only instance, shardSize = 3": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", ReadOnly: true, Tokens: gen.GenerateTokens(128, nil)}, @@ -1458,7 +1458,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 2}, }, "single zone, with read only instance, shardSize = 0": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", ReadOnly: true, Tokens: gen.GenerateTokens(128, nil)}, @@ -1471,7 +1471,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 2}, }, "multiple zones, shard size < num zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-c", Tokens: gen.GenerateTokens(128, nil)}, @@ -1484,7 +1484,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 1, "zone-b": 1, "zone-c": 1}, }, "multiple zones, shard size divisible by num zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, @@ -1500,7 +1500,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 1, "zone-b": 1, "zone-c": 1}, }, "multiple zones, shard size NOT divisible by num zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, @@ -1516,7 +1516,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 2, "zone-b": 2, "zone-c": 2}, }, "multiple zones, shard size NOT divisible by num zones, but zone awareness is disabled": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, @@ -1529,7 +1529,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedSize: 4, }, "multiple zones, with read only instance, shardSize=3": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-c", ReadOnly: true, Tokens: gen.GenerateTokens(128, nil)}, @@ -1542,7 +1542,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 1, "zone-b": 1, "zone-c": 0}, }, "multiple zones, with read only instance, shardSize=0": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil), ReadOnly: true}, @@ -1558,7 +1558,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 2, "zone-b": 1, "zone-c": 1}, }, "multiple zones, shard size == num instances, balanced zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, @@ -1574,7 +1574,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 2, "zone-b": 2, "zone-c": 2}, }, "multiple zones, shard size == num instances, unbalanced zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, @@ -1590,7 +1590,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 2, "zone-b": 2, "zone-c": 1}, }, "multiple zones, shard size > num instances, balanced zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-b", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-c", Tokens: gen.GenerateTokens(128, nil)}, @@ -1603,7 +1603,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 1, "zone-b": 1, "zone-c": 1}, }, "multiple zones, shard size > num instances, unbalanced zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, @@ -1619,7 +1619,7 @@ func TestRing_ShuffleShard(t *testing.T) { expectedInstancesInZoneCount: map[string]int{"zone-a": 3, "zone-b": 2, "zone-c": 1}, }, "multiple zones, shard size = 0, unbalanced zones": { - ringInstances: map[string]InstanceDesc{ + ringInstances: map[string]*InstanceDesc{ "instance-1": {Addr: "127.0.0.1", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-2": {Addr: "127.0.0.2", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, "instance-3": {Addr: "127.0.0.3", Zone: "zone-a", Tokens: gen.GenerateTokens(128, nil)}, @@ -1751,10 +1751,10 @@ func TestRing_ShuffleShard_Shuffling(t *testing.T) { // Initialise the ring instances. To have stable tests we generate tokens using a linear // distribution. Tokens within the same zone are evenly distributed too. - instances := make(map[string]InstanceDesc, numInstances) + instances := make(map[string]*InstanceDesc, numInstances) for i := 0; i < numInstances; i++ { id := fmt.Sprintf("instance-%d", i) - instances[id] = InstanceDesc{ + instances[id] = &InstanceDesc{ Addr: fmt.Sprintf("127.0.0.%d", i), Timestamp: time.Now().Unix(), RegisteredTimestamp: time.Now().Unix(), @@ -1935,7 +1935,7 @@ func TestRing_ShuffleShard_Consistency(t *testing.T) { func TestRing_ShuffleShard_ConsistencyOnShardSizeChanged(t *testing.T) { // Create 30 instances in 3 zones. - ringInstances := map[string]InstanceDesc{} + ringInstances := map[string]*InstanceDesc{} for i := 0; i < 30; i++ { name, desc, _ := generateRingInstance(initTokenGenerator(t), i, i%3, 128, nil) ringInstances[name] = desc @@ -2005,7 +2005,7 @@ func TestRing_ShuffleShard_ConsistencyOnShardSizeChanged(t *testing.T) { func TestRing_ShuffleShard_ConsistencyOnZonesChanged(t *testing.T) { // Create 20 instances in 2 zones. - ringInstances := map[string]InstanceDesc{} + ringInstances := map[string]*InstanceDesc{} for i := 0; i < 20; i++ { name, desc, _ := generateRingInstance(initTokenGenerator(t), i, i%2, 128, nil) ringInstances[name] = desc @@ -2086,7 +2086,7 @@ func TestRing_ShuffleShardWithLookback(t *testing.T) { type event struct { what eventType instanceID string - instanceDesc InstanceDesc + instanceDesc *InstanceDesc shardSize int expected []string readOnly bool @@ -2465,7 +2465,7 @@ func TestRing_ShuffleShardWithLookback(t *testing.T) { for _, updateReadOnlyInstances := range []bool{false, true} { t.Run(fmt.Sprintf("%s/%v/%v", testName, updateRegisteredTimestampCache, updateReadOnlyInstances), func(t *testing.T) { // Initialise the ring. - ringDesc := &Desc{Ingesters: map[string]InstanceDesc{}} + ringDesc := &Desc{Ingesters: map[string]*InstanceDesc{}} ring := newRingForTesting(Config{ HeartbeatTimeout: time.Hour, ZoneAwarenessEnabled: true, @@ -2573,7 +2573,7 @@ func TestRing_ShuffleShardWithLookback_CorrectnessWithFuzzy(t *testing.T) { } // Track instances that have been marked as read-only - readOnlyInstances := make(map[string]InstanceDesc) + readOnlyInstances := make(map[string]*InstanceDesc) // Simulate a progression of random events over the time and, at each iteration of the simulation, // make sure the subring includes all non-removed instances picked from previous versions of the @@ -2707,11 +2707,11 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { now := time.Now() scenarios := map[string]struct { - instances []InstanceDesc + instances []*InstanceDesc test func(t *testing.T, ring *Ring) }{ "identical request": { - instances: []InstanceDesc{ + instances: []*InstanceDesc{ generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -2739,7 +2739,7 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { }, }, "identical request after cleaning subring cache": { - instances: []InstanceDesc{ + instances: []*InstanceDesc{ generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -2772,7 +2772,7 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { }, }, "different subring sizes": { - instances: []InstanceDesc{ + instances: []*InstanceDesc{ generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -2804,7 +2804,7 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { }, }, "different identifiers": { - instances: []InstanceDesc{ + instances: []*InstanceDesc{ generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -2836,7 +2836,7 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { }, }, "all changes before beginning of either lookback window": { - instances: []InstanceDesc{ + instances: []*InstanceDesc{ generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -2864,7 +2864,7 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { }, }, "change within both lookback windows": { - instances: []InstanceDesc{ + instances: []*InstanceDesc{ generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-5*time.Minute)), generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -2892,7 +2892,7 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { }, }, "change on threshold of second lookback window": { - instances: []InstanceDesc{ + instances: []*InstanceDesc{ generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-1*time.Hour)), generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -2920,7 +2920,7 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { }, }, "change on threshold of first lookback window": { - instances: []InstanceDesc{ + instances: []*InstanceDesc{ generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-63*time.Minute)), generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -2952,7 +2952,7 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { }, }, "change between thresholds of first and second lookback windows": { - instances: []InstanceDesc{ + instances: []*InstanceDesc{ generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-62*time.Minute)), generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -2984,7 +2984,7 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { }, }, "change between thresholds of first and second lookback windows with out-of-order subring calls": { - instances: []InstanceDesc{ + instances: []*InstanceDesc{ generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-62*time.Minute)), generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -3037,7 +3037,7 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { }, }, "different lookback windows": { - instances: []InstanceDesc{ + instances: []*InstanceDesc{ generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-1*time.Hour)), generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -3096,7 +3096,7 @@ func TestRing_ShuffleShardWithLookback_Caching(t *testing.T) { ring, err := NewWithStoreClientAndStrategy(cfg, testRingName, testRingKey, nil, NewDefaultReplicationStrategy(), registry, log.NewNopLogger()) require.NoError(t, err) - instancesMap := make(map[string]InstanceDesc, len(scenario.instances)) + instancesMap := make(map[string]*InstanceDesc, len(scenario.instances)) for _, instance := range scenario.instances { instancesMap[instance.Addr] = instance } @@ -3119,7 +3119,7 @@ func TestRing_ShuffleShardWithLookback_CachingAfterTopologyChange(t *testing.T) userID := "user-1" now := time.Now() - initialInstances := map[string]InstanceDesc{ + initialInstances := map[string]*InstanceDesc{ "instance-1": generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-2*time.Hour)), "instance-2": generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), "instance-3": generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -3142,7 +3142,7 @@ func TestRing_ShuffleShardWithLookback_CachingAfterTopologyChange(t *testing.T) require.Equal(t, 1, first.InstancesInZoneCount("zone-b")) require.Equal(t, 1, first.InstancesInZoneCount("zone-c")) - updatedInstances := map[string]InstanceDesc{ + updatedInstances := map[string]*InstanceDesc{ // instance-1 has unregistered "instance-2": generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), "instance-3": generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -3166,7 +3166,7 @@ func TestRing_ShuffleShardWithLookback_CachingAfterTopologyChange(t *testing.T) require.Equal(t, 1, second.InstancesInZoneCount("zone-c")) } -func makeReadOnly(desc InstanceDesc, ts time.Time) InstanceDesc { +func makeReadOnly(desc *InstanceDesc, ts time.Time) *InstanceDesc { desc.ReadOnly = true desc.ReadOnlyUpdatedTimestamp = ts.Unix() return desc @@ -3181,8 +3181,8 @@ func TestRing_ShuffleShardWithLookback_CachingAfterReadOnlyChange(t *testing.T) userID := "user-1" now := time.Now() - makeInstances := func() map[string]InstanceDesc { - return map[string]InstanceDesc{ + makeInstances := func() map[string]*InstanceDesc { + return map[string]*InstanceDesc{ "instance-1": generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-2*time.Hour)), "instance-2": generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), "instance-3": generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -3234,7 +3234,7 @@ func TestRing_ShuffleShardWithLookback_CachingAfterHeartbeatOrStateChange(t *tes userID := "user-1" now := time.Now() - initialInstances := map[string]InstanceDesc{ + initialInstances := map[string]*InstanceDesc{ "instance-1": generateRingInstanceWithInfo("instance-1", "zone-a", []uint32{userToken(userID, "zone-a", 0) + 1}, now.Add(-2*time.Hour)), "instance-2": generateRingInstanceWithInfo("instance-2", "zone-a", []uint32{userToken(userID, "zone-a", 1) + 1}, now.Add(-2*time.Hour)), "instance-3": generateRingInstanceWithInfo("instance-3", "zone-b", []uint32{userToken(userID, "zone-b", 0) + 1}, now.Add(-2*time.Hour)), @@ -3267,7 +3267,7 @@ func TestRing_ShuffleShardWithLookback_CachingAfterHeartbeatOrStateChange(t *tes updatedInstance3.Timestamp = initialInstances["instance-3"].Timestamp updatedInstance3.State = InstanceState_LEAVING - updatedInstances := map[string]InstanceDesc{ + updatedInstances := map[string]*InstanceDesc{ "instance-1": updatedInstance1, "instance-2": initialInstances["instance-2"], "instance-3": updatedInstance3, @@ -3312,7 +3312,7 @@ func TestRing_ShuffleShardWithLookback_CachingConcurrency(t *testing.T) { gen := initTokenGenerator(t) // Add some instances to the ring. - ringDesc := &Desc{Ingesters: map[string]InstanceDesc{ + ringDesc := &Desc{Ingesters: map[string]*InstanceDesc{ "instance-1": generateRingInstanceWithInfo("instance-1", "zone-a", gen.GenerateTokens(128, nil), now.Add(-2*time.Hour)), "instance-2": makeReadOnly(generateRingInstanceWithInfo("instance-2", "zone-a", gen.GenerateTokens(128, nil), now.Add(-2*time.Hour)), now), "instance-3": generateRingInstanceWithInfo("instance-3", "zone-b", gen.GenerateTokens(128, nil), now.Add(-2*time.Hour)), @@ -3516,8 +3516,8 @@ func generateTokensLinear(instanceID, numInstances, numTokens int) []uint32 { return tokens } -func generateRingInstances(gen TokenGenerator, numInstances, numZones, numTokens int) map[string]InstanceDesc { - instances := make(map[string]InstanceDesc, numInstances) +func generateRingInstances(gen TokenGenerator, numInstances, numZones, numTokens int) map[string]*InstanceDesc { + instances := make(map[string]*InstanceDesc, numInstances) var allTokens []uint32 @@ -3530,7 +3530,7 @@ func generateRingInstances(gen TokenGenerator, numInstances, numZones, numTokens return instances } -func generateRingInstance(gen TokenGenerator, id, zone, numTokens int, usedTokens []uint32) (string, InstanceDesc, Tokens) { +func generateRingInstance(gen TokenGenerator, id, zone, numTokens int, usedTokens []uint32) (string, *InstanceDesc, Tokens) { instanceID := fmt.Sprintf("instance-%d", id) zoneID := fmt.Sprintf("zone-%d", zone) newTokens := gen.GenerateTokens(numTokens, usedTokens) @@ -3538,12 +3538,12 @@ func generateRingInstance(gen TokenGenerator, id, zone, numTokens int, usedToken return instanceID, generateRingInstanceWithInfo(instanceID, zoneID, newTokens, time.Now()), newTokens } -func generateRingInstanceWithInfo(addr, zone string, tokens []uint32, registeredAt time.Time) InstanceDesc { +func generateRingInstanceWithInfo(addr, zone string, tokens []uint32, registeredAt time.Time) *InstanceDesc { var regts int64 if !registeredAt.IsZero() { regts = registeredAt.Unix() } - return InstanceDesc{ + return &InstanceDesc{ Addr: addr, Timestamp: time.Now().Unix(), RegisteredTimestamp: regts, @@ -3863,7 +3863,7 @@ func TestUpdateMetrics(t *testing.T) { require.NoError(t, err) ringDesc := Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "A": {Addr: "127.0.0.1", Timestamp: 22, Tokens: []uint32{math.MaxUint32 / 4, (math.MaxUint32 / 4) * 3}}, "B": {Addr: "127.0.0.2", Timestamp: 11, Tokens: []uint32{(math.MaxUint32 / 4) * 2, math.MaxUint32}}, }, @@ -3873,17 +3873,17 @@ func TestUpdateMetrics(t *testing.T) { err = testutil.GatherAndCompare(registry, bytes.NewBufferString(` # HELP ring_members Number of members in the ring # TYPE ring_members gauge - ring_members{name="test",state="InstanceState_ACTIVE"} 2 - ring_members{name="test",state="InstanceState_JOINING"} 0 - ring_members{name="test",state="InstanceState_LEAVING"} 0 - ring_members{name="test",state="InstanceState_PENDING"} 0 + ring_members{name="test",state="ACTIVE"} 2 + ring_members{name="test",state="JOINING"} 0 + ring_members{name="test",state="LEAVING"} 0 + ring_members{name="test",state="PENDING"} 0 ring_members{name="test",state="Unhealthy"} 0 # HELP ring_oldest_member_timestamp Timestamp of the oldest member in the ring. # TYPE ring_oldest_member_timestamp gauge - ring_oldest_member_timestamp{name="test",state="InstanceState_ACTIVE"} 11 - ring_oldest_member_timestamp{name="test",state="InstanceState_JOINING"} 0 - ring_oldest_member_timestamp{name="test",state="InstanceState_LEAVING"} 0 - ring_oldest_member_timestamp{name="test",state="InstanceState_PENDING"} 0 + ring_oldest_member_timestamp{name="test",state="ACTIVE"} 11 + ring_oldest_member_timestamp{name="test",state="JOINING"} 0 + ring_oldest_member_timestamp{name="test",state="LEAVING"} 0 + ring_oldest_member_timestamp{name="test",state="PENDING"} 0 ring_oldest_member_timestamp{name="test",state="Unhealthy"} 0 # HELP ring_tokens_total Number of tokens in the ring # TYPE ring_tokens_total gauge @@ -3907,7 +3907,7 @@ func TestUpdateMetricsWithRemoval(t *testing.T) { require.NoError(t, err) ringDesc := Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "A": {Addr: "127.0.0.1", Timestamp: 22, Tokens: []uint32{math.MaxUint32 / 4, (math.MaxUint32 / 4) * 3}}, "B": {Addr: "127.0.0.2", Timestamp: 11, Tokens: []uint32{(math.MaxUint32 / 4) * 2, math.MaxUint32}}, }, @@ -3917,17 +3917,17 @@ func TestUpdateMetricsWithRemoval(t *testing.T) { err = testutil.GatherAndCompare(registry, bytes.NewBufferString(` # HELP ring_members Number of members in the ring # TYPE ring_members gauge - ring_members{name="test",state="InstanceState_ACTIVE"} 2 - ring_members{name="test",state="InstanceState_JOINING"} 0 - ring_members{name="test",state="InstanceState_LEAVING"} 0 - ring_members{name="test",state="InstanceState_PENDING"} 0 + ring_members{name="test",state="ACTIVE"} 2 + ring_members{name="test",state="JOINING"} 0 + ring_members{name="test",state="LEAVING"} 0 + ring_members{name="test",state="PENDING"} 0 ring_members{name="test",state="Unhealthy"} 0 # HELP ring_oldest_member_timestamp Timestamp of the oldest member in the ring. # TYPE ring_oldest_member_timestamp gauge - ring_oldest_member_timestamp{name="test",state="InstanceState_ACTIVE"} 11 - ring_oldest_member_timestamp{name="test",state="InstanceState_JOINING"} 0 - ring_oldest_member_timestamp{name="test",state="InstanceState_LEAVING"} 0 - ring_oldest_member_timestamp{name="test",state="InstanceState_PENDING"} 0 + ring_oldest_member_timestamp{name="test",state="ACTIVE"} 11 + ring_oldest_member_timestamp{name="test",state="JOINING"} 0 + ring_oldest_member_timestamp{name="test",state="LEAVING"} 0 + ring_oldest_member_timestamp{name="test",state="PENDING"} 0 ring_oldest_member_timestamp{name="test",state="Unhealthy"} 0 # HELP ring_tokens_total Number of tokens in the ring # TYPE ring_tokens_total gauge @@ -3936,7 +3936,7 @@ func TestUpdateMetricsWithRemoval(t *testing.T) { require.NoError(t, err) ringDescNew := Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "A": {Addr: "127.0.0.1", Timestamp: 22, Tokens: []uint32{math.MaxUint32 / 4, (math.MaxUint32 / 4) * 3}}, }, } @@ -3945,17 +3945,17 @@ func TestUpdateMetricsWithRemoval(t *testing.T) { err = testutil.GatherAndCompare(registry, bytes.NewBufferString(` # HELP ring_members Number of members in the ring # TYPE ring_members gauge - ring_members{name="test",state="InstanceState_ACTIVE"} 1 - ring_members{name="test",state="InstanceState_JOINING"} 0 - ring_members{name="test",state="InstanceState_LEAVING"} 0 - ring_members{name="test",state="InstanceState_PENDING"} 0 + ring_members{name="test",state="ACTIVE"} 1 + ring_members{name="test",state="JOINING"} 0 + ring_members{name="test",state="LEAVING"} 0 + ring_members{name="test",state="PENDING"} 0 ring_members{name="test",state="Unhealthy"} 0 # HELP ring_oldest_member_timestamp Timestamp of the oldest member in the ring. # TYPE ring_oldest_member_timestamp gauge - ring_oldest_member_timestamp{name="test",state="InstanceState_ACTIVE"} 22 - ring_oldest_member_timestamp{name="test",state="InstanceState_JOINING"} 0 - ring_oldest_member_timestamp{name="test",state="InstanceState_LEAVING"} 0 - ring_oldest_member_timestamp{name="test",state="InstanceState_PENDING"} 0 + ring_oldest_member_timestamp{name="test",state="ACTIVE"} 22 + ring_oldest_member_timestamp{name="test",state="JOINING"} 0 + ring_oldest_member_timestamp{name="test",state="LEAVING"} 0 + ring_oldest_member_timestamp{name="test",state="PENDING"} 0 ring_oldest_member_timestamp{name="test",state="Unhealthy"} 0 # HELP ring_tokens_total Number of tokens in the ring # TYPE ring_tokens_total gauge @@ -4047,7 +4047,7 @@ func TestCountTokensSingleZone(t *testing.T) { }, "1 instance with 1 token in the ring": { ring: &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "ingester-1": {Tokens: []uint32{1000000}}, }, }, @@ -4057,7 +4057,7 @@ func TestCountTokensSingleZone(t *testing.T) { }, "1 instance with multiple tokens in the ring": { ring: &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "ingester-1": {Tokens: []uint32{1000000, 2000000, 3000000}}, }, }, @@ -4067,7 +4067,7 @@ func TestCountTokensSingleZone(t *testing.T) { }, "multiple instances with multiple tokens in the ring": { ring: &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "ingester-1": {Tokens: []uint32{1000000, 3000000, 6000000}}, "ingester-2": {Tokens: []uint32{2000000, 4000000, 8000000}}, "ingester-3": {Tokens: []uint32{5000000, 9000000}}, @@ -4099,7 +4099,7 @@ func TestCountTokensMultiZones(t *testing.T) { }, "1 instance per zone with 1 token in the ring": { ring: &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "ingester-zone-a-1": {Zone: "zone-a", Tokens: []uint32{1000000}}, "ingester-zone-b-1": {Zone: "zone-b", Tokens: []uint32{1000001}}, "ingester-zone-c-1": {Zone: "zone-c", Tokens: []uint32{1000002}}, @@ -4113,7 +4113,7 @@ func TestCountTokensMultiZones(t *testing.T) { }, "1 instance per zone with multiple tokens in the ring": { ring: &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "ingester-zone-a-1": {Zone: "zone-a", Tokens: []uint32{1000000, 2000000, 3000000}}, "ingester-zone-b-1": {Zone: "zone-b", Tokens: []uint32{1000001, 2000001, 3000001}}, "ingester-zone-c-1": {Zone: "zone-c", Tokens: []uint32{1000002, 2000002, 3000002}}, @@ -4127,7 +4127,7 @@ func TestCountTokensMultiZones(t *testing.T) { }, "multiple instances in multiple zones with multiple tokens in the ring": { ring: &Desc{ - Ingesters: map[string]InstanceDesc{ + Ingesters: map[string]*InstanceDesc{ "ingester-zone-a-1": {Zone: "zone-a", Tokens: []uint32{1000000, 3000000, 6000000}}, "ingester-zone-a-2": {Zone: "zone-a", Tokens: []uint32{2000000, 4000000, 8000000}}, "ingester-zone-a-3": {Zone: "zone-a", Tokens: []uint32{5000000, 9000000}}, @@ -4155,7 +4155,7 @@ func TestCountTokensMultiZones(t *testing.T) { } // To make tests reproducible we sort the instance IDs in the map, and then get a random index via rnd. -func getRandomInstanceID(instances map[string]InstanceDesc, rnd *rand.Rand) string { +func getRandomInstanceID(instances map[string]*InstanceDesc, rnd *rand.Rand) string { instanceIDs := make([]string, 0, len(instances)) for id := range instances { instanceIDs = append(instanceIDs, id) From 4124b8f56ce164655953501b14f8fdef793ed0f6 Mon Sep 17 00:00:00 2001 From: francoposa Date: Tue, 14 Jan 2025 13:47:49 -0800 Subject: [PATCH 11/22] fix compilation errors in spread_minimizing_token_generator_test.go, token_range_test.go, and util_test.go; opt for value getters in spread_minimizing_token_generator_test.go for compatibility with public CanJoin interface; pass all mentioned tests with race check --- ring/spread_minimizing_token_generator_test.go | 6 +++--- ring/token_range_test.go | 2 +- ring/util_test.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ring/spread_minimizing_token_generator_test.go b/ring/spread_minimizing_token_generator_test.go index cd4674bef..eed39ce5d 100644 --- a/ring/spread_minimizing_token_generator_test.go +++ b/ring/spread_minimizing_token_generator_test.go @@ -496,12 +496,12 @@ func TestSpreadMinimizingTokenGenerator_CanJoin(t *testing.T) { // if canJoinEnabled is false, the check is skipped tokenGenerator.canJoinEnabled = false - err = tokenGenerator.CanJoin(ringDesc.GetIngesters()) + err = tokenGenerator.CanJoin(ringDesc.GetIngesterVals()) require.NoError(t, err) // if canJoinEnabled is true, the check returns an error because not all previous instances have tokens tokenGenerator.canJoinEnabled = true - err = tokenGenerator.CanJoin(ringDesc.GetIngesters()) + err = tokenGenerator.CanJoin(ringDesc.GetIngesterVals()) require.Error(t, err) require.Equal(t, errorMissingPreviousInstance(pendingInstance), err) @@ -510,7 +510,7 @@ func TestSpreadMinimizingTokenGenerator_CanJoin(t *testing.T) { pendingInstanceDesc.State = InstanceState_ACTIVE pendingInstanceDesc.Tokens = allTokens[pendingInstanceID] ringDesc.Ingesters[pendingInstance] = pendingInstanceDesc - err = tokenGenerator.CanJoin(ringDesc.GetIngesters()) + err = tokenGenerator.CanJoin(ringDesc.GetIngesterVals()) require.NoError(t, err) } diff --git a/ring/token_range_test.go b/ring/token_range_test.go index 9015bf785..c62d2b5a4 100644 --- a/ring/token_range_test.go +++ b/ring/token_range_test.go @@ -93,7 +93,7 @@ func TestGetTokenRangesForInstance(t *testing.T) { for testName, testData := range tests { t.Run(testName, func(t *testing.T) { - instances := map[string]InstanceDesc{} + instances := map[string]*InstanceDesc{} allTokens := []uint32{} // generate test zone diff --git a/ring/util_test.go b/ring/util_test.go index 744196773..b26ee58d5 100644 --- a/ring/util_test.go +++ b/ring/util_test.go @@ -97,7 +97,7 @@ func (r *RingMock) ZonesCount() int { func createStartingRing() *Ring { // Init the ring. - ringDesc := &Desc{Ingesters: map[string]InstanceDesc{ + ringDesc := &Desc{Ingesters: map[string]*InstanceDesc{ "instance-1": {Id: "instance-1", Addr: "127.0.0.1", State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()}, "instance-2": {Id: "instance-2", Addr: "127.0.0.2", State: InstanceState_PENDING, Timestamp: time.Now().Unix()}, "instance-3": {Id: "instance-3", Addr: "127.0.0.3", State: InstanceState_JOINING, Timestamp: time.Now().Unix()}, @@ -162,7 +162,7 @@ func addInstanceAfterSomeTime(ring *Ring, addInstanceAfter time.Duration) { defer ring.mtx.Unlock() ringDesc := ring.ringDesc instanceID := fmt.Sprintf("127.0.0.%d", len(ringDesc.Ingesters)+1) - ringDesc.Ingesters[instanceID] = InstanceDesc{Addr: instanceID, State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()} + ringDesc.Ingesters[instanceID] = &InstanceDesc{Addr: instanceID, State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()} ring.ringDesc = ringDesc ring.ringTokens = ringDesc.GetTokens() ring.ringTokensByZone = ringDesc.getTokensByZone() @@ -228,7 +228,7 @@ func addInstancesPeriodically(ring *Ring) chan struct{} { ring.mtx.Lock() ringDesc := ring.ringDesc instanceID := fmt.Sprintf("127.0.0.%d", len(ringDesc.Ingesters)+1) - ringDesc.Ingesters[instanceID] = InstanceDesc{Id: instanceID, Addr: instanceID, State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()} + ringDesc.Ingesters[instanceID] = &InstanceDesc{Id: instanceID, Addr: instanceID, State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()} ring.ringDesc = ringDesc ring.ringTokens = ringDesc.GetTokens() ring.ringTokensByZone = ringDesc.getTokensByZone() From be27c8169640f03cb2c3d84c94c84fd16ce775d4 Mon Sep 17 00:00:00 2001 From: francoposa Date: Tue, 14 Jan 2025 13:48:34 -0800 Subject: [PATCH 12/22] go mod tidy and vendor --- ring/example/local/go.mod | 8 ++++---- ring/example/local/go.sum | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ring/example/local/go.mod b/ring/example/local/go.mod index 258f22f74..d49bede59 100644 --- a/ring/example/local/go.mod +++ b/ring/example/local/go.mod @@ -59,15 +59,15 @@ require ( go.uber.org/zap v1.17.0 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.26.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.21.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.23.0 // indirect + golang.org/x/text v0.17.0 // indirect golang.org/x/time v0.1.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect google.golang.org/grpc v1.66.0 // indirect - google.golang.org/protobuf v1.34.1 // indirect + google.golang.org/protobuf v1.36.2 // indirect ) replace github.com/hashicorp/memberlist => github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe diff --git a/ring/example/local/go.sum b/ring/example/local/go.sum index 9d0fe7587..be58c55ed 100644 --- a/ring/example/local/go.sum +++ b/ring/example/local/go.sum @@ -342,6 +342,7 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -375,6 +376,7 @@ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= @@ -383,6 +385,7 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.1.0 h1:xYY+Bajn2a7VBmTM5GikTmnK8ZuX8YgnQCqZpbBNtmA= golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -437,6 +440,9 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0 google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 4e891fd90d4fbc2c5c068a71d57f54affd8256de Mon Sep 17 00:00:00 2001 From: francoposa Date: Tue, 14 Jan 2025 13:48:53 -0800 Subject: [PATCH 13/22] fix proto file enum prefixes --- ring/ring.proto | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ring/ring.proto b/ring/ring.proto index f55515f78..13a62fb3a 100644 --- a/ring/ring.proto +++ b/ring/ring.proto @@ -55,13 +55,13 @@ message InstanceDesc { } enum InstanceState { - InstanceState_ACTIVE = 0; - InstanceState_LEAVING = 1; + ACTIVE = 0; + LEAVING = 1; - InstanceState_PENDING = 2; - InstanceState_JOINING = 3; + PENDING = 2; + JOINING = 3; // This state is only used by gossiping code to distribute information about // instances that have been removed from the ring. Ring users should not use it directly. - InstanceState_LEFT = 4; + LEFT = 4; } From a542409a0afd435d9b7f8fdfc465017a13979698 Mon Sep 17 00:00:00 2001 From: francoposa Date: Tue, 14 Jan 2025 13:54:10 -0800 Subject: [PATCH 14/22] go mod tidy and vendor for ring/example/local --- ring/example/local/go.mod | 1 + ring/example/local/go.sum | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/ring/example/local/go.mod b/ring/example/local/go.mod index d49bede59..9ab24fcc6 100644 --- a/ring/example/local/go.mod +++ b/ring/example/local/go.mod @@ -11,6 +11,7 @@ require ( ) require ( + github.com/CrowdStrike/csproto v0.33.0 // indirect github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect github.com/armon/go-metrics v0.3.10 // indirect github.com/beorn7/perks v1.0.1 // indirect diff --git a/ring/example/local/go.sum b/ring/example/local/go.sum index be58c55ed..b074bbae9 100644 --- a/ring/example/local/go.sum +++ b/ring/example/local/go.sum @@ -1,6 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/CrowdStrike/csproto v0.33.0 h1:xdGHWB/WFcAwV1OmxCSOkoUcRrQRc3fDDKcKRCN0Zlg= +github.com/CrowdStrike/csproto v0.33.0/go.mod h1:quhKDsPpKaXwLWgG5xvW47QCtlmV41of4gRmMZrSxEs= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= @@ -257,15 +259,15 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= -github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/uber/jaeger-client-go v2.28.0+incompatible h1:G4QSBfvPKvg5ZM2j9MrJFdfI5iSljY/WnJqOGFao6HI= github.com/uber/jaeger-client-go v2.28.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= @@ -340,8 +342,7 @@ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -374,8 +375,7 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -383,8 +383,7 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.1.0 h1:xYY+Bajn2a7VBmTM5GikTmnK8ZuX8YgnQCqZpbBNtmA= golang.org/x/time v0.1.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -438,10 +437,7 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= -google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +google.golang.org/protobuf v1.36.2 h1:R8FeyR1/eLmkutZOM5CWghmo5itiG9z0ktFlTVLuTmU= google.golang.org/protobuf v1.36.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From e9d081bd1f6d73041a268bb5636631224775295e Mon Sep 17 00:00:00 2001 From: francoposa Date: Tue, 14 Jan 2025 14:41:06 -0800 Subject: [PATCH 15/22] fix server/server_test.go with testify EqualExportedValues in place of EqualValues --- server/server_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/server_test.go b/server/server_test.go index d5390e7aa..768dca973 100644 --- a/server/server_test.go +++ b/server/server_test.go @@ -206,7 +206,7 @@ func TestErrorInstrumentationMiddleware(t *testing.T) { client := NewFakeServerClient(conn) res, err := client.Succeed(context.Background(), &empty) require.NoError(t, err) - require.EqualValues(t, &empty, res) + require.EqualExportedValues(t, &empty, res) res, err = client.FailWithError(context.Background(), &empty) require.Nil(t, res) @@ -618,7 +618,7 @@ func TestTLSServer(t *testing.T) { grpcClient := NewFakeServerClient(conn) grpcRes, err := grpcClient.Succeed(context.Background(), &empty) require.NoError(t, err) - require.EqualValues(t, &empty, grpcRes) + require.EqualExportedValues(t, &empty, grpcRes) } func TestTLSServerWithInlineCerts(t *testing.T) { @@ -709,7 +709,7 @@ func TestTLSServerWithInlineCerts(t *testing.T) { grpcClient := NewFakeServerClient(conn) grpcRes, err := grpcClient.Succeed(context.Background(), &empty) require.NoError(t, err) - require.EqualValues(t, &empty, grpcRes) + require.EqualExportedValues(t, &empty, grpcRes) } type FakeLogger struct { From 0b89619c6fb67bd0bea81e7b7d1ff20f0d02b43f Mon Sep 17 00:00:00 2001 From: francoposa Date: Tue, 14 Jan 2025 15:44:19 -0800 Subject: [PATCH 16/22] const aliases for InstanceState enum --- ring/ring_extra.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ring/ring_extra.go b/ring/ring_extra.go index a49a61c70..fc3df18d9 100644 --- a/ring/ring_extra.go +++ b/ring/ring_extra.go @@ -1,5 +1,11 @@ package ring +const ACTIVE = InstanceState_ACTIVE +const LEAVING = InstanceState_LEAVING +const PENDING = InstanceState_PENDING +const JOINING = InstanceState_JOINING +const LEFT = InstanceState_LEFT + func (this *InstanceDesc) Equal(that interface{}) bool { if that == nil { return this == nil From 2f54583ae877b2c76ea2f065bdae2eba8e0671e8 Mon Sep 17 00:00:00 2001 From: francoposa Date: Tue, 14 Jan 2025 18:37:01 -0800 Subject: [PATCH 17/22] fix clone to use standard proto clone instead of incompatible gogoproto clone --- ring/model.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ring/model.go b/ring/model.go index 8a57f5216..ada720d5f 100644 --- a/ring/model.go +++ b/ring/model.go @@ -7,7 +7,8 @@ import ( "sync" "time" - "github.com/gogo/protobuf/proto" + gogoproto "github.com/gogo/protobuf/proto" + "google.golang.org/protobuf/proto" "github.com/grafana/dskit/kv/codec" "github.com/grafana/dskit/kv/memberlist" @@ -29,7 +30,7 @@ func (ts ByID) Swap(i, j int) { ts[i], ts[j] = ts[j], ts[i] } func (ts ByID) Less(i, j int) bool { return ts[i].Id < ts[j].Id } // ProtoDescFactory makes new Descs -func ProtoDescFactory() proto.Message { +func ProtoDescFactory() gogoproto.Message { return NewDesc() } From 1194d2ca58ce137dddd6ff879701075c876be482 Mon Sep 17 00:00:00 2001 From: francoposa Date: Tue, 14 Jan 2025 21:11:18 -0800 Subject: [PATCH 18/22] fix kv protos and ring/partition_ring_desc protos --- Makefile | 2 +- kv/client_test.go | 38 +- kv/codec/codec.go | 5 +- kv/memberlist/kv.pb.fm.go | 245 ++++ kv/memberlist/kv.pb.go | 826 +++--------- kv/memberlist/kv.proto | 5 +- kv/mock.pb.fm.go | 107 ++ kv/mock.pb.go | 126 ++ kv/mock.proto | 10 + ring/model.go | 3 +- ring/partition_instance_lifecycler.go | 4 +- ring/partition_instance_ring_test.go | 32 +- ring/partition_ring_desc.pb.fm.go | 526 ++++++++ ring/partition_ring_desc.pb.go | 1693 +++++-------------------- ring/partition_ring_desc.proto | 9 +- ring/partition_ring_http_test.go | 4 +- ring/partition_ring_model.go | 154 ++- ring/partition_ring_model_test.go | 634 ++++----- ring/partition_ring_test.go | 7 +- ring/ring.pb.go | 8 +- ring/ring.proto | 2 +- 21 files changed, 1992 insertions(+), 2448 deletions(-) create mode 100644 kv/memberlist/kv.pb.fm.go create mode 100644 kv/mock.pb.fm.go create mode 100644 kv/mock.pb.go create mode 100644 kv/mock.proto create mode 100644 ring/partition_ring_desc.pb.fm.go diff --git a/Makefile b/Makefile index cf31515ee..f57f33bc2 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ clean-protos: ## Removes the proto files .PHONY: protos protos: .tools/bin/protoc .tools/bin/protoc-gen-gogoslick .tools/bin/protoc-gen-go $(PROTO_GOS) ## Creates proto files -PROTO_DEFS_CSPROTO := ./ring/ring.proto +PROTO_DEFS_CSPROTO := ./ring/ring.proto ./ring/partition_ring_desc.proto ./kv/mock.proto ./kv/memberlist/kv.proto .PHONY: protos-csproto protos-csproto: @for name in $(PROTO_DEFS_CSPROTO); do \ diff --git a/kv/client_test.go b/kv/client_test.go index a15adc34e..280149cdd 100644 --- a/kv/client_test.go +++ b/kv/client_test.go @@ -7,10 +7,10 @@ import ( "time" "github.com/go-kit/log" - "github.com/gogo/protobuf/proto" "github.com/prometheus/client_golang/prometheus" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" "gopkg.in/yaml.v2" "github.com/grafana/dskit/kv/codec" @@ -68,7 +68,7 @@ func Test_createClient_singleBackend_mustContainRoleAndTypeLabels(t *testing.T) client, err := createClient("mock", "/test1", storeCfg, testCodec, Primary, reg, testLogger{}) require.NoError(t, err) require.NoError(t, client.CAS(context.Background(), "/test", func(_ interface{}) (out interface{}, retry bool, err error) { - out = &mockMessage{id: "inCAS"} + out = &MockMessage{Id: "inCAS"} retry = false return })) @@ -86,7 +86,7 @@ func Test_createClient_multiBackend_mustContainRoleAndTypeLabels(t *testing.T) { client, err := createClient("multi", "/test1", storeCfg, testCodec, Primary, reg, testLogger{}) require.NoError(t, err) require.NoError(t, client.CAS(context.Background(), "/test", func(_ interface{}) (out interface{}, retry bool, err error) { - out = &mockMessage{id: "inCAS"} + out = &MockMessage{Id: "inCAS"} retry = false return })) @@ -133,26 +133,26 @@ func newConfigsForTest() (cfg StoreConfig, c codec.Codec) { }, } c = codec.NewProtoCodec("test", func() proto.Message { - return &mockMessage{id: "inCodec"} + return &MockMessage{Id: "inCodec"} }) return } -type mockMessage struct { - id string -} - -func (m *mockMessage) Reset() { - panic("do not use") -} - -func (m *mockMessage) String() string { - panic("do not use") -} - -func (m *mockMessage) ProtoMessage() { - panic("do not use") -} +//type mockMessage struct { +// id string +//} +// +//func (m *mockMessage) Reset() { +// panic("do not use") +//} +// +//func (m *mockMessage) String() string { +// panic("do not use") +//} +// +//func (m *mockMessage) ProtoMessage() { +// panic("do not use") +//} type testLogger struct{} diff --git a/kv/codec/codec.go b/kv/codec/codec.go index 49540fe3a..5a732455d 100644 --- a/kv/codec/codec.go +++ b/kv/codec/codec.go @@ -1,8 +1,8 @@ package codec import ( - "github.com/gogo/protobuf/proto" "github.com/golang/snappy" + "google.golang.org/protobuf/proto" ) // Codec allows KV clients to serialise and deserialise values. @@ -44,6 +44,9 @@ func (p Proto) Decode(bytes []byte) (interface{}, error) { // Encode implements Codec func (p Proto) Encode(msg interface{}) ([]byte, error) { + if msg == nil { + return nil, nil + } bytes, err := proto.Marshal(msg.(proto.Message)) if err != nil { return nil, err diff --git a/kv/memberlist/kv.pb.fm.go b/kv/memberlist/kv.pb.fm.go new file mode 100644 index 000000000..d345efd78 --- /dev/null +++ b/kv/memberlist/kv.pb.fm.go @@ -0,0 +1,245 @@ +// GENERATED CODE - DO NOT EDIT +// This file was generated by protoc-gen-fastmarshal + +package memberlist + +import ( + "fmt" + "sync/atomic" + "github.com/CrowdStrike/csproto" +) + +//------------------------------------------------------------------------------ +// Custom Protobuf size/marshal/unmarshal code for KeyValueStore + +// Size calculates and returns the size, in bytes, required to hold the contents of m using the Protobuf +// binary encoding. +func (m *KeyValueStore) Size() int { + // nil message is always 0 bytes + if m == nil { + return 0 + } + // return cached size, if present + if csz := int(atomic.LoadInt32(&m.sizeCache)); csz > 0 { + return csz + } + // calculate and cache + var sz, l int + _ = l // avoid unused variable + + // Pairs (message,repeated) + for _, val := range m.Pairs { + if l = csproto.Size(val); l > 0 { + sz += csproto.SizeOfTagKey(1) + csproto.SizeOfVarint(uint64(l)) + l + } + } + // cache the size so it can be re-used in Marshal()/MarshalTo() + atomic.StoreInt32(&m.sizeCache, int32(sz)) + return sz +} + +// Marshal converts the contents of m to the Protobuf binary encoding and returns the result or an error. +func (m *KeyValueStore) Marshal() ([]byte, error) { + siz := m.Size() + if siz == 0 { + return []byte{}, nil + } + buf := make([]byte, siz) + err := m.MarshalTo(buf) + return buf, err +} + +// MarshalTo converts the contents of m to the Protobuf binary encoding and writes the result to dest. +func (m *KeyValueStore) MarshalTo(dest []byte) error { + // nil message == no-op + if m == nil { + return nil + } + var ( + enc = csproto.NewEncoder(dest) + buf []byte + err error + extVal interface{} + ) + // ensure no unused variables + _ = enc + _ = buf + _ = err + _ = extVal + + // Pairs (1,message,repeated) + for _, mm := range m.Pairs { + if err = enc.EncodeNested(1, mm); err != nil { + return fmt.Errorf("unable to encode message data for field 'pairs' (tag=1): %w", err) + } + } + return nil +} + +// Unmarshal decodes a binary encoded Protobuf message from p and populates m with the result. +func (m *KeyValueStore) Unmarshal(p []byte) error { + m.Reset() + if len(p) == 0 { + return nil + } + dec := csproto.NewDecoder(p) + for dec.More() { + tag, wt, err := dec.DecodeTag() + if err != nil { + return err + } + switch tag { + case 1: // Pairs (message,repeated) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'pairs' (tag=1), expected 2 (length-delimited)", wt) + } + var mm KeyValuePair + if err = dec.DecodeNested(&mm); err != nil { + return fmt.Errorf("unable to decode message value for field 'pairs' (tag=1): %w", err) + } + m.Pairs = append(m.Pairs, &mm) + + default: + if skipped, err := dec.Skip(tag, wt); err != nil { + return fmt.Errorf("invalid operation skipping tag %v: %w", tag, err) + } else { + m.unknownFields = append(m.unknownFields, skipped...) + } + } + } + return nil +} + +//------------------------------------------------------------------------------ +// Custom Protobuf size/marshal/unmarshal code for KeyValuePair + +// Size calculates and returns the size, in bytes, required to hold the contents of m using the Protobuf +// binary encoding. +func (m *KeyValuePair) Size() int { + // nil message is always 0 bytes + if m == nil { + return 0 + } + // return cached size, if present + if csz := int(atomic.LoadInt32(&m.sizeCache)); csz > 0 { + return csz + } + // calculate and cache + var sz, l int + _ = l // avoid unused variable + + // Key (string,optional) + if l = len(m.Key); l > 0 { + sz += csproto.SizeOfTagKey(1) + csproto.SizeOfVarint(uint64(l)) + l + } + // Value (bytes,optional) + if l = len(m.Value); l > 0 { + sz += csproto.SizeOfTagKey(2) + csproto.SizeOfVarint(uint64(l)) + l + } + // Codec (string,optional) + if l = len(m.Codec); l > 0 { + sz += csproto.SizeOfTagKey(3) + csproto.SizeOfVarint(uint64(l)) + l + } + // cache the size so it can be re-used in Marshal()/MarshalTo() + atomic.StoreInt32(&m.sizeCache, int32(sz)) + return sz +} + +// Marshal converts the contents of m to the Protobuf binary encoding and returns the result or an error. +func (m *KeyValuePair) Marshal() ([]byte, error) { + siz := m.Size() + if siz == 0 { + return []byte{}, nil + } + buf := make([]byte, siz) + err := m.MarshalTo(buf) + return buf, err +} + +// MarshalTo converts the contents of m to the Protobuf binary encoding and writes the result to dest. +func (m *KeyValuePair) MarshalTo(dest []byte) error { + // nil message == no-op + if m == nil { + return nil + } + var ( + enc = csproto.NewEncoder(dest) + buf []byte + err error + extVal interface{} + ) + // ensure no unused variables + _ = enc + _ = buf + _ = err + _ = extVal + + // Key (1,string,optional) + if len(m.Key) > 0 { + enc.EncodeString(1, m.Key) + } + // Value (2,bytes,optional) + if len(m.Value) > 0 { + enc.EncodeBytes(2, m.Value) + } + // Codec (3,string,optional) + if len(m.Codec) > 0 { + enc.EncodeString(3, m.Codec) + } + return nil +} + +// Unmarshal decodes a binary encoded Protobuf message from p and populates m with the result. +func (m *KeyValuePair) Unmarshal(p []byte) error { + m.Reset() + if len(p) == 0 { + return nil + } + dec := csproto.NewDecoder(p) + for dec.More() { + tag, wt, err := dec.DecodeTag() + if err != nil { + return err + } + switch tag { + case 1: // Key (string,optional) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'key' (tag=1), expected 2 (length-delimited)", wt) + } + if s, err := dec.DecodeString(); err != nil { + return fmt.Errorf("unable to decode string value for field 'key' (tag=1): %w", err) + } else { + m.Key = s + } + + case 2: // Value (bytes,optional) + + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'value' (tag=2), expected 2 (length-delimited)", wt) + } + if b, err := dec.DecodeBytes(); err != nil { + return fmt.Errorf("unable to decode bytes value for field 'value' (tag=2): %w", err) + } else { + m.Value = b + } + + case 3: // Codec (string,optional) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'codec' (tag=3), expected 2 (length-delimited)", wt) + } + if s, err := dec.DecodeString(); err != nil { + return fmt.Errorf("unable to decode string value for field 'codec' (tag=3): %w", err) + } else { + m.Codec = s + } + + default: + if skipped, err := dec.Skip(tag, wt); err != nil { + return fmt.Errorf("invalid operation skipping tag %v: %w", tag, err) + } else { + m.unknownFields = append(m.unknownFields, skipped...) + } + } + } + return nil +} diff --git a/kv/memberlist/kv.pb.go b/kv/memberlist/kv.pb.go index a7096f4d0..68602d384 100644 --- a/kv/memberlist/kv.pb.go +++ b/kv/memberlist/kv.pb.go @@ -1,735 +1,199 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: kv.proto +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.2 +// protoc v5.29.3 +// source: kv/memberlist/kv.proto package memberlist import ( - bytes "bytes" - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" - strings "strings" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) // KV Store is just a series of key-value pairs. type KeyValueStore struct { - Pairs []*KeyValuePair `protobuf:"bytes,1,rep,name=pairs,proto3" json:"pairs,omitempty"` + state protoimpl.MessageState `protogen:"open.v1"` + Pairs []*KeyValuePair `protobuf:"bytes,1,rep,name=pairs,proto3" json:"pairs,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } -func (m *KeyValueStore) Reset() { *m = KeyValueStore{} } -func (*KeyValueStore) ProtoMessage() {} -func (*KeyValueStore) Descriptor() ([]byte, []int) { - return fileDescriptor_2216fe83c9c12408, []int{0} -} -func (m *KeyValueStore) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *KeyValueStore) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_KeyValueStore.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } +func (x *KeyValueStore) Reset() { + *x = KeyValueStore{} + mi := &file_kv_memberlist_kv_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } -func (m *KeyValueStore) XXX_Merge(src proto.Message) { - xxx_messageInfo_KeyValueStore.Merge(m, src) -} -func (m *KeyValueStore) XXX_Size() int { - return m.Size() -} -func (m *KeyValueStore) XXX_DiscardUnknown() { - xxx_messageInfo_KeyValueStore.DiscardUnknown(m) -} - -var xxx_messageInfo_KeyValueStore proto.InternalMessageInfo -func (m *KeyValueStore) GetPairs() []*KeyValuePair { - if m != nil { - return m.Pairs - } - return nil +func (x *KeyValueStore) String() string { + return protoimpl.X.MessageStringOf(x) } -// Single Key-Value pair. Key must be non-empty. -type KeyValuePair struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` - // ID of the codec used to write the value - Codec string `protobuf:"bytes,3,opt,name=codec,proto3" json:"codec,omitempty"` -} +func (*KeyValueStore) ProtoMessage() {} -func (m *KeyValuePair) Reset() { *m = KeyValuePair{} } -func (*KeyValuePair) ProtoMessage() {} -func (*KeyValuePair) Descriptor() ([]byte, []int) { - return fileDescriptor_2216fe83c9c12408, []int{1} -} -func (m *KeyValuePair) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *KeyValuePair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_KeyValuePair.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err +func (x *KeyValueStore) ProtoReflect() protoreflect.Message { + mi := &file_kv_memberlist_kv_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) } - return b[:n], nil + return ms } -} -func (m *KeyValuePair) XXX_Merge(src proto.Message) { - xxx_messageInfo_KeyValuePair.Merge(m, src) -} -func (m *KeyValuePair) XXX_Size() int { - return m.Size() -} -func (m *KeyValuePair) XXX_DiscardUnknown() { - xxx_messageInfo_KeyValuePair.DiscardUnknown(m) + return mi.MessageOf(x) } -var xxx_messageInfo_KeyValuePair proto.InternalMessageInfo - -func (m *KeyValuePair) GetKey() string { - if m != nil { - return m.Key - } - return "" +// Deprecated: Use KeyValueStore.ProtoReflect.Descriptor instead. +func (*KeyValueStore) Descriptor() ([]byte, []int) { + return file_kv_memberlist_kv_proto_rawDescGZIP(), []int{0} } -func (m *KeyValuePair) GetValue() []byte { - if m != nil { - return m.Value +func (x *KeyValueStore) GetPairs() []*KeyValuePair { + if x != nil { + return x.Pairs } return nil } -func (m *KeyValuePair) GetCodec() string { - if m != nil { - return m.Codec - } - return "" +// Single Key-Value pair. Key must be non-empty. +type KeyValuePair struct { + state protoimpl.MessageState `protogen:"open.v1"` + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + // ID of the codec used to write the value + Codec string `protobuf:"bytes,3,opt,name=codec,proto3" json:"codec,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } -func init() { - proto.RegisterType((*KeyValueStore)(nil), "memberlist.KeyValueStore") - proto.RegisterType((*KeyValuePair)(nil), "memberlist.KeyValuePair") +func (x *KeyValuePair) Reset() { + *x = KeyValuePair{} + mi := &file_kv_memberlist_kv_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } -func init() { proto.RegisterFile("kv.proto", fileDescriptor_2216fe83c9c12408) } - -var fileDescriptor_2216fe83c9c12408 = []byte{ - // 236 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0xc8, 0x2e, 0xd3, 0x2b, - 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xca, 0x4d, 0xcd, 0x4d, 0x4a, 0x2d, 0xca, 0xc9, 0x2c, 0x2e, - 0x91, 0xd2, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0x4f, - 0xcf, 0xd7, 0x07, 0x2b, 0x49, 0x2a, 0x4d, 0x03, 0xf3, 0xc0, 0x1c, 0x30, 0x0b, 0xa2, 0x55, 0xc9, - 0x9e, 0x8b, 0xd7, 0x3b, 0xb5, 0x32, 0x2c, 0x31, 0xa7, 0x34, 0x35, 0xb8, 0x24, 0xbf, 0x28, 0x55, - 0x48, 0x8f, 0x8b, 0xb5, 0x20, 0x31, 0xb3, 0xa8, 0x58, 0x82, 0x51, 0x81, 0x59, 0x83, 0xdb, 0x48, - 0x42, 0x0f, 0x61, 0xb6, 0x1e, 0x4c, 0x65, 0x40, 0x62, 0x66, 0x51, 0x10, 0x44, 0x99, 0x92, 0x0f, - 0x17, 0x0f, 0xb2, 0xb0, 0x90, 0x00, 0x17, 0x73, 0x76, 0x6a, 0xa5, 0x04, 0xa3, 0x02, 0xa3, 0x06, - 0x67, 0x10, 0x88, 0x29, 0x24, 0xc2, 0xc5, 0x5a, 0x06, 0x92, 0x96, 0x60, 0x52, 0x60, 0xd4, 0xe0, - 0x09, 0x82, 0x70, 0x40, 0xa2, 0xc9, 0xf9, 0x29, 0xa9, 0xc9, 0x12, 0xcc, 0x60, 0x95, 0x10, 0x8e, - 0x93, 0xc9, 0x85, 0x87, 0x72, 0x0c, 0x37, 0x1e, 0xca, 0x31, 0x7c, 0x78, 0x28, 0xc7, 0xd8, 0xf0, - 0x48, 0x8e, 0x71, 0xc5, 0x23, 0x39, 0xc6, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, - 0xf0, 0x48, 0x8e, 0xf1, 0xc5, 0x23, 0x39, 0x86, 0x0f, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, - 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x24, 0x36, 0xb0, 0x5f, 0x8c, 0x01, 0x01, - 0x00, 0x00, 0xff, 0xff, 0x7a, 0x22, 0xdf, 0xec, 0x12, 0x01, 0x00, 0x00, +func (x *KeyValuePair) String() string { + return protoimpl.X.MessageStringOf(x) } -func (this *KeyValueStore) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*KeyValueStore) - if !ok { - that2, ok := that.(KeyValueStore) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.Pairs) != len(that1.Pairs) { - return false - } - for i := range this.Pairs { - if !this.Pairs[i].Equal(that1.Pairs[i]) { - return false - } - } - return true -} -func (this *KeyValuePair) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*KeyValuePair) - if !ok { - that2, ok := that.(KeyValuePair) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Key != that1.Key { - return false - } - if !bytes.Equal(this.Value, that1.Value) { - return false - } - if this.Codec != that1.Codec { - return false - } - return true -} -func (this *KeyValueStore) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 5) - s = append(s, "&memberlist.KeyValueStore{") - if this.Pairs != nil { - s = append(s, "Pairs: "+fmt.Sprintf("%#v", this.Pairs)+",\n") - } - s = append(s, "}") - return strings.Join(s, "") -} -func (this *KeyValuePair) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 7) - s = append(s, "&memberlist.KeyValuePair{") - s = append(s, "Key: "+fmt.Sprintf("%#v", this.Key)+",\n") - s = append(s, "Value: "+fmt.Sprintf("%#v", this.Value)+",\n") - s = append(s, "Codec: "+fmt.Sprintf("%#v", this.Codec)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringKv(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} -func (m *KeyValueStore) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *KeyValueStore) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} +func (*KeyValuePair) ProtoMessage() {} -func (m *KeyValueStore) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Pairs) > 0 { - for iNdEx := len(m.Pairs) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.Pairs[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintKv(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa +func (x *KeyValuePair) ProtoReflect() protoreflect.Message { + mi := &file_kv_memberlist_kv_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) } + return ms } - return len(dAtA) - i, nil + return mi.MessageOf(x) } -func (m *KeyValuePair) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *KeyValuePair) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *KeyValuePair) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Codec) > 0 { - i -= len(m.Codec) - copy(dAtA[i:], m.Codec) - i = encodeVarintKv(dAtA, i, uint64(len(m.Codec))) - i-- - dAtA[i] = 0x1a - } - if len(m.Value) > 0 { - i -= len(m.Value) - copy(dAtA[i:], m.Value) - i = encodeVarintKv(dAtA, i, uint64(len(m.Value))) - i-- - dAtA[i] = 0x12 - } - if len(m.Key) > 0 { - i -= len(m.Key) - copy(dAtA[i:], m.Key) - i = encodeVarintKv(dAtA, i, uint64(len(m.Key))) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil +// Deprecated: Use KeyValuePair.ProtoReflect.Descriptor instead. +func (*KeyValuePair) Descriptor() ([]byte, []int) { + return file_kv_memberlist_kv_proto_rawDescGZIP(), []int{1} } -func encodeVarintKv(dAtA []byte, offset int, v uint64) int { - offset -= sovKv(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *KeyValueStore) Size() (n int) { - if m == nil { - return 0 +func (x *KeyValuePair) GetKey() string { + if x != nil { + return x.Key } - var l int - _ = l - if len(m.Pairs) > 0 { - for _, e := range m.Pairs { - l = e.Size() - n += 1 + l + sovKv(uint64(l)) - } - } - return n + return "" } -func (m *KeyValuePair) Size() (n int) { - if m == nil { - return 0 +func (x *KeyValuePair) GetValue() []byte { + if x != nil { + return x.Value } - var l int - _ = l - l = len(m.Key) - if l > 0 { - n += 1 + l + sovKv(uint64(l)) - } - l = len(m.Value) - if l > 0 { - n += 1 + l + sovKv(uint64(l)) - } - l = len(m.Codec) - if l > 0 { - n += 1 + l + sovKv(uint64(l)) - } - return n + return nil } -func sovKv(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozKv(x uint64) (n int) { - return sovKv(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *KeyValueStore) String() string { - if this == nil { - return "nil" - } - repeatedStringForPairs := "[]*KeyValuePair{" - for _, f := range this.Pairs { - repeatedStringForPairs += strings.Replace(f.String(), "KeyValuePair", "KeyValuePair", 1) + "," +func (x *KeyValuePair) GetCodec() string { + if x != nil { + return x.Codec } - repeatedStringForPairs += "}" - s := strings.Join([]string{`&KeyValueStore{`, - `Pairs:` + repeatedStringForPairs + `,`, - `}`, - }, "") - return s -} -func (this *KeyValuePair) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&KeyValuePair{`, - `Key:` + fmt.Sprintf("%v", this.Key) + `,`, - `Value:` + fmt.Sprintf("%v", this.Value) + `,`, - `Codec:` + fmt.Sprintf("%v", this.Codec) + `,`, - `}`, - }, "") - return s -} -func valueToStringKv(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) + return "" } -func (m *KeyValueStore) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: KeyValueStore: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: KeyValueStore: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Pairs", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthKv - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Pairs = append(m.Pairs, &KeyValuePair{}) - if err := m.Pairs[len(m.Pairs)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipKv(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthKv - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *KeyValuePair) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: KeyValuePair: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: KeyValuePair: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Key", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthKv - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Key = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthKv - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Value = append(m.Value[:0], dAtA[iNdEx:postIndex]...) - if m.Value == nil { - m.Value = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Codec", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowKv - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthKv - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthKv - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Codec = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipKv(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthKv - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } +var File_kv_memberlist_kv_proto protoreflect.FileDescriptor - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipKv(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowKv - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthKv - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupKv - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthKv - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF +var file_kv_memberlist_kv_proto_rawDesc = []byte{ + 0x0a, 0x16, 0x6b, 0x76, 0x2f, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x6c, 0x69, 0x73, 0x74, 0x2f, + 0x6b, 0x76, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, + 0x6c, 0x69, 0x73, 0x74, 0x22, 0x3f, 0x0a, 0x0d, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, + 0x53, 0x74, 0x6f, 0x72, 0x65, 0x12, 0x2e, 0x0a, 0x05, 0x70, 0x61, 0x69, 0x72, 0x73, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x6c, 0x69, 0x73, + 0x74, 0x2e, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x50, 0x61, 0x69, 0x72, 0x52, 0x05, + 0x70, 0x61, 0x69, 0x72, 0x73, 0x22, 0x4c, 0x0a, 0x0c, 0x4b, 0x65, 0x79, 0x56, 0x61, 0x6c, 0x75, + 0x65, 0x50, 0x61, 0x69, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x14, 0x0a, + 0x05, 0x63, 0x6f, 0x64, 0x65, 0x63, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x63, 0x6f, + 0x64, 0x65, 0x63, 0x42, 0x33, 0x5a, 0x31, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x67, 0x72, 0x61, 0x66, 0x61, 0x6e, 0x61, 0x2f, 0x64, 0x73, 0x6b, 0x69, 0x74, 0x2f, + 0x6b, 0x76, 0x2f, 0x6d, 0x65, 0x6d, 0x62, 0x65, 0x72, 0x6c, 0x69, 0x73, 0x74, 0x3b, 0x6d, 0x65, + 0x6d, 0x62, 0x65, 0x72, 0x6c, 0x69, 0x73, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - ErrInvalidLengthKv = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowKv = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupKv = fmt.Errorf("proto: unexpected end of group") + file_kv_memberlist_kv_proto_rawDescOnce sync.Once + file_kv_memberlist_kv_proto_rawDescData = file_kv_memberlist_kv_proto_rawDesc ) + +func file_kv_memberlist_kv_proto_rawDescGZIP() []byte { + file_kv_memberlist_kv_proto_rawDescOnce.Do(func() { + file_kv_memberlist_kv_proto_rawDescData = protoimpl.X.CompressGZIP(file_kv_memberlist_kv_proto_rawDescData) + }) + return file_kv_memberlist_kv_proto_rawDescData +} + +var file_kv_memberlist_kv_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_kv_memberlist_kv_proto_goTypes = []any{ + (*KeyValueStore)(nil), // 0: memberlist.KeyValueStore + (*KeyValuePair)(nil), // 1: memberlist.KeyValuePair +} +var file_kv_memberlist_kv_proto_depIdxs = []int32{ + 1, // 0: memberlist.KeyValueStore.pairs:type_name -> memberlist.KeyValuePair + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] 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 +} + +func init() { file_kv_memberlist_kv_proto_init() } +func file_kv_memberlist_kv_proto_init() { + if File_kv_memberlist_kv_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_kv_memberlist_kv_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_kv_memberlist_kv_proto_goTypes, + DependencyIndexes: file_kv_memberlist_kv_proto_depIdxs, + MessageInfos: file_kv_memberlist_kv_proto_msgTypes, + }.Build() + File_kv_memberlist_kv_proto = out.File + file_kv_memberlist_kv_proto_rawDesc = nil + file_kv_memberlist_kv_proto_goTypes = nil + file_kv_memberlist_kv_proto_depIdxs = nil +} diff --git a/kv/memberlist/kv.proto b/kv/memberlist/kv.proto index cc5f12463..5b025d6ea 100644 --- a/kv/memberlist/kv.proto +++ b/kv/memberlist/kv.proto @@ -2,10 +2,7 @@ syntax = "proto3"; package memberlist; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; - -option (gogoproto.marshaler_all) = true; -option (gogoproto.unmarshaler_all) = true; +option go_package = "github.com/grafana/dskit/kv/memberlist;memberlist"; // KV Store is just a series of key-value pairs. message KeyValueStore { diff --git a/kv/mock.pb.fm.go b/kv/mock.pb.fm.go new file mode 100644 index 000000000..ea82cd6b7 --- /dev/null +++ b/kv/mock.pb.fm.go @@ -0,0 +1,107 @@ +// GENERATED CODE - DO NOT EDIT +// This file was generated by protoc-gen-fastmarshal + +package kv + +import ( + "fmt" + "sync/atomic" + "github.com/CrowdStrike/csproto" +) + +//------------------------------------------------------------------------------ +// Custom Protobuf size/marshal/unmarshal code for MockMessage + +// Size calculates and returns the size, in bytes, required to hold the contents of m using the Protobuf +// binary encoding. +func (m *MockMessage) Size() int { + // nil message is always 0 bytes + if m == nil { + return 0 + } + // return cached size, if present + if csz := int(atomic.LoadInt32(&m.sizeCache)); csz > 0 { + return csz + } + // calculate and cache + var sz, l int + _ = l // avoid unused variable + + // Id (string,optional) + if l = len(m.Id); l > 0 { + sz += csproto.SizeOfTagKey(1) + csproto.SizeOfVarint(uint64(l)) + l + } + // cache the size so it can be re-used in Marshal()/MarshalTo() + atomic.StoreInt32(&m.sizeCache, int32(sz)) + return sz +} + +// Marshal converts the contents of m to the Protobuf binary encoding and returns the result or an error. +func (m *MockMessage) Marshal() ([]byte, error) { + siz := m.Size() + if siz == 0 { + return []byte{}, nil + } + buf := make([]byte, siz) + err := m.MarshalTo(buf) + return buf, err +} + +// MarshalTo converts the contents of m to the Protobuf binary encoding and writes the result to dest. +func (m *MockMessage) MarshalTo(dest []byte) error { + // nil message == no-op + if m == nil { + return nil + } + var ( + enc = csproto.NewEncoder(dest) + buf []byte + err error + extVal interface{} + ) + // ensure no unused variables + _ = enc + _ = buf + _ = err + _ = extVal + + // Id (1,string,optional) + if len(m.Id) > 0 { + enc.EncodeString(1, m.Id) + } + return nil +} + +// Unmarshal decodes a binary encoded Protobuf message from p and populates m with the result. +func (m *MockMessage) Unmarshal(p []byte) error { + m.Reset() + if len(p) == 0 { + return nil + } + dec := csproto.NewDecoder(p) + for dec.More() { + tag, wt, err := dec.DecodeTag() + if err != nil { + return err + } + switch tag { + case 1: // Id (string,optional) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for field 'id' (tag=1), expected 2 (length-delimited)", wt) + } + if s, err := dec.DecodeString(); err != nil { + return fmt.Errorf("unable to decode string value for field 'id' (tag=1): %w", err) + } else { + m.Id = s + } + + default: + if skipped, err := dec.Skip(tag, wt); err != nil { + return fmt.Errorf("invalid operation skipping tag %v: %w", tag, err) + } else { + m.unknownFields = append(m.unknownFields, skipped...) + } + } + } + return nil +} diff --git a/kv/mock.pb.go b/kv/mock.pb.go new file mode 100644 index 000000000..b9ea7306b --- /dev/null +++ b/kv/mock.pb.go @@ -0,0 +1,126 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.2 +// protoc v5.29.3 +// source: kv/mock.proto + +package kv + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// MockMessage is for testing purposes. +type MockMessage struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *MockMessage) Reset() { + *x = MockMessage{} + mi := &file_kv_mock_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MockMessage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MockMessage) ProtoMessage() {} + +func (x *MockMessage) ProtoReflect() protoreflect.Message { + mi := &file_kv_mock_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 MockMessage.ProtoReflect.Descriptor instead. +func (*MockMessage) Descriptor() ([]byte, []int) { + return file_kv_mock_proto_rawDescGZIP(), []int{0} +} + +func (x *MockMessage) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +var File_kv_mock_proto protoreflect.FileDescriptor + +var file_kv_mock_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x6b, 0x76, 0x2f, 0x6d, 0x6f, 0x63, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x02, 0x6b, 0x76, 0x22, 0x1d, 0x0a, 0x0b, 0x4d, 0x6f, 0x63, 0x6b, 0x4d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, + 0x69, 0x64, 0x42, 0x20, 0x5a, 0x1e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, + 0x2f, 0x67, 0x72, 0x61, 0x66, 0x61, 0x6e, 0x61, 0x2f, 0x64, 0x73, 0x6b, 0x69, 0x74, 0x2f, 0x6b, + 0x76, 0x3b, 0x6b, 0x76, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_kv_mock_proto_rawDescOnce sync.Once + file_kv_mock_proto_rawDescData = file_kv_mock_proto_rawDesc +) + +func file_kv_mock_proto_rawDescGZIP() []byte { + file_kv_mock_proto_rawDescOnce.Do(func() { + file_kv_mock_proto_rawDescData = protoimpl.X.CompressGZIP(file_kv_mock_proto_rawDescData) + }) + return file_kv_mock_proto_rawDescData +} + +var file_kv_mock_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_kv_mock_proto_goTypes = []any{ + (*MockMessage)(nil), // 0: kv.MockMessage +} +var file_kv_mock_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_kv_mock_proto_init() } +func file_kv_mock_proto_init() { + if File_kv_mock_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_kv_mock_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_kv_mock_proto_goTypes, + DependencyIndexes: file_kv_mock_proto_depIdxs, + MessageInfos: file_kv_mock_proto_msgTypes, + }.Build() + File_kv_mock_proto = out.File + file_kv_mock_proto_rawDesc = nil + file_kv_mock_proto_goTypes = nil + file_kv_mock_proto_depIdxs = nil +} diff --git a/kv/mock.proto b/kv/mock.proto new file mode 100644 index 000000000..234089fb6 --- /dev/null +++ b/kv/mock.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; + +package kv; + +option go_package = "github.com/grafana/dskit/kv;kv"; + +// MockMessage is for testing purposes. +message MockMessage { + string id = 1; +} \ No newline at end of file diff --git a/ring/model.go b/ring/model.go index ada720d5f..72f2dcfa3 100644 --- a/ring/model.go +++ b/ring/model.go @@ -7,7 +7,6 @@ import ( "sync" "time" - gogoproto "github.com/gogo/protobuf/proto" "google.golang.org/protobuf/proto" "github.com/grafana/dskit/kv/codec" @@ -30,7 +29,7 @@ func (ts ByID) Swap(i, j int) { ts[i], ts[j] = ts[j], ts[i] } func (ts ByID) Less(i, j int) bool { return ts[i].Id < ts[j].Id } // ProtoDescFactory makes new Descs -func ProtoDescFactory() gogoproto.Message { +func ProtoDescFactory() proto.Message { return NewDesc() } diff --git a/ring/partition_instance_lifecycler.go b/ring/partition_instance_lifecycler.go index 29e68211a..49d5d8a61 100644 --- a/ring/partition_instance_lifecycler.go +++ b/ring/partition_instance_lifecycler.go @@ -281,7 +281,7 @@ func (l *PartitionInstanceLifecycler) createPartitionAndRegisterOwner(ctx contex } // Ensure the instance is added as partition owner. - if ring.AddOrUpdateOwner(l.cfg.InstanceID, OwnerActive, l.cfg.PartitionID, now) { + if ring.AddOrUpdateOwner(l.cfg.InstanceID, OwnerState_OwnerActive, l.cfg.PartitionID, now) { changed = true } @@ -329,7 +329,7 @@ func (l *PartitionInstanceLifecycler) waitPartitionAndRegisterOwner(ctx context. // Ensure the instance is added as partition owner. return l.updateRing(ctx, func(ring *PartitionRingDesc) (bool, error) { - return ring.AddOrUpdateOwner(l.cfg.InstanceID, OwnerActive, l.cfg.PartitionID, time.Now()), nil + return ring.AddOrUpdateOwner(l.cfg.InstanceID, OwnerState_OwnerActive, l.cfg.PartitionID, time.Now()), nil }) } diff --git a/ring/partition_instance_ring_test.go b/ring/partition_instance_ring_test.go index 87dfcc1cc..0d68b485d 100644 --- a/ring/partition_instance_ring_test.go +++ b/ring/partition_instance_ring_test.go @@ -36,11 +36,11 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }, "should return error on empty instances ring": { partitionsRing: PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {State: PartitionActive}, 2: {State: PartitionInactive}, }, - Owners: map[string]OwnerDesc{ + Owners: map[string]*OwnerDesc{ "instance-1": {OwnedPartition: 1}, "instance-2": {OwnedPartition: 2}, }, @@ -50,11 +50,11 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }, "should return replication sets with at least 1 instance per partition, if every partition has at least 1 healthy instance": { partitionsRing: PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {State: PartitionActive}, 2: {State: PartitionInactive}, }, - Owners: map[string]OwnerDesc{ + Owners: map[string]*OwnerDesc{ "instance-zone-a-1": {OwnedPartition: 1}, "instance-zone-a-2": {OwnedPartition: 2}, "instance-zone-b-2": {OwnedPartition: 2}, @@ -72,11 +72,11 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }, "should return error if there are no healthy instances for a partition": { partitionsRing: PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {State: PartitionActive}, 2: {State: PartitionInactive}, }, - Owners: map[string]OwnerDesc{ + Owners: map[string]*OwnerDesc{ "instance-zone-a-1": {OwnedPartition: 1}, "instance-zone-a-2": {OwnedPartition: 2}, "instance-zone-b-2": {OwnedPartition: 2}, @@ -90,11 +90,11 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }, "should return replication sets excluding unhealthy instances as long as there's at least 1 healthy instance per partition": { partitionsRing: PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {State: PartitionActive}, 2: {State: PartitionInactive}, }, - Owners: map[string]OwnerDesc{ + Owners: map[string]*OwnerDesc{ "instance-zone-a-1": {OwnedPartition: 1}, "instance-zone-b-1": {OwnedPartition: 1}, "instance-zone-a-2": {OwnedPartition: 2}, @@ -114,11 +114,11 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }, "should NOT return error if an instance is missing in the instances ring but there's another healthy instance for the partition": { partitionsRing: PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {State: PartitionActive}, 2: {State: PartitionInactive}, }, - Owners: map[string]OwnerDesc{ + Owners: map[string]*OwnerDesc{ "instance-zone-a-1": {OwnedPartition: 1}, "instance-zone-b-1": {OwnedPartition: 1}, // Missing in the instances ring. "instance-zone-a-2": {OwnedPartition: 2}, // Missing in the instances ring. @@ -136,11 +136,11 @@ func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) { }, "should return replication sets with MaxUnavailableZones=0 if there are multiple instances per zone but all instances belong to the same zone": { partitionsRing: PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {State: PartitionActive}, 2: {State: PartitionInactive}, }, - Owners: map[string]OwnerDesc{ + Owners: map[string]*OwnerDesc{ "instance-zone-a-1": {OwnedPartition: 1}, "instance-zone-b-1": {OwnedPartition: 1}, "instance-zone-a-2": {OwnedPartition: 2}, @@ -200,7 +200,7 @@ func BenchmarkPartitionInstanceRing_GetReplicationSetsForOperation(b *testing.B) for _, zone := range zones { instanceID := fmt.Sprintf("instance-zone-%s-%d", zone, partitionID) instancesRing.ringDesc.AddIngester(instanceID, instanceID, zone, nil, InstanceState_ACTIVE, now, false, readOnlyUpdated) - partitionsRing.AddOrUpdateOwner(instanceID, OwnerActive, int32(partitionID), now) + partitionsRing.AddOrUpdateOwner(instanceID, OwnerState_OwnerActive, int32(partitionID), now) } } @@ -226,9 +226,9 @@ func TestPartitionInstanceRing_ShuffleShard(t *testing.T) { partitionsRing.AddPartition(1, PartitionActive, now.Add(-120*time.Minute)) partitionsRing.AddPartition(2, PartitionActive, now.Add(-30*time.Minute)) partitionsRing.AddPartition(3, PartitionActive, now.Add(-30*time.Minute)) - partitionsRing.AddOrUpdateOwner("instance-1", OwnerActive, 1, now.Add(-30*time.Minute)) - partitionsRing.AddOrUpdateOwner("instance-2", OwnerActive, 2, now.Add(-30*time.Minute)) - partitionsRing.AddOrUpdateOwner("instance-3", OwnerActive, 3, now.Add(-30*time.Minute)) + partitionsRing.AddOrUpdateOwner("instance-1", OwnerState_OwnerActive, 1, now.Add(-30*time.Minute)) + partitionsRing.AddOrUpdateOwner("instance-2", OwnerState_OwnerActive, 2, now.Add(-30*time.Minute)) + partitionsRing.AddOrUpdateOwner("instance-3", OwnerState_OwnerActive, 3, now.Add(-30*time.Minute)) instancesRing := &Desc{Ingesters: map[string]*InstanceDesc{ "instance-1": {Id: "instance-1", State: InstanceState_ACTIVE, Timestamp: time.Now().Unix()}, diff --git a/ring/partition_ring_desc.pb.fm.go b/ring/partition_ring_desc.pb.fm.go new file mode 100644 index 000000000..f18d3508c --- /dev/null +++ b/ring/partition_ring_desc.pb.fm.go @@ -0,0 +1,526 @@ +// GENERATED CODE - DO NOT EDIT +// This file was generated by protoc-gen-fastmarshal + +package ring + +import ( + "fmt" + "sync/atomic" + "github.com/CrowdStrike/csproto" +) + +//------------------------------------------------------------------------------ +// Custom Protobuf size/marshal/unmarshal code for PartitionRingDesc + +// Size calculates and returns the size, in bytes, required to hold the contents of m using the Protobuf +// binary encoding. +func (m *PartitionRingDesc) Size() int { + // nil message is always 0 bytes + if m == nil { + return 0 + } + // return cached size, if present + if csz := int(atomic.LoadInt32(&m.sizeCache)); csz > 0 { + return csz + } + // calculate and cache + var sz, l int + _ = l // avoid unused variable + + // Partitions (message,repeated) + for k, v := range m.Partitions { + // size of key (always has an internal tag of 1) + keySize := 1 + csproto.SizeOfVarint(uint64(k)) + // size of value (always has an internal tag of 2) + if v != nil { + l = csproto.Size(v) + valueSize := 1 + csproto.SizeOfVarint(uint64(l)) + l + sz += csproto.SizeOfTagKey(1) + csproto.SizeOfVarint(uint64(keySize+valueSize)) + keySize + valueSize + } + } + + // Owners (message,repeated) + for k, v := range m.Owners { + // size of key (always has an internal tag of 1) + l = len(k) + keySize := 1 + csproto.SizeOfVarint(uint64(l)) + l + // size of value (always has an internal tag of 2) + if v != nil { + l = csproto.Size(v) + valueSize := 1 + csproto.SizeOfVarint(uint64(l)) + l + sz += csproto.SizeOfTagKey(2) + csproto.SizeOfVarint(uint64(keySize+valueSize)) + keySize + valueSize + } + } + + // cache the size so it can be re-used in Marshal()/MarshalTo() + atomic.StoreInt32(&m.sizeCache, int32(sz)) + return sz +} + +// Marshal converts the contents of m to the Protobuf binary encoding and returns the result or an error. +func (m *PartitionRingDesc) Marshal() ([]byte, error) { + siz := m.Size() + if siz == 0 { + return []byte{}, nil + } + buf := make([]byte, siz) + err := m.MarshalTo(buf) + return buf, err +} + +// MarshalTo converts the contents of m to the Protobuf binary encoding and writes the result to dest. +func (m *PartitionRingDesc) MarshalTo(dest []byte) error { + // nil message == no-op + if m == nil { + return nil + } + var ( + enc = csproto.NewEncoder(dest) + buf []byte + err error + extVal interface{} + ) + // ensure no unused variables + _ = enc + _ = buf + _ = err + _ = extVal + + // Partitions (1,map) + for k, v := range m.Partitions { + if v == nil { + continue + } + valueSize := csproto.Size(v) + itemSize := 1 + csproto.SizeOfVarint(uint64(valueSize)) + valueSize + itemSize += 1 + csproto.SizeOfVarint(uint64(k)) + enc.EncodeMapEntryHeader(1, itemSize) + enc.EncodeInt32(1, k) + enc.EncodeNested(2, v) + } + + // Owners (2,map) + for k, v := range m.Owners { + if v == nil { + continue + } + valueSize := csproto.Size(v) + itemSize := 1 + csproto.SizeOfVarint(uint64(valueSize)) + valueSize + keySize := len(k) + itemSize += 1 + csproto.SizeOfVarint(uint64(keySize)) + keySize + enc.EncodeMapEntryHeader(2, itemSize) + enc.EncodeString(1, k) + enc.EncodeNested(2, v) + } + + return nil +} + +// Unmarshal decodes a binary encoded Protobuf message from p and populates m with the result. +func (m *PartitionRingDesc) Unmarshal(p []byte) error { + m.Reset() + if len(p) == 0 { + return nil + } + dec := csproto.NewDecoder(p) + for dec.More() { + tag, wt, err := dec.DecodeTag() + if err != nil { + return err + } + switch tag { + case 1: // Partitions (map) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for map field 'partitions' (tag=1), expected 2 (length-delimited)", wt) + } + + if m.Partitions == nil { + m.Partitions = make(map[int32]*PartitionDesc) + } + // consume the map entry size + // TODO - should we validate this? + if _, err = dec.DecodeInt32(); err != nil { + return err + } + // always 2 values + var ( + entryKey int32 + entryValue *PartitionDesc + ) + for i := 0; i < 2; i++ { + etag, ewt, err := dec.DecodeTag() + if err != nil { + return err + } + switch etag { + case 1: // key + if ewt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for map key for field 'partitions' (tag=1), expected 0 (varint)", ewt) + } + if entryKey, err = dec.DecodeInt32(); err != nil { + return err + } + case 2: // value + if ewt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for map value for field 'partitions' (tag=1), expected 2 (length-delimited)", ewt) + } + var v PartitionDesc + if err = dec.DecodeNested(&v); err != nil { + return err + } else { + entryValue = &v + } + default: + return fmt.Errorf("invalid map entry field tag %d, expected 1 or 2", etag) + } + } + m.Partitions[entryKey] = entryValue + case 2: // Owners (map) + if wt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for map field 'owners' (tag=2), expected 2 (length-delimited)", wt) + } + + if m.Owners == nil { + m.Owners = make(map[string]*OwnerDesc) + } + // consume the map entry size + // TODO - should we validate this? + if _, err = dec.DecodeInt32(); err != nil { + return err + } + // always 2 values + var ( + entryKey string + entryValue *OwnerDesc + ) + for i := 0; i < 2; i++ { + etag, ewt, err := dec.DecodeTag() + if err != nil { + return err + } + switch etag { + case 1: // key + if ewt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for map key for field 'owners' (tag=2), expected 2 (length-delimited)", ewt) + } + if entryKey, err = dec.DecodeString(); err != nil { + return err + } + case 2: // value + if ewt != csproto.WireTypeLengthDelimited { + return fmt.Errorf("incorrect wire type %v for map value for field 'owners' (tag=2), expected 2 (length-delimited)", ewt) + } + var v OwnerDesc + if err = dec.DecodeNested(&v); err != nil { + return err + } else { + entryValue = &v + } + default: + return fmt.Errorf("invalid map entry field tag %d, expected 1 or 2", etag) + } + } + m.Owners[entryKey] = entryValue + + default: + if skipped, err := dec.Skip(tag, wt); err != nil { + return fmt.Errorf("invalid operation skipping tag %v: %w", tag, err) + } else { + m.unknownFields = append(m.unknownFields, skipped...) + } + } + } + return nil +} + +//------------------------------------------------------------------------------ +// Custom Protobuf size/marshal/unmarshal code for PartitionDesc + +// Size calculates and returns the size, in bytes, required to hold the contents of m using the Protobuf +// binary encoding. +func (m *PartitionDesc) Size() int { + // nil message is always 0 bytes + if m == nil { + return 0 + } + // return cached size, if present + if csz := int(atomic.LoadInt32(&m.sizeCache)); csz > 0 { + return csz + } + // calculate and cache + var sz, l int + _ = l // avoid unused variable + + // Id (int32,optional) + if m.Id != 0 { + sz += csproto.SizeOfTagKey(4) + csproto.SizeOfVarint(uint64(m.Id)) + } + // Tokens (uint32,repeated,packed) + if len(m.Tokens) > 0 { + sz += csproto.SizeOfTagKey(1) + l = 0 + for _, iv := range m.Tokens { + l += csproto.SizeOfVarint(uint64(iv)) + } + sz += csproto.SizeOfVarint(uint64(l)) + l + } + // State (enum,optional) + if m.State != 0 { + sz += csproto.SizeOfTagKey(2) + csproto.SizeOfVarint(uint64(m.State)) + } + // StateTimestamp (int64,optional) + if m.StateTimestamp != 0 { + sz += csproto.SizeOfTagKey(3) + csproto.SizeOfVarint(uint64(m.StateTimestamp)) + } + // cache the size so it can be re-used in Marshal()/MarshalTo() + atomic.StoreInt32(&m.sizeCache, int32(sz)) + return sz +} + +// Marshal converts the contents of m to the Protobuf binary encoding and returns the result or an error. +func (m *PartitionDesc) Marshal() ([]byte, error) { + siz := m.Size() + if siz == 0 { + return []byte{}, nil + } + buf := make([]byte, siz) + err := m.MarshalTo(buf) + return buf, err +} + +// MarshalTo converts the contents of m to the Protobuf binary encoding and writes the result to dest. +func (m *PartitionDesc) MarshalTo(dest []byte) error { + // nil message == no-op + if m == nil { + return nil + } + var ( + enc = csproto.NewEncoder(dest) + buf []byte + err error + extVal interface{} + ) + // ensure no unused variables + _ = enc + _ = buf + _ = err + _ = extVal + + // Id (4,int32,optional) + if m.Id != 0 { + enc.EncodeInt32(4, m.Id) + } + // Tokens (1,uint32,repeated,packed) + if len(m.Tokens) > 0 { + enc.EncodePackedUInt32(1, m.Tokens) + } + // State (2,enum,optional) + if m.State != 0 { + enc.EncodeInt32(2, int32(m.State)) + } + // StateTimestamp (3,int64,optional) + if m.StateTimestamp != 0 { + enc.EncodeInt64(3, m.StateTimestamp) + } + return nil +} + +// Unmarshal decodes a binary encoded Protobuf message from p and populates m with the result. +func (m *PartitionDesc) Unmarshal(p []byte) error { + m.Reset() + if len(p) == 0 { + return nil + } + dec := csproto.NewDecoder(p) + for dec.More() { + tag, wt, err := dec.DecodeTag() + if err != nil { + return err + } + switch tag { + case 4: // Id (int32,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'id' (tag=4), expected 0 (varint)", wt) + } + if v, err := dec.DecodeInt32(); err != nil { + return fmt.Errorf("unable to decode int32 value for field 'id' (tag=4): %w", err) + } else { + m.Id = v + } + case 1: // Tokens (uint32,repeated,packed) + switch wt { + case csproto.WireTypeVarint: + if v, err := dec.DecodeUInt32(); err != nil { + return fmt.Errorf("unable to decode uint32 value for field 'tokens' (tag=1): %w", err) + } else { + m.Tokens = append(m.Tokens, v) + } + case csproto.WireTypeLengthDelimited: + if v, err := dec.DecodePackedUint32(); err != nil { + return fmt.Errorf("unable to decode packed uint32 values for field 'tokens' (tag=1): %w", err) + } else { + m.Tokens = append(m.Tokens, v...) + } + default: + return fmt.Errorf("incorrect wire type %v for repeated field 'tokens' (tag=1), expected 0 (varint) or 1 (length-delimited)", wt) + } + case 2: // State (enum,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'state' (tag=2), expected 0 (varint)", wt) + } + if v, err := dec.DecodeInt32(); err != nil { + return fmt.Errorf("unable to decode int32 enum value for field 'state' (tag=2): %w", err) + } else { + m.State = PartitionState(v) + } + case 3: // StateTimestamp (int64,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'stateTimestamp' (tag=3), expected 0 (varint)", wt) + } + if v, err := dec.DecodeInt64(); err != nil { + return fmt.Errorf("unable to decode int64 value for field 'stateTimestamp' (tag=3): %w", err) + } else { + m.StateTimestamp = v + } + + default: + if skipped, err := dec.Skip(tag, wt); err != nil { + return fmt.Errorf("invalid operation skipping tag %v: %w", tag, err) + } else { + m.unknownFields = append(m.unknownFields, skipped...) + } + } + } + return nil +} + +//------------------------------------------------------------------------------ +// Custom Protobuf size/marshal/unmarshal code for OwnerDesc + +// Size calculates and returns the size, in bytes, required to hold the contents of m using the Protobuf +// binary encoding. +func (m *OwnerDesc) Size() int { + // nil message is always 0 bytes + if m == nil { + return 0 + } + // return cached size, if present + if csz := int(atomic.LoadInt32(&m.sizeCache)); csz > 0 { + return csz + } + // calculate and cache + var sz, l int + _ = l // avoid unused variable + + // OwnedPartition (int32,optional) + if m.OwnedPartition != 0 { + sz += csproto.SizeOfTagKey(1) + csproto.SizeOfVarint(uint64(m.OwnedPartition)) + } + // State (enum,optional) + if m.State != 0 { + sz += csproto.SizeOfTagKey(2) + csproto.SizeOfVarint(uint64(m.State)) + } + // UpdatedTimestamp (int64,optional) + if m.UpdatedTimestamp != 0 { + sz += csproto.SizeOfTagKey(3) + csproto.SizeOfVarint(uint64(m.UpdatedTimestamp)) + } + // cache the size so it can be re-used in Marshal()/MarshalTo() + atomic.StoreInt32(&m.sizeCache, int32(sz)) + return sz +} + +// Marshal converts the contents of m to the Protobuf binary encoding and returns the result or an error. +func (m *OwnerDesc) Marshal() ([]byte, error) { + siz := m.Size() + if siz == 0 { + return []byte{}, nil + } + buf := make([]byte, siz) + err := m.MarshalTo(buf) + return buf, err +} + +// MarshalTo converts the contents of m to the Protobuf binary encoding and writes the result to dest. +func (m *OwnerDesc) MarshalTo(dest []byte) error { + // nil message == no-op + if m == nil { + return nil + } + var ( + enc = csproto.NewEncoder(dest) + buf []byte + err error + extVal interface{} + ) + // ensure no unused variables + _ = enc + _ = buf + _ = err + _ = extVal + + // OwnedPartition (1,int32,optional) + if m.OwnedPartition != 0 { + enc.EncodeInt32(1, m.OwnedPartition) + } + // State (2,enum,optional) + if m.State != 0 { + enc.EncodeInt32(2, int32(m.State)) + } + // UpdatedTimestamp (3,int64,optional) + if m.UpdatedTimestamp != 0 { + enc.EncodeInt64(3, m.UpdatedTimestamp) + } + return nil +} + +// Unmarshal decodes a binary encoded Protobuf message from p and populates m with the result. +func (m *OwnerDesc) Unmarshal(p []byte) error { + m.Reset() + if len(p) == 0 { + return nil + } + dec := csproto.NewDecoder(p) + for dec.More() { + tag, wt, err := dec.DecodeTag() + if err != nil { + return err + } + switch tag { + case 1: // OwnedPartition (int32,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'ownedPartition' (tag=1), expected 0 (varint)", wt) + } + if v, err := dec.DecodeInt32(); err != nil { + return fmt.Errorf("unable to decode int32 value for field 'ownedPartition' (tag=1): %w", err) + } else { + m.OwnedPartition = v + } + case 2: // State (enum,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'state' (tag=2), expected 0 (varint)", wt) + } + if v, err := dec.DecodeInt32(); err != nil { + return fmt.Errorf("unable to decode int32 enum value for field 'state' (tag=2): %w", err) + } else { + m.State = OwnerState(v) + } + case 3: // UpdatedTimestamp (int64,optional) + if wt != csproto.WireTypeVarint { + return fmt.Errorf("incorrect wire type %v for tag field 'updatedTimestamp' (tag=3), expected 0 (varint)", wt) + } + if v, err := dec.DecodeInt64(); err != nil { + return fmt.Errorf("unable to decode int64 value for field 'updatedTimestamp' (tag=3): %w", err) + } else { + m.UpdatedTimestamp = v + } + + default: + if skipped, err := dec.Skip(tag, wt); err != nil { + return fmt.Errorf("invalid operation skipping tag %v: %w", tag, err) + } else { + m.unknownFields = append(m.unknownFields, skipped...) + } + } + } + return nil +} diff --git a/ring/partition_ring_desc.pb.go b/ring/partition_ring_desc.pb.go index d699c6db3..eb6ea57fe 100644 --- a/ring/partition_ring_desc.pb.go +++ b/ring/partition_ring_desc.pb.go @@ -1,155 +1,200 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: partition_ring_desc.proto +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.2 +// protoc v5.29.3 +// source: ring/partition_ring_desc.proto package ring import ( - fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - github_com_gogo_protobuf_sortkeys "github.com/gogo/protobuf/sortkeys" - io "io" - math "math" - math_bits "math/bits" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" - strconv "strconv" - strings "strings" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) type PartitionState int32 const ( - PartitionUnknown PartitionState = 0 - // Pending partition is a partition that is about to be switched to ACTIVE. This state is used + PartitionState_PartitionUnknown PartitionState = 0 + // Pending partition is a partition that is about to be switched to InstanceState_ACTIVE. This state is used // to let owners to attach to the partition and get ready to handle the partition. // // When a partition is in this state, it must not be used for writing or reading. - PartitionPending PartitionState = 1 + PartitionState_PartitionPending PartitionState = 1 // Active partition in read-write mode. - PartitionActive PartitionState = 2 + PartitionState_PartitionActive PartitionState = 2 // Inactive partition in read-only mode. This partition will be deleted after a grace period, // unless its state changes to Active again. - PartitionInactive PartitionState = 3 + PartitionState_PartitionInactive PartitionState = 3 // Deleted partition. This state is not visible to ring clients: it's only used to propagate // via memberlist the information that a partition has been deleted. - PartitionDeleted PartitionState = 4 + PartitionState_PartitionDeleted PartitionState = 4 +) + +// Enum value maps for PartitionState. +var ( + PartitionState_name = map[int32]string{ + 0: "PartitionUnknown", + 1: "PartitionPending", + 2: "PartitionActive", + 3: "PartitionInactive", + 4: "PartitionDeleted", + } + PartitionState_value = map[string]int32{ + "PartitionUnknown": 0, + "PartitionPending": 1, + "PartitionActive": 2, + "PartitionInactive": 3, + "PartitionDeleted": 4, + } ) -var PartitionState_name = map[int32]string{ - 0: "PartitionUnknown", - 1: "PartitionPending", - 2: "PartitionActive", - 3: "PartitionInactive", - 4: "PartitionDeleted", +func (x PartitionState) Enum() *PartitionState { + p := new(PartitionState) + *p = x + return p +} + +func (x PartitionState) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (PartitionState) Descriptor() protoreflect.EnumDescriptor { + return file_ring_partition_ring_desc_proto_enumTypes[0].Descriptor() +} + +func (PartitionState) Type() protoreflect.EnumType { + return &file_ring_partition_ring_desc_proto_enumTypes[0] } -var PartitionState_value = map[string]int32{ - "PartitionUnknown": 0, - "PartitionPending": 1, - "PartitionActive": 2, - "PartitionInactive": 3, - "PartitionDeleted": 4, +func (x PartitionState) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) } +// Deprecated: Use PartitionState.Descriptor instead. func (PartitionState) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_4df2762174d93dc4, []int{0} + return file_ring_partition_ring_desc_proto_rawDescGZIP(), []int{0} } type OwnerState int32 const ( - OwnerUnknown OwnerState = 0 + OwnerState_OwnerUnknown OwnerState = 0 // Active owner. - OwnerActive OwnerState = 1 + OwnerState_OwnerActive OwnerState = 1 // Deleted owner. This state is not visible to ring clients: it's only used to propagate // via memberlist the information that a owner has been deleted. Owners in this state // are removed before client can see them. - OwnerDeleted OwnerState = 2 + OwnerState_OwnerDeleted OwnerState = 2 ) -var OwnerState_name = map[int32]string{ - 0: "OwnerUnknown", - 1: "OwnerActive", - 2: "OwnerDeleted", +// Enum value maps for OwnerState. +var ( + OwnerState_name = map[int32]string{ + 0: "OwnerUnknown", + 1: "OwnerActive", + 2: "OwnerDeleted", + } + OwnerState_value = map[string]int32{ + "OwnerUnknown": 0, + "OwnerActive": 1, + "OwnerDeleted": 2, + } +) + +func (x OwnerState) Enum() *OwnerState { + p := new(OwnerState) + *p = x + return p +} + +func (x OwnerState) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (OwnerState) Descriptor() protoreflect.EnumDescriptor { + return file_ring_partition_ring_desc_proto_enumTypes[1].Descriptor() } -var OwnerState_value = map[string]int32{ - "OwnerUnknown": 0, - "OwnerActive": 1, - "OwnerDeleted": 2, +func (OwnerState) Type() protoreflect.EnumType { + return &file_ring_partition_ring_desc_proto_enumTypes[1] } +func (x OwnerState) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use OwnerState.Descriptor instead. func (OwnerState) EnumDescriptor() ([]byte, []int) { - return fileDescriptor_4df2762174d93dc4, []int{1} + return file_ring_partition_ring_desc_proto_rawDescGZIP(), []int{1} } // PartitionRingDesc holds the state of the partitions ring. type PartitionRingDesc struct { + state protoimpl.MessageState `protogen:"open.v1"` // Mapping between partition ID and partition info. - Partitions map[int32]PartitionDesc `protobuf:"bytes,1,rep,name=partitions,proto3" json:"partitions" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Partitions map[int32]*PartitionDesc `protobuf:"bytes,1,rep,name=partitions,proto3" json:"partitions,omitempty" protobuf_key:"varint,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` // Mapping between instance ID and partition ownership info. - Owners map[string]OwnerDesc `protobuf:"bytes,2,rep,name=owners,proto3" json:"owners" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Owners map[string]*OwnerDesc `protobuf:"bytes,2,rep,name=owners,proto3" json:"owners,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } -func (m *PartitionRingDesc) Reset() { *m = PartitionRingDesc{} } -func (*PartitionRingDesc) ProtoMessage() {} -func (*PartitionRingDesc) Descriptor() ([]byte, []int) { - return fileDescriptor_4df2762174d93dc4, []int{0} +func (x *PartitionRingDesc) Reset() { + *x = PartitionRingDesc{} + mi := &file_ring_partition_ring_desc_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } -func (m *PartitionRingDesc) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + +func (x *PartitionRingDesc) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *PartitionRingDesc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_PartitionRingDesc.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err + +func (*PartitionRingDesc) ProtoMessage() {} + +func (x *PartitionRingDesc) ProtoReflect() protoreflect.Message { + mi := &file_ring_partition_ring_desc_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) } - return b[:n], nil + return ms } -} -func (m *PartitionRingDesc) XXX_Merge(src proto.Message) { - xxx_messageInfo_PartitionRingDesc.Merge(m, src) -} -func (m *PartitionRingDesc) XXX_Size() int { - return m.Size() -} -func (m *PartitionRingDesc) XXX_DiscardUnknown() { - xxx_messageInfo_PartitionRingDesc.DiscardUnknown(m) + return mi.MessageOf(x) } -var xxx_messageInfo_PartitionRingDesc proto.InternalMessageInfo +// Deprecated: Use PartitionRingDesc.ProtoReflect.Descriptor instead. +func (*PartitionRingDesc) Descriptor() ([]byte, []int) { + return file_ring_partition_ring_desc_proto_rawDescGZIP(), []int{0} +} -func (m *PartitionRingDesc) GetPartitions() map[int32]PartitionDesc { - if m != nil { - return m.Partitions +func (x *PartitionRingDesc) GetPartitions() map[int32]*PartitionDesc { + if x != nil { + return x.Partitions } return nil } -func (m *PartitionRingDesc) GetOwners() map[string]OwnerDesc { - if m != nil { - return m.Owners +func (x *PartitionRingDesc) GetOwners() map[string]*OwnerDesc { + if x != nil { + return x.Owners } return nil } // PartitionDesc holds the state of a single partition. type PartitionDesc struct { + state protoimpl.MessageState `protogen:"open.v1"` // The partition ID. This value is the same as the key in the partitions map in PartitionRingDesc. Id int32 `protobuf:"varint,4,opt,name=id,proto3" json:"id,omitempty"` // Unique tokens, generated with deterministic token generator. Tokens MUST be immutable: @@ -159,70 +204,71 @@ type PartitionDesc struct { State PartitionState `protobuf:"varint,2,opt,name=state,proto3,enum=ring.PartitionState" json:"state,omitempty"` // Unix timestamp (with seconds precision) of when has the state changed last time for this partition. StateTimestamp int64 `protobuf:"varint,3,opt,name=stateTimestamp,proto3" json:"stateTimestamp,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } -func (m *PartitionDesc) Reset() { *m = PartitionDesc{} } -func (*PartitionDesc) ProtoMessage() {} -func (*PartitionDesc) Descriptor() ([]byte, []int) { - return fileDescriptor_4df2762174d93dc4, []int{1} +func (x *PartitionDesc) Reset() { + *x = PartitionDesc{} + mi := &file_ring_partition_ring_desc_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } -func (m *PartitionDesc) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + +func (x *PartitionDesc) String() string { + return protoimpl.X.MessageStringOf(x) } -func (m *PartitionDesc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_PartitionDesc.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err + +func (*PartitionDesc) ProtoMessage() {} + +func (x *PartitionDesc) ProtoReflect() protoreflect.Message { + mi := &file_ring_partition_ring_desc_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) } - return b[:n], nil + return ms } -} -func (m *PartitionDesc) XXX_Merge(src proto.Message) { - xxx_messageInfo_PartitionDesc.Merge(m, src) -} -func (m *PartitionDesc) XXX_Size() int { - return m.Size() -} -func (m *PartitionDesc) XXX_DiscardUnknown() { - xxx_messageInfo_PartitionDesc.DiscardUnknown(m) + return mi.MessageOf(x) } -var xxx_messageInfo_PartitionDesc proto.InternalMessageInfo +// Deprecated: Use PartitionDesc.ProtoReflect.Descriptor instead. +func (*PartitionDesc) Descriptor() ([]byte, []int) { + return file_ring_partition_ring_desc_proto_rawDescGZIP(), []int{1} +} -func (m *PartitionDesc) GetId() int32 { - if m != nil { - return m.Id +func (x *PartitionDesc) GetId() int32 { + if x != nil { + return x.Id } return 0 } -func (m *PartitionDesc) GetTokens() []uint32 { - if m != nil { - return m.Tokens +func (x *PartitionDesc) GetTokens() []uint32 { + if x != nil { + return x.Tokens } return nil } -func (m *PartitionDesc) GetState() PartitionState { - if m != nil { - return m.State +func (x *PartitionDesc) GetState() PartitionState { + if x != nil { + return x.State } - return PartitionUnknown + return PartitionState_PartitionUnknown } -func (m *PartitionDesc) GetStateTimestamp() int64 { - if m != nil { - return m.StateTimestamp +func (x *PartitionDesc) GetStateTimestamp() int64 { + if x != nil { + return x.StateTimestamp } return 0 } // OwnerDesc holds the information of a partition owner. type OwnerDesc struct { + state protoimpl.MessageState `protogen:"open.v1"` // Partition that belongs to this owner. A owner can own only 1 partition, but 1 partition can be // owned by multiple owners. OwnedPartition int32 `protobuf:"varint,1,opt,name=ownedPartition,proto3" json:"ownedPartition,omitempty"` @@ -232,1279 +278,180 @@ type OwnerDesc struct { // This timestamp is used to resolve conflicts when merging updates via memberlist (the most recent // update wins). UpdatedTimestamp int64 `protobuf:"varint,3,opt,name=updatedTimestamp,proto3" json:"updatedTimestamp,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache } -func (m *OwnerDesc) Reset() { *m = OwnerDesc{} } -func (*OwnerDesc) ProtoMessage() {} -func (*OwnerDesc) Descriptor() ([]byte, []int) { - return fileDescriptor_4df2762174d93dc4, []int{2} -} -func (m *OwnerDesc) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *OwnerDesc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_OwnerDesc.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *OwnerDesc) XXX_Merge(src proto.Message) { - xxx_messageInfo_OwnerDesc.Merge(m, src) +func (x *OwnerDesc) Reset() { + *x = OwnerDesc{} + mi := &file_ring_partition_ring_desc_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } -func (m *OwnerDesc) XXX_Size() int { - return m.Size() -} -func (m *OwnerDesc) XXX_DiscardUnknown() { - xxx_messageInfo_OwnerDesc.DiscardUnknown(m) -} - -var xxx_messageInfo_OwnerDesc proto.InternalMessageInfo - -func (m *OwnerDesc) GetOwnedPartition() int32 { - if m != nil { - return m.OwnedPartition - } - return 0 -} - -func (m *OwnerDesc) GetState() OwnerState { - if m != nil { - return m.State - } - return OwnerUnknown -} - -func (m *OwnerDesc) GetUpdatedTimestamp() int64 { - if m != nil { - return m.UpdatedTimestamp - } - return 0 -} - -func init() { - proto.RegisterEnum("ring.PartitionState", PartitionState_name, PartitionState_value) - proto.RegisterEnum("ring.OwnerState", OwnerState_name, OwnerState_value) - proto.RegisterType((*PartitionRingDesc)(nil), "ring.PartitionRingDesc") - proto.RegisterMapType((map[string]OwnerDesc)(nil), "ring.PartitionRingDesc.OwnersEntry") - proto.RegisterMapType((map[int32]PartitionDesc)(nil), "ring.PartitionRingDesc.PartitionsEntry") - proto.RegisterType((*PartitionDesc)(nil), "ring.PartitionDesc") - proto.RegisterType((*OwnerDesc)(nil), "ring.OwnerDesc") -} - -func init() { proto.RegisterFile("partition_ring_desc.proto", fileDescriptor_4df2762174d93dc4) } - -var fileDescriptor_4df2762174d93dc4 = []byte{ - // 497 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0x7d, 0x76, 0x12, 0xa9, 0x2f, 0x34, 0x39, 0xae, 0x05, 0x99, 0x0c, 0x47, 0x14, 0x44, - 0x09, 0x91, 0x48, 0xa5, 0xc0, 0x80, 0xd8, 0x52, 0x95, 0x01, 0x24, 0x44, 0x65, 0x60, 0xae, 0x9c, - 0xf8, 0x30, 0xa7, 0x34, 0x77, 0x91, 0x7d, 0x6e, 0xd5, 0x05, 0xb1, 0x31, 0xb0, 0xf0, 0x31, 0xf8, - 0x22, 0x48, 0x1d, 0x33, 0x76, 0x42, 0xc4, 0x59, 0x18, 0xfb, 0x11, 0x90, 0xcf, 0xae, 0x63, 0xbb, - 0xea, 0x76, 0xef, 0x7f, 0xef, 0xfd, 0xfe, 0xff, 0x3b, 0x9f, 0xe1, 0xc1, 0xc2, 0x0d, 0x14, 0x57, - 0x5c, 0x8a, 0xe3, 0x80, 0x0b, 0xff, 0xd8, 0x63, 0xe1, 0x74, 0xb8, 0x08, 0xa4, 0x92, 0xa4, 0x96, - 0x08, 0x9d, 0x67, 0x3e, 0x57, 0x5f, 0xa2, 0xc9, 0x70, 0x2a, 0xe7, 0xfb, 0xbe, 0xf4, 0xe5, 0xbe, - 0xde, 0x9c, 0x44, 0x9f, 0x75, 0xa5, 0x0b, 0xbd, 0x4a, 0x87, 0x7a, 0xbf, 0x4d, 0xb8, 0x7b, 0x74, - 0x8d, 0x74, 0xb8, 0xf0, 0x0f, 0x59, 0x38, 0x25, 0xef, 0x00, 0x72, 0x9f, 0xd0, 0x46, 0x5d, 0xab, - 0xdf, 0x1c, 0x3d, 0x19, 0x26, 0xfc, 0xe1, 0x8d, 0xe6, 0x8d, 0x12, 0xbe, 0x16, 0x2a, 0x38, 0x3f, - 0xa8, 0x5d, 0xfc, 0x79, 0x68, 0x38, 0x05, 0x00, 0x19, 0x43, 0x43, 0x9e, 0x09, 0x16, 0x84, 0xb6, - 0xa9, 0x51, 0x8f, 0x6e, 0x43, 0xbd, 0xd7, 0x5d, 0x45, 0x4c, 0x36, 0xd8, 0x71, 0xa0, 0x5d, 0xf1, - 0x21, 0x18, 0xac, 0x19, 0x3b, 0xb7, 0x51, 0x17, 0xf5, 0xeb, 0x4e, 0xb2, 0x24, 0x4f, 0xa1, 0x7e, - 0xea, 0x9e, 0x44, 0xcc, 0x36, 0xbb, 0xa8, 0xdf, 0x1c, 0xed, 0x54, 0x6c, 0x12, 0x0b, 0x27, 0xed, - 0x78, 0x65, 0xbe, 0x44, 0x9d, 0xb7, 0xd0, 0x2c, 0x18, 0x16, 0x79, 0x5b, 0x29, 0xef, 0x71, 0x99, - 0xd7, 0x4e, 0x79, 0x7a, 0xa6, 0xc2, 0xea, 0xfd, 0x40, 0xb0, 0x5d, 0x32, 0x22, 0x2d, 0x30, 0xb9, - 0x67, 0xd7, 0x74, 0x3a, 0x93, 0x7b, 0xe4, 0x3e, 0x34, 0x94, 0x9c, 0xb1, 0xec, 0x3e, 0xb7, 0x9d, - 0xac, 0x22, 0x03, 0xa8, 0x87, 0xca, 0x55, 0xa9, 0x49, 0x6b, 0xb4, 0x5b, 0x09, 0xfd, 0x21, 0xd9, - 0x73, 0xd2, 0x16, 0xb2, 0x07, 0x2d, 0xbd, 0xf8, 0xc8, 0xe7, 0x2c, 0x54, 0xee, 0x7c, 0x61, 0x5b, - 0x5d, 0xd4, 0xb7, 0x9c, 0x8a, 0xda, 0xfb, 0x8e, 0x60, 0x2b, 0x8f, 0x99, 0x4c, 0x25, 0xb7, 0xe8, - 0xe5, 0xcc, 0xec, 0xce, 0x2a, 0x2a, 0xd9, 0x2b, 0x27, 0xc1, 0x85, 0xe3, 0x96, 0x52, 0x0c, 0x00, - 0x47, 0x0b, 0xcf, 0x55, 0xcc, 0xab, 0xe6, 0xb8, 0xa1, 0x0f, 0xbe, 0x42, 0xab, 0x7c, 0x14, 0xb2, - 0x0b, 0x38, 0x57, 0x3e, 0x89, 0x99, 0x90, 0x67, 0x02, 0x1b, 0x25, 0xf5, 0x88, 0x09, 0x8f, 0x0b, - 0x1f, 0x23, 0xb2, 0x53, 0xf8, 0xea, 0xe3, 0xa9, 0xe2, 0xa7, 0x0c, 0x9b, 0xe4, 0x5e, 0xe1, 0xc5, - 0xbe, 0x11, 0x6e, 0x2a, 0x5b, 0x25, 0xc2, 0x21, 0x3b, 0x61, 0x8a, 0x79, 0xb8, 0x36, 0x18, 0x03, - 0x6c, 0x0e, 0x40, 0x30, 0xdc, 0xd1, 0xd5, 0xc6, 0xb7, 0x9d, 0xbd, 0x81, 0x8c, 0x8e, 0xf2, 0x96, - 0x6b, 0x84, 0x79, 0xf0, 0x62, 0xb9, 0xa2, 0xc6, 0xe5, 0x8a, 0x1a, 0x57, 0x2b, 0x8a, 0xbe, 0xc5, - 0x14, 0xfd, 0x8a, 0x29, 0xba, 0x88, 0x29, 0x5a, 0xc6, 0x14, 0xfd, 0x8d, 0x29, 0xfa, 0x17, 0x53, - 0xe3, 0x2a, 0xa6, 0xe8, 0xe7, 0x9a, 0x1a, 0xcb, 0x35, 0x35, 0x2e, 0xd7, 0xd4, 0x98, 0x34, 0xf4, - 0xff, 0xf5, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc9, 0xd1, 0xa7, 0xbd, 0xb1, 0x03, 0x00, - 0x00, -} - -func (x PartitionState) String() string { - s, ok := PartitionState_name[int32(x)] - if ok { - return s - } - return strconv.Itoa(int(x)) -} -func (x OwnerState) String() string { - s, ok := OwnerState_name[int32(x)] - if ok { - return s - } - return strconv.Itoa(int(x)) -} -func (this *PartitionRingDesc) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - that1, ok := that.(*PartitionRingDesc) - if !ok { - that2, ok := that.(PartitionRingDesc) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if len(this.Partitions) != len(that1.Partitions) { - return false - } - for i := range this.Partitions { - a := this.Partitions[i] - b := that1.Partitions[i] - if !(&a).Equal(&b) { - return false - } - } - if len(this.Owners) != len(that1.Owners) { - return false - } - for i := range this.Owners { - a := this.Owners[i] - b := that1.Owners[i] - if !(&a).Equal(&b) { - return false - } - } - return true +func (x *OwnerDesc) String() string { + return protoimpl.X.MessageStringOf(x) } -func (this *PartitionDesc) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - that1, ok := that.(*PartitionDesc) - if !ok { - that2, ok := that.(PartitionDesc) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.Id != that1.Id { - return false - } - if len(this.Tokens) != len(that1.Tokens) { - return false - } - for i := range this.Tokens { - if this.Tokens[i] != that1.Tokens[i] { - return false - } - } - if this.State != that1.State { - return false - } - if this.StateTimestamp != that1.StateTimestamp { - return false - } - return true -} -func (this *OwnerDesc) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*OwnerDesc) - if !ok { - that2, ok := that.(OwnerDesc) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.OwnedPartition != that1.OwnedPartition { - return false - } - if this.State != that1.State { - return false - } - if this.UpdatedTimestamp != that1.UpdatedTimestamp { - return false - } - return true -} -func (this *PartitionRingDesc) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 6) - s = append(s, "&ring.PartitionRingDesc{") - keysForPartitions := make([]int32, 0, len(this.Partitions)) - for k, _ := range this.Partitions { - keysForPartitions = append(keysForPartitions, k) - } - github_com_gogo_protobuf_sortkeys.Int32s(keysForPartitions) - mapStringForPartitions := "map[int32]PartitionDesc{" - for _, k := range keysForPartitions { - mapStringForPartitions += fmt.Sprintf("%#v: %#v,", k, this.Partitions[k]) - } - mapStringForPartitions += "}" - if this.Partitions != nil { - s = append(s, "Partitions: "+mapStringForPartitions+",\n") - } - keysForOwners := make([]string, 0, len(this.Owners)) - for k, _ := range this.Owners { - keysForOwners = append(keysForOwners, k) - } - github_com_gogo_protobuf_sortkeys.Strings(keysForOwners) - mapStringForOwners := "map[string]OwnerDesc{" - for _, k := range keysForOwners { - mapStringForOwners += fmt.Sprintf("%#v: %#v,", k, this.Owners[k]) - } - mapStringForOwners += "}" - if this.Owners != nil { - s = append(s, "Owners: "+mapStringForOwners+",\n") - } - s = append(s, "}") - return strings.Join(s, "") -} -func (this *PartitionDesc) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 8) - s = append(s, "&ring.PartitionDesc{") - s = append(s, "Id: "+fmt.Sprintf("%#v", this.Id)+",\n") - s = append(s, "Tokens: "+fmt.Sprintf("%#v", this.Tokens)+",\n") - s = append(s, "State: "+fmt.Sprintf("%#v", this.State)+",\n") - s = append(s, "StateTimestamp: "+fmt.Sprintf("%#v", this.StateTimestamp)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func (this *OwnerDesc) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 7) - s = append(s, "&ring.OwnerDesc{") - s = append(s, "OwnedPartition: "+fmt.Sprintf("%#v", this.OwnedPartition)+",\n") - s = append(s, "State: "+fmt.Sprintf("%#v", this.State)+",\n") - s = append(s, "UpdatedTimestamp: "+fmt.Sprintf("%#v", this.UpdatedTimestamp)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringPartitionRingDesc(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} -func (m *PartitionRingDesc) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *PartitionRingDesc) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *PartitionRingDesc) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.Owners) > 0 { - for k := range m.Owners { - v := m.Owners[k] - baseI := i - { - size, err := (&v).MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - i -= len(k) - copy(dAtA[i:], k) - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(len(k))) - i-- - dAtA[i] = 0xa - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(baseI-i)) - i-- - dAtA[i] = 0x12 - } - } - if len(m.Partitions) > 0 { - for k := range m.Partitions { - v := m.Partitions[k] - baseI := i - { - size, err := (&v).MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x12 - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(k)) - i-- - dAtA[i] = 0x8 - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(baseI-i)) - i-- - dAtA[i] = 0xa - } - } - return len(dAtA) - i, nil -} - -func (m *PartitionDesc) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *PartitionDesc) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *PartitionDesc) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Id != 0 { - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(m.Id)) - i-- - dAtA[i] = 0x20 - } - if m.StateTimestamp != 0 { - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(m.StateTimestamp)) - i-- - dAtA[i] = 0x18 - } - if m.State != 0 { - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(m.State)) - i-- - dAtA[i] = 0x10 - } - if len(m.Tokens) > 0 { - dAtA4 := make([]byte, len(m.Tokens)*10) - var j3 int - for _, num := range m.Tokens { - for num >= 1<<7 { - dAtA4[j3] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j3++ - } - dAtA4[j3] = uint8(num) - j3++ - } - i -= j3 - copy(dAtA[i:], dAtA4[:j3]) - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(j3)) - i-- - dAtA[i] = 0xa - } - return len(dAtA) - i, nil -} - -func (m *OwnerDesc) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *OwnerDesc) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *OwnerDesc) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.UpdatedTimestamp != 0 { - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(m.UpdatedTimestamp)) - i-- - dAtA[i] = 0x18 - } - if m.State != 0 { - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(m.State)) - i-- - dAtA[i] = 0x10 - } - if m.OwnedPartition != 0 { - i = encodeVarintPartitionRingDesc(dAtA, i, uint64(m.OwnedPartition)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func encodeVarintPartitionRingDesc(dAtA []byte, offset int, v uint64) int { - offset -= sovPartitionRingDesc(v) - base := offset - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return base -} -func (m *PartitionRingDesc) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Partitions) > 0 { - for k, v := range m.Partitions { - _ = k - _ = v - l = v.Size() - mapEntrySize := 1 + sovPartitionRingDesc(uint64(k)) + 1 + l + sovPartitionRingDesc(uint64(l)) - n += mapEntrySize + 1 + sovPartitionRingDesc(uint64(mapEntrySize)) - } - } - if len(m.Owners) > 0 { - for k, v := range m.Owners { - _ = k - _ = v - l = v.Size() - mapEntrySize := 1 + len(k) + sovPartitionRingDesc(uint64(len(k))) + 1 + l + sovPartitionRingDesc(uint64(l)) - n += mapEntrySize + 1 + sovPartitionRingDesc(uint64(mapEntrySize)) - } - } - return n -} +func (*OwnerDesc) ProtoMessage() {} -func (m *PartitionDesc) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if len(m.Tokens) > 0 { - l = 0 - for _, e := range m.Tokens { - l += sovPartitionRingDesc(uint64(e)) +func (x *OwnerDesc) ProtoReflect() protoreflect.Message { + mi := &file_ring_partition_ring_desc_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) } - n += 1 + sovPartitionRingDesc(uint64(l)) + l - } - if m.State != 0 { - n += 1 + sovPartitionRingDesc(uint64(m.State)) - } - if m.StateTimestamp != 0 { - n += 1 + sovPartitionRingDesc(uint64(m.StateTimestamp)) + return ms } - if m.Id != 0 { - n += 1 + sovPartitionRingDesc(uint64(m.Id)) - } - return n + return mi.MessageOf(x) } -func (m *OwnerDesc) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.OwnedPartition != 0 { - n += 1 + sovPartitionRingDesc(uint64(m.OwnedPartition)) - } - if m.State != 0 { - n += 1 + sovPartitionRingDesc(uint64(m.State)) - } - if m.UpdatedTimestamp != 0 { - n += 1 + sovPartitionRingDesc(uint64(m.UpdatedTimestamp)) - } - return n +// Deprecated: Use OwnerDesc.ProtoReflect.Descriptor instead. +func (*OwnerDesc) Descriptor() ([]byte, []int) { + return file_ring_partition_ring_desc_proto_rawDescGZIP(), []int{2} } -func sovPartitionRingDesc(x uint64) (n int) { - return (math_bits.Len64(x|1) + 6) / 7 -} -func sozPartitionRingDesc(x uint64) (n int) { - return sovPartitionRingDesc(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *PartitionRingDesc) String() string { - if this == nil { - return "nil" - } - keysForPartitions := make([]int32, 0, len(this.Partitions)) - for k, _ := range this.Partitions { - keysForPartitions = append(keysForPartitions, k) - } - github_com_gogo_protobuf_sortkeys.Int32s(keysForPartitions) - mapStringForPartitions := "map[int32]PartitionDesc{" - for _, k := range keysForPartitions { - mapStringForPartitions += fmt.Sprintf("%v: %v,", k, this.Partitions[k]) - } - mapStringForPartitions += "}" - keysForOwners := make([]string, 0, len(this.Owners)) - for k, _ := range this.Owners { - keysForOwners = append(keysForOwners, k) - } - github_com_gogo_protobuf_sortkeys.Strings(keysForOwners) - mapStringForOwners := "map[string]OwnerDesc{" - for _, k := range keysForOwners { - mapStringForOwners += fmt.Sprintf("%v: %v,", k, this.Owners[k]) - } - mapStringForOwners += "}" - s := strings.Join([]string{`&PartitionRingDesc{`, - `Partitions:` + mapStringForPartitions + `,`, - `Owners:` + mapStringForOwners + `,`, - `}`, - }, "") - return s -} -func (this *PartitionDesc) String() string { - if this == nil { - return "nil" +func (x *OwnerDesc) GetOwnedPartition() int32 { + if x != nil { + return x.OwnedPartition } - s := strings.Join([]string{`&PartitionDesc{`, - `Tokens:` + fmt.Sprintf("%v", this.Tokens) + `,`, - `State:` + fmt.Sprintf("%v", this.State) + `,`, - `StateTimestamp:` + fmt.Sprintf("%v", this.StateTimestamp) + `,`, - `Id:` + fmt.Sprintf("%v", this.Id) + `,`, - `}`, - }, "") - return s -} -func (this *OwnerDesc) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&OwnerDesc{`, - `OwnedPartition:` + fmt.Sprintf("%v", this.OwnedPartition) + `,`, - `State:` + fmt.Sprintf("%v", this.State) + `,`, - `UpdatedTimestamp:` + fmt.Sprintf("%v", this.UpdatedTimestamp) + `,`, - `}`, - }, "") - return s -} -func valueToStringPartitionRingDesc(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) + return 0 } -func (m *PartitionRingDesc) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: PartitionRingDesc: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: PartitionRingDesc: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Partitions", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthPartitionRingDesc - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Partitions == nil { - m.Partitions = make(map[int32]PartitionDesc) - } - var mapkey int32 - mapvalue := &PartitionDesc{} - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapkey |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - } else if fieldNum == 2 { - var mapmsglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapmsglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if mapmsglen < 0 { - return ErrInvalidLengthPartitionRingDesc - } - postmsgIndex := iNdEx + mapmsglen - if postmsgIndex < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if postmsgIndex > l { - return io.ErrUnexpectedEOF - } - mapvalue = &PartitionDesc{} - if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { - return err - } - iNdEx = postmsgIndex - } else { - iNdEx = entryPreIndex - skippy, err := skipPartitionRingDesc(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if (iNdEx + skippy) > postIndex { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - m.Partitions[mapkey] = *mapvalue - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Owners", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthPartitionRingDesc - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if m.Owners == nil { - m.Owners = make(map[string]OwnerDesc) - } - var mapkey string - mapvalue := &OwnerDesc{} - for iNdEx < postIndex { - entryPreIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - if fieldNum == 1 { - var stringLenmapkey uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLenmapkey |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLenmapkey := int(stringLenmapkey) - if intStringLenmapkey < 0 { - return ErrInvalidLengthPartitionRingDesc - } - postStringIndexmapkey := iNdEx + intStringLenmapkey - if postStringIndexmapkey < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if postStringIndexmapkey > l { - return io.ErrUnexpectedEOF - } - mapkey = string(dAtA[iNdEx:postStringIndexmapkey]) - iNdEx = postStringIndexmapkey - } else if fieldNum == 2 { - var mapmsglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - mapmsglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if mapmsglen < 0 { - return ErrInvalidLengthPartitionRingDesc - } - postmsgIndex := iNdEx + mapmsglen - if postmsgIndex < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if postmsgIndex > l { - return io.ErrUnexpectedEOF - } - mapvalue = &OwnerDesc{} - if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil { - return err - } - iNdEx = postmsgIndex - } else { - iNdEx = entryPreIndex - skippy, err := skipPartitionRingDesc(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if (iNdEx + skippy) > postIndex { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - m.Owners[mapkey] = *mapvalue - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipPartitionRingDesc(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - if iNdEx > l { - return io.ErrUnexpectedEOF +func (x *OwnerDesc) GetState() OwnerState { + if x != nil { + return x.State } - return nil + return OwnerState_OwnerUnknown } -func (m *PartitionDesc) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: PartitionDesc: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: PartitionDesc: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType == 0 { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Tokens = append(m.Tokens, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthPartitionRingDesc - } - postIndex := iNdEx + packedLen - if postIndex < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - var elementCount int - var count int - for _, integer := range dAtA[iNdEx:postIndex] { - if integer < 128 { - count++ - } - } - elementCount = count - if elementCount != 0 && len(m.Tokens) == 0 { - m.Tokens = make([]uint32, 0, elementCount) - } - for iNdEx < postIndex { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - m.Tokens = append(m.Tokens, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field Tokens", wireType) - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) - } - m.State = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.State |= PartitionState(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field StateTimestamp", wireType) - } - m.StateTimestamp = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.StateTimestamp |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType) - } - m.Id = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Id |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipPartitionRingDesc(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - if iNdEx > l { - return io.ErrUnexpectedEOF +func (x *OwnerDesc) GetUpdatedTimestamp() int64 { + if x != nil { + return x.UpdatedTimestamp } - return nil + return 0 } -func (m *OwnerDesc) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: OwnerDesc: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: OwnerDesc: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field OwnedPartition", wireType) - } - m.OwnedPartition = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.OwnedPartition |= int32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field State", wireType) - } - m.State = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.State |= OwnerState(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field UpdatedTimestamp", wireType) - } - m.UpdatedTimestamp = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.UpdatedTimestamp |= int64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipPartitionRingDesc(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthPartitionRingDesc - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipPartitionRingDesc(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - depth := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - case 1: - iNdEx += 8 - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowPartitionRingDesc - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if length < 0 { - return 0, ErrInvalidLengthPartitionRingDesc - } - iNdEx += length - case 3: - depth++ - case 4: - if depth == 0 { - return 0, ErrUnexpectedEndOfGroupPartitionRingDesc - } - depth-- - case 5: - iNdEx += 4 - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - if iNdEx < 0 { - return 0, ErrInvalidLengthPartitionRingDesc - } - if depth == 0 { - return iNdEx, nil - } - } - return 0, io.ErrUnexpectedEOF +var File_ring_partition_ring_desc_proto protoreflect.FileDescriptor + +var file_ring_partition_ring_desc_proto_rawDesc = []byte{ + 0x0a, 0x1e, 0x72, 0x69, 0x6e, 0x67, 0x2f, 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, + 0x5f, 0x72, 0x69, 0x6e, 0x67, 0x5f, 0x64, 0x65, 0x73, 0x63, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x12, 0x04, 0x72, 0x69, 0x6e, 0x67, 0x22, 0xb9, 0x02, 0x0a, 0x11, 0x50, 0x61, 0x72, 0x74, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x69, 0x6e, 0x67, 0x44, 0x65, 0x73, 0x63, 0x12, 0x47, 0x0a, 0x0a, + 0x70, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x27, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x52, 0x69, 0x6e, 0x67, 0x44, 0x65, 0x73, 0x63, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, + 0x69, 0x6f, 0x6e, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0a, 0x70, 0x61, 0x72, 0x74, 0x69, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x3b, 0x0a, 0x06, 0x6f, 0x77, 0x6e, 0x65, 0x72, 0x73, 0x18, + 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x23, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x50, 0x61, 0x72, + 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x69, 0x6e, 0x67, 0x44, 0x65, 0x73, 0x63, 0x2e, 0x4f, + 0x77, 0x6e, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x6f, 0x77, 0x6e, 0x65, + 0x72, 0x73, 0x1a, 0x52, 0x0a, 0x0f, 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x50, 0x61, + 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x44, 0x65, 0x73, 0x63, 0x52, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x4a, 0x0a, 0x0b, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x73, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x25, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x4f, 0x77, + 0x6e, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, + 0x38, 0x01, 0x22, 0x8b, 0x01, 0x0a, 0x0d, 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, + 0x44, 0x65, 0x73, 0x63, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x02, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0d, 0x52, 0x06, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x73, 0x12, 0x2a, 0x0a, 0x05, + 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x72, 0x69, + 0x6e, 0x67, 0x2e, 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, + 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x73, 0x74, 0x61, 0x74, + 0x65, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, + 0x52, 0x0e, 0x73, 0x74, 0x61, 0x74, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x22, 0x87, 0x01, 0x0a, 0x09, 0x4f, 0x77, 0x6e, 0x65, 0x72, 0x44, 0x65, 0x73, 0x63, 0x12, 0x26, + 0x0a, 0x0e, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0e, 0x6f, 0x77, 0x6e, 0x65, 0x64, 0x50, 0x61, 0x72, + 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x26, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x10, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x4f, 0x77, 0x6e, + 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x65, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x12, 0x2a, + 0x0a, 0x10, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, + 0x6d, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x10, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, + 0x64, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x2a, 0x7e, 0x0a, 0x0e, 0x50, 0x61, + 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x14, 0x0a, 0x10, + 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, + 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x50, + 0x65, 0x6e, 0x64, 0x69, 0x6e, 0x67, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x50, 0x61, 0x72, 0x74, + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x10, 0x02, 0x12, 0x15, 0x0a, + 0x11, 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x61, 0x63, 0x74, 0x69, + 0x76, 0x65, 0x10, 0x03, 0x12, 0x14, 0x0a, 0x10, 0x50, 0x61, 0x72, 0x74, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x10, 0x04, 0x2a, 0x41, 0x0a, 0x0a, 0x4f, 0x77, + 0x6e, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x10, 0x0a, 0x0c, 0x4f, 0x77, 0x6e, 0x65, + 0x72, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x4f, 0x77, + 0x6e, 0x65, 0x72, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, 0x4f, + 0x77, 0x6e, 0x65, 0x72, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x10, 0x02, 0x42, 0x24, 0x5a, + 0x22, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x61, 0x66, + 0x61, 0x6e, 0x61, 0x2f, 0x64, 0x73, 0x6b, 0x69, 0x74, 0x2f, 0x72, 0x69, 0x6e, 0x67, 0x3b, 0x72, + 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( - ErrInvalidLengthPartitionRingDesc = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowPartitionRingDesc = fmt.Errorf("proto: integer overflow") - ErrUnexpectedEndOfGroupPartitionRingDesc = fmt.Errorf("proto: unexpected end of group") + file_ring_partition_ring_desc_proto_rawDescOnce sync.Once + file_ring_partition_ring_desc_proto_rawDescData = file_ring_partition_ring_desc_proto_rawDesc ) + +func file_ring_partition_ring_desc_proto_rawDescGZIP() []byte { + file_ring_partition_ring_desc_proto_rawDescOnce.Do(func() { + file_ring_partition_ring_desc_proto_rawDescData = protoimpl.X.CompressGZIP(file_ring_partition_ring_desc_proto_rawDescData) + }) + return file_ring_partition_ring_desc_proto_rawDescData +} + +var file_ring_partition_ring_desc_proto_enumTypes = make([]protoimpl.EnumInfo, 2) +var file_ring_partition_ring_desc_proto_msgTypes = make([]protoimpl.MessageInfo, 5) +var file_ring_partition_ring_desc_proto_goTypes = []any{ + (PartitionState)(0), // 0: ring.PartitionState + (OwnerState)(0), // 1: ring.OwnerState + (*PartitionRingDesc)(nil), // 2: ring.PartitionRingDesc + (*PartitionDesc)(nil), // 3: ring.PartitionDesc + (*OwnerDesc)(nil), // 4: ring.OwnerDesc + nil, // 5: ring.PartitionRingDesc.PartitionsEntry + nil, // 6: ring.PartitionRingDesc.OwnersEntry +} +var file_ring_partition_ring_desc_proto_depIdxs = []int32{ + 5, // 0: ring.PartitionRingDesc.partitions:type_name -> ring.PartitionRingDesc.PartitionsEntry + 6, // 1: ring.PartitionRingDesc.owners:type_name -> ring.PartitionRingDesc.OwnersEntry + 0, // 2: ring.PartitionDesc.state:type_name -> ring.PartitionState + 1, // 3: ring.OwnerDesc.state:type_name -> ring.OwnerState + 3, // 4: ring.PartitionRingDesc.PartitionsEntry.value:type_name -> ring.PartitionDesc + 4, // 5: ring.PartitionRingDesc.OwnersEntry.value:type_name -> ring.OwnerDesc + 6, // [6:6] is the sub-list for method output_type + 6, // [6:6] is the sub-list for method input_type + 6, // [6:6] is the sub-list for extension type_name + 6, // [6:6] is the sub-list for extension extendee + 0, // [0:6] is the sub-list for field type_name +} + +func init() { file_ring_partition_ring_desc_proto_init() } +func file_ring_partition_ring_desc_proto_init() { + if File_ring_partition_ring_desc_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_ring_partition_ring_desc_proto_rawDesc, + NumEnums: 2, + NumMessages: 5, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_ring_partition_ring_desc_proto_goTypes, + DependencyIndexes: file_ring_partition_ring_desc_proto_depIdxs, + EnumInfos: file_ring_partition_ring_desc_proto_enumTypes, + MessageInfos: file_ring_partition_ring_desc_proto_msgTypes, + }.Build() + File_ring_partition_ring_desc_proto = out.File + file_ring_partition_ring_desc_proto_rawDesc = nil + file_ring_partition_ring_desc_proto_goTypes = nil + file_ring_partition_ring_desc_proto_depIdxs = nil +} diff --git a/ring/partition_ring_desc.proto b/ring/partition_ring_desc.proto index 312d7193d..b0a9678ed 100644 --- a/ring/partition_ring_desc.proto +++ b/ring/partition_ring_desc.proto @@ -2,18 +2,15 @@ syntax = "proto3"; package ring; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; - -option (gogoproto.marshaler_all) = true; -option (gogoproto.unmarshaler_all) = true; +option go_package = "github.com/grafana/dskit/ring;ring"; // PartitionRingDesc holds the state of the partitions ring. message PartitionRingDesc { // Mapping between partition ID and partition info. - map partitions = 1 [(gogoproto.nullable) = false]; + map partitions = 1; // Mapping between instance ID and partition ownership info. - map owners = 2 [(gogoproto.nullable) = false]; + map owners = 2; } // PartitionDesc holds the state of a single partition. diff --git a/ring/partition_ring_http_test.go b/ring/partition_ring_http_test.go index 13293ff32..2fb660589 100644 --- a/ring/partition_ring_http_test.go +++ b/ring/partition_ring_http_test.go @@ -24,7 +24,7 @@ func TestPartitionRingPageHandler_ViewPage(t *testing.T) { handler := NewPartitionRingPageHandler( newStaticPartitionRingReader( NewPartitionRing(PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: { State: PartitionActive, StateTimestamp: time.Now().Unix(), @@ -36,7 +36,7 @@ func TestPartitionRingPageHandler_ViewPage(t *testing.T) { Tokens: []uint32{2000000, 4000000, 5000000, 7000000}, }, }, - Owners: map[string]OwnerDesc{ + Owners: map[string]*OwnerDesc{ "ingester-zone-a-0": { OwnedPartition: 1, }, diff --git a/ring/partition_ring_model.go b/ring/partition_ring_model.go index cecda6b89..2e8e05b0b 100644 --- a/ring/partition_ring_model.go +++ b/ring/partition_ring_model.go @@ -7,12 +7,128 @@ import ( "strings" "time" - "github.com/gogo/protobuf/proto" + "google.golang.org/protobuf/proto" "github.com/grafana/dskit/kv/codec" "github.com/grafana/dskit/kv/memberlist" ) +const PartitionUnknown = PartitionState_PartitionUnknown +const PartitionPending = PartitionState_PartitionPending +const PartitionActive = PartitionState_PartitionActive +const PartitionInactive = PartitionState_PartitionInactive +const PartitionDeleted = PartitionState_PartitionDeleted + +func (this *PartitionRingDesc) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*PartitionRingDesc) + if !ok { + that2, ok := that.(PartitionRingDesc) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if len(this.Partitions) != len(that1.Partitions) { + return false + } + for i := range this.Partitions { + a := this.Partitions[i] + b := that1.Partitions[i] + if !(a).Equal(b) { + return false + } + } + if len(this.Owners) != len(that1.Owners) { + return false + } + for i := range this.Owners { + a := this.Owners[i] + b := that1.Owners[i] + if !(a).Equal(b) { + return false + } + } + return true +} +func (this *PartitionDesc) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*PartitionDesc) + if !ok { + that2, ok := that.(PartitionDesc) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.Id != that1.Id { + return false + } + if len(this.Tokens) != len(that1.Tokens) { + return false + } + for i := range this.Tokens { + if this.Tokens[i] != that1.Tokens[i] { + return false + } + } + if this.State != that1.State { + return false + } + if this.StateTimestamp != that1.StateTimestamp { + return false + } + return true +} +func (this *OwnerDesc) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*OwnerDesc) + if !ok { + that2, ok := that.(OwnerDesc) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.OwnedPartition != that1.OwnedPartition { + return false + } + if this.State != that1.State { + return false + } + if this.UpdatedTimestamp != that1.UpdatedTimestamp { + return false + } + return true +} + type partitionRingCodec struct { codec.Codec } @@ -27,10 +143,10 @@ func (c *partitionRingCodec) Decode(in []byte) (interface{}, error) { // Ensure maps are initialised. This makes working with PartitionRingDesc more convenient. if actual, ok := out.(*PartitionRingDesc); ok { if actual.Partitions == nil { - actual.Partitions = map[int32]PartitionDesc{} + actual.Partitions = map[int32]*PartitionDesc{} } if actual.Owners == nil { - actual.Owners = map[string]OwnerDesc{} + actual.Owners = map[string]*OwnerDesc{} } } @@ -63,8 +179,8 @@ func GetOrCreatePartitionRingDesc(in any) *PartitionRingDesc { func NewPartitionRingDesc() *PartitionRingDesc { return &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, - Owners: map[string]OwnerDesc{}, + Partitions: map[int32]*PartitionDesc{}, + Owners: map[string]*OwnerDesc{}, } } @@ -168,8 +284,8 @@ func (m *PartitionRingDesc) activePartitionsCount() int { // WithPartitions returns a new PartitionRingDesc with only the specified partitions and their owners included. func (m *PartitionRingDesc) WithPartitions(partitions map[int32]struct{}) PartitionRingDesc { - newPartitions := make(map[int32]PartitionDesc, len(partitions)) - newOwners := make(map[string]OwnerDesc, len(partitions)*2) // assuming two owners per partition. + newPartitions := make(map[int32]*PartitionDesc, len(partitions)) + newOwners := make(map[string]*OwnerDesc, len(partitions)*2) // assuming two owners per partition. for pid, p := range m.Partitions { if _, ok := partitions[pid]; ok { @@ -196,7 +312,7 @@ func (m *PartitionRingDesc) AddPartition(id int32, state PartitionState, now tim // Partitions don't use zones. spreadMinimizing := NewSpreadMinimizingTokenGeneratorForInstanceAndZoneID("", int(id), 0, false) - m.Partitions[id] = PartitionDesc{ + m.Partitions[id] = &PartitionDesc{ Id: id, Tokens: spreadMinimizing.GenerateTokens(optimalTokensPerInstance, nil), State: state, @@ -237,7 +353,10 @@ func (m *PartitionRingDesc) HasPartition(id int32) bool { // owner was added or updated, false if it was left unchanged. func (m *PartitionRingDesc) AddOrUpdateOwner(id string, state OwnerState, ownedPartition int32, now time.Time) bool { prev, ok := m.Owners[id] - updated := OwnerDesc{ + if !ok { + prev = &OwnerDesc{} + } + updated := &OwnerDesc{ State: state, OwnedPartition: ownedPartition, @@ -368,12 +487,15 @@ func (m *PartitionRingDesc) mergeWithTime(mergeable memberlist.Mergeable, localC // Now let's handle owners. for id, otherOwner := range other.Owners { - thisOwner := m.Owners[id] + thisOwner, ok := m.Owners[id] + if !ok { + thisOwner = &OwnerDesc{} + } // In case the timestamp is equal we give priority to the deleted state. // Reason is that timestamp has second precision, so we cover the case an // update and subsequent deletion occur within the same second. - if otherOwner.UpdatedTimestamp > thisOwner.UpdatedTimestamp || (otherOwner.UpdatedTimestamp == thisOwner.UpdatedTimestamp && otherOwner.State == OwnerDeleted && thisOwner.State != OwnerDeleted) { + if otherOwner.UpdatedTimestamp > thisOwner.UpdatedTimestamp || (otherOwner.UpdatedTimestamp == thisOwner.UpdatedTimestamp && otherOwner.State == OwnerState_OwnerDeleted && thisOwner.State != OwnerState_OwnerDeleted) { m.Owners[id] = otherOwner change.Owners[id] = otherOwner } @@ -383,9 +505,9 @@ func (m *PartitionRingDesc) mergeWithTime(mergeable memberlist.Mergeable, localC // Mark all missing owners as deleted. // This breaks commutativity! But we only do it locally, not when gossiping with others. for id, thisOwner := range m.Owners { - if _, exists := other.Owners[id]; !exists && thisOwner.State != OwnerDeleted { + if _, exists := other.Owners[id]; !exists && thisOwner.State != OwnerState_OwnerDeleted { // Owner was removed from the ring. We need to preserve it locally, but we set state to OwnerDeleted. - thisOwner.State = OwnerDeleted + thisOwner.State = OwnerState_OwnerDeleted thisOwner.UpdatedTimestamp = now.Unix() m.Owners[id] = thisOwner change.Owners[id] = thisOwner @@ -430,7 +552,7 @@ func (m *PartitionRingDesc) RemoveTombstones(limit time.Time) (total, removed in } for n, owner := range m.Owners { - if owner.State == OwnerDeleted { + if owner.State == OwnerState_OwnerDeleted { if limit.IsZero() || time.Unix(owner.UpdatedTimestamp, 0).Before(limit) { delete(m.Owners, n) removed++ @@ -449,10 +571,10 @@ func (m *PartitionRingDesc) Clone() memberlist.Mergeable { // Ensure empty maps are preserved (easier to compare with a deep equal in tests). if m.Partitions != nil && clone.Partitions == nil { - clone.Partitions = map[int32]PartitionDesc{} + clone.Partitions = map[int32]*PartitionDesc{} } if m.Owners != nil && clone.Owners == nil { - clone.Owners = map[string]OwnerDesc{} + clone.Owners = map[string]*OwnerDesc{} } return clone diff --git a/ring/partition_ring_model_test.go b/ring/partition_ring_model_test.go index ca71429b4..5a170c27a 100644 --- a/ring/partition_ring_model_test.go +++ b/ring/partition_ring_model_test.go @@ -14,13 +14,13 @@ import ( func TestPartitionRingDesc_tokens(t *testing.T) { desc := &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Tokens: []uint32{1, 5, 8}, State: PartitionActive, StateTimestamp: 10}, 2: {Tokens: []uint32{3, 4, 9}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, }, } @@ -29,13 +29,13 @@ func TestPartitionRingDesc_tokens(t *testing.T) { func TestPartitionRingDesc_partitionByToken(t *testing.T) { desc := &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Tokens: []uint32{1, 5, 8}, State: PartitionActive, StateTimestamp: 10}, 2: {Tokens: []uint32{3, 4, 9}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, }, } @@ -51,10 +51,10 @@ func TestPartitionRingDesc_countPartitionsByState(t *testing.T) { t.Run("ring with only active partitions should other states with 0 partitions each", func(t *testing.T) { desc := &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{}, + Owners: map[string]*OwnerDesc{}, } assert.Equal(t, map[PartitionState]int{PartitionPending: 0, PartitionActive: 1, PartitionInactive: 0}, desc.countPartitionsByState()) @@ -62,7 +62,7 @@ func TestPartitionRingDesc_countPartitionsByState(t *testing.T) { t.Run("ring with some partitions in each state should correctly report the count", func(t *testing.T) { desc := &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Tokens: []uint32{1}, State: PartitionActive, StateTimestamp: 10}, 2: {Tokens: []uint32{2}, State: PartitionActive, StateTimestamp: 20}, 3: {Tokens: []uint32{3}, State: PartitionActive, StateTimestamp: 30}, @@ -70,9 +70,9 @@ func TestPartitionRingDesc_countPartitionsByState(t *testing.T) { 5: {Tokens: []uint32{5}, State: PartitionInactive, StateTimestamp: 50}, 6: {Tokens: []uint32{6}, State: PartitionPending, StateTimestamp: 60}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, }, } @@ -91,7 +91,7 @@ func TestPartitionRingDesc_countTokens(t *testing.T) { t.Run("ring with some partitions should return correct distances", func(t *testing.T) { desc := &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Tokens: []uint32{1000000, 3000000, 6000000}}, 2: {Tokens: []uint32{2000000, 4000000, 8000000}}, 3: {Tokens: []uint32{5000000, 9000000}}, @@ -110,7 +110,7 @@ func TestPartitionRingDesc_countTokens(t *testing.T) { t.Run("partitions with no tokens should be present in the result, with 0 distance", func(t *testing.T) { desc := &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Tokens: []uint32{1000000, 3000000, 6000000}}, 2: {Tokens: []uint32{2000000, 4000000, 8000000}}, 3: {Tokens: []uint32{5000000, 9000000}}, @@ -130,14 +130,14 @@ func TestPartitionRingDesc_AddOrUpdateOwner(t *testing.T) { t.Run("should add a new owner", func(t *testing.T) { desc := NewPartitionRingDesc() - require.True(t, desc.AddOrUpdateOwner("instance-1", OwnerActive, 1, now)) + require.True(t, desc.AddOrUpdateOwner("instance-1", OwnerState_OwnerActive, 1, now)) assert.Equal(t, &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, - Owners: map[string]OwnerDesc{ + Partitions: map[int32]*PartitionDesc{}, + Owners: map[string]*OwnerDesc{ "instance-1": { UpdatedTimestamp: now.Unix(), - State: OwnerActive, + State: OwnerState_OwnerActive, OwnedPartition: 1, }, }, @@ -146,17 +146,17 @@ func TestPartitionRingDesc_AddOrUpdateOwner(t *testing.T) { t.Run("should update an existing owner", func(t *testing.T) { desc := NewPartitionRingDesc() - require.True(t, desc.AddOrUpdateOwner("instance-1", OwnerActive, 1, now)) + require.True(t, desc.AddOrUpdateOwner("instance-1", OwnerState_OwnerActive, 1, now)) // Update the owner. - require.True(t, desc.AddOrUpdateOwner("instance-1", OwnerActive, 2, now.Add(time.Second))) + require.True(t, desc.AddOrUpdateOwner("instance-1", OwnerState_OwnerActive, 2, now.Add(time.Second))) assert.Equal(t, &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, - Owners: map[string]OwnerDesc{ + Partitions: map[int32]*PartitionDesc{}, + Owners: map[string]*OwnerDesc{ "instance-1": { UpdatedTimestamp: now.Add(time.Second).Unix(), - State: OwnerActive, + State: OwnerState_OwnerActive, OwnedPartition: 2, }, }, @@ -165,17 +165,17 @@ func TestPartitionRingDesc_AddOrUpdateOwner(t *testing.T) { t.Run("should be a no-op if the owner already exist", func(t *testing.T) { desc := NewPartitionRingDesc() - desc.AddOrUpdateOwner("instance-1", OwnerActive, 1, now) + desc.AddOrUpdateOwner("instance-1", OwnerState_OwnerActive, 1, now) // Update the owner. - require.False(t, desc.AddOrUpdateOwner("instance-1", OwnerActive, 1, now.Add(time.Second))) + require.False(t, desc.AddOrUpdateOwner("instance-1", OwnerState_OwnerActive, 1, now.Add(time.Second))) assert.Equal(t, &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, - Owners: map[string]OwnerDesc{ + Partitions: map[int32]*PartitionDesc{}, + Owners: map[string]*OwnerDesc{ "instance-1": { UpdatedTimestamp: now.Unix(), // Timestamp should not be updated. - State: OwnerActive, + State: OwnerState_OwnerActive, OwnedPartition: 1, }, }, @@ -192,139 +192,139 @@ func TestPartitionRingDesc_Merge_AddPartition(t *testing.T) { }{ "the first partition is added without owners": { local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, - Owners: map[string]OwnerDesc{}, + Partitions: map[int32]*PartitionDesc{}, + Owners: map[string]*OwnerDesc{}, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{}, + Owners: map[string]*OwnerDesc{}, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{}, + Owners: map[string]*OwnerDesc{}, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{}, + Owners: map[string]*OwnerDesc{}, }, }, "the first partition is added with owners": { local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, - Owners: map[string]OwnerDesc{}, + Partitions: map[int32]*PartitionDesc{}, + Owners: map[string]*OwnerDesc{}, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, }, }, }, "a new partition is added without owners": { local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{}, + Owners: map[string]*OwnerDesc{}, }, }, "a new partition is added with owners": { local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, }, @@ -341,7 +341,7 @@ func TestPartitionRingDesc_Merge_AddPartition(t *testing.T) { change, err := localCopy.Merge(incomingCopy, localCAS) require.NoError(t, err) - assert.Equal(t, testData.expectedUpdatedLocal, localCopy) + assert.EqualExportedValues(t, testData.expectedUpdatedLocal, localCopy) assert.Equal(t, testData.expectedChange, change) }) } @@ -358,129 +358,129 @@ func TestPartitionRingDesc_Merge_UpdatePartition(t *testing.T) { }{ "partition state changed with newer timestamp": { local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionInactive, StateTimestamp: 30}, // State changed with newer timestamp. }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionInactive, StateTimestamp: 30}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionInactive, StateTimestamp: 30}, }, - Owners: map[string]OwnerDesc{}, + Owners: map[string]*OwnerDesc{}, }, }, "partition state changed with older timestamp": { local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionInactive, StateTimestamp: 10}, // State changed with older timestamp. }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, expectedChange: nil, }, "partition state not changed but state timestamp updated with newer one": { local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 30}, // State timestamp updated with newer one. }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 30}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 15}, - "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 25}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 15}, + "ingester-zone-b-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 25}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 30}, }, - Owners: map[string]OwnerDesc{}, + Owners: map[string]*OwnerDesc{}, }, }, } @@ -496,7 +496,7 @@ func TestPartitionRingDesc_Merge_UpdatePartition(t *testing.T) { change, err := localCopy.Merge(incomingCopy, localCAS) require.NoError(t, err) - assert.Equal(t, testData.expectedUpdatedLocal, localCopy) + assert.EqualExportedValues(t, testData.expectedUpdatedLocal, localCopy) assert.Equal(t, testData.expectedChange, change) }) } @@ -517,72 +517,72 @@ func TestPartitionRingDesc_Merge_RemovePartition(t *testing.T) { "local change: partition removed and local partition state is not deleted yet": { localCAS: true, local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, // Partition 2 removed. }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionDeleted, StateTimestamp: now.Unix()}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionDeleted, StateTimestamp: now.Unix()}, }, - Owners: map[string]OwnerDesc{}, + Owners: map[string]*OwnerDesc{}, }, }, "local change: partition removed and local partition state is already deleted": { localCAS: true, local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionDeleted, StateTimestamp: 20}, // Local state is already deleted. }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, // Partition 2 removed. }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionDeleted, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedChange: nil, @@ -590,111 +590,111 @@ func TestPartitionRingDesc_Merge_RemovePartition(t *testing.T) { "incoming change: partition removed with newer timestamp": { localCAS: false, local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionDeleted, StateTimestamp: 30}, // Partition deleted with newer timestamp. }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionDeleted, StateTimestamp: 30}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionDeleted, StateTimestamp: 30}, }, - Owners: map[string]OwnerDesc{}, + Owners: map[string]*OwnerDesc{}, }, }, "incoming change: partition removed with equal timestamp, deletion should win": { localCAS: false, local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionDeleted, StateTimestamp: 20}, // Partition deleted with equal timestamp. }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionDeleted, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionDeleted, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{}, + Owners: map[string]*OwnerDesc{}, }, }, "incoming change: partition removed with older timestamp": { localCAS: false, local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionDeleted, StateTimestamp: 10}, // Partition deleted with older timestamp. }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedChange: nil, @@ -710,7 +710,7 @@ func TestPartitionRingDesc_Merge_RemovePartition(t *testing.T) { change, err := localCopy.mergeWithTime(incomingCopy, testData.localCAS, now) require.NoError(t, err) - assert.Equal(t, testData.expectedUpdatedLocal, localCopy) + assert.EqualExportedValues(t, testData.expectedUpdatedLocal, localCopy) assert.Equal(t, testData.expectedChange, change) }) } @@ -725,65 +725,65 @@ func TestPartitionRingDesc_Merge_AddOwner(t *testing.T) { }{ "add the first owner to a partition": { local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{}, + Owners: map[string]*OwnerDesc{}, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, + Partitions: map[int32]*PartitionDesc{}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, }, }, }, "add the second owner to a partition": { local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, - Owners: map[string]OwnerDesc{ - "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 20}, + Partitions: map[int32]*PartitionDesc{}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-b-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, }, @@ -800,7 +800,7 @@ func TestPartitionRingDesc_Merge_AddOwner(t *testing.T) { change, err := localCopy.Merge(incomingCopy, localCAS) require.NoError(t, err) - assert.Equal(t, testData.expectedUpdatedLocal, localCopy) + assert.EqualExportedValues(t, testData.expectedUpdatedLocal, localCopy) assert.Equal(t, testData.expectedChange, change) }) } @@ -821,72 +821,72 @@ func TestPartitionRingDesc_Merge_RemoveOwner(t *testing.T) { "local change: owner removed and local owner state is not deleted yet": { localCAS: true, local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, // Owner ingester-zone-a-1 removed. }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: now.Unix()}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerDeleted, UpdatedTimestamp: now.Unix()}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: now.Unix()}, + Partitions: map[int32]*PartitionDesc{}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerDeleted, UpdatedTimestamp: now.Unix()}, }, }, }, "local change: partition removed and local partition state is already deleted": { localCAS: true, local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: 20}, // Local state is already deleted. + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerDeleted, UpdatedTimestamp: 20}, // Local state is already deleted. }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, // Owner ingester-zone-a-1 removed. }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerDeleted, UpdatedTimestamp: 20}, }, }, expectedChange: nil, @@ -894,111 +894,111 @@ func TestPartitionRingDesc_Merge_RemoveOwner(t *testing.T) { "incoming change: owner removed with newer timestamp": { localCAS: false, local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: 30}, // Owner deleted with newer timestamp. + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerDeleted, UpdatedTimestamp: 30}, // Owner deleted with newer timestamp. }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: 30}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerDeleted, UpdatedTimestamp: 30}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: 30}, + Partitions: map[int32]*PartitionDesc{}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerDeleted, UpdatedTimestamp: 30}, }, }, }, "incoming change: owner removed with equal timestamp, deletion should win": { localCAS: false, local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: 20}, // Owner deleted with equal timestamp. + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerDeleted, UpdatedTimestamp: 20}, // Owner deleted with equal timestamp. }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerDeleted, UpdatedTimestamp: 20}, }, }, expectedChange: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: 20}, + Partitions: map[int32]*PartitionDesc{}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerDeleted, UpdatedTimestamp: 20}, }, }, }, "incoming change: owner removed with older timestamp": { localCAS: false, local: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, incoming: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerDeleted, UpdatedTimestamp: 10}, // Owner deleted with older timestamp. + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerDeleted, UpdatedTimestamp: 10}, // Owner deleted with older timestamp. }, }, expectedUpdatedLocal: &PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{ + Partitions: map[int32]*PartitionDesc{ 1: {Id: 1, Tokens: []uint32{1, 2, 3}, State: PartitionActive, StateTimestamp: 10}, 2: {Id: 2, Tokens: []uint32{4, 5, 6}, State: PartitionActive, StateTimestamp: 20}, }, - Owners: map[string]OwnerDesc{ - "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerActive, UpdatedTimestamp: 10}, - "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerActive, UpdatedTimestamp: 20}, + Owners: map[string]*OwnerDesc{ + "ingester-zone-a-0": {OwnedPartition: 1, State: OwnerState_OwnerActive, UpdatedTimestamp: 10}, + "ingester-zone-a-1": {OwnedPartition: 2, State: OwnerState_OwnerActive, UpdatedTimestamp: 20}, }, }, expectedChange: nil, @@ -1014,7 +1014,7 @@ func TestPartitionRingDesc_Merge_RemoveOwner(t *testing.T) { change, err := localCopy.mergeWithTime(incomingCopy, testData.localCAS, now) require.NoError(t, err) - assert.Equal(t, testData.expectedUpdatedLocal, localCopy) + assert.EqualExportedValues(t, testData.expectedUpdatedLocal, localCopy) assert.Equal(t, testData.expectedChange, change) }) } @@ -1059,12 +1059,12 @@ func TestPartitionRingDesc_Merge_EdgeCases(t *testing.T) { // Then the local process receives an incoming update with some partitions and owners. incoming := NewPartitionRingDesc() incoming.AddPartition(1, PartitionActive, time.Unix(10, 0)) - incoming.AddOrUpdateOwner("instance-1", OwnerActive, 1, time.Unix(10, 0)) + incoming.AddOrUpdateOwner("instance-1", OwnerState_OwnerActive, 1, time.Unix(10, 0)) change, err := local.Merge(incoming, false) require.NoError(t, err) - assert.Equal(t, incoming, local) - assert.Equal(t, incoming, change) + assert.EqualExportedValues(t, incoming, local) + assert.EqualExportedValues(t, incoming, change) }) } @@ -1076,9 +1076,9 @@ func TestPartitionRingDesc_RemoveTombstones(t *testing.T) { desc.AddPartition(1, PartitionActive, now.Add(1*time.Second)) desc.AddPartition(2, PartitionInactive, now.Add(2*time.Second)) desc.AddPartition(3, PartitionDeleted, now.Add(3*time.Second)) - desc.AddOrUpdateOwner("owner-1", OwnerActive, 1, now.Add(4*time.Second)) - desc.AddOrUpdateOwner("owner-2", OwnerActive, 2, now.Add(4*time.Second)) - desc.AddOrUpdateOwner("owner-3", OwnerDeleted, 3, now.Add(4*time.Second)) + desc.AddOrUpdateOwner("owner-1", OwnerState_OwnerActive, 1, now.Add(4*time.Second)) + desc.AddOrUpdateOwner("owner-2", OwnerState_OwnerActive, 2, now.Add(4*time.Second)) + desc.AddOrUpdateOwner("owner-3", OwnerState_OwnerDeleted, 3, now.Add(4*time.Second)) return desc } @@ -1120,10 +1120,10 @@ func TestPartitionRingDesc_PartitionOwnersCountUpdatedBefore(t *testing.T) { desc := NewPartitionRingDesc() desc.AddPartition(1, PartitionActive, now) desc.AddPartition(2, PartitionActive, now) - desc.AddOrUpdateOwner("owner-1-a", OwnerActive, 1, now) - desc.AddOrUpdateOwner("owner-1-b", OwnerActive, 1, now.Add(-1*time.Second)) - desc.AddOrUpdateOwner("owner-1-c", OwnerActive, 1, now.Add(-2*time.Second)) - desc.AddOrUpdateOwner("owner-2-a", OwnerActive, 2, now.Add(-3*time.Second)) + desc.AddOrUpdateOwner("owner-1-a", OwnerState_OwnerActive, 1, now) + desc.AddOrUpdateOwner("owner-1-b", OwnerState_OwnerActive, 1, now.Add(-1*time.Second)) + desc.AddOrUpdateOwner("owner-1-c", OwnerState_OwnerActive, 1, now.Add(-2*time.Second)) + desc.AddOrUpdateOwner("owner-2-a", OwnerState_OwnerActive, 2, now.Add(-3*time.Second)) assert.Equal(t, 2, desc.PartitionOwnersCountUpdatedBefore(1, now)) assert.Equal(t, 1, desc.PartitionOwnersCountUpdatedBefore(1, now.Add(-1*time.Second))) diff --git a/ring/partition_ring_test.go b/ring/partition_ring_test.go index 145274cc2..c4c12322d 100644 --- a/ring/partition_ring_test.go +++ b/ring/partition_ring_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/exp/maps" + "google.golang.org/protobuf/proto" ) func TestPartitionRing_ActivePartitionForKey(t *testing.T) { @@ -624,7 +625,7 @@ func TestPartitionRing_ShuffleShardWithLookback(t *testing.T) { var ok bool event.partitionDesc.Tokens, ok = testData.partitionTokens[event.partitionID] require.True(t, ok, "no tokens for partition %d", event.partitionID) - ringDesc.Partitions[event.partitionID] = event.partitionDesc + ringDesc.Partitions[event.partitionID] = proto.Clone(&event.partitionDesc).(*PartitionDesc) case remove: delete(ringDesc.Partitions, event.partitionID) case test: @@ -1048,11 +1049,11 @@ func TestPartitionRingGetTokenRangesForPartition(t *testing.T) { for testName, testData := range tests { t.Run(testName, func(t *testing.T) { ringDesc := PartitionRingDesc{ - Partitions: map[int32]PartitionDesc{}, + Partitions: map[int32]*PartitionDesc{}, } for p, t := range testData.partitionTokens { - ringDesc.Partitions[int32(p)] = PartitionDesc{ + ringDesc.Partitions[int32(p)] = &PartitionDesc{ Tokens: t, } } diff --git a/ring/ring.pb.go b/ring/ring.pb.go index 1c5007820..34b377ae3 100644 --- a/ring/ring.pb.go +++ b/ring/ring.pb.go @@ -293,10 +293,10 @@ var file_ring_ring_proto_rawDesc = []byte{ 0x45, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x4c, 0x45, 0x41, 0x56, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x45, 0x4e, 0x44, 0x49, 0x4e, 0x47, 0x10, 0x02, 0x12, 0x0b, 0x0a, 0x07, 0x4a, 0x4f, 0x49, 0x4e, 0x49, 0x4e, 0x47, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x4c, 0x45, - 0x46, 0x54, 0x10, 0x04, 0x42, 0x29, 0x5a, 0x27, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x61, 0x66, 0x61, 0x6e, 0x61, 0x2f, 0x63, 0x6f, 0x72, 0x74, 0x65, - 0x78, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x72, 0x69, 0x6e, 0x67, 0x3b, 0x72, 0x69, 0x6e, 0x67, 0x62, - 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x46, 0x54, 0x10, 0x04, 0x42, 0x24, 0x5a, 0x22, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x67, 0x72, 0x61, 0x66, 0x61, 0x6e, 0x61, 0x2f, 0x64, 0x73, 0x6b, 0x69, 0x74, + 0x2f, 0x72, 0x69, 0x6e, 0x67, 0x3b, 0x72, 0x69, 0x6e, 0x67, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/ring/ring.proto b/ring/ring.proto index 13a62fb3a..dc09aeaf2 100644 --- a/ring/ring.proto +++ b/ring/ring.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package ring; -option go_package = "github.com/grafana/cortex/pkg/ring;ring"; +option go_package = "github.com/grafana/dskit/ring;ring"; // Desc is the top-level type used to model a ring, containing information for individual instances. message Desc { From da175eaec0136be47c6185d233890d07300e1a55 Mon Sep 17 00:00:00 2001 From: francoposa Date: Wed, 22 Jan 2025 10:54:15 -0800 Subject: [PATCH 19/22] WIP improving benchmark perf --- ring/ring.go | 5 ++--- ring/ring_test.go | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ring/ring.go b/ring/ring.go index a481affaa..912723be9 100644 --- a/ring/ring.go +++ b/ring/ring.go @@ -1075,11 +1075,10 @@ func (r *Ring) getCachedShuffledSubring(identifier string, size int) *Ring { // Update instance states and timestamps. We know that the topology is the same, // so zones and tokens are equal. - for name, cachedIng := range cached.ringDesc.GetIngesterVals() { - ing, _ := r.ringDesc.GetIngesterVal(name) + for name, cachedIng := range cached.ringDesc.GetIngesters() { + ing := r.ringDesc.GetIngester(name) cachedIng.State = ing.State cachedIng.Timestamp = ing.Timestamp - cached.ringDesc.SetIngesterVal(name, cachedIng) } return cached } diff --git a/ring/ring_test.go b/ring/ring_test.go index e8eb04dbf..8830cdd64 100644 --- a/ring/ring_test.go +++ b/ring/ring_test.go @@ -3427,6 +3427,29 @@ func benchmarkShuffleSharding(b *testing.B, numInstances, numZones, numTokens, s } } +//func BenchmarkRing_Clone(b *testing.B) { +// for _, numInstances := range []int{50, 100, 1000} { +// for _, numZones := range []int{1, 3} { +// for _, shardSize := range []int{0, 3, 10, 30, 100, 1000} { +// b.Run(fmt.Sprintf("num instances = %d, num zones = %d, shard size = %d", numInstances, numZones, shardSize), func(b *testing.B) { +// benchmarkClone(b, numInstances, numZones, 128, shardSize, false) +// }) +// } +// } +// } +//} +// +//func benchmarkClone(b *testing.B, numInstances, numZones, numTokens, shardSize int, cache bool) { +// // Initialise the ring. +// ringDesc := &Desc{Ingesters: generateRingInstances(initTokenGenerator(b), numInstances, numZones, numTokens)} +// +// b.ResetTimer() +// +// for n := 0; n < b.N; n++ { +// ringDesc.Clone() +// } +//} + func BenchmarkRing_Get(b *testing.B) { benchCases := map[string]struct { numInstances int From 9b827a7dbf5bda04602232fa2b0a215fa26b7200 Mon Sep 17 00:00:00 2001 From: francoposa Date: Wed, 22 Jan 2025 20:26:36 -0800 Subject: [PATCH 20/22] removing a few more usages of value methods --- ring/model.go | 4 ++-- ring/ring.go | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ring/model.go b/ring/model.go index 72f2dcfa3..e24f13233 100644 --- a/ring/model.go +++ b/ring/model.go @@ -141,9 +141,9 @@ func (d *Desc) ClaimTokens(from, to string) Tokens { // FindIngestersByState returns the list of ingesters in the given state func (d *Desc) FindIngestersByState(state InstanceState) []InstanceDesc { var result []InstanceDesc - for _, ing := range d.GetIngesterVals() { + for _, ing := range d.GetIngesters() { if ing.State == state { - result = append(result, ing) + result = append(result, *ing) } } return result diff --git a/ring/ring.go b/ring/ring.go index 912723be9..760f2fb8e 100644 --- a/ring/ring.go +++ b/ring/ring.go @@ -526,9 +526,9 @@ func (r *Ring) GetAllHealthy(op Operation) (ReplicationSet, error) { now := time.Now() instances := make([]InstanceDesc, 0, len(r.ringDesc.Ingesters)) - for _, instance := range r.ringDesc.GetIngesterVals() { - if r.IsHealthy(&instance, op, now) { - instances = append(instances, instance) + for _, instance := range r.ringDesc.GetIngesters() { + if r.IsHealthy(instance, op, now) { + instances = append(instances, *instance) } } @@ -552,9 +552,9 @@ func (r *Ring) GetReplicationSetForOperation(op Operation) (ReplicationSet, erro zoneFailures := make(map[string]struct{}) now := time.Now() - for _, instance := range r.ringDesc.GetIngesterVals() { - if r.IsHealthy(&instance, op, now) { - healthyInstances = append(healthyInstances, instance) + for _, instance := range r.ringDesc.GetIngesters() { + if r.IsHealthy(instance, op, now) { + healthyInstances = append(healthyInstances, *instance) } else { zoneFailures[instance.Zone] = struct{}{} } @@ -670,9 +670,9 @@ func (r *Ring) updateRingMetrics() { oldestTimestampByState[s] = 0 } - for _, instance := range r.ringDesc.GetIngesterVals() { + for _, instance := range r.ringDesc.GetIngesters() { s := instance.State.String() - if !r.IsHealthy(&instance, Reporting, time.Now()) { + if !r.IsHealthy(instance, Reporting, time.Now()) { s = unhealthy } numByState[s]++ @@ -1130,11 +1130,10 @@ func (r *Ring) getCachedShuffledSubringWithLookback(identifier string, size int, // Update instance states and timestamps. We know that the topology is the same, // so zones and tokens are equal. - for name, cachedIng := range cachedSubring.ringDesc.GetIngesterVals() { - ing, _ := r.ringDesc.GetIngesterVal(name) + for name, cachedIng := range cachedSubring.ringDesc.GetIngesters() { + ing := r.ringDesc.GetIngester(name) cachedIng.State = ing.State cachedIng.Timestamp = ing.Timestamp - cachedSubring.ringDesc.SetIngesterVal(name, cachedIng) } return cachedSubring From c584f3d832459569c863e5eeeda868c506747244 Mon Sep 17 00:00:00 2001 From: francoposa Date: Wed, 22 Jan 2025 21:35:41 -0800 Subject: [PATCH 21/22] Revert "removing a few more usages of value methods" This reverts commit 9b827a7dbf5bda04602232fa2b0a215fa26b7200. --- ring/model.go | 4 ++-- ring/ring.go | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ring/model.go b/ring/model.go index e24f13233..72f2dcfa3 100644 --- a/ring/model.go +++ b/ring/model.go @@ -141,9 +141,9 @@ func (d *Desc) ClaimTokens(from, to string) Tokens { // FindIngestersByState returns the list of ingesters in the given state func (d *Desc) FindIngestersByState(state InstanceState) []InstanceDesc { var result []InstanceDesc - for _, ing := range d.GetIngesters() { + for _, ing := range d.GetIngesterVals() { if ing.State == state { - result = append(result, *ing) + result = append(result, ing) } } return result diff --git a/ring/ring.go b/ring/ring.go index 760f2fb8e..912723be9 100644 --- a/ring/ring.go +++ b/ring/ring.go @@ -526,9 +526,9 @@ func (r *Ring) GetAllHealthy(op Operation) (ReplicationSet, error) { now := time.Now() instances := make([]InstanceDesc, 0, len(r.ringDesc.Ingesters)) - for _, instance := range r.ringDesc.GetIngesters() { - if r.IsHealthy(instance, op, now) { - instances = append(instances, *instance) + for _, instance := range r.ringDesc.GetIngesterVals() { + if r.IsHealthy(&instance, op, now) { + instances = append(instances, instance) } } @@ -552,9 +552,9 @@ func (r *Ring) GetReplicationSetForOperation(op Operation) (ReplicationSet, erro zoneFailures := make(map[string]struct{}) now := time.Now() - for _, instance := range r.ringDesc.GetIngesters() { - if r.IsHealthy(instance, op, now) { - healthyInstances = append(healthyInstances, *instance) + for _, instance := range r.ringDesc.GetIngesterVals() { + if r.IsHealthy(&instance, op, now) { + healthyInstances = append(healthyInstances, instance) } else { zoneFailures[instance.Zone] = struct{}{} } @@ -670,9 +670,9 @@ func (r *Ring) updateRingMetrics() { oldestTimestampByState[s] = 0 } - for _, instance := range r.ringDesc.GetIngesters() { + for _, instance := range r.ringDesc.GetIngesterVals() { s := instance.State.String() - if !r.IsHealthy(instance, Reporting, time.Now()) { + if !r.IsHealthy(&instance, Reporting, time.Now()) { s = unhealthy } numByState[s]++ @@ -1130,10 +1130,11 @@ func (r *Ring) getCachedShuffledSubringWithLookback(identifier string, size int, // Update instance states and timestamps. We know that the topology is the same, // so zones and tokens are equal. - for name, cachedIng := range cachedSubring.ringDesc.GetIngesters() { - ing := r.ringDesc.GetIngester(name) + for name, cachedIng := range cachedSubring.ringDesc.GetIngesterVals() { + ing, _ := r.ringDesc.GetIngesterVal(name) cachedIng.State = ing.State cachedIng.Timestamp = ing.Timestamp + cachedSubring.ringDesc.SetIngesterVal(name, cachedIng) } return cachedSubring From 8c7f0bad830da8d391baf4fcbdde10c27f8fa6d2 Mon Sep 17 00:00:00 2001 From: francoposa Date: Thu, 23 Jan 2025 15:02:56 -0800 Subject: [PATCH 22/22] fix race conditions & performance for usages of values map compat with mutexes & pointers instead --- ring/model.go | 4 ++-- ring/ring.go | 31 +++++++++++++++---------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/ring/model.go b/ring/model.go index 72f2dcfa3..e24f13233 100644 --- a/ring/model.go +++ b/ring/model.go @@ -141,9 +141,9 @@ func (d *Desc) ClaimTokens(from, to string) Tokens { // FindIngestersByState returns the list of ingesters in the given state func (d *Desc) FindIngestersByState(state InstanceState) []InstanceDesc { var result []InstanceDesc - for _, ing := range d.GetIngesterVals() { + for _, ing := range d.GetIngesters() { if ing.State == state { - result = append(result, ing) + result = append(result, *ing) } } return result diff --git a/ring/ring.go b/ring/ring.go index 912723be9..f90560185 100644 --- a/ring/ring.go +++ b/ring/ring.go @@ -526,9 +526,9 @@ func (r *Ring) GetAllHealthy(op Operation) (ReplicationSet, error) { now := time.Now() instances := make([]InstanceDesc, 0, len(r.ringDesc.Ingesters)) - for _, instance := range r.ringDesc.GetIngesterVals() { - if r.IsHealthy(&instance, op, now) { - instances = append(instances, instance) + for _, instance := range r.ringDesc.GetIngesters() { + if r.IsHealthy(instance, op, now) { + instances = append(instances, *instance) } } @@ -552,9 +552,9 @@ func (r *Ring) GetReplicationSetForOperation(op Operation) (ReplicationSet, erro zoneFailures := make(map[string]struct{}) now := time.Now() - for _, instance := range r.ringDesc.GetIngesterVals() { - if r.IsHealthy(&instance, op, now) { - healthyInstances = append(healthyInstances, instance) + for _, instance := range r.ringDesc.GetIngesters() { + if r.IsHealthy(instance, op, now) { + healthyInstances = append(healthyInstances, *instance) } else { zoneFailures[instance.Zone] = struct{}{} } @@ -670,9 +670,9 @@ func (r *Ring) updateRingMetrics() { oldestTimestampByState[s] = 0 } - for _, instance := range r.ringDesc.GetIngesterVals() { + for _, instance := range r.ringDesc.GetIngesters() { s := instance.State.String() - if !r.IsHealthy(&instance, Reporting, time.Now()) { + if !r.IsHealthy(instance, Reporting, time.Now()) { s = unhealthy } numByState[s]++ @@ -1056,8 +1056,8 @@ func (r *Ring) getCachedShuffledSubring(identifier string, size int) *Ring { return nil } - r.mtx.RLock() - defer r.mtx.RUnlock() + r.mtx.Lock() + defer r.mtx.Unlock() // if shuffledSubringCache map is nil, reading it returns default value (nil pointer). cached := r.shuffledSubringCache[subringCacheKey{identifier: identifier, shardSize: size}] @@ -1104,8 +1104,8 @@ func (r *Ring) getCachedShuffledSubringWithLookback(identifier string, size int, return nil } - r.mtx.RLock() - defer r.mtx.RUnlock() + r.mtx.Lock() + defer r.mtx.Unlock() cached, ok := r.shuffledSubringWithLookbackCache[subringCacheKey{identifier: identifier, shardSize: size, lookbackPeriod: lookbackPeriod}] if !ok { @@ -1130,11 +1130,10 @@ func (r *Ring) getCachedShuffledSubringWithLookback(identifier string, size int, // Update instance states and timestamps. We know that the topology is the same, // so zones and tokens are equal. - for name, cachedIng := range cachedSubring.ringDesc.GetIngesterVals() { - ing, _ := r.ringDesc.GetIngesterVal(name) + for name, cachedIng := range cachedSubring.ringDesc.GetIngesters() { + ing := r.ringDesc.GetIngester(name) cachedIng.State = ing.State cachedIng.Timestamp = ing.Timestamp - cachedSubring.ringDesc.SetIngesterVal(name, cachedIng) } return cachedSubring @@ -1282,7 +1281,7 @@ func (r *Ring) ZonesCount() int { func (r *Ring) readOnlyInstanceCount() int { r.mtx.RLock() c := 0 - for _, i := range r.ringDesc.GetIngesterVals() { + for _, i := range r.ringDesc.GetIngesters() { if i.ReadOnly { c++ }