[JAVA-1474] Add ability to run single operations with different timeout (e.g. Datastore.ensureIndexes()) Created: 23/Sep/14  Updated: 31/Jan/18  Resolved: 31/Jan/18

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: 2.11.3
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: David Gubler Assignee: Unassigned
Resolution: Won't Fix Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

We use Datastore.ensureIndexes(true) to let Morphia create the indexes. We also use a 30 second operation timeout (MongoOptions. socketTimeout(30000)) to make the application more robust against random problems (e.g. network issues).

Now if Morphia needs to create an index on a huge collection, ensureIndexes(true) will block even though background index build is enabled, which in itself is ok, since we don't want to start the application before the indexes are ready. However, it also obeys the timeout of 30 seconds (again not a bug per se), so the operation will eventually fail.

At this point the initialization of our entire application fails, because the ensureIndexes() call is part of the initialization, and we have to try to start it again, possibly several times. This is annoying.

I can see several ways around this.

  • A workaround would be to create an additional MongoDB connection and Morphia session without timeout just to create the indexes. This is possible, but a bit cumbersome.
  • Better: Being able to re-configure the MongoClient object. Currently it can only return the current options (MongoClient.getMongoClientOptions()), but there's no way to set them. If this were possible we could disable the timeouts for this one operation. However it would be a bit nasty to reconfigure the Mongo client globally, affecting the entire application, while the application is running (not an issue for ensureIndexes() though).
  • Best: Enable a single operation to use different timeout settings. This way the ensureIndexes() call could use different timeouts.

Apart from the Datastore.ensureIndexes() feature, the ability to run operations with different timeouts would also be useful for statistics/reporting or any sort of batch jobs.

I realize that we do not run the lastest version of the driver, but I have not found any change in this area in the changelogs nor the API docs.



 Comments   
Comment by Jeffrey Yemin [ 31/Jan/18 ]

I believe this has been addressed, as all relevant CRUD operation methods now take a maxTime parameter. See for example CreateIndexOptions.maxTime.

While this doesn't change the per-message readSocketTimeout, it will instruct the server to give up after maxTime has been exceeded.

Generated at Thu Feb 08 08:54:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.