Skip to content

Commit

Permalink
Added OpenSearch dialect support to acronis-db-bench
Browse files Browse the repository at this point in the history
  • Loading branch information
iluhinsky committed Oct 11, 2024
1 parent e346434 commit e894bee
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion acronis-db-bench/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (t *TestDesc) getDBs() string {

var (
// ALL is a list of all supported databases
ALL = []db.DialectName{db.POSTGRES, db.MYSQL, db.MSSQL, db.SQLITE, db.CLICKHOUSE, db.CASSANDRA, db.ELASTICSEARCH}
ALL = []db.DialectName{db.POSTGRES, db.MYSQL, db.MSSQL, db.SQLITE, db.CLICKHOUSE, db.CASSANDRA, db.ELASTICSEARCH, db.OPENSEARCH}
// RELATIONAL is a list of all supported relational databases
RELATIONAL = []db.DialectName{db.POSTGRES, db.MYSQL, db.MSSQL, db.SQLITE}
// PMWSA is a list of all supported databases except ClickHouse
Expand Down
2 changes: 2 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
CLICKHOUSE DialectName = "clickhouse" // CLICKHOUSE is the ClickHouse driver name
CASSANDRA DialectName = "cassandra" // CASSANDRA is the Cassandra driver name
ELASTICSEARCH DialectName = "elasticsearch" // ELASTICSEARCH is the Elasticsearch driver name
OPENSEARCH DialectName = "opensearch" // OPENSEARCH is the OpenSearch driver name
)

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

return ret
}
7 changes: 7 additions & 0 deletions db/es/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func init() {
}
}

type elasticSearchDialect struct{}

func (d *elasticSearchDialect) name() db.DialectName {
return db.ELASTICSEARCH
}

// nolint:gocritic //TODO refactor unnamed returns
func elasticCredentialsAndConnString(cs string, tlsEnabled bool) (string, string, string, error) {
var u, err = url.Parse(cs)
Expand Down Expand Up @@ -126,6 +132,7 @@ func (c *esConnector) ConnectionPool(cfg db.Config) (db.Database, error) {
return &esDatabase{
rw: rw,
mig: rw,
dialect: &elasticSearchDialect{},
queryLogger: cfg.QueryLogger,
}, nil
}
Expand Down
11 changes: 8 additions & 3 deletions db/es/es.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ func (s *esSession) Transact(fn func(tx db.DatabaseAccessor) error) error {
}

type esDatabase struct {
rw accessor
mig migrator
rw accessor
mig migrator
dialect dialect

queryLogger db.Logger
}
Expand All @@ -60,7 +61,7 @@ func (d *esDatabase) UseTruncate() bool {
}

func (d *esDatabase) GetVersion() (db.DialectName, string, error) {
return getVersion(d.rw)
return getVersion(d.dialect)
}

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

return tq.q.count(ctx, idxName, request)
}

type dialect interface {
name() db.DialectName
}
4 changes: 2 additions & 2 deletions db/es/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package es
import "github.com/acronis/perfkit/db"

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

// GetInfo returns DB info
Expand Down
9 changes: 8 additions & 1 deletion db/es/opensearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ func init() {
}
}

type openSearchDialect struct{}

func (d *openSearchDialect) name() db.DialectName {
return db.OPENSEARCH
}

type openSearchConnector struct{}

func (c *openSearchConnector) ConnectionPool(cfg db.Config) (db.Database, error) {
Expand Down Expand Up @@ -97,12 +103,13 @@ func (c *openSearchConnector) ConnectionPool(cfg db.Config) (db.Database, error)
return &esDatabase{
rw: rw,
mig: mig,
dialect: &openSearchDialect{},
queryLogger: cfg.QueryLogger,
}, nil
}

func (c *openSearchConnector) DialectName(scheme string) (db.DialectName, error) {
return db.ELASTICSEARCH, nil
return db.OPENSEARCH, nil
}

type openSearchQuerier struct {
Expand Down

0 comments on commit e894bee

Please sign in to comment.