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

Rename is_major to is_clustering #2219

Merged
merged 2 commits into from
Aug 17, 2024
Merged
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
4 changes: 2 additions & 2 deletions pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1548,16 +1548,16 @@ def load_balance(
def compact(
self,
collection_name: str,
is_clustering: Optional[bool] = False,
timeout: Optional[float] = None,
is_major: Optional[bool] = False,
**kwargs,
) -> int:
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_major)
req = Prepare.manual_compaction(response.collectionID, is_clustering)
future = self._stub.ManualCompaction.future(req, timeout=timeout)
response = future.result()
check_status(response.status)
Expand Down
7 changes: 5 additions & 2 deletions pymilvus/client/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,13 +995,16 @@ def load_balance_request(
)

@classmethod
def manual_compaction(cls, collection_id: int, is_major: bool):
def manual_compaction(cls, collection_id: int, 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")

if is_clustering is None or not isinstance(is_clustering, bool):
raise ParamError(message=f"is_clustering value {is_clustering} is illegal")

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

return request

Expand Down
22 changes: 12 additions & 10 deletions pymilvus/client/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,42 +1044,44 @@ def load_balance(
**kwargs,
)

def compact(self, collection_name, timeout=None, is_major=False, **kwargs) -> int:
def compact(self, collection_name, is_clustering=False, timeout=None, **kwargs) -> int:
"""
Do compaction for the collection.

:param collection_name: The collection name to compact
:type collection_name: str

:param is_clustering: trigger clustering compaction
:type is_clustering: bool

:param timeout: The timeout for this method, unit: second
:type timeout: int

:param is_major: trigger major compaction
:type is_major: bool

:return: the compaction ID
:rtype: int

:raises MilvusException: If collection name not exist.
"""
with self._connection() as handler:
return handler.compact(collection_name, timeout=timeout, is_major=is_major, **kwargs)
return handler.compact(
collection_name, is_clustering=is_clustering, timeout=timeout, **kwargs
)

def get_compaction_state(
self, compaction_id: int, timeout=None, is_major=False, **kwargs
self, compaction_id: int, is_clustering=False, timeout=None, **kwargs
) -> CompactionState:
"""
Get compaction states of a targeted compaction id

:param compaction_id: the id returned by compact
:type compaction_id: int

:param is_clustering: get clustering compaction
:type is_clustering: bool

:param timeout: The timeout for this method, unit: second
:type timeout: int

:param is_major: get major compaction
:type is_major: bool

:return: the state of the compaction
:rtype: CompactionState

Expand All @@ -1088,7 +1090,7 @@ def get_compaction_state(

with self._connection() as handler:
return handler.get_compaction_state(
compaction_id, timeout=timeout, is_major=is_major, **kwargs
compaction_id, is_clustering=is_clustering, timeout=timeout, **kwargs
)

def wait_for_compaction_completed(
Expand Down
32 changes: 18 additions & 14 deletions pymilvus/orm/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,31 +1487,33 @@ def drop_index(self, timeout: Optional[float] = None, **kwargs):
**copy_kwargs,
)

def compact(self, timeout: Optional[float] = None, is_major: Optional[bool] = False, **kwargs):
def compact(
self, is_clustering: Optional[bool] = False, timeout: Optional[float] = None, **kwargs
):
"""Compact merge the small segments in a collection

Args:
timeout (``float``, optional): An optional duration of time in seconds to allow
for the RPC. When timeout is set to None, client waits until server response
or error occur.

is_major (``bool``, optional): An optional setting to trigger major compaction.
is_clustering (``bool``, optional): Option to trigger clustering compaction.

Raises:
MilvusException: If anything goes wrong.
"""
conn = self._get_connection()
if is_major:
self.major_compaction_id = conn.compact(
self._name, timeout=timeout, is_major=is_major, **kwargs
if is_clustering:
self.clustering_compaction_id = conn.compact(
self._name, is_clustering=is_clustering, timeout=timeout, **kwargs
)
else:
self.compaction_id = conn.compact(
self._name, timeout=timeout, is_major=is_major, **kwargs
self._name, is_clustering=is_clustering, timeout=timeout, **kwargs
)

def get_compaction_state(
self, timeout: Optional[float] = None, is_major: Optional[bool] = False, **kwargs
self, timeout: Optional[float] = None, is_clustering: Optional[bool] = False, **kwargs
) -> CompactionState:
"""Get the current compaction state

Expand All @@ -1520,20 +1522,22 @@ def get_compaction_state(
for the RPC. When timeout is set to None, client waits until server response
or error occur.

is_major (``bool``, optional): An optional setting to get major compaction state.
is_clustering (``bool``, optional): Option to get clustering compaction state.

Raises:
MilvusException: If anything goes wrong.
"""
conn = self._get_connection()
if is_major:
return conn.get_compaction_state(self.major_compaction_id, timeout=timeout, **kwargs)
if is_clustering:
return conn.get_compaction_state(
self.clustering_compaction_id, timeout=timeout, **kwargs
)
return conn.get_compaction_state(self.compaction_id, timeout=timeout, **kwargs)

def wait_for_compaction_completed(
self,
timeout: Optional[float] = None,
is_major: Optional[bool] = False,
is_clustering: Optional[bool] = False,
**kwargs,
) -> CompactionState:
"""Block until the current collection's compaction completed
Expand All @@ -1543,15 +1547,15 @@ def wait_for_compaction_completed(
for the RPC. When timeout is set to None, client waits until server response
or error occur.

is_major (``bool``, optional): An optional setting to get major compaction state.
is_clustering (``bool``, optional): Option to get clustering compaction state.

Raises:
MilvusException: If anything goes wrong.
"""
conn = self._get_connection()
if is_major:
if is_clustering:
return conn.wait_for_compaction_completed(
self.major_compaction_id, timeout=timeout, **kwargs
self.clustering_compaction_id, timeout=timeout, **kwargs
)
return conn.wait_for_compaction_completed(self.compaction_id, timeout=timeout, **kwargs)

Expand Down