[VOL-5486] Fix deprecated versions
Change-Id: I3e03ea246020547ae75fa92ce8cf5cbba7e8f3bb
Signed-off-by: Abhay Kumar <abhay.kumar@radisys.com>
diff --git a/vendor/github.com/buraksezer/consistent/.gitignore b/vendor/github.com/buraksezer/consistent/.gitignore
index a1338d6..9bb118b 100644
--- a/vendor/github.com/buraksezer/consistent/.gitignore
+++ b/vendor/github.com/buraksezer/consistent/.gitignore
@@ -4,6 +4,9 @@
*.so
*.dylib
+# Vim creates this
+*.swp
+
# Test binary, build with `go test -c`
*.test
@@ -12,3 +15,10 @@
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
+
+# GoLand creates this
+.idea/
+
+# OSX creates this
+.DS_Store
+
diff --git a/vendor/github.com/buraksezer/consistent/LICENSE b/vendor/github.com/buraksezer/consistent/LICENSE
index e470334..9b28a31 100644
--- a/vendor/github.com/buraksezer/consistent/LICENSE
+++ b/vendor/github.com/buraksezer/consistent/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2018 Burak Sezer
+Copyright (c) 2018-2021 Burak Sezer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/vendor/github.com/buraksezer/consistent/README.md b/vendor/github.com/buraksezer/consistent/README.md
index bde53d1..85de75b 100644
--- a/vendor/github.com/buraksezer/consistent/README.md
+++ b/vendor/github.com/buraksezer/consistent/README.md
@@ -1,6 +1,6 @@
consistent
==========
-[](https://godoc.org/github.com/buraksezer/consistent) [](https://travis-ci.org/buraksezer/consistent) [](http://gocover.io/github.com/buraksezer/consistent) [](https://goreportcard.com/report/github.com/buraksezer/consistent) [](https://opensource.org/licenses/MIT) [](https://github.com/avelino/awesome-go)
+[](https://pkg.go.dev/github.com/buraksezer/consistent)   [](http://gocover.io/github.com/buraksezer/consistent) [](https://goreportcard.com/report/github.com/buraksezer/consistent) [](https://opensource.org/licenses/MIT) [](https://github.com/avelino/awesome-go)
This library provides a consistent hashing function which simultaneously achieves both uniformity and consistency.
@@ -15,6 +15,7 @@
----------------
- [Overview](#overview)
+- [Notable Users](#notable-users)
- [Install](#install)
- [Configuration](#configuration)
- [Usage](#usage)
@@ -45,6 +46,24 @@
Note that the number of partitions cannot be changed after creation.
+Notable Users
+-------------
+
+[buraksezer/consistent](https://github.com/buraksezer/consistent) is used at production by the following projects:
+
+* [buraksezer/olric](https://github.com/buraksezer/olric): Embeddable, distributed data structures in Go.
+* [open-telemetry/opentelemetry-operator](https://github.com/open-telemetry/opentelemetry-operator): Kubernetes Operator for OpenTelemetry Collector.
+* [megaease/easegress](https://github.com/megaease/easegress): A Cloud Native traffic orchestration system.
+* [chrislusf/seaweedfs](https://github.com/chrislusf/seaweedfs): SeaweedFS is a distributed storage system for blobs, objects, files, and data warehouse, to store and serve billions of files fast!.
+* [erda-project/erda](https://github.com/erda-project/erda): An enterprise-grade Cloud-Native application platform for Kubernetes.
+* [celo-org/celo-blockchain](https://github.com/celo-org/celo-blockchain): Global payments infrastructure built for mobile.
+* [koderover/zadig](https://github.com/koderover/zadig): Zadig is a cloud native, distributed, developer-oriented continuous delivery product.
+* [mason-leap-lab/infinicache](https://github.com/mason-leap-lab/infinicache): InfiniCache: A cost-effective memory cache that is built atop ephemeral serverless functions.
+* [opencord/voltha-lib-go](https://github.com/opencord/voltha-lib-go): Voltha common library code.
+* [kubeedge/edgemesh](https://github.com/kubeedge/edgemesh): Simplified network and services for edge applications.
+* [authorizer-tech/access-controller](https://github.com/authorizer-tech/access-controller) An implementation of a distributed access-control server that is based on Google Zanzibar - "Google's Consistent, Global Authorization System.
+* [Conflux-Chain/confura](https://github.com/Conflux-Chain/confura) Implementation of an Ethereum Infura equivalent public RPC service on Conflux Network.
+
Install
-------
diff --git a/vendor/github.com/buraksezer/consistent/consistent.go b/vendor/github.com/buraksezer/consistent/consistent.go
index a1446d6..071dc8a 100644
--- a/vendor/github.com/buraksezer/consistent/consistent.go
+++ b/vendor/github.com/buraksezer/consistent/consistent.go
@@ -1,4 +1,4 @@
-// Copyright (c) 2018 Burak Sezer
+// Copyright (c) 2018-2022 Burak Sezer
// All rights reserved.
//
// This code is licensed under the MIT License.
@@ -21,35 +21,39 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-// Package consistent provides a consistent hashing function with bounded loads.
-// For more information about the underlying algorithm, please take a look at
-// https://research.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html
+// Package consistent provides a consistent hashing function with bounded loads. This implementation also adds
+// partitioning logic on top of the original algorithm. For more information about the underlying algorithm,
+// please take a look at https://research.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html
//
// Example Use:
-// cfg := consistent.Config{
-// PartitionCount: 71,
-// ReplicationFactor: 20,
-// Load: 1.25,
-// Hasher: hasher{},
+//
+// cfg := consistent.Config{
+// PartitionCount: 71,
+// ReplicationFactor: 20,
+// Load: 1.25,
+// Hasher: hasher{},
// }
//
-// // Create a new consistent object
-// // You may call this with a list of members
-// // instead of adding them one by one.
+// Now you can create a new Consistent instance. This function can take a list of the members.
+//
// c := consistent.New(members, cfg)
//
-// // myMember struct just needs to implement a String method.
-// // New/Add/Remove distributes partitions among members using the algorithm
-// // defined on Google Research Blog.
+// In the following sample, you add a new Member to the consistent hash ring. myMember is just a Go struct that
+// implements the Member interface. You should know that modifying the consistent hash ring distributes partitions among
+// members using the algorithm defined on Google Research Blog.
+//
// c.Add(myMember)
//
-// key := []byte("my-key")
-// // LocateKey hashes the key and calculates partition ID with
-// // this modulo operation: MOD(hash result, partition count)
-// // The owner of the partition is already calculated by New/Add/Remove.
-// // LocateKey just returns the member which's responsible for the key.
-// member := c.LocateKey(key)
+// Remove a member from the consistent hash ring:
//
+// c.Remove(member-name)
+//
+// LocateKey hashes the key and calculates partition ID with this modulo operation: MOD(hash result, partition count)
+// The owner of the partition is already calculated by New/Add/Remove. LocateKey just returns the member that is responsible
+// for the key.
+//
+// key := []byte("my-key")
+// member := c.LocateKey(key)
package consistent
import (
@@ -61,15 +65,16 @@
"sync"
)
-var (
- //ErrInsufficientMemberCount represents an error which means there are not enough members to complete the task.
- ErrInsufficientMemberCount = errors.New("insufficient member count")
-
- // ErrMemberNotFound represents an error which means requested member could not be found in consistent hash ring.
- ErrMemberNotFound = errors.New("member could not be found in ring")
+const (
+ DefaultPartitionCount int = 271
+ DefaultReplicationFactor int = 20
+ DefaultLoad float64 = 1.25
)
-// Hasher is responsible for generating unsigned, 64 bit hash of provided byte slice.
+// ErrInsufficientMemberCount represents an error which means there are not enough members to complete the task.
+var ErrInsufficientMemberCount = errors.New("insufficient member count")
+
+// Hasher is responsible for generating unsigned, 64-bit hash of provided byte slice.
// Hasher should minimize collisions (generating same hash for different byte slice)
// and while performance is also important fast functions are preferable (i.e.
// you can use FarmHash family).
@@ -84,7 +89,7 @@
// Config represents a structure to control consistent package.
type Config struct {
- // Hasher is responsible for generating unsigned, 64 bit hash of provided byte slice.
+ // Hasher is responsible for generating unsigned, 64-bit hash of provided byte slice.
Hasher Hasher
// Keys are distributed among partitions. Prime numbers are good to
@@ -116,16 +121,26 @@
// New creates and returns a new Consistent object.
func New(members []Member, config Config) *Consistent {
+ if config.Hasher == nil {
+ panic("Hasher cannot be nil")
+ }
+ if config.PartitionCount == 0 {
+ config.PartitionCount = DefaultPartitionCount
+ }
+ if config.ReplicationFactor == 0 {
+ config.ReplicationFactor = DefaultReplicationFactor
+ }
+ if config.Load == 0 {
+ config.Load = DefaultLoad
+ }
+
c := &Consistent{
config: config,
members: make(map[string]*Member),
partitionCount: uint64(config.PartitionCount),
ring: make(map[uint64]*Member),
}
- if config.Hasher == nil {
- panic("Hasher cannot be nil")
- }
- // TODO: Check configuration here
+
c.hasher = config.Hasher
for _, member := range members {
c.add(member)
@@ -136,7 +151,7 @@
return c
}
-// GetMembers returns a thread-safe copy of members.
+// GetMembers returns a thread-safe copy of members. If there are no members, it returns an empty slice of Member.
func (c *Consistent) GetMembers() []Member {
c.mu.RLock()
defer c.mu.RUnlock()
@@ -151,12 +166,23 @@
// AverageLoad exposes the current average load.
func (c *Consistent) AverageLoad() float64 {
+ c.mu.RLock()
+ defer c.mu.RUnlock()
+
+ return c.averageLoad()
+}
+
+func (c *Consistent) averageLoad() float64 {
+ if len(c.members) == 0 {
+ return 0
+ }
+
avgLoad := float64(c.partitionCount/uint64(len(c.members))) * c.config.Load
return math.Ceil(avgLoad)
}
func (c *Consistent) distributeWithLoad(partID, idx int, partitions map[int]*Member, loads map[string]float64) {
- avgLoad := c.AverageLoad()
+ avgLoad := c.averageLoad()
var count int
for {
count++
@@ -285,6 +311,11 @@
c.mu.RLock()
defer c.mu.RUnlock()
+ return c.getPartitionOwner(partID)
+}
+
+// getPartitionOwner returns the owner of the given partition. It's not thread-safe.
+func (c *Consistent) getPartitionOwner(partID int) Member {
member, ok := c.partitions[partID]
if !ok {
return nil
@@ -303,15 +334,15 @@
c.mu.RLock()
defer c.mu.RUnlock()
- res := []Member{}
+ var res []Member
if count > len(c.members) {
return res, ErrInsufficientMemberCount
}
var ownerKey uint64
- owner := c.GetPartitionOwner(partID)
+ owner := c.getPartitionOwner(partID)
// Hash and sort all the names.
- keys := []uint64{}
+ var keys []uint64
kmems := make(map[uint64]*Member)
for name, member := range c.members {
key := c.hasher.Sum64([]byte(name))