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

enhance(client): support checkpoint in remote datastore #3099

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
22 changes: 15 additions & 7 deletions client/starwhale/api/_impl/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@
)
from starwhale.utils.config import SWCliConfigMixed
from starwhale.base.models.base import SwBaseModel
from starwhale.base.client.models.models import ColumnSchemaDesc, KeyValuePairSchema
from starwhale.base.client.models.models import (
ColumnSchemaDesc,
KeyValuePairSchema,
CreateCheckpointRequest,
)
from starwhale.base.client.api.data_store import DataStoreApi

datastore_manifest_file_name = "manifest.json"
datastore_max_dirty_records = int(os.getenv("DATASTORE_MAX_DIRTY_RECORDS", "10000"))
Expand Down Expand Up @@ -2591,6 +2596,7 @@ def __init__(self, instance_uri: str, token: str) -> None:

self.instance_uri = instance_uri
self.token = token
self.client = DataStoreApi(instance_uri, token)

def __str__(self) -> str:
return f"RemoteDataStore for {self.instance_uri}"
Expand Down Expand Up @@ -2710,21 +2716,23 @@ def delete_by_range(
return ""

def list_table_checkpoints(self, table_name: str) -> List[Checkpoint]:
return []
resp = self.client.list_checkpoints(table_name)
return [Checkpoint(revision=cp.id) for cp in resp]

def add_checkpoint(self, table_name: str, revision: str) -> None:
...
def add_checkpoint(self, table_name: str) -> Checkpoint:
resp = self.client.create_checkpoint(CreateCheckpointRequest(table=table_name))
return Checkpoint(revision=resp.id)

def remove_checkpoint(self, table_name: str, cp: Checkpoint) -> None:
...
self.client.delete_checkpoint(table_name, cp.revision)

def get_table_size(self, table_name: str, cp: Checkpoint | None = None) -> int:
return 0


class Checkpoint(SwBaseModel):
revision: str
created_at: int # timestamp in milliseconds
created_at: Optional[int] # timestamp in milliseconds


class DataStore(Protocol):
Expand Down Expand Up @@ -2777,7 +2785,7 @@ def delete_by_range(
def list_table_checkpoints(self, table_name: str) -> List[Checkpoint]:
...

def add_checkpoint(self, table_name: str, revision: str) -> None:
def add_checkpoint(self, table_name: str) -> Checkpoint:
...

def remove_checkpoint(self, table_name: str, cp: Checkpoint) -> None:
Expand Down
33 changes: 33 additions & 0 deletions client/starwhale/base/client/api/data_store.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from __future__ import annotations

from typing import List

from starwhale.base.client.client import Client, TypeWrapper
from starwhale.base.client.models.models import (
CheckpointVo,
CreateCheckpointRequest,
ResponseMessageListCheckpointVo,
)

_URI = "/api/v1/project/datastore/checkpoint"


class DataStoreApi(Client):
def __init__(self, url: str, token: str) -> None:
super().__init__(url, token)

def list_checkpoints(self, table: str) -> List[CheckpointVo]:
return (
TypeWrapper(
ResponseMessageListCheckpointVo,
self.http_get(_URI, params={"table": table}),
)
.response()
.data
)

def create_checkpoint(self, req: CreateCheckpointRequest) -> CheckpointVo:
return TypeWrapper(CheckpointVo, self.http_post(_URI, json=req)).response().data

def delete_checkpoint(self, table: str, revision: str) -> None:
self.http_delete(_URI, params={"table": table, "id": revision})
24 changes: 24 additions & 0 deletions client/starwhale/base/client/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,24 @@ class FlushRequest(SwBaseModel):
pass


class CreateCheckpointRequest(SwBaseModel):
table: str
user_data: Optional[str] = Field(None, alias='userData')


class CheckpointVo(SwBaseModel):
id: str
created_time: int = Field(..., alias='createdTime')
row_count: int = Field(..., alias='rowCount')
user_data: Optional[str] = Field(None, alias='userData')


class ResponseMessageCheckpointVo(SwBaseModel):
code: str
message: str
data: CheckpointVo


class InitUploadBlobRequest(SwBaseModel):
content_md5: str = Field(..., alias='contentMd5')
content_length: int = Field(..., alias='contentLength')
Expand Down Expand Up @@ -1127,6 +1145,12 @@ class RuntimeSuggestionVo(SwBaseModel):
runtimes: Optional[List[RuntimeVersionVo]] = None


class ResponseMessageListCheckpointVo(SwBaseModel):
code: str
message: str
data: List[CheckpointVo]


class UserRoleDeleteRequest(UserCheckPasswordRequest):
pass

Expand Down
Loading