Skip to content

Commit

Permalink
Skip stored but not indexed error for shards from unavailable nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jotare committed Feb 23, 2024
1 parent eb91bf8 commit e2c1fb2
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions nucliadb/nucliadb/purge/orphan_shards.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,26 @@ async def detect_orphan_shards(driver: Driver) -> dict[str, ShardLocation]:
"""
# To avoid detecting a new shard as orphan, query the index first and maindb
# afterwards
indexed_shards = await _get_indexed_shards()
indexed_shards: dict[str, ShardLocation] = {}
available_nodes = manager.get_index_nodes()
for node in available_nodes:
node_shards = await _get_indexed_shards(node)
indexed_shards.update(node_shards)

stored_shards = await _get_stored_shards(driver)

# Log an error in case we found a shard stored but not indexed, this should
# never happen as shards are created in the index node and then stored in
# maindb
not_indexed_shards = stored_shards.keys() - indexed_shards.keys()
available_nodes_ids = [node.id for node in available_nodes]
for shard_id in not_indexed_shards:
location = stored_shards[shard_id]

# skip shards from unavailable nodes
if location.node_id not in available_nodes_ids:
continue

logger.error(
"Found a shard on maindb not indexed in the index nodes",
extra={
Expand All @@ -75,11 +86,11 @@ async def detect_orphan_shards(driver: Driver) -> dict[str, ShardLocation]:

orphan_shard_ids = indexed_shards.keys() - stored_shards.keys()
orphan_shards: dict[str, ShardLocation] = {}
unavailable_nodes = set()
unavailable_nodes: set[str] = set()
rollover_dm = RolloverDataManager(driver)
for shard_id in orphan_shard_ids:
node_id = indexed_shards[shard_id].node_id
node = manager.get_index_node(node_id)
node = manager.get_index_node(node_id) # type: ignore
if node is None:
unavailable_nodes.add(node_id)
kbid = UNKNOWN_KB
Expand All @@ -104,13 +115,11 @@ async def detect_orphan_shards(driver: Driver) -> dict[str, ShardLocation]:
return orphan_shards


async def _get_indexed_shards() -> dict[str, ShardLocation]:
async def _get_indexed_shards(node: AbstractIndexNode) -> dict[str, ShardLocation]:
indexed_shards: dict[str, ShardLocation] = {}
available_nodes = manager.get_index_nodes()
for node in available_nodes:
node_shards = await node.list_shards()
for shard_id in node_shards:
indexed_shards[shard_id] = ShardLocation(kbid=UNKNOWN_KB, node_id=node.id)
node_shards = await node.list_shards()
for shard_id in node_shards:
indexed_shards[shard_id] = ShardLocation(kbid=UNKNOWN_KB, node_id=node.id)
return indexed_shards


Expand Down

3 comments on commit e2c1fb2

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: e2c1fb2 Previous: d4afd82 Ratio
nucliadb/search/tests/unit/search/test_fetch.py::test_highligh_error 12961.795402928765 iter/sec (stddev: 8.980130720768561e-7) 13028.533525895236 iter/sec (stddev: 4.192637045977425e-7) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: e2c1fb2 Previous: d4afd82 Ratio
nucliadb/search/tests/unit/search/test_fetch.py::test_highligh_error 13183.754647810953 iter/sec (stddev: 2.463130718254394e-7) 13028.533525895236 iter/sec (stddev: 4.192637045977425e-7) 0.99

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: e2c1fb2 Previous: d4afd82 Ratio
nucliadb/search/tests/unit/search/test_fetch.py::test_highligh_error 13009.881741291518 iter/sec (stddev: 8.835295566259368e-7) 13028.533525895236 iter/sec (stddev: 4.192637045977425e-7) 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.