Skip to content

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Sep 24, 2025

Q A
Type feature
BC Break no
Fixed issues PHPORM-399

Summary

This method waits until all search indexes for specified (or all) document classes are both queryable and have indexed all documents in their corresponding collections.

  • It takes up to three arguments: a list of document class names ($classNames, optional), a maximum wait time in milliseconds ($maxTimeMs, default 10,000 ms), and a delay between checks in milliseconds ($waitTimeMs, default 100 ms).
  • The method validates input arguments, then iterates over the document classes to identify the search indexes that need to be checked.
  • In a loop, it checks whether all required search indexes exist and are marked as queryable.
  • For queryable indexes, it further verifies if all documents have been indexed by comparing the count of indexed documents with the total collection count, using aggregation pipelines appropriate for either 'search' or 'vectorSearch' index types. (removed because unreliable)
  • If not all indexes are ready, it waits for $waitTimeMs before checking again, until either all indexes are ready or the maximum wait time ($maxTimeMs) is exceeded (in which case an exception is thrown).

This addition provides a mechanism for applications to block until search indexes are fully prepared for querying, ensuring consistency and readiness before proceeding with operations that depend on those indexes.

Similar implementation: https://github.com/mongodb-labs/pymongo-search-utils/blob/dddd51f6e1784caa43e0dc66ec8d9487e0762d58/pymongo_search_utils/index.py#L259-L298

@GromNaN GromNaN force-pushed the wait-search-index branch 2 times, most recently from 074c6cb to d40615c Compare September 25, 2025 23:48
@GromNaN GromNaN marked this pull request as ready for review September 26, 2025 13:27
@GromNaN GromNaN added this to the 2.13.0 milestone Sep 26, 2025
@GromNaN GromNaN requested a review from jmikola September 26, 2025 14:01
@GromNaN
Copy link
Member Author

GromNaN commented Sep 29, 2025

I reviewed the full implementation to remove the counting of collection vs search index. In fact when documents are inserted with wc:majority before creating the search index, then the status of the search index is queryable: true only when all documents are synchronized. (at least from my tests with atlas local container).

$this->dm->flush();

// Write with majority concern to ensure data is visible for search
$this->dm->flush(['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]);
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, I asked about this in #atlas-search as I couldn't find this discussed in the Atlas Search docs. In any event, no action needed on your part here.

@GromNaN GromNaN force-pushed the wait-search-index branch 2 times, most recently from 614a5fd to 9eb071c Compare September 30, 2025 12:14
$collection = $this->dm->getDocumentCollection($className);

/** @var array<string, bool> $indexStatus Queryable status for each index name */
$indexStatus = array_column(iterator_to_array($collection->listSearchIndexes([
Copy link
Member

Choose a reason for hiding this comment

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

What a marvelous function array_column() is. Thank you, @ramsey.

@GromNaN GromNaN merged commit f22d8ec into doctrine:2.13.x Sep 30, 2025
23 checks passed
@GromNaN GromNaN deleted the wait-search-index branch September 30, 2025 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants