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

kvclient: draining not started SQL #112992

Merged
merged 1 commit into from
Oct 25, 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
12 changes: 7 additions & 5 deletions pkg/server/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,13 @@ func (s *drainServer) drainClients(
if err != nil {
return err
}

instanceID := s.sqlServer.sqlIDContainer.SQLInstanceID()
err = s.sqlServer.sqlInstanceStorage.ReleaseInstance(ctx, session, instanceID)
if err != nil {
return err
// If we started a sql session on this node.
if session != "" {
instanceID := s.sqlServer.sqlIDContainer.SQLInstanceID()
err = s.sqlServer.sqlInstanceStorage.ReleaseInstance(ctx, session, instanceID)
if err != nil {
return err
}
}

// Mark the node as fully drained.
Expand Down
24 changes: 24 additions & 0 deletions pkg/server/drain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,27 @@ func TestServerShutdownReleasesSession(t *testing.T) {
require.False(t, sessionExists(*session), "expected session %s to be deleted from the sqlliveness table, but it still exists", *session)
require.Nil(t, queryOwner(tmpSQLInstance), "expected sql_instance %d to have no owning session_id", tmpSQLInstance)
}

// Verify that drain works correctly even if we don't start the sql instance.
func TestNoSQLServer(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

ctx := context.Background()
tc := testcluster.StartTestCluster(t, 2,
base.TestClusterArgs{
ServerArgs: base.TestServerArgs{
DefaultTestTenant: base.TestIsSpecificToStorageLayerAndNeedsASystemTenant,
DisableSQLServer: true,
},
})

defer tc.Stopper().Stop(ctx)
req := serverpb.DrainRequest{Shutdown: false, DoDrain: true, NodeId: "2"}
drainStream, err := tc.Server(0).ApplicationLayer().GetAdminClient(t).Drain(ctx, &req)
require.NoError(t, err)
// When we get this next response the drain has started - check the error.
drainResp, err := drainStream.Recv()
require.NoError(t, err)
require.True(t, drainResp.IsDraining)
}
2 changes: 1 addition & 1 deletion pkg/sql/sqlliveness/slinstance/slinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (l *Instance) Release(ctx context.Context) (sqlliveness.SessionID, error) {
}()

if session == nil {
return sqlliveness.SessionID(""), errors.New("no session to release")
return "", nil
}

if err := l.storage.Delete(ctx, session.ID()); err != nil {
Expand Down