Skip to content

Commit 2322de3

Browse files
committed
Add elasticsearch test case for nested and parent-child
1 parent d37250a commit 2322de3

File tree

9 files changed

+1283
-50
lines changed

9 files changed

+1283
-50
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
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package nested_objects_search
2+
3+
import (
4+
"github.com/acronis/perfkit/db"
5+
6+
"github.com/acronis/perfkit/acronis-db-bench/engine"
7+
)
8+
9+
// TestTableEmailNested is table to store email objects with nested fields
10+
var TestTableEmailNested = engine.TestTable{
11+
TableName: "acronis_db_bench_email_nested",
12+
Databases: []db.DialectName{db.ELASTICSEARCH, db.OPENSEARCH},
13+
Columns: [][]interface{}{
14+
{"id", "dataset.id"},
15+
{"uuid", "uuid"},
16+
{"euc_id", "int", 2147483647},
17+
{"progress", "int", 100},
18+
{"sender", "dataset.From"},
19+
{"recipient", "dataset.To"},
20+
{"subject", "dataset.Subject"},
21+
{"body", "dataset.Body"},
22+
//{"history.history_type", "string", 3, 32, 4},
23+
//{"history.timestamp", "time_ns", 90},
24+
//{"history.event", "string", 10, 32, 8},
25+
},
26+
InsertColumns: []string{}, // all
27+
UpdateColumns: []string{"progress"},
28+
TableDefinition: func(_ db.DialectName) *db.TableDefinition {
29+
return &db.TableDefinition{
30+
TableRows: []db.TableRow{
31+
db.TableRowItem{Name: "id", Type: db.DataTypeBigIntAutoInc},
32+
db.TableRowItem{Name: "uuid", Type: db.DataTypeUUID, NotNull: true, Indexed: true},
33+
db.TableRowItem{Name: "euc_id", Type: db.DataTypeInt, NotNull: true, Indexed: true},
34+
db.TableRowItem{Name: "progress", Type: db.DataTypeInt},
35+
db.TableRowItem{Name: "sender", Type: db.DataTypeVarChar, Indexed: true},
36+
db.TableRowItem{Name: "recipient", Type: db.DataTypeVarChar, Indexed: true},
37+
db.TableRowItem{Name: "subject", Type: db.DataTypeVarChar, Indexed: true},
38+
db.TableRowItem{Name: "body", Type: db.DataTypeText, Indexed: true},
39+
db.TableRowSubtable{
40+
Name: "history",
41+
Type: db.DataTypeNested,
42+
Subtable: []db.TableRow{
43+
db.TableRowItem{Name: "history_type", Type: db.DataTypeVarChar, Indexed: true},
44+
db.TableRowItem{Name: "timestamp", Type: db.DataTypeDateTime, Indexed: true},
45+
db.TableRowItem{Name: "event", Type: db.DataTypeVarChar, Indexed: true},
46+
},
47+
},
48+
},
49+
PrimaryKey: []string{"id"},
50+
}
51+
},
52+
CreateQuery: `create table {table} (
53+
id {$bigint_autoinc_pk},
54+
uuid {$varchar_uuid} {$notnull},
55+
euc_id int {$notnull},
56+
progress int {$null}
57+
) {$engine};`,
58+
Indexes: [][]string{{"tenant_id"}},
59+
DisableAutoCreation: true,
60+
}
61+
62+
// TestTableEmailParentChild is table to store email objects with parent child
63+
var TestTableEmailParentChild = engine.TestTable{
64+
TableName: "acronis_db_bench_email_pc",
65+
Databases: []db.DialectName{db.ELASTICSEARCH, db.OPENSEARCH},
66+
Columns: [][]interface{}{
67+
{"id", "dataset.id"},
68+
{"uuid", "uuid"},
69+
{"euc_id", "int", 2147483647},
70+
{"progress", "int", 100},
71+
{"sender", "dataset.From"},
72+
{"recipient", "dataset.To"},
73+
{"subject", "dataset.Subject"},
74+
{"body", "dataset.Body"},
75+
//{"history_type", "string", 3, 32, 4},
76+
//{"history_timestamp", "time_ns", 90},
77+
//{"history_event", "string", 10, 32, 8},
78+
},
79+
InsertColumns: []string{}, // all
80+
UpdateColumns: []string{"progress"},
81+
TableDefinition: func(_ db.DialectName) *db.TableDefinition {
82+
return &db.TableDefinition{
83+
TableRows: []db.TableRow{
84+
db.TableRowItem{Name: "id", Type: db.DataTypeBigIntAutoInc},
85+
db.TableRowItem{Name: "uuid", Type: db.DataTypeUUID, NotNull: true, Indexed: true},
86+
db.TableRowItem{Name: "euc_id", Type: db.DataTypeInt, NotNull: true, Indexed: true},
87+
db.TableRowItem{Name: "progress", Type: db.DataTypeInt},
88+
db.TableRowItem{Name: "sender", Type: db.DataTypeVarChar, Indexed: true},
89+
db.TableRowItem{Name: "recipient", Type: db.DataTypeVarChar, Indexed: true},
90+
db.TableRowItem{Name: "subject", Type: db.DataTypeVarChar, Indexed: true},
91+
db.TableRowItem{Name: "body", Type: db.DataTypeText, Indexed: true},
92+
db.TableRowItem{Name: "doc_type", Type: db.DataTypeVarChar, Indexed: true},
93+
db.TableRowItem{Name: "history_type", Type: db.DataTypeVarChar, Indexed: true},
94+
db.TableRowItem{Name: "history_timestamp", Type: db.DataTypeDateTime, Indexed: true},
95+
db.TableRowItem{Name: "history_event", Type: db.DataTypeVarChar, Indexed: true},
96+
},
97+
PrimaryKey: []string{"id"},
98+
}
99+
},
100+
CreateQuery: `create table {table} (
101+
id {$bigint_autoinc_pk},
102+
uuid {$varchar_uuid} {$notnull},
103+
euc_id int {$notnull},
104+
progress int {$null}
105+
) {$engine};`,
106+
Indexes: [][]string{{"tenant_id"}},
107+
DisableAutoCreation: true,
108+
}

0 commit comments

Comments
 (0)