-
-
Notifications
You must be signed in to change notification settings - Fork 514
Add SchemaManager::waitForSearchIndexes()
#2830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
074c6cb
to
d40615c
Compare
I reviewed the full implementation to remove the counting of collection vs search index. In fact when documents are inserted with |
$this->dm->flush(); | ||
|
||
// Write with majority concern to ensure data is visible for search | ||
$this->dm->flush(['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]); |
There was a problem hiding this comment.
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.
614a5fd
to
9eb071c
Compare
9eb071c
to
d447ba1
Compare
$collection = $this->dm->getDocumentCollection($className); | ||
|
||
/** @var array<string, bool> $indexStatus Queryable status for each index name */ | ||
$indexStatus = array_column(iterator_to_array($collection->listSearchIndexes([ |
There was a problem hiding this comment.
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.
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.
$classNames
, optional), a maximum wait time in milliseconds ($maxTimeMs
, default 10,000 ms), and a delay between checks in milliseconds ($waitTimeMs
, default 100 ms).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(removed because unreliable)'search'
or'vectorSearch'
index types.$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