Skip to content

Commit

Permalink
fix: grant ManualCompact api doesn't work
Browse files Browse the repository at this point in the history
cause RBAC require to check collection name, but ManualCompact rpc pass
collection id in request, so grant ManualCompact api doesn't work.

This PR refine compact api impl to pass collection name in request.

Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
weiliu1031 committed Nov 29, 2024
1 parent 053c568 commit cfa78ec
Show file tree
Hide file tree
Showing 11 changed files with 368 additions and 338 deletions.
3 changes: 2 additions & 1 deletion pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1589,12 +1589,13 @@ def compact(
timeout: Optional[float] = None,
**kwargs,
) -> int:
# should be removed, but to be compatible with old milvus server, keep it for now.
request = Prepare.describe_collection_request(collection_name)
rf = self._stub.DescribeCollection.future(request, timeout=timeout)
response = rf.result()
check_status(response.status)

req = Prepare.manual_compaction(response.collectionID, is_clustering)
req = Prepare.manual_compaction(response.collectionID, collection_name, is_clustering)
future = self._stub.ManualCompaction.future(req, timeout=timeout)
response = future.result()
check_status(response.status)
Expand Down
3 changes: 2 additions & 1 deletion pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ def load_balance_request(
)

@classmethod
def manual_compaction(cls, collection_id: int, is_clustering: bool):
def manual_compaction(cls, collection_id: int, collection_name: str, is_clustering: bool):
if collection_id is None or not isinstance(collection_id, int):
raise ParamError(message=f"collection_id value {collection_id} is illegal")

Expand All @@ -1307,6 +1307,7 @@ def manual_compaction(cls, collection_id: int, is_clustering: bool):

request = milvus_types.ManualCompactionRequest()
request.collectionID = collection_id
request.collection_name = collection_name
request.majorCompaction = is_clustering

return request
Expand Down
96 changes: 48 additions & 48 deletions pymilvus/grpc_gen/common_pb2.py

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions pymilvus/grpc_gen/common_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class MsgType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
Connect: _ClassVar[MsgType]
ListClientInfos: _ClassVar[MsgType]
AllocTimestamp: _ClassVar[MsgType]
Replicate: _ClassVar[MsgType]
CreateCredential: _ClassVar[MsgType]
GetCredential: _ClassVar[MsgType]
DeleteCredential: _ClassVar[MsgType]
Expand Down Expand Up @@ -515,6 +516,7 @@ DataNodeTt: MsgType
Connect: MsgType
ListClientInfos: MsgType
AllocTimestamp: MsgType
Replicate: MsgType
CreateCredential: MsgType
GetCredential: MsgType
DeleteCredential: MsgType
Expand Down Expand Up @@ -742,12 +744,14 @@ class MsgBase(_message.Message):
def __init__(self, msg_type: _Optional[_Union[MsgType, str]] = ..., msgID: _Optional[int] = ..., timestamp: _Optional[int] = ..., sourceID: _Optional[int] = ..., targetID: _Optional[int] = ..., properties: _Optional[_Mapping[str, str]] = ..., replicateInfo: _Optional[_Union[ReplicateInfo, _Mapping]] = ...) -> None: ...

class ReplicateInfo(_message.Message):
__slots__ = ("isReplicate", "msgTimestamp")
__slots__ = ("isReplicate", "msgTimestamp", "replicateID")
ISREPLICATE_FIELD_NUMBER: _ClassVar[int]
MSGTIMESTAMP_FIELD_NUMBER: _ClassVar[int]
REPLICATEID_FIELD_NUMBER: _ClassVar[int]
isReplicate: bool
msgTimestamp: int
def __init__(self, isReplicate: bool = ..., msgTimestamp: _Optional[int] = ...) -> None: ...
replicateID: str
def __init__(self, isReplicate: bool = ..., msgTimestamp: _Optional[int] = ..., replicateID: _Optional[str] = ...) -> None: ...

class MsgHeader(_message.Message):
__slots__ = ("base",)
Expand Down
440 changes: 220 additions & 220 deletions pymilvus/grpc_gen/milvus_pb2.py

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions pymilvus/grpc_gen/milvus_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1230,14 +1230,18 @@ class LoadBalanceRequest(_message.Message):
def __init__(self, base: _Optional[_Union[_common_pb2.MsgBase, _Mapping]] = ..., src_nodeID: _Optional[int] = ..., dst_nodeIDs: _Optional[_Iterable[int]] = ..., sealed_segmentIDs: _Optional[_Iterable[int]] = ..., collectionName: _Optional[str] = ..., db_name: _Optional[str] = ...) -> None: ...

class ManualCompactionRequest(_message.Message):
__slots__ = ("collectionID", "timetravel", "majorCompaction")
__slots__ = ("collectionID", "timetravel", "majorCompaction", "collection_name", "db_name")
COLLECTIONID_FIELD_NUMBER: _ClassVar[int]
TIMETRAVEL_FIELD_NUMBER: _ClassVar[int]
MAJORCOMPACTION_FIELD_NUMBER: _ClassVar[int]
COLLECTION_NAME_FIELD_NUMBER: _ClassVar[int]
DB_NAME_FIELD_NUMBER: _ClassVar[int]
collectionID: int
timetravel: int
majorCompaction: bool
def __init__(self, collectionID: _Optional[int] = ..., timetravel: _Optional[int] = ..., majorCompaction: bool = ...) -> None: ...
collection_name: str
db_name: str
def __init__(self, collectionID: _Optional[int] = ..., timetravel: _Optional[int] = ..., majorCompaction: bool = ..., collection_name: _Optional[str] = ..., db_name: _Optional[str] = ...) -> None: ...

class ManualCompactionResponse(_message.Message):
__slots__ = ("status", "compactionID", "compactionPlanCount")
Expand Down
8 changes: 5 additions & 3 deletions pymilvus/grpc_gen/msg_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions pymilvus/grpc_gen/msg_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,17 @@ class DataNodeTtMsg(_message.Message):
timestamp: int
segments_stats: _containers.RepeatedCompositeFieldContainer[_common_pb2.SegmentStats]
def __init__(self, base: _Optional[_Union[_common_pb2.MsgBase, _Mapping]] = ..., channel_name: _Optional[str] = ..., timestamp: _Optional[int] = ..., segments_stats: _Optional[_Iterable[_Union[_common_pb2.SegmentStats, _Mapping]]] = ...) -> None: ...

class ReplicateMsg(_message.Message):
__slots__ = ("base", "is_end", "is_cluster", "database", "collection")
BASE_FIELD_NUMBER: _ClassVar[int]
IS_END_FIELD_NUMBER: _ClassVar[int]
IS_CLUSTER_FIELD_NUMBER: _ClassVar[int]
DATABASE_FIELD_NUMBER: _ClassVar[int]
COLLECTION_FIELD_NUMBER: _ClassVar[int]
base: _common_pb2.MsgBase
is_end: bool
is_cluster: bool
database: str
collection: str
def __init__(self, base: _Optional[_Union[_common_pb2.MsgBase, _Mapping]] = ..., is_end: bool = ..., is_cluster: bool = ..., database: _Optional[str] = ..., collection: _Optional[str] = ...) -> None: ...
Loading

0 comments on commit cfa78ec

Please sign in to comment.