MCPcopy Create free account
hub / github.com/Permify/permify / New

Function New

pkg/consistent/consistent.go:94–125  ·  view source on GitHub ↗

New initializes and returns a new instance of the Consistent struct. It takes a Config parameter and applies default values for any unset fields.

(config Config)

Source from the content-addressed store, hash-verified

92// New initializes and returns a new instance of the Consistent struct.
93// It takes a Config parameter and applies default values for any unset fields.
94func New(config Config) *Consistent {
95 // Ensure the Hasher is not nil; a nil Hasher would make consistent hashing unusable.
96 if config.Hasher == nil {
97 panic("Hasher cannot be nil")
98 }
99
100 // Set default values for partition count, replication factor, load, and picker width if not provided.
101 if config.PartitionCount == 0 {
102 config.PartitionCount = DefaultPartitionCount
103 }
104 if config.ReplicationFactor == 0 {
105 config.ReplicationFactor = DefaultReplicationFactor
106 }
107 if config.Load == 0 {
108 config.Load = DefaultLoad
109 }
110 if config.PickerWidth == 0 {
111 config.PickerWidth = DefaultPickerWidth
112 }
113
114 // Initialize a new Consistent instance with the provided configuration.
115 c := &Consistent{
116 config: config,
117 members: make(map[string]*Member),
118 partitionCount: uint64(config.PartitionCount),
119 ring: make(map[uint64]*Member),
120 }
121
122 // Assign the provided Hasher implementation to the instance.
123 c.hasher = config.Hasher
124 return c
125}
126
127// Members returns a slice of all the members currently in the consistent hash ring.
128// It safely retrieves the members using a read lock to prevent data races while

Callers 4

UpdateClientConnStateMethod · 0.92
balancer_test.goFile · 0.92
picker_test.goFile · 0.92
consistent_test.goFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected