Skip to content

Commit

Permalink
added shard data path to coordinator config
Browse files Browse the repository at this point in the history
  • Loading branch information
debebantur committed Jul 24, 2023
1 parent 53f1b6d commit b74f92c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
1 change: 1 addition & 0 deletions docker/coordinator/cfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ addr: '[spqr_coordinator]:7002'
http_addr: 'spqr_coordinator:7003'
qdb_addr: '[spqr_qdb_0_1]:2379'
log_level: INFO
shard_data: '/spqr/docker/coordinator/shard_data.yaml'
1 change: 1 addition & 0 deletions examples/coordinator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ addr: 'localhost:7002'
http_addr: 'localhost:7003'
qdb_addr: 'localhost:2379'
log_level: INFO
shard_data: '/spqr/docker/coordinator/shard_data.yaml'

9 changes: 5 additions & 4 deletions pkg/config/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
var cfgCoordinator Coordinator

type Coordinator struct {
LogLevel string `json:"log_level" toml:"log_level" yaml:"log_level"`
QdbAddr string `json:"qdb_addr" toml:"qdb_addr" yaml:"qdb_addr"`
HttpAddr string `json:"http_addr" toml:"http_addr" yaml:"http_addr"`
Addr string `json:"addr" toml:"addr" yaml:"addr"`
LogLevel string `json:"log_level" toml:"log_level" yaml:"log_level"`
QdbAddr string `json:"qdb_addr" toml:"qdb_addr" yaml:"qdb_addr"`
HttpAddr string `json:"http_addr" toml:"http_addr" yaml:"http_addr"`
Addr string `json:"addr" toml:"addr" yaml:"addr"`
ShardDataCfg string `json:"shard_data" toml:"shard_data" yaml:"shard_data"`
}

func LoadCoordinatorCfg(cfgPath string) error {
Expand Down
7 changes: 3 additions & 4 deletions pkg/datatransfers/data_transfers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,16 @@ func (p *ProxyW) Write(bt []byte) (int, error) {
var shards *config.DatatransferConnections
var txFrom pgx.Tx
var txTo pgx.Tx
var remoteConfigDir = "/spqr/docker/coordinator/shard_data.yaml"
var localConfigDir = "/pkg/datatransfers/shard_data.yaml"

func createConnString(shardID string) string {
sd := shards.ShardsData[shardID]
return fmt.Sprintf("user=%s host=%s port=%s dbname=%s password=%s", sd.User, sd.Host, sd.Port, sd.DB, sd.Password)
}

func LoadConfig() error {
func LoadConfig(path string) error {
var err error
shards, err = config.LoadShardDataCfg(remoteConfigDir)
shards, err = config.LoadShardDataCfg(path)
if err != nil {
p, _ := os.Getwd()
shards, err = config.LoadShardDataCfg(p + localConfigDir)
Expand All @@ -58,7 +57,7 @@ func LoadConfig() error {

func MoveKeys(ctx context.Context, fromId, toId string, keyr qdb.KeyRange, shr []*shrule.ShardingRule) error {
if shards == nil {
err := LoadConfig()
err := LoadConfig(config.CoordinatorConfig().ShardDataCfg)
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions test/feature/conf/coordinator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ addr: '[regress_coordinator]:7002'
http_addr: 'regress_coordinator:7003'
qdb_addr: '[regress_qdb_0_1]:2379'
log_level: INFO
shard_data: '/spqr/test/feature/conf/shard_data.yaml'
13 changes: 13 additions & 0 deletions test/feature/conf/shard_data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
shards:
sh1:
db: regress
user: regress
Password: 12345678
host: 'spqr_shard_1'
port: '6432'
sh2:
db: regress
user: regress
Password: 12345678
host: 'spqr_shard_2'
port: '6432'
3 changes: 0 additions & 3 deletions test/feature/spqr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,9 @@ func (tctx *testContext) cleanup() {

// nolint: unparam
func (tctx *testContext) connectPostgresql(addr string, timeout time.Duration) (*sqlx.DB, error) {
log.Default().Printf("connecting host: %s\n", addr)
if strings.Contains(addr, strconv.Itoa(coordinatorPort)) {
log.Default().Printf("connecting coordinator: %s\n", addr)
return tctx.connectCoordinatorWithCredentials(shardUser, shardPassword, addr, timeout)
}
log.Default().Printf("connecting no coordinator: %s\n", addr)
return tctx.connectPostgresqlWithCredentials(shardUser, shardPassword, addr, timeout)
}

Expand Down

0 comments on commit b74f92c

Please sign in to comment.