Skip to content

Commit f1a94df

Browse files
committed
Added ability to stop generating values by plugins to benchmark faker
1 parent 37c17df commit f1a94df

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

acronis-db-bench/engine/helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ func (p *DataSetSourcePlugin) GenCommonFakeValue(columnType string, rz *benchmar
219219
}
220220

221221
if row == nil {
222-
return false, nil
222+
return true, nil
223223
}
224224

225225
p.currentValues = make(map[string]interface{}, len(row))
226226
for i, value := range row {
227227
p.currentValues[p.columns[i]] = value
228228
}
229229

230-
return true, p.currentValues[columnType]
230+
return false, p.currentValues[columnType]
231231
}
232232

233233
func (p *DataSetSourcePlugin) GenFakeValue(columnType string, rz *benchmark.Randomizer, cardinality int, preGenerated map[string]interface{}) (bool, interface{}) {

acronis-db-bench/tenants-cache/tenant_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ func (tc *TenantsCache) GenCommonFakeValue(columnType string, rz *benchmark.Rand
10031003
tc.benchmark.Exit(err.Error())
10041004
}
10051005

1006-
return true, tenantUUID
1006+
return false, tenantUUID
10071007
}
10081008

10091009
func (tc *TenantsCache) GenFakeValue(columnType string, rz *benchmark.Randomizer, cardinality int, preGenerated map[string]interface{}) (bool, interface{}) {

benchmark/faker.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,16 @@ func (rz *Randomizer) GenFakeData(colConfs *[]DBFakeColumnConf, WithAutoInc bool
339339
var preGenerated map[string]interface{}
340340
for _, plugin := range rz.plugins {
341341
for _, c := range *colConfs {
342-
if exists, value := plugin.GenCommonFakeValue(c.ColumnType, rz, c.Cardinality); exists {
343-
if preGenerated == nil {
344-
preGenerated = make(map[string]interface{})
342+
if shouldStop, value := plugin.GenCommonFakeValue(c.ColumnType, rz, c.Cardinality); !shouldStop {
343+
if value != nil {
344+
if preGenerated == nil {
345+
preGenerated = make(map[string]interface{})
346+
}
347+
preGenerated[c.ColumnType] = value
345348
}
346-
preGenerated[c.ColumnType] = value
349+
} else {
350+
// End of generation
351+
return nil, nil, nil
347352
}
348353
}
349354
}
@@ -372,11 +377,16 @@ func (rz *Randomizer) GenFakeDataAsMap(colConfs *[]DBFakeColumnConf, WithAutoInc
372377
var preGenerated map[string]interface{}
373378
for _, plugin := range rz.plugins {
374379
for _, c := range *colConfs {
375-
if exists, value := plugin.GenCommonFakeValue(c.ColumnType, rz, c.Cardinality); exists {
376-
if preGenerated == nil {
377-
preGenerated = make(map[string]interface{})
380+
if shouldStop, value := plugin.GenCommonFakeValue(c.ColumnType, rz, c.Cardinality); !shouldStop {
381+
if value != nil {
382+
if preGenerated == nil {
383+
preGenerated = make(map[string]interface{})
384+
}
385+
preGenerated[c.ColumnType] = value
378386
}
379-
preGenerated[c.ColumnType] = value
387+
} else {
388+
// End of generation
389+
return nil, nil
380390
}
381391
}
382392
}

0 commit comments

Comments
 (0)