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

fix lock/unlock key range wrong namespace in qdb #270

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion coordinator/provider/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ func DialRouter(r *topology.Router) (*grpc.ClientConn, error) {
return grpc.Dial(r.Address, grpc.WithInsecure()) //nolint:all
}

type CoordinatorClient interface {
client.Client

CancelMsg() *pgproto3.CancelRequest
}

type qdbCoordinator struct {
coordinator.Coordinator
db qdb.QDB
Expand Down Expand Up @@ -909,13 +915,17 @@ func (qc *qdbCoordinator) UnregisterRouter(ctx context.Context, rID string) erro
return qc.db.DeleteRouter(ctx, rID)
}

func (qc *qdbCoordinator) PrepareClient(nconn net.Conn) (client.Client, error) {
func (qc *qdbCoordinator) PrepareClient(nconn net.Conn) (CoordinatorClient, error) {
cl := psqlclient.NewPsqlClient(nconn)

if err := cl.Init(nil); err != nil {
return nil, err
}

if cl.CancelMsg() != nil {
return cl, nil
}

spqrlog.Zero.Info().
Str("user", cl.Usr()).
Str("db", cl.DB()).
Expand Down Expand Up @@ -946,6 +956,11 @@ func (qc *qdbCoordinator) ProcClient(ctx context.Context, nconn net.Conn) error
return err
}

if cl.CancelMsg() != nil {
// TODO: cancel client here
return nil
}

ci := grpcConnectionIterator{qdbCoordinator: qc}
cli := clientinteractor.NewPSQLInteractor(cl)
for {
Expand Down
10 changes: 0 additions & 10 deletions docker/tests/bin/move.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,11 @@ psql "host=spqr_router_1_1 sslmode=disable user=user1 dbname=db1 port=6432" -c "
exit 1
}

psql "host=spqr_coordinator sslmode=disable user=user1 dbname=db1 port=7002" -c "LOCK KEY RANGE krid2;" || {
echo "ERROR: tests failed"
exit 1
}

psql "host=spqr_coordinator sslmode=disable user=user1 dbname=db1 port=7002" -c "MOVE KEY RANGE krid2 to sh1;" || {
echo "ERROR: tests failed"
exit 1
}

psql "host=spqr_coordinator sslmode=disable user=user1 dbname=db1 port=7002" -c "UNLOCK KEY RANGE krid2;" || {
echo "ERROR: tests failed"
exit 1
}

out=$(psql "host=spqr_shard_1 sslmode=disable user=user1 dbname=db1 port=6432" -c "select * from xMove")
test "$out" = " w_id | s
------+-----
Expand Down
4 changes: 2 additions & 2 deletions qdb/etcdqdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (q *EtcdQDB) LockKeyRange(ctx context.Context, id string) (*KeyRange, error
}
defer unlockMutex(mu, ctx)

resp, err := q.cli.Get(ctx, keyLockPath(keyRangeID))
resp, err := q.cli.Get(ctx, keyLockPath(keyRangeNodePath(keyRangeID)))
diPhantxm marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -428,7 +428,7 @@ func (q *EtcdQDB) UnlockKeyRange(ctx context.Context, id string) error {
}
defer unlockMutex(mu, ctx)

resp, err := q.cli.Get(ctx, keyLockPath(keyRangeID))
resp, err := q.cli.Get(ctx, keyLockPath(keyRangeNodePath(keyRangeID)))
if err != nil {
return err
}
Expand Down
Loading