-
Notifications
You must be signed in to change notification settings - Fork 0
/
shard_lookup.go
192 lines (167 loc) · 6.28 KB
/
shard_lookup.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
package goshard
import (
"math"
"strconv"
"github.com/pkg/errors"
)
// build an interface so the user can redefine ShardLookup
type ShardLookup interface {
GetAllHosts() []string
GetAll() []*ConnectionParams
Lookup(uint64) (error, *ConnectionParams)
GetShardId(uint64) uint
}
//build all the connection params
type RangeShardLookup struct {
hosts []*ConnectionParams
}
// RangeShardLookup implements ShardLookup
func NewShardLookup(hosts []*ConnectionParams) RangeShardLookup {
return RangeShardLookup{hosts: hosts}
}
// return a list of hostnames
func (r RangeShardLookup) GetAllHosts() []string {
var ret []string
for _, cp := range r.hosts {
ret = append(ret, cp.Host)
}
return ret
}
// return all the connection params
func (r RangeShardLookup) GetAll() []*ConnectionParams {
return r.hosts
}
// for the shots version of shard
const ENTITIES_PER_SHARD uint64 = 200000
// skip a chunk of ids from old DC on the east cost to new DC on the west cost
const OLD_DC_UID = 3313360
// amount to skip
const USER_ID_GAP_ADJUSTMENT = 14193526
// don't let anyone else share special shards
const SKIP_JB_SHARD_ADJUSTMENT = 24193526
// return the shard id for a given entity_id
func (r RangeShardLookup) GetShardId(entity_id uint64) uint {
var lookup_override map[uint64]uint = map[uint64]uint{
215337: 51, //sirbizzle 741404
2851622: 16, //shots 555518
209799: 18, //ryanbutler 352498
2205606: 21, //alfredoflores 345196
2721589: 1, //floydmayweather 312733
17519275: 12, //kylizzlejennizle 240564
2207508: 27, //jeremybieber 224519
3012331: 19, //madisonbeer 221901
2206037: 10, //djtayjames 213912
2956708: 2, //nickdemoura 173424
3188639: 22, //khalil 163185
222348: 27, //scooterbraun 154819
17537932: 30, //snoopdogg 152662
3058701: 30, //lilza 151097
2932211: 28, //pattiemallette 148486
2: 1, //sammy 147729
17549768: 10, //pizzle100 131332
3163223: 27, //dankanter 129801
2940269: 9, //benjaminlasnier 127197
209421: 13, //miketyson 121221
17628444: 31, //amandasteele 119000
3056390: 28, //daniellagrace 118663
1: 3, //johnny 113143
2930347: 12, //erinwagner 111876
17625290: 17, //kingbach 111773
2930684: 31, //nickbilton 110927
3213286: 16, //haileybaldwin 106060
2959609: 7, //maejorali 105716
17607650: 9, //selfiec 103426
2938553: 10, //jaxonbieber 102774
119824: 11, //ochocinco 102360
17790657: 12, //redfoo 93261
2938572: 17, //jazmynbieber 92252
17661632: 22, //destorm 91884
3178962: 15, //giovanna 90384
2762678: 6, //djirie 90187
17530758: 16, //cairusso 78478
17555239: 12, //stassiebaby 77269
3174307: 15, //anthony 74301
2951639: 12, //lukebroadlick 67896
1330861: 10, //hoogs 65524
3281319: 11, //christianbeadles 62869
210453: 5, //carin 62150
17544401: 6, //bizzlesbro_ 60936
2931080: 7, //dustinfolkes 59008
209670: 8, //erinandrews 55898
3008450: 9, //maalikacosta 54921
17522691: 10, //chanteezy 53744
2972828: 1, //jeppewest 52621
3106450: 2, //chazsomers 52373
365228: 3, //robkardashian 52343
3241452: 4, //helenowen 51989
3161493: 5, //jccaylen 51494
2493355: 6, //jozyaltidore 50985
17721829: 27, //krisjenner 48988
17915502: 13, //carter_reynolds 46039
3117998: 10, //tashoakley 45688
3281251: 1, //devin_brugman 44614
3198170: 2, //tonyofficial 43367
17583960: 9, //souljaboy 42387
3299551: 10, //willdanila 42378
3081114: 11, //marianson_ 41543
2972003: 12, //yeshuathegudwin 41499
17519272: 13, //jordynwoods 39739
17578056: 14, //arianak 39617
3241112: 15, //jakobkulke 38831
2982818: 16, //rickybush_ 38381
3055925: 17, //jbforce 37675
2931925: 18, //msalifiore 37287
2930550: 19, //teddibiase 36037
3306996: 20, //caitlinbeadles 34037
17590094: 21, //trevormoran 33552
2939732: 22, //sammisweetheart 33011
17559611: 23, //kayden 32677
2930305: 24, //tyflo 32281
3185687: 25, //danielkucz 31764
209302: 26, //crg 31102
3075840: 27, //amazingkidjt 30948
3298613: 28, //kylemassey 30850
17903969: 29, //jleonlove 30692
3121109: 30, //quincy 30362
17682299: 31, //djvice 30230
303629: 1, //holdenvw 29579
2931369: 2, //badoujack 29471
2933218: 3, //jeffdarlington 28411
304498: 4, //vega 27939
3227331: 5, //hugo 27875
2993834: 6, //jessie 27686
17574659: 7, //yungrich 27506
2931021: 8, //byggis 27340
3260856: 9, //joeygreco 27219
3073141: 10, //poobear 26982
3065384: 11, //ramal 26920
3098597: 12, //anastasiaashley 26689
2479513: 13, //robinverrecas 26387
17963673: 14, //garyvee 25456
2362476: 15, //joseph 25028
3189473: 16, //iaan 24832
2948448: 17, //justincrew 24546
17636888: 18, //vulpix 24446
}
if shard_id, ok := lookup_override[entity_id]; ok {
return shard_id
}
if entity_id >= SKIP_JB_SHARD_ADJUSTMENT {
entity_id += ENTITIES_PER_SHARD
}
if entity_id > OLD_DC_UID { // there is a big gap after 3313360
entity_id = entity_id - USER_ID_GAP_ADJUSTMENT
}
floorit := (float64(entity_id) / float64(ENTITIES_PER_SHARD)) + 1.0
shard_id := math.Floor((floorit))
return uint(shard_id)
}
// lookup an entity
func (r RangeShardLookup) Lookup(entity_id uint64) (error, *ConnectionParams) {
shard_id := r.GetShardId(entity_id)
shard_id = shard_id - 1 // hosts is 0 based
if r.hosts == nil || len(r.hosts) == 0 || shard_id > uint(len(r.hosts)) || r.hosts[shard_id] == nil {
return errors.New("UNKNOWN SHARD_ID: " + strconv.Itoa(int(shard_id))), nil
}
return nil, r.hosts[shard_id]
}