From 651c4ba3f94a3820ef413a50b951d68ef260de70 Mon Sep 17 00:00:00 2001 From: searKing <471030698@qq.com> Date: Wed, 30 Oct 2024 19:55:36 +0800 Subject: [PATCH] refactor(exp/container/hashring): private GetMaxHashKey. --- go/exp/container/hashring/hashring.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/go/exp/container/hashring/hashring.go b/go/exp/container/hashring/hashring.go index 1084c220..d31acec9 100644 --- a/go/exp/container/hashring/hashring.go +++ b/go/exp/container/hashring/hashring.go @@ -20,7 +20,6 @@ package hashring import ( - "fmt" "maps" "math" "slices" @@ -93,13 +92,13 @@ func (c *NodeLocator[Node]) getPrimaryNode(name string) (Node, bool) { return c.getNodeForHashKey(c.getHashKey(name)) } -// GetMaxHashKey returns the last available node's HashKey +// getMaxHashKey returns the last available node's HashKey // that is, Maximum HashKey in the Hash Cycle -func (c *NodeLocator[Node]) GetMaxHashKey() (uint32, error) { +func (c *NodeLocator[Node]) getMaxHashKey() (key uint32, ok bool) { if len(c.sortedKeys) == 0 { - return 0, fmt.Errorf("NoSuchElementException") + return 0, false } - return c.sortedKeys[len(c.sortedKeys)-1], nil + return c.sortedKeys[len(c.sortedKeys)-1], true } // getNodeForHashKey returns the first available node since iterateHashKey, such as HASH(“127.0.0.1:11311-0”)