Skip to content

Commit

Permalink
Fix unittests and etcd paths (#344)
Browse files Browse the repository at this point in the history
* fix etcd paths

* fix unittests

* fix issue

* fix
  • Loading branch information
Denchick committed Dec 6, 2023
1 parent 07caa67 commit c860b67
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 99 deletions.
9 changes: 9 additions & 0 deletions pkg/shard/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package shard

func ShardIDs(shards []Shard) []string {
ret := []string{}
for _, shard := range shards {
ret = append(ret, shard.ID())
}
return ret
}
16 changes: 8 additions & 8 deletions qdb/etcdqdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ func NewEtcdQDB(addr string) (*EtcdQDB, error) {
}

const (
keyspace = "key_space"
keyRangesNamespace = "/keyranges"
dataspaceNamespace = "/dataspaces"
keyRangeMovesNamespace = "/krmoves"
routersNamespace = "/routers"
shardingRulesNamespace = "/sharding_rules"
shardsNamespace = "/shards"
keyRangesNamespace = "/keyranges/"
dataspaceNamespace = "/dataspaces/"
keyRangeMovesNamespace = "/krmoves/"
routersNamespace = "/routers/"
shardingRulesNamespace = "/sharding_rules/"
shardsNamespace = "/shards/"

CoordKeepAliveTtl = 3
keyspace = "key_space"
coordLockKey = "coordinator_exists"
coordLockVal = "exists"
)

func keyLockPath(key string) string {
Expand Down
4 changes: 4 additions & 0 deletions router/frontend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func TestFrontendSimple(t *testing.T) {

beRule := &config.BackendRule{}


srv.EXPECT().Datashards().AnyTimes().Return([]shard.Shard{})
srv.EXPECT().Name().AnyTimes().Return("serv1")

cl.EXPECT().Server().AnyTimes().Return(srv)
Expand Down Expand Up @@ -167,6 +169,7 @@ func TestFrontendXProto(t *testing.T) {
beRule := &config.BackendRule{}

srv.EXPECT().Name().AnyTimes().Return("serv1")
srv.EXPECT().Datashards().AnyTimes().Return([]shard.Shard{})

/* query Router */

Expand Down Expand Up @@ -302,6 +305,7 @@ func TestFrontendSimpleCopyIn(t *testing.T) {
beRule := &config.BackendRule{}

srv.EXPECT().Name().AnyTimes().Return("serv1")
srv.EXPECT().Datashards().AnyTimes().Return([]shard.Shard{})

cl.EXPECT().Server().AnyTimes().Return(srv)

Expand Down
175 changes: 87 additions & 88 deletions router/mock/server/mock_server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions router/relay/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func (rst *RelayStateImpl) ProcQuery(query pgproto3.FrontendMessage, waitForResp
}

spqrlog.Zero.Debug().
Str("server", server.Datashards()[0].ID()).
Strs("shards", shard.ShardIDs(server.Datashards())).
Type("query-type", query).
Msg("client process query")

Expand Down Expand Up @@ -918,7 +918,7 @@ func (rst *RelayStateImpl) DeployPrepStmt(qname string) (shard.PreparedStatement
Str("query", query).
Uint64("hash", hash).
Str("client", rst.Client().ID()).
Str("shard", rst.Client().Server().Datashards()[0].ID()).
Strs("shards", shard.ShardIDs(rst.Client().Server().Datashards())).
Msg("deploy prepared statement")

// TODO: multi-shard statements
Expand Down
2 changes: 1 addition & 1 deletion router/server/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (srv *ShardServer) Receive() (pgproto3.BackendMessage, error) {
Uint("single-shard", spqrlog.GetPointer(srv)).
Type("message-type", msg).
Str("txstatus", srv.TxStatus().String()).
Str("shard", srv.Datashards()[0].ID()).
Strs("shards", shard.ShardIDs(srv.Datashards())).
Msg("single-shard receiving msg from server")
return msg, err
}
Expand Down

0 comments on commit c860b67

Please sign in to comment.