Skip to content

Commit

Permalink
fix: Change vfolder name when deleted to allow reusing the name (#3061)
Browse files Browse the repository at this point in the history
Co-authored-by: Joongi Kim <[email protected]>
Backported-from: main (24.12)
Backported-to: 24.03
Backport-of: 3061
  • Loading branch information
fregataa and achimnol committed Nov 12, 2024
1 parent c502915 commit 0e47c74
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions changes/3061.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Change the name of deleted vfolders with a timestamp suffix when sending them to DELETE_ONGOING status to allow reuse of the vfolder name, for cases when actual deletion takes a long time
38 changes: 19 additions & 19 deletions src/ai/backend/manager/models/vfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import logging
import os.path
import uuid
from collections.abc import Iterable, Mapping
from datetime import datetime
from collections.abc import Container, Iterable, Mapping
from contextlib import AbstractAsyncContextManager as AbstractAsyncCtxMgr
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import PurePosixPath
from typing import (
TYPE_CHECKING,
Expand All @@ -25,7 +27,6 @@
import yaml
from dateutil.parser import ParserError
from dateutil.parser import parse as dtparse
from dateutil.tz import tzutc
from graphene.types.datetime import DateTime as GQLDateTime
from graphql import Undefined
from sqlalchemy.dialects import postgresql as pgsql
Expand Down Expand Up @@ -996,25 +997,24 @@ async def update_vfolder_status(
elif vfolder_info_len == 1:
cond = vfolders.c.id == vfolder_ids[0]

now = datetime.now(tzutc())
now = datetime.now(timezone.utc)

async def _update() -> None:
async with engine.begin_session() as db_session:
query = (
sa.update(vfolders)
.values(
status=update_status,
status_changed=now,
status_history=sql_json_merge(
vfolders.c.status_history,
(),
{
update_status.name: now.isoformat(),
},
),
)
.where(cond)
)
values = {
"status": update_status,
"status_changed": now,
"status_history": sql_json_merge(
VFolderRow.status_history,
(),
{
update_status.name: now.isoformat(),
},
),
}
if update_status == VFolderOperationStatus.DELETE_ONGOING:
values["name"] = VFolderRow.name + f"_deleted_{now.strftime("%Y-%m-%dT%H%M%S%z")}"
query = sa.update(vfolders).values(**values).where(cond)
await db_session.execute(query)

await execute_with_retry(_update)
Expand Down

0 comments on commit 0e47c74

Please sign in to comment.