Skip to content

Commit 926a868

Browse files
authored
Add elasticsearch test cases (#23)
* Add support for object fields in Elasticsearch 8 * Add elasticsearch test case for nested and parent-child
1 parent 39169da commit 926a868

File tree

26 files changed

+1856
-236
lines changed

26 files changed

+1856
-236
lines changed

acronis-db-bench/acronis-db-bench.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
_ "github.com/acronis/perfkit/acronis-db-bench/test-groups/json-search" // json-search
1919
_ "github.com/acronis/perfkit/acronis-db-bench/test-groups/large-objects-operations" // large-objects-operations
2020
_ "github.com/acronis/perfkit/acronis-db-bench/test-groups/logs-search" // logs-search
21+
_ "github.com/acronis/perfkit/acronis-db-bench/test-groups/nested-objects-search" // nested-objects-search
2122
_ "github.com/acronis/perfkit/acronis-db-bench/test-groups/ping" // ping
2223
_ "github.com/acronis/perfkit/acronis-db-bench/test-groups/sample-dwh" // sample-dwh
2324
_ "github.com/acronis/perfkit/acronis-db-bench/test-groups/select-one" // select-one

acronis-db-bench/engine/db.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ type DBWorkerData struct {
153153
workingConn *DBConnector
154154
}
155155

156+
func (d *DBWorkerData) WorkingConn() *DBConnector {
157+
return d.workingConn
158+
}
159+
156160
func (d *DBWorkerData) release() {
157161
if d.workingConn != nil {
158162
d.workingConn.Release()

acronis-db-bench/engine/suite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (s suiteStepTestExecute) Execute(b *benchmark.Benchmark, testOpts *TestOpts
7979
}
8080

8181
// Get current dialect
82-
var dialectName = getDBDriver(b)
82+
var dialectName = GetDBDriver(b)
8383

8484
// Skip if current dialect is not supported by this test
8585
dialectSupported := false

acronis-db-bench/engine/tables.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type TestTable struct {
2424
CreateQuery string
2525
CreateQueryPatchFuncs []CreateQueryPatchFunc
2626
Indexes [][]string
27+
DisableAutoCreation bool
2728

2829
// runtime information
2930
RowsCount uint64

acronis-db-bench/engine/workers.go

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -60,54 +60,57 @@ func initGeneric(b *benchmark.Benchmark, testDesc *TestDesc, rowsRequired uint64
6060
return
6161
}
6262

63-
var ddlConnDatabase *DBConnector
64-
if ddlConnDatabase, err = NewDBConnector(&tenantCacheDBOpts, -1, true, b.Logger, 1); err != nil {
65-
b.Exit("db: cannot create connection for DDL: %v", err)
66-
return
67-
}
63+
var rowNum int64
64+
65+
if !testDesc.Table.DisableAutoCreation {
66+
var ddlConnDatabase *DBConnector
67+
if ddlConnDatabase, err = NewDBConnector(&b.TestOpts.(*TestOpts).DBOpts, -1, true, b.Logger, 1); err != nil {
68+
b.Exit("db: cannot create connection for DDL: %v", err)
69+
return
70+
}
6871

69-
conn := ddlConnDatabase
72+
conn := ddlConnDatabase
7073

71-
t := testRegistry.GetTableByName(tableName)
74+
t := testRegistry.GetTableByName(tableName)
7275

73-
b.Logger.Debug("initializing table '%s'", tableName)
74-
if testDesc.IsReadonly {
75-
t.Create(conn, b)
76-
b.Logger.Debug("readonly test, skipping table '%s' initialization", tableName)
77-
if exists, err := conn.Database.TableExists(tableName); err != nil {
78-
b.Exit(fmt.Sprintf("db: cannot check if table '%s' exists: %v", tableName, err))
79-
} else if !exists {
80-
b.Exit("The '%s' table doesn't exist, please create tables using -I option, or use individual insert test using the -t `insert-***`", tableName)
76+
b.Logger.Debug("initializing table '%s'", tableName)
77+
if testDesc.IsReadonly {
78+
t.Create(conn, b)
79+
b.Logger.Debug("readonly test, skipping table '%s' initialization", tableName)
80+
if exists, err := conn.Database.TableExists(tableName); err != nil {
81+
b.Exit(fmt.Sprintf("db: cannot check if table '%s' exists: %v", tableName, err))
82+
} else if !exists {
83+
b.Exit("The '%s' table doesn't exist, please create tables using -I option, or use individual insert test using the -t `insert-***`", tableName)
84+
}
85+
} else {
86+
b.Logger.Debug("creating table '%s'", tableName)
87+
t.Create(conn, b)
8188
}
82-
} else {
83-
b.Logger.Debug("creating table '%s'", tableName)
84-
t.Create(conn, b)
85-
}
8689

87-
var session = conn.Database.Session(conn.Database.Context(context.Background(), false))
88-
var rowNum int64
89-
if rows, err := session.Select(tableName, &db.SelectCtrl{Fields: []string{"COUNT(0)"}}); err != nil {
90-
b.Exit(fmt.Sprintf("db: cannot get rows count in table '%s': %v", tableName, err))
91-
} else {
92-
for rows.Next() {
93-
if scanErr := rows.Scan(&rowNum); scanErr != nil {
94-
b.Exit(fmt.Sprintf("db: cannot get rows count in table '%s': %v", tableName, scanErr))
90+
var session = conn.Database.Session(conn.Database.Context(context.Background(), false))
91+
if rows, err := session.Select(tableName, &db.SelectCtrl{Fields: []string{"COUNT(0)"}}); err != nil {
92+
b.Exit(fmt.Sprintf("db: cannot get rows count in table '%s': %v", tableName, err))
93+
} else {
94+
for rows.Next() {
95+
if scanErr := rows.Scan(&rowNum); scanErr != nil {
96+
b.Exit(fmt.Sprintf("db: cannot get rows count in table '%s': %v", tableName, scanErr))
97+
}
9598
}
99+
rows.Close()
96100
}
97-
rows.Close()
98-
}
99101

100-
testDesc.Table.RowsCount = uint64(rowNum)
101-
b.Logger.Debug("table '%s' has %d rows", tableName, testDesc.Table.RowsCount)
102+
testDesc.Table.RowsCount = uint64(rowNum)
103+
b.Logger.Debug("table '%s' has %d rows", tableName, testDesc.Table.RowsCount)
102104

103-
if rowsRequired > 0 {
104-
if testDesc.Table.RowsCount < rowsRequired {
105-
b.Exit(fmt.Sprintf("table '%s' has %d rows, but this test requires at least %d rows, please insert it first and then re-run the test",
106-
testDesc.Table.TableName, testDesc.Table.RowsCount, rowsRequired))
105+
if rowsRequired > 0 {
106+
if testDesc.Table.RowsCount < rowsRequired {
107+
b.Exit(fmt.Sprintf("table '%s' has %d rows, but this test requires at least %d rows, please insert it first and then re-run the test",
108+
testDesc.Table.TableName, testDesc.Table.RowsCount, rowsRequired))
109+
}
107110
}
108-
}
109111

110-
ddlConnDatabase.Release()
112+
ddlConnDatabase.Release()
113+
}
111114

112115
if b.TestOpts.(*TestOpts).BenchOpts.ParquetDataSource != "" {
113116
var offset int64
@@ -144,7 +147,7 @@ func initWorker(worker *benchmark.BenchmarkWorker) {
144147
worker.Logger.Trace("worker is initialized")
145148
}
146149

147-
func initCommon(b *benchmark.Benchmark, testDesc *TestDesc, rowsRequired uint64) {
150+
func InitCommon(b *benchmark.Benchmark, testDesc *TestDesc, rowsRequired uint64) {
148151
b.Init = func() {
149152
initGeneric(b, testDesc, rowsRequired)
150153
}
@@ -192,7 +195,7 @@ func initCommon(b *benchmark.Benchmark, testDesc *TestDesc, rowsRequired uint64)
192195
*/
193196

194197
func TestGeneric(b *benchmark.Benchmark, testDesc *TestDesc, workerFunc TestWorkerFunc, rowsRequired uint64) {
195-
initCommon(b, testDesc, rowsRequired)
198+
InitCommon(b, testDesc, rowsRequired)
196199

197200
b.WorkerRunFunc = func(worker *benchmark.BenchmarkWorker) (loops int) {
198201
c := worker.Data.(*DBWorkerData).workingConn
@@ -216,7 +219,7 @@ func TestSelectRun(
216219
orderByFunc func(worker *benchmark.BenchmarkWorker) []string,
217220
rowsRequired uint64,
218221
) {
219-
initCommon(b, testDesc, rowsRequired)
222+
InitCommon(b, testDesc, rowsRequired)
220223

221224
testOpts, ok := b.TestOpts.(*TestOpts)
222225
if !ok {
@@ -285,7 +288,7 @@ func TestSelectRawSQLQuery(
285288
orderByFunc func(worker *benchmark.BenchmarkWorker) string,
286289
rowsRequired uint64,
287290
) {
288-
initCommon(b, testDesc, rowsRequired)
291+
InitCommon(b, testDesc, rowsRequired)
289292
batch := b.Vault.(*DBTestData).EffectiveBatch
290293

291294
b.WorkerRunFunc = func(worker *benchmark.BenchmarkWorker) (loops int) {
@@ -368,7 +371,7 @@ func TestSelectRawSQLQuery(
368371
* INSERT worker
369372
*/
370373

371-
func getDBDriver(b *benchmark.Benchmark) db.DialectName {
374+
func GetDBDriver(b *benchmark.Benchmark) db.DialectName {
372375
var dialectName, err = db.GetDialectName(b.TestOpts.(*TestOpts).DBOpts.ConnString)
373376
if err != nil {
374377
b.Exit(err)
@@ -378,13 +381,13 @@ func getDBDriver(b *benchmark.Benchmark) db.DialectName {
378381
}
379382

380383
func TestInsertGeneric(b *benchmark.Benchmark, testDesc *TestDesc) {
381-
colConfs := testDesc.Table.GetColumnsForInsert(db.WithAutoInc(getDBDriver(b)))
384+
colConfs := testDesc.Table.GetColumnsForInsert(db.WithAutoInc(GetDBDriver(b)))
382385

383386
if len(*colConfs) == 0 {
384387
b.Exit(fmt.Sprintf("internal error: no columns eligible for INSERT found in '%s' configuration", testDesc.Table.TableName))
385388
}
386389

387-
initCommon(b, testDesc, 0)
390+
InitCommon(b, testDesc, 0)
388391

389392
batch := b.Vault.(*DBTestData).EffectiveBatch
390393
table := &testDesc.Table
@@ -492,7 +495,7 @@ func InsertMultiValueDataWorker(b *benchmark.Benchmark, c *DBConnector, testDesc
492495
for i := 0; i < batch; i++ {
493496
var genColumns, vals, err = b.Randomizer.GenFakeData(colConfs, db.WithAutoInc(c.Database.DialectName()))
494497
if err != nil {
495-
b.Exit(err)
498+
b.Exit(err.Error())
496499
}
497500

498501
if genColumns == nil {
@@ -525,14 +528,14 @@ func InsertMultiValueDataWorker(b *benchmark.Benchmark, c *DBConnector, testDesc
525528

526529
func TestUpdateGeneric(b *benchmark.Benchmark, testDesc *TestDesc, updateRows uint64, colConfs *[]benchmark.DBFakeColumnConf) {
527530
if colConfs == nil {
528-
colConfs = testDesc.Table.GetColumnsForUpdate(db.WithAutoInc(getDBDriver(b)))
531+
colConfs = testDesc.Table.GetColumnsForUpdate(db.WithAutoInc(GetDBDriver(b)))
529532
}
530533

531534
if len(*colConfs) == 0 {
532535
b.Exit(fmt.Sprintf("internal error: no columns eligible for UPDATE found in '%s' configuration", testDesc.Table.TableName))
533536
}
534537

535-
initCommon(b, testDesc, updateRows)
538+
InitCommon(b, testDesc, updateRows)
536539

537540
batch := b.Vault.(*DBTestData).EffectiveBatch
538541
table := &testDesc.Table
@@ -594,7 +597,7 @@ func TestUpdateGeneric(b *benchmark.Benchmark, testDesc *TestDesc, updateRows ui
594597
*/
595598
// testDeleteGeneric is a generic DELETE worker
596599
func testDeleteGeneric(b *benchmark.Benchmark, testDesc *TestDesc, deleteRows uint64) { //nolint:unused
597-
initCommon(b, testDesc, deleteRows)
600+
InitCommon(b, testDesc, deleteRows)
598601

599602
batch := b.Vault.(*DBTestData).EffectiveBatch
600603
table := &testDesc.Table

acronis-db-bench/test-groups/basic-scenarios/blob.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ var TestTableBlob = engine.TestTable{
2222
TableDefinition: func(dialect db.DialectName) *db.TableDefinition {
2323
return &db.TableDefinition{
2424
TableRows: []db.TableRow{
25-
{Name: "id", Type: db.DataTypeBigIntAutoIncPK},
26-
{Name: "uuid", Type: db.DataTypeUUID, NotNull: true, Indexed: true},
27-
{Name: "tenant_id", Type: db.DataTypeUUID, NotNull: true, Indexed: true},
28-
{Name: "timestamp", Type: db.DataTypeBigInt, NotNull: true, Indexed: true},
29-
{Name: "data", Type: db.DataTypeHugeBlob, NotNull: true},
25+
db.TableRowItem{Name: "id", Type: db.DataTypeBigIntAutoIncPK},
26+
db.TableRowItem{Name: "uuid", Type: db.DataTypeUUID, NotNull: true, Indexed: true},
27+
db.TableRowItem{Name: "tenant_id", Type: db.DataTypeUUID, NotNull: true, Indexed: true},
28+
db.TableRowItem{Name: "timestamp", Type: db.DataTypeBigInt, NotNull: true, Indexed: true},
29+
db.TableRowItem{Name: "data", Type: db.DataTypeHugeBlob, NotNull: true},
3030
},
3131
}
3232
},

0 commit comments

Comments
 (0)