Skip to content

Commit eaaa984

Browse files
authored
fix: update sync filtering conditions (#5828)
1 parent 2a30a96 commit eaaa984

File tree

1 file changed

+15
-11
lines changed
  • servers/fai/src/fai/utils/turbopuffer

1 file changed

+15
-11
lines changed

servers/fai/src/fai/utils/turbopuffer/sync.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ async def sync_index_to_target_incremental(
471471
This is more efficient than full sync when only a subset of content has changed.
472472
"""
473473
if not parent_ids:
474-
LOGGER.info("No parent_ids provided for incremental sync, skipping")
474+
LOGGER.info("No parent_ids provided for incremental sync, completing successfully")
475475
return
476476

477477
source_namespace_id = get_tpuf_namespace(domain, source_index_name)
@@ -487,16 +487,20 @@ async def sync_index_to_target_incremental(
487487
source_ns = tpuf_client.namespace(source_namespace_id)
488488
target_ns = tpuf_client.namespace(target_namespace_id)
489489

490-
for parent_id in parent_ids:
491-
try:
492-
await target_ns.write(
493-
delete_by_filter=[["source", "Eq", source_index_name], ["parent_id", "Eq", parent_id]]
494-
)
495-
except Exception as e:
496-
# The parent_id might not exist in target yet (net new)
497-
LOGGER.warning(f"Failed to delete parent_id {parent_id} from target: {e}")
498-
499-
LOGGER.info(f"Deleted old records for {len(parent_ids)} parent_ids from target")
490+
try:
491+
await target_ns.write(
492+
delete_by_filter=("And", [("source", "Eq", source_index_name), ("parent_id", "In", parent_ids)])
493+
)
494+
LOGGER.info(f"Deleted old records for {len(parent_ids)} parent_ids from target")
495+
except Exception as e:
496+
LOGGER.warning(f"Batch delete failed, trying individual deletes: {e}")
497+
for parent_id in parent_ids:
498+
try:
499+
await target_ns.write(
500+
delete_by_filter=("And", [("source", "Eq", source_index_name), ("parent_id", "Eq", parent_id)])
501+
)
502+
except Exception as delete_error:
503+
LOGGER.warning(f"Failed to delete parent_id {parent_id}: {delete_error}")
500504

501505
source_ns_exists = await source_ns.exists()
502506
if not source_ns_exists:

0 commit comments

Comments
 (0)