Skip to content

Commit bdedfcf

Browse files
authored
Merge pull request #1164 from jawad-khan/jawad/sharding-support
Add sharding support
2 parents cde48b9 + a2e8c97 commit bdedfcf

File tree

5 files changed

+63
-2
lines changed

5 files changed

+63
-2
lines changed

meilisearch/models/task.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Task(CamelBase):
2121
enqueued_at: datetime
2222
started_at: Optional[datetime] = None
2323
finished_at: Optional[datetime] = None
24+
network: Optional[Dict[str, Any]] = None
2425

2526
if is_pydantic_2():
2627

tests/client/test_client_multi_search_meilisearch.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from meilisearch.errors import MeilisearchApiError
44
from tests.common import INDEX_UID, REMOTE_MS_1, REMOTE_MS_2
5+
from tests.test_utils import disable_sharding
56

67

78
def test_basic_multi_search(client, empty_index):
@@ -84,14 +85,17 @@ def test_multi_search_with_network(client, index_with_documents):
8485
resp = client.add_or_update_networks(
8586
{
8687
"self": REMOTE_MS_1,
88+
"sharding": True,
8789
"remotes": {
8890
REMOTE_MS_1: {
8991
"url": "http://ms-1235.example.meilisearch.io",
9092
"searchApiKey": "xxxxxxxx",
93+
"writeApiKey": "xxxxxxxx",
9194
},
9295
REMOTE_MS_2: {
9396
"url": "http://ms-1255.example.meilisearch.io",
9497
"searchApiKey": "xxxxxxxx",
98+
"writeApiKey": "xxxxxxxx",
9599
},
96100
},
97101
}
@@ -108,3 +112,4 @@ def test_multi_search_with_network(client, index_with_documents):
108112
assert response["hits"][0]["_federation"]["indexUid"] == INDEX_UID
109113
assert response["hits"][0]["_federation"]["remote"] == REMOTE_MS_1
110114
assert response["remoteErrors"] == {}
115+
disable_sharding(client)

tests/client/test_client_network.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from tests.common import REMOTE_MS_1, REMOTE_MS_2
4+
from tests.test_utils import disable_sharding
45

56

67
@pytest.mark.usefixtures("enable_network_options")
@@ -16,15 +17,27 @@ def test_add_or_update_networks(client):
1617
"""Tests upsert network remote instance."""
1718
body = {
1819
"self": REMOTE_MS_1,
20+
"sharding": True,
1921
"remotes": {
20-
REMOTE_MS_1: {"url": "http://localhost:7700", "searchApiKey": "xxxxxxxxxxxxxx"},
21-
REMOTE_MS_2: {"url": "http://localhost:7720", "searchApiKey": "xxxxxxxxxxxxxxx"},
22+
REMOTE_MS_1: {
23+
"url": "http://localhost:7700",
24+
"searchApiKey": "xxxxxxxxxxxxxx",
25+
"writeApiKey": "xxxxxxxxx",
26+
},
27+
REMOTE_MS_2: {
28+
"url": "http://localhost:7720",
29+
"searchApiKey": "xxxxxxxxxxxxxxx",
30+
"writeApiKey": "xxxxxxxx",
31+
},
2232
},
2333
}
2434
response = client.add_or_update_networks(body=body)
2535

2636
assert isinstance(response, dict)
2737
assert response["self"] == REMOTE_MS_1
38+
assert response["sharding"] is True
2839
assert len(response["remotes"]) >= 2
2940
assert REMOTE_MS_2 in response["remotes"]
3041
assert REMOTE_MS_1 in response["remotes"]
42+
43+
disable_sharding(client)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
3+
from tests.common import BASE_URL, REMOTE_MS_1
4+
from tests.test_utils import disable_sharding
5+
6+
7+
@pytest.mark.usefixtures("enable_network_options")
8+
def test_update_and_get_network_settings(client):
9+
"""Test updating and getting network settings."""
10+
instance_name = REMOTE_MS_1
11+
options = {
12+
"self": instance_name,
13+
"remotes": {
14+
instance_name: {
15+
"url": BASE_URL,
16+
"searchApiKey": "search-key-1",
17+
"writeApiKey": "write-key-1",
18+
}
19+
},
20+
"sharding": True,
21+
}
22+
23+
client.add_or_update_networks(options)
24+
response = client.get_all_networks()
25+
26+
assert response["self"] == options["self"]
27+
assert response["remotes"][instance_name]["url"] == options["remotes"][instance_name]["url"]
28+
assert (
29+
response["remotes"][instance_name]["searchApiKey"]
30+
== options["remotes"][instance_name]["searchApiKey"]
31+
)
32+
assert (
33+
response["remotes"][instance_name]["writeApiKey"]
34+
== options["remotes"][instance_name]["writeApiKey"]
35+
)
36+
assert response["sharding"] == options["sharding"]
37+
disable_sharding(client)

tests/test_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ def test_iso_to_date_time(iso_date, expected):
3131
def test_iso_to_date_time_invalid_format():
3232
with pytest.raises(ValueError):
3333
iso_to_date_time("2023-07-13T23:37:20Z")
34+
35+
36+
# Refactor to use the unified API to toggle experimental features
37+
def disable_sharding(client):
38+
client.add_or_update_networks(body={"sharding": False})

0 commit comments

Comments
 (0)