@@ -93,6 +93,28 @@ func (ss StaticSettings) Generate(seed int64) config.SimulationSettings {
93
93
return ret
94
94
}
95
95
96
+ type MultiLoad []BasicLoad
97
+
98
+ // MultiLoad implements the LoadGen interface. It is a collection of
99
+ // BasicLoad.
100
+ var _ LoadGen = MultiLoad {}
101
+
102
+ func (ml MultiLoad ) String () string {
103
+ var str string
104
+ for _ , load := range ml {
105
+ str += fmt .Sprintf ("%s\n " , load .String ())
106
+ }
107
+ return str
108
+ }
109
+
110
+ func (ml MultiLoad ) Generate (seed int64 , settings * config.SimulationSettings ) []workload.Generator {
111
+ var generators []workload.Generator
112
+ for _ , load := range ml {
113
+ generators = append (generators , load .Generate (seed , settings )... )
114
+ }
115
+ return generators
116
+ }
117
+
96
118
// BasicLoad implements the LoadGen interface.
97
119
type BasicLoad struct {
98
120
RWRatio float64
@@ -103,6 +125,8 @@ type BasicLoad struct {
103
125
MinKey , MaxKey int64
104
126
}
105
127
128
+ var _ LoadGen = BasicLoad {}
129
+
106
130
func (bl BasicLoad ) String () string {
107
131
return fmt .Sprintf (
108
132
"basic load with rw_ratio=%0.2f, rate=%0.2f, skewed_access=%t, min_block_size=%d, max_block_size=%d, " +
@@ -212,6 +236,8 @@ const (
212
236
Skewed
213
237
Random
214
238
WeightedRandom
239
+ Weighted
240
+ ReplicaPlacement
215
241
)
216
242
217
243
func (p PlacementType ) String () string {
@@ -224,6 +250,10 @@ func (p PlacementType) String() string {
224
250
return "random"
225
251
case WeightedRandom :
226
252
return "weighted_rand"
253
+ case Weighted :
254
+ return "weighted"
255
+ case ReplicaPlacement :
256
+ return "replica_placement"
227
257
default :
228
258
panic ("unknown placement type" )
229
259
}
@@ -239,6 +269,10 @@ func GetRangePlacementType(s string) PlacementType {
239
269
return Random
240
270
case "weighted_rand" :
241
271
return WeightedRandom
272
+ case "weighted" :
273
+ return Weighted
274
+ case "replica_placement" :
275
+ return ReplicaPlacement
242
276
default :
243
277
panic (fmt .Sprintf ("unknown placement type %s" , s ))
244
278
}
@@ -251,13 +285,14 @@ func GetRangePlacementType(s string) PlacementType {
251
285
// WeightedRandomizedBasicRanges.
252
286
type BaseRanges struct {
253
287
Ranges int
254
- KeySpace int
288
+ MinKey , MaxKey int64
255
289
ReplicationFactor int
256
290
Bytes int64
291
+ ReplicaPlacement state.ReplicaPlacement
257
292
}
258
293
259
294
func (b BaseRanges ) String () string {
260
- return fmt .Sprintf ("ranges=%d, key_space =%d, replication_factor=%d, bytes=%d" , b .Ranges , b .KeySpace , b .ReplicationFactor , b .Bytes )
295
+ return fmt .Sprintf ("ranges=%d, min_key =%d, max_key=%d, replication_factor=%d, bytes=%d" , b .Ranges , b .MinKey , b . MaxKey , b .ReplicationFactor , b .Bytes )
261
296
}
262
297
263
298
// GetRangesInfo generates and distributes ranges across stores based on
@@ -267,13 +302,25 @@ func (b BaseRanges) GetRangesInfo(
267
302
) state.RangesInfo {
268
303
switch pType {
269
304
case Even :
270
- return state .RangesInfoEvenDistribution (numOfStores , b .Ranges , b .KeySpace , b .ReplicationFactor , b .Bytes )
305
+ return state .RangesInfoEvenDistribution (numOfStores , b .Ranges , b .MinKey , b . MaxKey , b .ReplicationFactor , b .Bytes )
271
306
case Skewed :
272
- return state .RangesInfoSkewedDistribution (numOfStores , b .Ranges , b .KeySpace , b .ReplicationFactor , b .Bytes )
307
+ return state .RangesInfoSkewedDistribution (numOfStores , b .Ranges , b .MinKey , b . MaxKey , b .ReplicationFactor , b .Bytes )
273
308
case Random :
274
- return state .RangesInfoRandDistribution (randSource , numOfStores , b .Ranges , b .KeySpace , b .ReplicationFactor , b .Bytes )
309
+ return state .RangesInfoRandDistribution (randSource , numOfStores , b .Ranges , b .MinKey , b . MaxKey , b .ReplicationFactor , b .Bytes )
275
310
case WeightedRandom :
276
- return state .RangesInfoWeightedRandDistribution (randSource , weightedRandom , b .Ranges , b .KeySpace , b .ReplicationFactor , b .Bytes )
311
+ return state .RangesInfoWeightedRandDistribution (
312
+ randSource , weightedRandom , b .Ranges , b .MinKey , b .MaxKey , b .ReplicationFactor , b .Bytes )
313
+ case ReplicaPlacement :
314
+ // TODO(tbg): port this over from the prototype.
315
+ /*
316
+ return state.RangesInfoWithReplicaPlacement(
317
+ b.ReplicaPlacement,
318
+ b.Ranges,
319
+ state.DefaultSpanConfigWithRF(b.ReplicationFactor),
320
+ b.MinKey, b.MaxKey, b.Bytes,
321
+ )
322
+ */
323
+ panic ("unimplemented" )
277
324
default :
278
325
panic (fmt .Sprintf ("unexpected range placement type %v" , pType ))
279
326
}
@@ -292,6 +339,9 @@ func (b BaseRanges) LoadRangeInfo(s state.State, rangesInfo state.RangesInfo) {
292
339
type BasicRanges struct {
293
340
BaseRanges
294
341
PlacementType PlacementType
342
+ // ReplicaWeights and LeaseWeights are only non-nil when the placement type
343
+ // is Weighted.
344
+ ReplicaWeights , LeaseWeights []float64
295
345
}
296
346
297
347
func (br BasicRanges ) String () string {
@@ -311,3 +361,45 @@ func (br BasicRanges) Generate(
311
361
br .LoadRangeInfo (s , rangesInfo )
312
362
return s
313
363
}
364
+
365
+ // MultiRanges implements the RangeGen interface, supporting multiple
366
+ // BasicRanges generation.
367
+ type MultiRanges []BasicRanges
368
+
369
+ var _ RangeGen = MultiRanges {}
370
+
371
+ func (mr MultiRanges ) String () string {
372
+ var str string
373
+ for _ , ranges := range mr {
374
+ str += fmt .Sprintf ("%s\n " , ranges .String ())
375
+ }
376
+ return str
377
+ }
378
+
379
+ func (mr MultiRanges ) Generate (
380
+ seed int64 , settings * config.SimulationSettings , s state.State ,
381
+ ) state.State {
382
+ var rangeInfos []state.RangeInfo
383
+ for _ , ranges := range mr {
384
+ var nextInfos state.RangesInfo
385
+ if ranges .PlacementType == Weighted {
386
+ // TODO(tbg): instead refactoring GetRangesInfo to be more general.
387
+ var storeIDs []state.StoreID
388
+ for _ , store := range s .Stores () {
389
+ storeIDs = append (storeIDs , store .StoreID ())
390
+ }
391
+ nextInfos = state .RangesInfoWithDistribution (storeIDs ,
392
+ ranges .ReplicaWeights , ranges .LeaseWeights ,
393
+ ranges .Ranges , state .DefaultSpanConfigWithRF (ranges .ReplicationFactor ),
394
+ ranges .MinKey , ranges .MaxKey , ranges .Bytes )
395
+ } else {
396
+ if ranges .LeaseWeights != nil || ranges .ReplicaWeights != nil {
397
+ panic ("leaseWeights and replicaWeights should be nil for non-weighted placement types" )
398
+ }
399
+ nextInfos = ranges .GetRangesInfo (ranges .PlacementType , len (s .Stores ()), nil , []float64 {})
400
+ }
401
+ rangeInfos = append (rangeInfos , nextInfos ... )
402
+ }
403
+ state .LoadRangeInfo (s , rangeInfos ... )
404
+ return s
405
+ }
0 commit comments