Skip to content

Commit

Permalink
Merge pull request #34605 from dimagi/gh/es/fix-bug-with-reindex-output
Browse files Browse the repository at this point in the history
Gevent doesn't guarantee ordering when calculating ES adapter doc counts
  • Loading branch information
gherceg authored Dec 3, 2024
2 parents f2911d0 + ae510fa commit 2d8e800
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions corehq/apps/es/management/commands/elastic_sync_multiplexed.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,23 @@ def display_source_destination_doc_count(self, adapter):
"""
es_manager.index_refresh(adapter.primary.index_name)
es_manager.index_refresh(adapter.secondary.index_name)

self.perform_cleanup(adapter)

def get_doc_count(_adapter):
return {_adapter.index_name: _adapter.count({})}

greenlets = gevent.joinall([
gevent.spawn(adapter.count, {}),
gevent.spawn(adapter.secondary.count, {})
gevent.spawn(get_doc_count, adapter.primary),
gevent.spawn(get_doc_count, adapter.secondary)
])
primary_count, secondary_count = [g.get() for g in greenlets]
counts = {}
for greenlet in greenlets:
counts.update(greenlet.get())

print(f"\nDoc Count In Old Index '{adapter.primary.index_name}' - {primary_count}")
print(f"\nDoc Count In New Index '{adapter.secondary.index_name}' - {secondary_count}\n\n")
print(f"\nDoc Count In Old Index '{adapter.primary.index_name}' - {counts[adapter.primary.index_name]}")
print(
f"\nDoc Count In New Index '{adapter.secondary.index_name}' - {counts[adapter.secondary.index_name]}\n"
)

def display_backfill_subindex_doc_counts_for_domain(self, source_adapter, destination_adapter, domain):
if not destination_adapter.parent_index_cname:
Expand Down

0 comments on commit 2d8e800

Please sign in to comment.