Skip to content

Commit 600eaf6

Browse files
better console messages (#629)
* Update interactor.go * Update interactor.go * fix tests * fix interactor.go and fix tests * fix tests rows count * fix feature tests * fix feauture tests * fix feauture tests * fix feature tests * fix feature tests * Update memqdb.feature * update feature tests * final fix * Update coordinator.feature
1 parent 45114fd commit 600eaf6

26 files changed

+456
-416
lines changed

pkg/clientinteractor/interactor.go

+30-19
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,13 @@ func (pi *PSQLInteractor) Version(_ context.Context) error {
252252
// Returns:
253253
// - error: An error if sending the messages fails, otherwise nil.
254254
func (pi *PSQLInteractor) AddShard(shard *datashards.DataShard) error {
255-
if err := pi.WriteHeader("add datashard"); err != nil {
255+
if err := pi.WriteHeader("add shard"); err != nil {
256256
spqrlog.Zero.Error().Err(err).Msg("")
257257
return err
258258
}
259259

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

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

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

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

419420
for _, msg := range []pgproto3.BackendMessage{
420421
&pgproto3.DataRow{Values: [][]byte{
421-
[]byte(fmt.Sprintf("lock key range with id %v", krid))},
422+
[]byte(fmt.Sprintf("key range id -> %v", krid))},
422423
},
423424
} {
424425
if err := pi.cl.Send(msg); err != nil {
@@ -450,7 +451,7 @@ func (pi *PSQLInteractor) UnlockKeyRange(ctx context.Context, krid string) error
450451
for _, msg := range []pgproto3.BackendMessage{
451452
&pgproto3.DataRow{Values: [][]byte{
452453
[]byte(
453-
fmt.Sprintf("unlocked key range with id %v", krid)),
454+
fmt.Sprintf("key range id -> %v", krid)),
454455
},
455456
},
456457
} {
@@ -551,7 +552,7 @@ func (pi *PSQLInteractor) Shards(ctx context.Context, shards []*datashards.DataS
551552

552553
for _, shard := range shards {
553554
if err := pi.cl.Send(&pgproto3.DataRow{
554-
Values: [][]byte{[]byte(fmt.Sprintf("datashard with ID %s", shard.ID))},
555+
Values: [][]byte{[]byte(fmt.Sprintf("shard id -> %s", shard.ID))},
555556
}); err != nil {
556557
spqrlog.Zero.Error().Err(err).Msg("")
557558
return err
@@ -927,7 +928,7 @@ func (pi *PSQLInteractor) Routers(resp []*topology.Router) error {
927928
}
928929

929930
for _, msg := range resp {
930-
if err := pi.WriteDataRow(fmt.Sprintf("router %s-%s", msg.ID, msg.Address), string(msg.State)); err != nil {
931+
if err := pi.WriteDataRow(fmt.Sprintf("router -> %s-%s", msg.ID, msg.Address), string(msg.State)); err != nil {
931932
spqrlog.Zero.Error().Err(err).Msg("")
932933
return err
933934
}
@@ -946,12 +947,12 @@ func (pi *PSQLInteractor) Routers(resp []*topology.Router) error {
946947
// Returns:
947948
// - error: An error if any occurred during the operation.
948949
func (pi *PSQLInteractor) UnregisterRouter(id string) error {
949-
if err := pi.WriteHeader("unregister routers"); err != nil {
950+
if err := pi.WriteHeader("unregister router"); err != nil {
950951
spqrlog.Zero.Error().Err(err).Msg("")
951952
return err
952953
}
953954

954-
if err := pi.WriteDataRow(fmt.Sprintf("router %s unregistered", id)); err != nil {
955+
if err := pi.WriteDataRow(fmt.Sprintf("router id -> %s", id)); err != nil {
955956
spqrlog.Zero.Error().Err(err).Msg("")
956957
return err
957958
}
@@ -971,12 +972,12 @@ func (pi *PSQLInteractor) UnregisterRouter(id string) error {
971972
// Returns:
972973
// - error: An error if any occurred during the operation.
973974
func (pi *PSQLInteractor) RegisterRouter(ctx context.Context, id string, addr string) error {
974-
if err := pi.WriteHeader("register routers"); err != nil {
975+
if err := pi.WriteHeader("register router"); err != nil {
975976
spqrlog.Zero.Error().Err(err).Msg("")
976977
return err
977978
}
978979

979-
if err := pi.WriteDataRow(fmt.Sprintf("router %s-%s registered", id, addr)); err != nil {
980+
if err := pi.WriteDataRow(fmt.Sprintf("router -> %s-%s", id, addr)); err != nil {
980981
spqrlog.Zero.Error().Err(err).Msg("")
981982
return err
982983
}
@@ -1046,7 +1047,7 @@ func (pi *PSQLInteractor) DropKeyRange(ctx context.Context, ids []string) error
10461047
}
10471048

10481049
for _, id := range ids {
1049-
if err := pi.WriteDataRow(fmt.Sprintf("drop key range %s", id)); err != nil {
1050+
if err := pi.WriteDataRow(fmt.Sprintf("key range id -> %s", id)); err != nil {
10501051
spqrlog.Zero.Error().Err(err).Msg("")
10511052
return err
10521053
}
@@ -1071,7 +1072,7 @@ func (pi *PSQLInteractor) AddDistribution(ctx context.Context, ks *distributions
10711072
return err
10721073
}
10731074

1074-
if err := pi.WriteDataRow(fmt.Sprintf("created distribution with id %s", ks.ID())); err != nil {
1075+
if err := pi.WriteDataRow(fmt.Sprintf("distribution id -> %s", ks.ID())); err != nil {
10751076
spqrlog.Zero.Error().Err(err).Msg("")
10761077
return err
10771078
}
@@ -1095,7 +1096,7 @@ func (pi *PSQLInteractor) DropDistribution(ctx context.Context, ids []string) er
10951096
}
10961097

10971098
for _, id := range ids {
1098-
if err := pi.WriteDataRow(fmt.Sprintf("drop distribution %s", id)); err != nil {
1099+
if err := pi.WriteDataRow(fmt.Sprintf("distribution id -> %s", id)); err != nil {
10991100
spqrlog.Zero.Error().Err(err).Msg("")
11001101
return err
11011102
}
@@ -1122,7 +1123,12 @@ func (pi *PSQLInteractor) AlterDistributionAttach(ctx context.Context, id string
11221123
}
11231124

11241125
for _, r := range ds {
1125-
if err := pi.WriteDataRow(fmt.Sprintf("attached relation %s to distribution %s", r.Name, id)); err != nil {
1126+
if err := pi.WriteDataRow(fmt.Sprintf("relation name -> %s", r.Name)); err != nil {
1127+
spqrlog.Zero.Error().Err(err).Msg("")
1128+
return err
1129+
}
1130+
1131+
if err := pi.WriteDataRow(fmt.Sprintf("distribution id -> %s", id)); err != nil {
11261132
spqrlog.Zero.Error().Err(err).Msg("")
11271133
return err
11281134
}
@@ -1148,7 +1154,12 @@ func (pi *PSQLInteractor) AlterDistributionDetach(_ context.Context, id string,
11481154
return err
11491155
}
11501156

1151-
if err := pi.WriteDataRow(fmt.Sprintf("detached relation %s from distribution %s", relName, id)); err != nil {
1157+
if err := pi.WriteDataRow(fmt.Sprintf("relation name -> %s", relName)); err != nil {
1158+
spqrlog.Zero.Error().Err(err).Msg("")
1159+
return err
1160+
}
1161+
1162+
if err := pi.WriteDataRow(fmt.Sprintf("distribution id -> %s", id)); err != nil {
11521163
spqrlog.Zero.Error().Err(err).Msg("")
11531164
return err
11541165
}
@@ -1193,7 +1204,7 @@ func (pi *PSQLInteractor) KillClient(clientID uint) error {
11931204
return err
11941205
}
11951206

1196-
if err := pi.WriteDataRow(fmt.Sprintf("the client %d was killed", clientID)); err != nil {
1207+
if err := pi.WriteDataRow(fmt.Sprintf("client id -> %d", clientID)); err != nil {
11971208
spqrlog.Zero.Error().Err(err).Msg("")
11981209
return err
11991210
}

test/feature/features/coordinator.feature

+8-8
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Feature: Coordinator test
122122
Then command return code should be "0"
123123
And SQL result should match regexp
124124
"""
125-
router r2-regress_router:7000
125+
router -\\u003e r2-regress_router:7000
126126
"""
127127

128128
Scenario: Register 2 routers with same address fails
@@ -141,7 +141,7 @@ Feature: Coordinator test
141141
"""
142142
Then SQL result should match regexp
143143
"""
144-
router r1-regress_router:7000
144+
router -\\u003e r1-regress_router:7000
145145
"""
146146

147147
Scenario: Register 2 routers with same id fails
@@ -160,7 +160,7 @@ Feature: Coordinator test
160160
"""
161161
Then SQL result should match regexp
162162
"""
163-
router r1-regress_router:7000
163+
router -\\u003e r1-regress_router:7000
164164
"""
165165

166166
Scenario: Register router with invalid address fails
@@ -180,7 +180,7 @@ Feature: Coordinator test
180180
Then SQL result should match json_exactly
181181
"""
182182
[{
183-
"show routers":"router r1-regress_router:7000",
183+
"show routers":"router -\u003e r1-regress_router:7000",
184184
"status":"OPENED"
185185
}]
186186
"""
@@ -465,10 +465,10 @@ Feature: Coordinator test
465465
"""
466466
[
467467
{
468-
"listing data shards": "datashard with ID sh1"
468+
"listing data shards": "shard id -\u003e sh1"
469469
},
470470
{
471-
"listing data shards": "datashard with ID sh2"
471+
"listing data shards": "shard id -\u003e sh2"
472472
}
473473
]
474474
"""
@@ -486,7 +486,7 @@ Feature: Coordinator test
486486
"""
487487
[
488488
{
489-
"listing data shards": "datashard with ID sh2"
489+
"listing data shards": "shard id -\u003e sh2"
490490
}
491491
]
492492
"""
@@ -503,7 +503,7 @@ Feature: Coordinator test
503503
Then command return code should be "0"
504504
And SQL result should match regexp
505505
"""
506-
router r1-regress_router:7000
506+
router -\\u003e r1-regress_router:7000
507507
"""
508508

509509
#

test/feature/features/memqdb.feature

+2-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Feature: MemQDB save state into a file
130130
Then command return code should be "0"
131131
And SQL result should match regexp
132132
"""
133-
lock key range with id krid1
133+
key range id -\\u003e krid1
134134
"""
135135
When host "router" is stopped
136136
And host "router" is started
@@ -141,7 +141,7 @@ Feature: MemQDB save state into a file
141141
Then command return code should be "0"
142142
And SQL result should match regexp
143143
"""
144-
unlocked key range with id krid1
144+
key range id -\\u003e krid1
145145
"""
146146

147147
Scenario: Sharding is not initialized if init.sql file doesn't exists

test/feature/features/proxy_console.feature

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ Feature: Proxy console
230230
"""
231231
Then SQL result should match regexp
232232
"""
233-
router r1-regress_router:7000
233+
router -\\u003e r1-regress_router:7000
234234
"""
235235
And SQL result should match regexp
236236
"""
237-
router r2-regress_router_2:7000
237+
router -\\u003e r2-regress_router_2:7000
238238
"""

test/regress/tests/console/expected/add.out

+15-15
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66
https://github.com/pg-sharding/spqr/tree/master/docs
77

88
CREATE DISTRIBUTION ds1 COLUMN TYPES integer;
9-
add distribution
10-
----------------------------------
11-
created distribution with id ds1
9+
add distribution
10+
------------------------
11+
distribution id -> ds1
1212
(1 row)
1313

1414
CREATE KEY RANGE krid1 FROM 1 ROUTE TO sh1 FOR DISTRIBUTION ds1;
15-
add key range
16-
--------------------------------
17-
created key range with bound 1
15+
add key range
16+
---------------
17+
bound -> 1
1818
(1 row)
1919

2020
CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh1 FOR DISTRIBUTION ds1;
21-
add key range
22-
---------------------------------
23-
created key range with bound 11
21+
add key range
22+
---------------
23+
bound -> 11
2424
(1 row)
2525

2626
SHOW key_ranges;
@@ -31,9 +31,9 @@ SHOW key_ranges;
3131
(2 rows)
3232

3333
DROP KEY RANGE krid1;
34-
drop key range
35-
----------------------
36-
drop key range krid1
34+
drop key range
35+
-----------------------
36+
key range id -> krid1
3737
(1 row)
3838

3939
CREATE KEY RANGE krid2 FROM 11 ROUTE TO sh2 FOR DISTRIBUTION ds1;
@@ -47,9 +47,9 @@ SHOW key_ranges;
4747
CREATE KEY RANGE krid2 FROM 33 ROUTE TO nonexistentshard FOR DISTRIBUTION ds1;
4848
ERROR: unknown shard nonexistentshard.
4949
DROP DISTRIBUTION ALL CASCADE;
50-
drop distribution
51-
-----------------------
52-
drop distribution ds1
50+
drop distribution
51+
------------------------
52+
distribution id -> ds1
5353
(1 row)
5454

5555
DROP KEY RANGE ALL;

0 commit comments

Comments
 (0)