fix: preserve alias in search load checkpoint
This commit is contained in:
@@ -246,6 +246,7 @@ def checkpoint_state(
|
||||
cluster_uuid: str,
|
||||
index_uuid: str,
|
||||
limit: int | None,
|
||||
alias: str | None,
|
||||
) -> tuple[dict, str | None]:
|
||||
source = input_root.resolve()
|
||||
destination = checkpoint.resolve()
|
||||
@@ -254,7 +255,7 @@ def checkpoint_state(
|
||||
manifest_sha256 = file_sha256(input_root / "manifest.sqlite3")
|
||||
if not resume:
|
||||
return {
|
||||
"schema_version": 1,
|
||||
"schema_version": 2,
|
||||
"url": url,
|
||||
"cluster_uuid": cluster_uuid,
|
||||
"index": index,
|
||||
@@ -262,6 +263,7 @@ def checkpoint_state(
|
||||
"input": str(source),
|
||||
"manifest_sha256": manifest_sha256,
|
||||
"limit": limit,
|
||||
"alias": alias,
|
||||
"last_document_code": None,
|
||||
"complete": False,
|
||||
}, None
|
||||
@@ -276,13 +278,14 @@ def checkpoint_state(
|
||||
"input",
|
||||
"manifest_sha256",
|
||||
"limit",
|
||||
"alias",
|
||||
"last_document_code",
|
||||
"complete",
|
||||
}
|
||||
if not isinstance(state, dict) or set(state) != expected:
|
||||
raise ValueError(f"Invalid checkpoint: {checkpoint}")
|
||||
if (
|
||||
state["schema_version"] != 1
|
||||
state["schema_version"] != 2
|
||||
or state["url"] != url
|
||||
or state["cluster_uuid"] != cluster_uuid
|
||||
or state["index"] != index
|
||||
@@ -292,6 +295,8 @@ def checkpoint_state(
|
||||
raise ValueError(f"Checkpoint does not match this load: {checkpoint}")
|
||||
if state["limit"] != limit:
|
||||
raise ValueError(f"Checkpoint limit does not match --limit: {checkpoint}")
|
||||
if state["alias"] != alias:
|
||||
raise ValueError(f"Checkpoint alias does not match --alias: {checkpoint}")
|
||||
if state["manifest_sha256"] != manifest_sha256:
|
||||
raise ValueError("Normalized manifest changed; create a new versioned index")
|
||||
if state["complete"] is not False:
|
||||
@@ -331,6 +336,7 @@ def load_bulk(
|
||||
cluster_uuid,
|
||||
index_uuid,
|
||||
limit,
|
||||
alias,
|
||||
)
|
||||
documents = document_count(input_root, limit, start_at)
|
||||
if not resume:
|
||||
|
||||
@@ -134,6 +134,21 @@ class MinjustOpenSearchTest(unittest.TestCase):
|
||||
{"test-index": {"settings": {"index": {"uuid": "index-1"}}}},
|
||||
]
|
||||
with self.assertRaisesRegex(ValueError, "does not match"):
|
||||
load_bulk(
|
||||
root / "normalized",
|
||||
"http://127.0.0.1:9200",
|
||||
"test-index",
|
||||
maximum_bytes=4096,
|
||||
resume=True,
|
||||
checkpoint=checkpoint,
|
||||
alias="test-current",
|
||||
)
|
||||
with patch("search.minjust_opensearch.request_json") as request:
|
||||
request.side_effect = [
|
||||
{"cluster_uuid": "cluster-1"},
|
||||
{"test-index": {"settings": {"index": {"uuid": "index-1"}}}},
|
||||
]
|
||||
with self.assertRaisesRegex(ValueError, "alias"):
|
||||
load_bulk(
|
||||
root / "normalized",
|
||||
"http://127.0.0.1:9200",
|
||||
@@ -156,11 +171,13 @@ class MinjustOpenSearchTest(unittest.TestCase):
|
||||
limit=1,
|
||||
resume=True,
|
||||
checkpoint=checkpoint,
|
||||
alias="test-current",
|
||||
)
|
||||
with patch("search.minjust_opensearch.request_json") as request:
|
||||
request.side_effect = [
|
||||
{"cluster_uuid": "cluster-1"},
|
||||
{"test-index": {"settings": {"index": {"uuid": "index-1"}}}},
|
||||
{"acknowledged": True},
|
||||
]
|
||||
self.assertEqual(
|
||||
load_bulk(
|
||||
@@ -170,10 +187,12 @@ class MinjustOpenSearchTest(unittest.TestCase):
|
||||
maximum_bytes=4096,
|
||||
resume=True,
|
||||
checkpoint=checkpoint,
|
||||
alias="test-current",
|
||||
),
|
||||
(1, 0),
|
||||
)
|
||||
self.assertTrue(all(call.args[1] == "GET" for call in request.call_args_list))
|
||||
self.assertTrue(all(call.args[1] == "GET" for call in request.call_args_list[:-1]))
|
||||
self.assertEqual(request.call_args_list[-1].args[1], "POST")
|
||||
|
||||
state["last_document_code"] = "9"
|
||||
state["complete"] = False
|
||||
@@ -191,6 +210,7 @@ class MinjustOpenSearchTest(unittest.TestCase):
|
||||
maximum_bytes=4096,
|
||||
resume=True,
|
||||
checkpoint=checkpoint,
|
||||
alias="test-current",
|
||||
)
|
||||
|
||||
failed_checkpoint = root / "failed-checkpoint.json"
|
||||
@@ -236,6 +256,7 @@ class MinjustOpenSearchTest(unittest.TestCase):
|
||||
maximum_bytes=4096,
|
||||
resume=True,
|
||||
checkpoint=checkpoint,
|
||||
alias="test-current",
|
||||
)
|
||||
|
||||
http_error = urllib.error.HTTPError(
|
||||
|
||||
Reference in New Issue
Block a user