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

feat: improve reliability & usability of VFolder removal API #1884

Closed
wants to merge 85 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
0dd2c65
feature: improve VFolder purge using background task
fregataa Feb 4, 2024
7d9667c
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Feb 5, 2024
cb3a525
set reporter nullable and set total_progress
fregataa Feb 5, 2024
ee7e0aa
pass total_progress arg to bgtask mgr
fregataa Feb 5, 2024
219791a
add log_type field to ProgressReporter
fregataa Feb 5, 2024
1d47b57
fix UUID json decode error and refactor log type
fregataa Feb 6, 2024
f4b67a9
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Feb 19, 2024
aa61704
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Feb 23, 2024
3c5700c
apply filelock to remove tree
fregataa Feb 23, 2024
8eecfde
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Feb 23, 2024
1a7da50
add news fragment
fregataa Feb 24, 2024
1b82f67
use asyncio.Semaphore for delete_tree instead of FileLock
fregataa Feb 24, 2024
924ac55
update news fragment
fregataa Feb 24, 2024
7ed0378
update test codes
fregataa Feb 24, 2024
d86084b
FileLock after entering delete semaphore
fregataa Feb 24, 2024
0a5bdae
update news fragment
fregataa Feb 24, 2024
34596ac
rename news fragment file
fregataa Feb 24, 2024
9399cf6
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Feb 27, 2024
9cc3016
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Feb 28, 2024
220203f
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Feb 29, 2024
013ceea
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Mar 5, 2024
b07df98
transit delete status correctly and replace legacy 'purge' logs
fregataa Mar 5, 2024
1526694
add GraphQL delete API and update purge API
fregataa Mar 5, 2024
f851ca1
add GQL restore API and remove user_email, group_name fields in VFold…
fregataa Mar 6, 2024
d877925
rename vfolder deletion APIs
fregataa Mar 6, 2024
86f6494
refactor usage of VFolder row
fregataa Mar 6, 2024
5dde934
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Mar 6, 2024
c9e4c4f
update API names
fregataa Mar 7, 2024
c17abc8
fix: send delete-forever request in client
fregataa Mar 7, 2024
39cb42b
update test codes
fregataa Mar 7, 2024
0a976bf
add cli cmd aliases for backward compat
fregataa Mar 7, 2024
79f28c7
follow-up BaseResponseModel
fregataa Mar 7, 2024
ca12909
'recover' is alias of 'restore'
fregataa Mar 7, 2024
07721d8
test: update CLI integration test codes
fregataa Mar 7, 2024
2a23e13
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Mar 10, 2024
d0ff442
update news fragment
fregataa Mar 10, 2024
ba99172
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Apr 1, 2024
6e5e158
chore: update GraphQL schema dump
fregataa Apr 1, 2024
5bbb531
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Apr 1, 2024
3944cc5
Merge remote-tracking branch 'origin/feature/improve-vf-purge-using-b…
fregataa Apr 1, 2024
e2774ce
add gql version
fregataa Apr 2, 2024
c114ae4
chore: update GraphQL schema dump
fregataa Apr 2, 2024
585425c
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Apr 5, 2024
d130b6d
Merge remote-tracking branch 'origin/feature/improve-vf-purge-using-b…
fregataa Apr 5, 2024
68fe62b
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Apr 6, 2024
c9c69fb
update gql schema versions
fregataa Apr 6, 2024
8811c47
chore: update GraphQL schema dump
fregataa Apr 6, 2024
04f4879
add version notations to gql types
fregataa Apr 6, 2024
0143856
Merge remote-tracking branch 'origin/feature/improve-vf-purge-using-b…
fregataa Apr 6, 2024
802e613
chore: update GraphQL schema dump
fregataa Apr 6, 2024
08d985b
add version notation to VFolderNode
fregataa Apr 6, 2024
ed9c897
chore: update GraphQL schema dump
fregataa Apr 6, 2024
a2b3405
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Apr 8, 2024
f63358e
apply formatting
fregataa Apr 8, 2024
37e176b
Merge remote-tracking branch 'origin/feature/improve-vf-purge-using-b…
fregataa Apr 8, 2024
787c501
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Apr 16, 2024
0eed86d
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Apr 16, 2024
79acf10
revert GQL mutations
fregataa Apr 16, 2024
da36224
chore: update GraphQL schema dump
fregataa Apr 16, 2024
25d9a10
better log messages
fregataa Apr 16, 2024
ed150c3
revert 'delete-trash' cli command and api function for backward compat
fregataa Apr 16, 2024
627a251
rename BackgroundTaskLogType to BackgroundTaskLogLevel
fregataa Apr 16, 2024
03f92b8
better var names
fregataa Apr 16, 2024
653ce28
update delete-concurreny config name and add to sample.toml
fregataa Apr 16, 2024
60c4d88
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Apr 16, 2024
a9de3a7
Merge remote-tracking branch 'origin/feature/improve-vf-purge-using-b…
fregataa Apr 16, 2024
9464071
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Apr 17, 2024
080afd3
let 'DEPRECATED' message afront in cmd description
fregataa Apr 17, 2024
df389ac
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Apr 29, 2024
8e3006e
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa May 1, 2024
9917f78
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa May 8, 2024
99cf192
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa May 16, 2024
60c33dd
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Jun 7, 2024
5313e37
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Jun 13, 2024
693fe5e
new Exception to catch Lock timeout
fregataa Jun 13, 2024
f8855d4
update news fragment
fregataa Jun 13, 2024
a027a09
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Jun 20, 2024
67bb3f2
little update about logging
fregataa Jun 20, 2024
493c084
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Jul 4, 2024
8fbaee4
remove nested task
fregataa Jul 4, 2024
e816580
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
achimnol Jul 6, 2024
8799c3c
Merge branch 'main' into feature/improve-vf-purge-using-bgtask
fregataa Jul 6, 2024
92b85ed
create deletion task grouped by storage proxy name
fregataa Jul 6, 2024
2e96bdf
update description
fregataa Jul 6, 2024
5d54cf2
Merge remote-tracking branch 'origin/feature/improve-vf-purge-using-b…
fregataa Jul 6, 2024
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
2 changes: 1 addition & 1 deletion src/ai/backend/manager/api/vfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class SuccessResponseModel(BaseResponseModel):

class BackgroundTaskResponseModel(BaseResponseModel):
task_id: uuid.UUID | None = Field(
description="Background task id. `None` when there is no vfolders to delete."
description="ID of background task. 'null' means there is no background task spawned."
)


Expand Down
38 changes: 36 additions & 2 deletions src/ai/backend/manager/models/vfolder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import enum
import itertools
import logging
import os.path
import uuid
Expand All @@ -9,6 +10,7 @@
from typing import TYPE_CHECKING, Any, Final, List, Mapping, NamedTuple, Optional, Sequence, cast

import aiohttp
import aiotools
import graphene
import sqlalchemy as sa
import trafaret as t
Expand Down Expand Up @@ -1717,13 +1719,16 @@ class Meta:
items = graphene.List(VirtualFolder, required=True)


async def delete_vfolders(
async def _delete_vfolders(
requested_vfolders: Sequence[VFolderDeletionInfo],
*,
storage_manager: StorageSessionManager,
db: ExtendedAsyncSAEngine,
reporter: ProgressReporter | None = None,
reporter: ProgressReporter | None,
) -> None:
"""
Request multiple vfolder deletion one by one.
"""
folders_to_be_deleted: list[VFolderDeletionInfo] = []
folders_failed_to_delete: list[tuple[VFolderDeletionInfo, str]] = []
for vfolder_info in requested_vfolders:
Expand Down Expand Up @@ -1779,6 +1784,35 @@ async def delete_vfolders(
)


async def delete_vfolders(
requested_vfolders: Sequence[VFolderDeletionInfo],
*,
storage_manager: StorageSessionManager,
db: ExtendedAsyncSAEngine,
reporter: ProgressReporter | None = None,
) -> None:
"""
Spawn vfolder deletion tasks grouped by a name of storage proxies.
"""

def _keyfunc(item: VFolderDeletionInfo) -> str:
proxy_name, _ = storage_manager.split_host(item.host)
return proxy_name

async with aiotools.TaskGroup() as tg:
for _, vfolder_iterator in itertools.groupby(
sorted(requested_vfolders, key=_keyfunc), key=_keyfunc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, using typing.Iterable seems more suitable than typing.Sequence for requested_vfolders.
(ref: https://docs.python.org/3/library/functions.html#sorted)

):
tg.create_task(
_delete_vfolders(
list(vfolder_iterator),
storage_manager=storage_manager,
db=db,
reporter=reporter,
)
)


class VirtualFolderNode(graphene.ObjectType):
class Meta:
interfaces = (AsyncNode,)
Expand Down
Loading