Skip to content

Commit b43aad1

Browse files
k-jamrozyuce
andauthored
Add support for backup count in Vector Collection configuration [AI-145] (#702)
Backup count configuration for vector collection was added in hazelcast/hazelcast-client-protocol#533 New parameters need #699 but the tests work with both 5.5 (skipped) and 6.0. Co-authored-by: Yüce Tekol <yuce.tekol@hazelcast.com>
1 parent d63c07d commit b43aad1

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed

hazelcast/client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,22 @@ def get_topic(self, name: str) -> Topic[MessageType]:
378378
"""
379379
return self._proxy_manager.get_or_create(TOPIC_SERVICE, name)
380380

381-
def create_vector_collection_config(self, name: str, indexes: typing.List[IndexConfig]) -> None:
381+
def create_vector_collection_config(
382+
self,
383+
name: str,
384+
indexes: typing.List[IndexConfig],
385+
backup_count: int = 1,
386+
async_backup_count: int = 0,
387+
) -> None:
382388
# check that indexes have different names
383389
if indexes:
384390
index_names = set(index.name for index in indexes)
385391
if len(index_names) != len(indexes):
386392
raise AssertionError("index names must be unique")
387393

388-
request = dynamic_config_add_vector_collection_config_codec.encode_request(name, indexes)
394+
request = dynamic_config_add_vector_collection_config_codec.encode_request(
395+
name, indexes, backup_count, async_backup_count
396+
)
389397
invocation = Invocation(request, response_handler=lambda m: m)
390398
self._invocation_service.invoke(invocation)
391399
invocation.future.result()

hazelcast/protocol/codec/dynamic_config_add_vector_collection_config_codec.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from hazelcast.serialization.bits import *
2+
from hazelcast.protocol.builtin import FixSizedTypesCodec
13
from hazelcast.protocol.client_message import OutboundMessage, REQUEST_HEADER_SIZE, create_initial_buffer
24
from hazelcast.protocol.builtin import StringCodec
35
from hazelcast.protocol.builtin import ListMultiFrameCodec
@@ -8,11 +10,15 @@
810
# hex: 0x1B1401
911
_RESPONSE_MESSAGE_TYPE = 1774593
1012

11-
_REQUEST_INITIAL_FRAME_SIZE = REQUEST_HEADER_SIZE
13+
_REQUEST_BACKUP_COUNT_OFFSET = REQUEST_HEADER_SIZE
14+
_REQUEST_ASYNC_BACKUP_COUNT_OFFSET = _REQUEST_BACKUP_COUNT_OFFSET + INT_SIZE_IN_BYTES
15+
_REQUEST_INITIAL_FRAME_SIZE = _REQUEST_ASYNC_BACKUP_COUNT_OFFSET + INT_SIZE_IN_BYTES
1216

1317

14-
def encode_request(name, index_configs):
18+
def encode_request(name, index_configs, backup_count, async_backup_count):
1519
buf = create_initial_buffer(_REQUEST_INITIAL_FRAME_SIZE, _REQUEST_MESSAGE_TYPE)
20+
FixSizedTypesCodec.encode_int(buf, _REQUEST_BACKUP_COUNT_OFFSET, backup_count)
21+
FixSizedTypesCodec.encode_int(buf, _REQUEST_ASYNC_BACKUP_COUNT_OFFSET, async_backup_count)
1622
StringCodec.encode(buf, name)
1723
ListMultiFrameCodec.encode(buf, index_configs, VectorIndexConfigCodec.encode, True)
1824
return OutboundMessage(buf, False)

tests/integration/backward_compatible/proxy/vector_collection_test.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,38 @@ def test_size(self):
169169
self.vector_collection.clear()
170170
self.assertEqual(self.vector_collection.size(), 0)
171171

172+
def test_backupCount_valid_values_pass(self):
173+
name = random_string()
174+
self.client.create_vector_collection_config(
175+
name, [IndexConfig("vector", Metric.COSINE, 3)], backup_count=2, async_backup_count=2
176+
)
177+
178+
def test_backupCount(self):
179+
skip_if_server_version_older_than(self, self.client, "6.0")
180+
name = random_string()
181+
# check that the parameter is used by ensuring that it is validated on server side
182+
# there is no simple way to check number of backups
183+
with self.assertRaises(hazelcast.errors.IllegalArgumentError):
184+
self.client.create_vector_collection_config(
185+
name,
186+
[IndexConfig("vector", Metric.COSINE, 3)],
187+
backup_count=7,
188+
async_backup_count=0,
189+
)
190+
191+
def test_asyncBackupCount(self):
192+
skip_if_server_version_older_than(self, self.client, "6.0")
193+
name = random_string()
194+
# check that the parameter is used by ensuring that it is validated on server side
195+
# there is no simple way to check number of backups
196+
with self.assertRaises(hazelcast.errors.IllegalArgumentError):
197+
self.client.create_vector_collection_config(
198+
name,
199+
[IndexConfig("vector", Metric.COSINE, 3)],
200+
backup_count=0,
201+
async_backup_count=7,
202+
)
203+
172204
def assert_document_equal(self, doc1, doc2) -> None:
173205
self.assertEqual(doc1.value, doc2.value)
174206
self.assertEqual(len(doc1.vectors), len(doc2.vectors))

0 commit comments

Comments
 (0)