forked from dropbox/godropbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatic_shard_manager.go
39 lines (31 loc) · 918 Bytes
/
static_shard_manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package memcache
import (
"log"
"github.com/dropbox/godropbox/net2"
)
// A shard manager that returns connections from a static list of memcache
// shards. NOTE: This is only for illustration purposes. DO NOT USE IN
// PRODUCTION.
type StaticShardManager struct {
BaseShardManager
}
// This creates a StaticShardManager, which returns connections from a static
// list of memcache shards.
func NewStaticShardManager(
serverAddrs []string,
shardFunc func(key string, numShard int) (shard int),
options net2.ConnectionOptions) ShardManager {
manager := &StaticShardManager{}
manager.Init(
shardFunc,
func(err error) { log.Print(err) },
log.Print,
options)
shardStates := make([]ShardState, len(serverAddrs), len(serverAddrs))
for i, addr := range serverAddrs {
shardStates[i].Address = addr
shardStates[i].State = ActiveServer
}
manager.UpdateShardStates(shardStates)
return manager
}