jdaugherty commented on code in PR #16495:
URL: https://github.com/apache/grails-core/pull/16495#discussion_r4175893539
##########
grails-data-mongodb/core/src/main/groovy/org/grails/datastore/mapping/mongo/MongoDatastore.java:
##########
@@ -315,10 +318,29 @@ public void newConnectionSource(final
ConnectionSource<MongoClient, MongoConnect
MongoDatastore childDatastore =
createChildDatastore(mappingContext, eventPublisher, parent,
singletonConnectionSources);
datastoresByConnectionSource.put(connectionSource.getName(), childDatastore);
registerAllEntitiesWithEnhancer();
- // Registered first and then checked: either close() has
not started, and will find this
- // child when it walks the map, or it has, and the build
is never started.
- if (!closed) {
- childDatastore.buildIndexAutomatically();
+ // Decided under the lifecycle monitor, so a connection
registered while start() or stop() is
+ // under way waits for it and is then treated as the
datastore now is.
+ synchronized (lifecycleMonitor) {
+ // Registered first and then checked: either close()
has not started, and will find this
+ // child when it walks the map, or it has, and the
build is never started.
+ if (closed) {
+ return;
+ }
+ if (running) {
+ // Unless the start() this waited for found it in
the map, and has connected and
+ // built it already.
+ if (!childDatastore.startupBuildDone) {
+
childDatastore.startClient(connectionSources.getFactory(), false);
+ childDatastore.buildIndexAutomatically();
+ childDatastore.startupBuildDone = true;
+ }
+ }
+ else if (stopped && childDatastore.ownsClient()) {
+ // Refused, like the others, until start()
connects it and builds its indexes.
+ childDatastore.stopClient();
Review Comment:
Thanks, verified at e115da9b27. A `buildIndex()` on a connection added while
stopped is now deferred and runs on `start()`, with `buildIndexes` on or off,
and nothing logs an error. Both new features fail against the previous listener.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]