Skip to content

Commit

Permalink
Update config store client to support SQL database (uber#5395)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaddoll authored Sep 8, 2023
1 parent e5f605c commit 98771a8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
3 changes: 2 additions & 1 deletion common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import (
"github.com/uber-go/tally/m3"
"github.com/uber-go/tally/prometheus"

yarpctls "go.uber.org/yarpc/api/transport/tls"

"github.com/uber/cadence/common/dynamicconfig"
c "github.com/uber/cadence/common/dynamicconfig/configstore/config"
"github.com/uber/cadence/common/peerprovider/ringpopprovider"
"github.com/uber/cadence/common/service"
yarpctls "go.uber.org/yarpc/api/transport/tls"
)

type (
Expand Down
30 changes: 20 additions & 10 deletions common/dynamicconfig/configstore/config_store_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
"github.com/uber/cadence/common/log/tag"
"github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/common/persistence/nosql"
"github.com/uber/cadence/common/persistence/sql"
"github.com/uber/cadence/common/persistence/sql/sqlplugin"
"github.com/uber/cadence/common/types"
)

Expand Down Expand Up @@ -104,14 +106,7 @@ func NewConfigStoreClient(clientCfg *csc.ClientConfig,
}

ds := persistenceCfg.DataStores[persistenceCfg.DefaultStore]
var dsConfig *config.ShardedNoSQL
if ds.ShardedNoSQL != nil {
dsConfig = ds.ShardedNoSQL
} else {
dsConfig = ds.NoSQL.ConvertToShardedNoSQLConfig()
}

client, err := newConfigStoreClient(clientCfg, dsConfig, logger, configType)
client, err := newConfigStoreClient(clientCfg, &ds, logger, configType)
if err != nil {
return nil, err
}
Expand All @@ -124,11 +119,26 @@ func NewConfigStoreClient(clientCfg *csc.ClientConfig,

func newConfigStoreClient(
clientCfg *csc.ClientConfig,
persistenceCfg *config.ShardedNoSQL,
ds *config.DataStore,
logger log.Logger,
configType persistence.ConfigType,
) (*configStoreClient, error) {
store, err := nosql.NewNoSQLConfigStore(*persistenceCfg, logger, nil)
var store persistence.ConfigStore
var err error
switch {
case ds.ShardedNoSQL != nil:
store, err = nosql.NewNoSQLConfigStore(*ds.ShardedNoSQL, logger, nil)
case ds.NoSQL != nil:
store, err = nosql.NewNoSQLConfigStore(*ds.NoSQL.ConvertToShardedNoSQLConfig(), logger, nil)
case ds.SQL != nil:
var db sqlplugin.DB
db, err = sql.NewSQLDB(ds.SQL)
if err != nil {
return nil, err
}
store, err = sql.NewSQLConfigStore(db, logger, nil)
default:
}
if err != nil {
return nil, err
}
Expand Down
9 changes: 5 additions & 4 deletions common/dynamicconfig/configstore/config_store_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,11 @@ func (s *configStoreClientSuite) SetupTest() {
FetchTimeout: time.Second * 1,
UpdateTimeout: time.Second * 1,
},

&config.ShardedNoSQL{
DefaultShard: config.NonShardedStoreName,
Connections: connections,
&config.DataStore{
ShardedNoSQL: &config.ShardedNoSQL{
DefaultShard: config.NonShardedStoreName,
Connections: connections,
},
}, log.NewNoop(), p.DynamicConfig)
s.Require().NoError(err)

Expand Down

0 comments on commit 98771a8

Please sign in to comment.