Skip to content

Commit

Permalink
fix: inconsistency of kernels.session_name column (#1985)
Browse files Browse the repository at this point in the history
Co-authored-by: Sion Kang <[email protected]>
Backported-from: main (24.09)
Backported-to: 24.03
  • Loading branch information
2 people authored and kyujin-cho committed Apr 16, 2024
1 parent 9df6e7d commit af42d4a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/1985.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sync mismatch between `kernels.session_name` and `sessions.name` and fix session-rename API to update `session_name` of sibling kernels atomically.
3 changes: 3 additions & 0 deletions src/ai/backend/manager/api/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,10 +1315,13 @@ async def rename_session(request: web.Request, params: Any) -> web.Response:
owner_access_key,
allow_stale=True,
for_update=True,
kernel_loading_strategy=KernelLoadingStrategy.ALL_KERNELS,
)
if compute_session.status != SessionStatus.RUNNING:
raise InvalidAPIParameters("Can't change name of not running session")
compute_session.name = new_name
for kernel in compute_session.kernels:
kernel.session_name = new_name
await db_sess.commit()

return web.Response(status=204)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""sync_kernelssessionname_to_real_session_name
Revision ID: dddf9be580f5
Revises: 857b763b8618
Create Date: 2024-04-01 16:58:14.341114
"""

import textwrap

from alembic import op
from sqlalchemy.sql import text

# revision identifiers, used by Alembic.
revision = "dddf9be580f5"
down_revision = "857b763b8618"
branch_labels = None
depends_on = None


def upgrade():
conn = op.get_bind()
sync_stmt = textwrap.dedent(
"""
UPDATE kernels
SET session_name = sessions.name
FROM sessions
WHERE kernels.session_id = sessions.id
AND kernels.session_name <> sessions.name;
"""
)
conn.execute(text(sync_stmt))


def downgrade():
pass

0 comments on commit af42d4a

Please sign in to comment.