Skip to content

Commit e894bee

Browse files
committed
Added OpenSearch dialect support to acronis-db-bench
1 parent e346434 commit e894bee

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

acronis-db-bench/tests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (t *TestDesc) getDBs() string {
105105

106106
var (
107107
// ALL is a list of all supported databases
108-
ALL = []db.DialectName{db.POSTGRES, db.MYSQL, db.MSSQL, db.SQLITE, db.CLICKHOUSE, db.CASSANDRA, db.ELASTICSEARCH}
108+
ALL = []db.DialectName{db.POSTGRES, db.MYSQL, db.MSSQL, db.SQLITE, db.CLICKHOUSE, db.CASSANDRA, db.ELASTICSEARCH, db.OPENSEARCH}
109109
// RELATIONAL is a list of all supported relational databases
110110
RELATIONAL = []db.DialectName{db.POSTGRES, db.MYSQL, db.MSSQL, db.SQLITE}
111111
// PMWSA is a list of all supported databases except ClickHouse

db/db.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
CLICKHOUSE DialectName = "clickhouse" // CLICKHOUSE is the ClickHouse driver name
2020
CASSANDRA DialectName = "cassandra" // CASSANDRA is the Cassandra driver name
2121
ELASTICSEARCH DialectName = "elasticsearch" // ELASTICSEARCH is the Elasticsearch driver name
22+
OPENSEARCH DialectName = "opensearch" // OPENSEARCH is the OpenSearch driver name
2223
)
2324

2425
// Special conditions for searching
@@ -359,6 +360,7 @@ func GetDatabases() []DBType {
359360
// "A" is used as the latest symbol of the "Cassandra" due to duplicate with ClickHouse "C"
360361
ret = append(ret, DBType{Driver: CASSANDRA, Symbol: "A", Name: "Cassandra"})
361362
ret = append(ret, DBType{Driver: ELASTICSEARCH, Symbol: "E", Name: "Elasticsearch"})
363+
ret = append(ret, DBType{Driver: OPENSEARCH, Symbol: "O", Name: "OpenSearch"})
362364

363365
return ret
364366
}

db/es/elasticsearch.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ func init() {
3333
}
3434
}
3535

36+
type elasticSearchDialect struct{}
37+
38+
func (d *elasticSearchDialect) name() db.DialectName {
39+
return db.ELASTICSEARCH
40+
}
41+
3642
// nolint:gocritic //TODO refactor unnamed returns
3743
func elasticCredentialsAndConnString(cs string, tlsEnabled bool) (string, string, string, error) {
3844
var u, err = url.Parse(cs)
@@ -126,6 +132,7 @@ func (c *esConnector) ConnectionPool(cfg db.Config) (db.Database, error) {
126132
return &esDatabase{
127133
rw: rw,
128134
mig: rw,
135+
dialect: &elasticSearchDialect{},
129136
queryLogger: cfg.QueryLogger,
130137
}, nil
131138
}

db/es/es.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ func (s *esSession) Transact(fn func(tx db.DatabaseAccessor) error) error {
4040
}
4141

4242
type esDatabase struct {
43-
rw accessor
44-
mig migrator
43+
rw accessor
44+
mig migrator
45+
dialect dialect
4546

4647
queryLogger db.Logger
4748
}
@@ -60,7 +61,7 @@ func (d *esDatabase) UseTruncate() bool {
6061
}
6162

6263
func (d *esDatabase) GetVersion() (db.DialectName, string, error) {
63-
return getVersion(d.rw)
64+
return getVersion(d.dialect)
6465
}
6566

6667
func (d *esDatabase) GetInfo(version string) (ret []string, dbInfo *db.Info, err error) {
@@ -193,3 +194,7 @@ func (tq timedQuerier) count(ctx context.Context, idxName indexName, request *Co
193194

194195
return tq.q.count(ctx, idxName, request)
195196
}
197+
198+
type dialect interface {
199+
name() db.DialectName
200+
}

db/es/info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package es
33
import "github.com/acronis/perfkit/db"
44

55
// GetVersion returns DB version and driver name
6-
func getVersion(q querier) (db.DialectName, string, error) {
7-
return db.ELASTICSEARCH, "", nil
6+
func getVersion(dia dialect) (db.DialectName, string, error) {
7+
return dia.name(), "", nil
88
}
99

1010
// GetInfo returns DB info

db/es/opensearch.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ func init() {
2727
}
2828
}
2929

30+
type openSearchDialect struct{}
31+
32+
func (d *openSearchDialect) name() db.DialectName {
33+
return db.OPENSEARCH
34+
}
35+
3036
type openSearchConnector struct{}
3137

3238
func (c *openSearchConnector) ConnectionPool(cfg db.Config) (db.Database, error) {
@@ -97,12 +103,13 @@ func (c *openSearchConnector) ConnectionPool(cfg db.Config) (db.Database, error)
97103
return &esDatabase{
98104
rw: rw,
99105
mig: mig,
106+
dialect: &openSearchDialect{},
100107
queryLogger: cfg.QueryLogger,
101108
}, nil
102109
}
103110

104111
func (c *openSearchConnector) DialectName(scheme string) (db.DialectName, error) {
105-
return db.ELASTICSEARCH, nil
112+
return db.OPENSEARCH, nil
106113
}
107114

108115
type openSearchQuerier struct {

0 commit comments

Comments
 (0)