From 169a1e9602a67b0eacc5b6b3e8db5b031851c27a Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Mon, 3 Jun 2024 13:56:38 +0000 Subject: [PATCH] rings: introduce RingID and its values Signed-off-by: Alejandro Mery --- pkg/rings/rings.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/rings/rings.go b/pkg/rings/rings.go index 9626120..ae75e1e 100644 --- a/pkg/rings/rings.go +++ b/pkg/rings/rings.go @@ -11,6 +11,17 @@ import ( ) const ( + // UnspecifiedRingID is the zero value of RingID and not considered + // valid. + UnspecifiedRingID RingID = iota + RingZeroID // RingZeroID is the RingID for RingZero (backbone) + RingOneID // RingOneID is the RingID for RingOne (local zone) + RingTwoID // RingTwoID is the RingID for RingTwo (region services) + RingThreeID // RingThreeID is the RingID for RingThree (region cluster pods) + + // RingMax indicates the highest [Ring] identifier + RingMax = RingThreeID + // RegionMax indicates the highest number that can be used for a [RegionID]. RegionMax = (1 << 4) - 1 // ZoneMax indicates the highest number that can be used for a [ZoneID]. @@ -33,6 +44,21 @@ const ( RingThreeBits = 12 ) +// RingID identifies a Ring +type RingID int + +// Valid tells a [RingID] is within the valid range. +func (n RingID) Valid() bool { return n > 0 && n <= RingMax } + +func (n RingID) String() string { + return idString(n) +} + +// A Ring identifies what ring an address belongs to +type Ring interface { + ID() RingID +} + // RegionID is the identifier of a region, valid between 1 and [RegionMax]. type RegionID int