Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better console messages #629

Merged
49 changes: 30 additions & 19 deletions pkg/clientinteractor/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ func (pi *PSQLInteractor) Version(_ context.Context) error {

// TODO : unit tests
func (pi *PSQLInteractor) AddShard(shard *datashards.DataShard) error {
if err := pi.WriteHeader("add datashard"); err != nil {
if err := pi.WriteHeader("add shard"); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}

for _, msg := range []pgproto3.BackendMessage{
&pgproto3.DataRow{Values: [][]byte{[]byte(fmt.Sprintf("created datashard with name %s", shard.ID))}},
&pgproto3.DataRow{Values: [][]byte{[]byte(fmt.Sprintf("shard id -> %s", shard.ID))}},
} {
if err := pi.cl.Send(msg); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
Expand All @@ -199,7 +199,7 @@ func (pi *PSQLInteractor) DropShard(id string) error {
}

for _, msg := range []pgproto3.BackendMessage{
&pgproto3.DataRow{Values: [][]byte{[]byte(fmt.Sprintf("dropped shard with %s", id))}},
&pgproto3.DataRow{Values: [][]byte{[]byte(fmt.Sprintf("shard id -> %s", id))}},
} {
if err := pi.cl.Send(msg); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
Expand Down Expand Up @@ -253,7 +253,7 @@ func (pi *PSQLInteractor) CreateKeyRange(ctx context.Context, keyRange *kr.KeyRa
}

for _, msg := range []pgproto3.BackendMessage{
&pgproto3.DataRow{Values: [][]byte{[]byte(fmt.Sprintf("created key range with bound %s", keyRange.LowerBound))}},
&pgproto3.DataRow{Values: [][]byte{[]byte(fmt.Sprintf("bound -> %s", keyRange.LowerBound))}},
} {
if err := pi.cl.Send(msg); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
Expand All @@ -272,7 +272,8 @@ func (pi *PSQLInteractor) SplitKeyRange(ctx context.Context, split *kr.SplitKeyR
}

for _, msg := range []pgproto3.BackendMessage{
&pgproto3.DataRow{Values: [][]byte{[]byte(fmt.Sprintf("split key range %v by %s", split.SourceID, string(split.Bound)))}},
&pgproto3.DataRow{Values: [][]byte{[]byte(fmt.Sprintf("key range id -> %v", split.SourceID))}},
&pgproto3.DataRow{Values: [][]byte{[]byte(fmt.Sprintf("bound -> %s", string(split.Bound)))}},
} {
if err := pi.cl.Send(msg); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
Expand All @@ -292,7 +293,7 @@ func (pi *PSQLInteractor) LockKeyRange(ctx context.Context, krid string) error {

for _, msg := range []pgproto3.BackendMessage{
&pgproto3.DataRow{Values: [][]byte{
[]byte(fmt.Sprintf("lock key range with id %v", krid))},
[]byte(fmt.Sprintf("key range id -> %v", krid))},
},
} {
if err := pi.cl.Send(msg); err != nil {
Expand All @@ -314,7 +315,7 @@ func (pi *PSQLInteractor) UnlockKeyRange(ctx context.Context, krid string) error
for _, msg := range []pgproto3.BackendMessage{
&pgproto3.DataRow{Values: [][]byte{
[]byte(
fmt.Sprintf("unlocked key range with id %v", krid)),
fmt.Sprintf("key range id -> %v", krid)),
},
},
} {
Expand All @@ -338,7 +339,7 @@ func (pi *PSQLInteractor) Shards(ctx context.Context, shards []*datashards.DataS

for _, shard := range shards {
if err := pi.cl.Send(&pgproto3.DataRow{
Values: [][]byte{[]byte(fmt.Sprintf("datashard with ID %s", shard.ID))},
Values: [][]byte{[]byte(fmt.Sprintf("shard id -> %s", shard.ID))},
}); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
Expand Down Expand Up @@ -611,7 +612,7 @@ func (pi *PSQLInteractor) Routers(resp []*topology.Router) error {
}

for _, msg := range resp {
if err := pi.WriteDataRow(fmt.Sprintf("router %s-%s", msg.ID, msg.Address), string(msg.State)); err != nil {
if err := pi.WriteDataRow(fmt.Sprintf("router -> %s-%s", msg.ID, msg.Address), string(msg.State)); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}
Expand All @@ -622,12 +623,12 @@ func (pi *PSQLInteractor) Routers(resp []*topology.Router) error {

// TODO : unit tests
func (pi *PSQLInteractor) UnregisterRouter(id string) error {
if err := pi.WriteHeader("unregister routers"); err != nil {
if err := pi.WriteHeader("unregister router"); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}

if err := pi.WriteDataRow(fmt.Sprintf("router %s unregistered", id)); err != nil {
if err := pi.WriteDataRow(fmt.Sprintf("router id -> %s", id)); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}
Expand All @@ -637,12 +638,12 @@ func (pi *PSQLInteractor) UnregisterRouter(id string) error {

// TODO : unit tests
func (pi *PSQLInteractor) RegisterRouter(ctx context.Context, id string, addr string) error {
if err := pi.WriteHeader("register routers"); err != nil {
if err := pi.WriteHeader("register router"); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}

if err := pi.WriteDataRow(fmt.Sprintf("router %s-%s registered", id, addr)); err != nil {
if err := pi.WriteDataRow(fmt.Sprintf("router -> %s-%s", id, addr)); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}
Expand Down Expand Up @@ -688,7 +689,7 @@ func (pi *PSQLInteractor) DropKeyRange(ctx context.Context, ids []string) error
}

for _, id := range ids {
if err := pi.WriteDataRow(fmt.Sprintf("drop key range %s", id)); err != nil {
if err := pi.WriteDataRow(fmt.Sprintf("key range id -> %s", id)); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}
Expand All @@ -704,7 +705,7 @@ func (pi *PSQLInteractor) AddDistribution(ctx context.Context, ks *distributions
return err
}

if err := pi.WriteDataRow(fmt.Sprintf("created distribution with id %s", ks.ID())); err != nil {
if err := pi.WriteDataRow(fmt.Sprintf("distribution id -> %s", ks.ID())); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}
Expand All @@ -719,7 +720,7 @@ func (pi *PSQLInteractor) DropDistribution(ctx context.Context, ids []string) er
}

for _, id := range ids {
if err := pi.WriteDataRow(fmt.Sprintf("drop distribution %s", id)); err != nil {
if err := pi.WriteDataRow(fmt.Sprintf("distribution id -> %s", id)); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}
Expand All @@ -736,7 +737,12 @@ func (pi *PSQLInteractor) AlterDistributionAttach(ctx context.Context, id string
}

for _, r := range ds {
if err := pi.WriteDataRow(fmt.Sprintf("attached relation %s to distribution %s", r.Name, id)); err != nil {
if err := pi.WriteDataRow(fmt.Sprintf("relation name -> %s", r.Name)); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}

if err := pi.WriteDataRow(fmt.Sprintf("distribution id -> %s", id)); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}
Expand All @@ -752,7 +758,12 @@ func (pi *PSQLInteractor) AlterDistributionDetach(_ context.Context, id string,
return err
}

if err := pi.WriteDataRow(fmt.Sprintf("detached relation %s from distribution %s", relName, id)); err != nil {
if err := pi.WriteDataRow(fmt.Sprintf("relation name -> %s", relName)); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}

if err := pi.WriteDataRow(fmt.Sprintf("distribution id -> %s", id)); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}
Expand Down Expand Up @@ -781,7 +792,7 @@ func (pi *PSQLInteractor) KillClient(clientID uint) error {
return err
}

if err := pi.WriteDataRow(fmt.Sprintf("the client %d was killed", clientID)); err != nil {
if err := pi.WriteDataRow(fmt.Sprintf("client id -> %d", clientID)); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}
Expand Down
16 changes: 8 additions & 8 deletions test/feature/features/coordinator.feature
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Feature: Coordinator test
Then command return code should be "0"
And SQL result should match regexp
"""
router r2-regress_router:7000
router -\\u003e r2-regress_router:7000
"""

Scenario: Register 2 routers with same address fails
Expand All @@ -141,7 +141,7 @@ Feature: Coordinator test
"""
Then SQL result should match regexp
"""
router r1-regress_router:7000
router -\\u003e r1-regress_router:7000
"""

Scenario: Register 2 routers with same id fails
Expand All @@ -160,7 +160,7 @@ Feature: Coordinator test
"""
Then SQL result should match regexp
"""
router r1-regress_router:7000
router -\\u003e r1-regress_router:7000
"""

Scenario: Register router with invalid address fails
Expand All @@ -180,7 +180,7 @@ Feature: Coordinator test
Then SQL result should match json_exactly
"""
[{
"show routers":"router r1-regress_router:7000",
"show routers":"router -\u003e r1-regress_router:7000",
"status":"OPENED"
}]
"""
Expand Down Expand Up @@ -465,10 +465,10 @@ Feature: Coordinator test
"""
[
{
"listing data shards": "datashard with ID sh1"
"listing data shards": "shard id -\u003e sh1"
},
{
"listing data shards": "datashard with ID sh2"
"listing data shards": "shard id -\u003e sh2"
}
]
"""
Expand All @@ -486,7 +486,7 @@ Feature: Coordinator test
"""
[
{
"listing data shards": "datashard with ID sh2"
"listing data shards": "shard id -\u003e sh2"
}
]
"""
Expand All @@ -503,7 +503,7 @@ Feature: Coordinator test
Then command return code should be "0"
And SQL result should match regexp
"""
router r1-regress_router:7000
router -\\u003e r1-regress_router:7000
"""

#
Expand Down
4 changes: 2 additions & 2 deletions test/feature/features/memqdb.feature
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Feature: MemQDB save state into a file
Then command return code should be "0"
And SQL result should match regexp
"""
lock key range with id krid1
key range id -\\u003e krid1
"""
When host "router" is stopped
And host "router" is started
Expand All @@ -141,7 +141,7 @@ Feature: MemQDB save state into a file
Then command return code should be "0"
And SQL result should match regexp
"""
unlocked key range with id krid1
key range id -\\u003e krid1
"""

Scenario: Sharding is not initialized if init.sql file doesn't exists
Expand Down
4 changes: 2 additions & 2 deletions test/feature/features/proxy_console.feature
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ Feature: Proxy console
"""
Then SQL result should match regexp
"""
router r1-regress_router:7000
router -\\u003e r1-regress_router:7000
"""
And SQL result should match regexp
"""
router r2-regress_router_2:7000
router -\\u003e r2-regress_router_2:7000
"""
30 changes: 15 additions & 15 deletions test/regress/tests/console/expected/add.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
https://github.com/pg-sharding/spqr/tree/master/docs

CREATE DISTRIBUTION ds1 COLUMN TYPES integer;
add distribution
----------------------------------
created distribution with id ds1
add distribution
------------------------
distribution id -> ds1
(1 row)

CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1;
add key range
--------------------------------
created key range with bound 1
add key range
---------------
bound -> 1
(1 row)

CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh1 FOR DISTRIBUTION ds1;
add key range
---------------------------------
created key range with bound 11
add key range
---------------
bound -> 11
(1 row)

SHOW key_ranges;
Expand All @@ -31,9 +31,9 @@ SHOW key_ranges;
(2 rows)

DROP KEY RANGE krid1;
drop key range
----------------------
drop key range krid1
drop key range
-----------------------
key range id -> krid1
(1 row)

CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1;
Expand All @@ -47,9 +47,9 @@ SHOW key_ranges;
CREATE KEY RANGE krid2 FROM 33 ROUTE TO nonexistentshard FOR DISTRIBUTION ds1;
ERROR: unknown shard nonexistentshard.
DROP DISTRIBUTION ALL CASCADE;
drop distribution
-----------------------
drop distribution ds1
drop distribution
------------------------
distribution id -> ds1
(1 row)

DROP KEY RANGE ALL;
Expand Down
Loading
Loading