Skip to content

Commit 3f20923

Browse files
wenyihu6tbg
authored andcommitted
asim: remove unused keyspace from BaseRanges and rand framework
Previously, we add min/max key to BaseRanges in 3da645a, which made keyspace field unused. This commit removes the unused keyspace field from BaseRanges. Additionally, it introduces min/max keys for the rand framework. Note that some rand tests now fail due to a simulator assumption that the first range must start with the key 0. A future commit will explain and address it. Epic: none Release note: none
1 parent 98809dc commit 3f20923

File tree

12 files changed

+1125
-133
lines changed

12 files changed

+1125
-133
lines changed

pkg/kv/kvserver/asim/gen/generator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ func GetRangePlacementType(s string) PlacementType {
286286
type BaseRanges struct {
287287
Ranges int
288288
MinKey, MaxKey int64
289-
KeySpace int
290289
ReplicationFactor int
291290
Bytes int64
292291
ReplicaPlacement state.ReplicaPlacement
@@ -307,9 +306,10 @@ func (b BaseRanges) GetRangesInfo(
307306
case Skewed:
308307
return state.RangesInfoSkewedDistribution(numOfStores, b.Ranges, b.MinKey, b.MaxKey, b.ReplicationFactor, b.Bytes)
309308
case Random:
310-
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)
311310
case WeightedRandom:
312-
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)
313313
case ReplicaPlacement:
314314
// TODO(tbg): port this over from the prototype.
315315
/*

pkg/kv/kvserver/asim/state/new_state.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func RangesInfoWeightedRandDistribution(
323323
randSource *rand.Rand,
324324
weightedStores []float64,
325325
ranges int,
326-
keyspace int,
326+
minKey, maxKey int64,
327327
replicationFactor int,
328328
rangeSize int64,
329329
) RangesInfo {
@@ -341,9 +341,8 @@ func RangesInfoWeightedRandDistribution(
341341
distribution,
342342
ranges,
343343
spanConfig,
344-
int64(MinKey),
345-
int64(keyspace),
346-
rangeSize, /* rangeSize */
344+
minKey, maxKey,
345+
rangeSize,
347346
)
348347
}
349348

@@ -353,7 +352,7 @@ func RangesInfoRandDistribution(
353352
randSource *rand.Rand,
354353
stores int,
355354
ranges int,
356-
keyspace int,
355+
minKey, maxKey int64,
357356
replicationFactor int,
358357
rangeSize int64,
359358
) RangesInfo {
@@ -369,5 +368,5 @@ func RangesInfoRandDistribution(
369368

370369
return RangesInfoWithDistribution(
371370
storeList, distribution, distribution, ranges, spanConfig,
372-
int64(MinKey), int64(keyspace), rangeSize)
371+
minKey, maxKey, rangeSize)
373372
}

pkg/kv/kvserver/asim/state/new_state_test_helper.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ func NewStateRandDistribution(
9494
) State {
9595
randSource := rand.New(rand.NewSource(seed))
9696
clusterInfo := ClusterInfoWithStoreCount(stores, 1 /* storesPerNode */)
97-
rangesInfo := RangesInfoRandDistribution(randSource, stores, ranges, keyspace, replicationFactor, 0 /* rangeSize */)
97+
rangesInfo := RangesInfoRandDistribution(randSource, stores, ranges, int64(MinKey),
98+
int64(keyspace), replicationFactor, 0 /* rangeSize */)
9899
return LoadConfig(clusterInfo, rangesInfo, settings)
99100
}
100101

@@ -110,6 +111,7 @@ func NewStateWeightedRandDistribution(
110111
) State {
111112
randSource := rand.New(rand.NewSource(seed))
112113
clusterInfo := ClusterInfoWithStoreCount(len(weightedStores), 1 /* storesPerNode */)
113-
rangesInfo := RangesInfoWeightedRandDistribution(randSource, weightedStores, ranges, keyspace, replicationFactor, 0 /* rangeSize */)
114+
rangesInfo := RangesInfoWeightedRandDistribution(randSource, weightedStores, ranges, int64(MinKey),
115+
int64(keyspace), replicationFactor, 0 /* rangeSize */)
114116
return LoadConfig(clusterInfo, rangesInfo, settings)
115117
}

pkg/kv/kvserver/asim/tests/datadriven_simulation_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,8 @@ func TestDataDriven(t *testing.T) {
379379
Ranges: 1,
380380
MinKey: 0, MaxKey: 1,
381381
ReplicationFactor: 1,
382-
KeySpace: defaultKeyspace,
383382
},
384383
})
385-
386384
}
387385
for sample := 0; sample < samples; sample++ {
388386
assertionFailures := []string{}

pkg/kv/kvserver/asim/tests/default_settings.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ func (f randTestingFramework) defaultBasicRangesGen() gen.BasicRanges {
113113
return gen.BasicRanges{
114114
BaseRanges: gen.BaseRanges{
115115
Ranges: f.defaultStaticSettings.ranges,
116-
KeySpace: f.defaultStaticSettings.keySpace,
116+
MinKey: f.defaultStaticSettings.minKey,
117+
MaxKey: f.defaultStaticSettings.maxKey,
117118
ReplicationFactor: f.defaultStaticSettings.replicationFactor,
118119
Bytes: f.defaultStaticSettings.bytes,
119120
},

pkg/kv/kvserver/asim/tests/rand_framework.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ func (f randTestingFramework) randomBasicRangesGen() gen.RangeGen {
213213
return gen.BasicRanges{
214214
BaseRanges: gen.BaseRanges{
215215
Ranges: convertInt64ToInt(f.rangeGenerator.key()),
216-
KeySpace: convertInt64ToInt(f.keySpaceGenerator.key()),
216+
MinKey: defaultMinKey,
217+
MaxKey: f.keySpaceGenerator.key(),
217218
ReplicationFactor: f.s.rangeGen.replicationFactor,
218219
Bytes: defaultBytes,
219220
},
@@ -226,7 +227,8 @@ func (f randTestingFramework) randomBasicRangesGen() gen.RangeGen {
226227
return RandomizedBasicRanges{
227228
BaseRanges: gen.BaseRanges{
228229
Ranges: convertInt64ToInt(f.rangeGenerator.key()),
229-
KeySpace: convertInt64ToInt(f.keySpaceGenerator.key()),
230+
MinKey: defaultMinKey,
231+
MaxKey: f.keySpaceGenerator.key(),
230232
ReplicationFactor: f.s.rangeGen.replicationFactor,
231233
Bytes: defaultBytes,
232234
},
@@ -247,7 +249,8 @@ func (f randTestingFramework) randomBasicRangesGen() gen.RangeGen {
247249
return WeightedRandomizedBasicRanges{
248250
BaseRanges: gen.BaseRanges{
249251
Ranges: convertInt64ToInt(f.rangeGenerator.key()),
250-
KeySpace: convertInt64ToInt(f.keySpaceGenerator.key()),
252+
MinKey: defaultMinKey,
253+
MaxKey: f.keySpaceGenerator.key(),
251254
ReplicationFactor: f.s.rangeGen.replicationFactor,
252255
Bytes: defaultBytes,
253256
},

0 commit comments

Comments
 (0)