spring-projects / spring-data-mongodb

Provides support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-mongodb/
Apache License 2.0
1.62k stars 1.09k forks source link

Index creation through ReactiveMongoTemplate uses blocking methods [DATAMONGO-1928] #2827

Closed spring-projects-issues closed 6 years ago

spring-projects-issues commented 6 years ago

Mark Paluch opened DATAMONGO-1928 and commented

ReactiveMongoTemplate reuses MongoPersistentEntityIndexCreator which follows an imperative (blocking) programming model. This requires wrapping of ReactiveIndexOperations in a blocking API and usage of .block() methods.

Calling blocking methods from within an application container thread (e.g. netty via Spring Boot) causes the application to hang forever as the event loop is blocked.

Ideally, indexes are created without blocking the application while retaining index creation for initial entities and on the fly


Affects: 2.0.6 (Kay SR6)

Issue Links:

Referenced from: pull request https://github.com/spring-projects/spring-data-mongodb/pull/550

spring-projects-issues commented 6 years ago

Mark Paluch commented

We decided to create indexes without blocking retaining most of the current functionality. Indexes are created asynchronously by subscribing to index creation publishers and optionally handing in an error callback (Consumer<Throwable>. Index creation failures no longer fail template API calls/creation as there's no execution path dependency anymore

spring-projects-issues commented 6 years ago

Mark Paluch commented

Not sure about backporting to 2.0.x. The issue is quite severe but on the other hand, we're breaking behavior to some extend

spring-projects-issues commented 6 years ago

KimJohn Quinn commented

Just adding to the comments since this relates closest to my issue...

Reactive calls using a reactive repository hang on the first attempt then subsequent attempts work.

This is a follow-up comment, for anyone's benefit, to a conversation posted on GitHub.

When using the Reactive Mongo API to find a record I had a reactive handler that "seemed" to hang on the first call and then subsequent calls work fine.  I turned on all of the logging and noticed in the logs the first call hanging where the index creation was happening. Follow-up calls did not run the index creation and worked fine.

In this case, it was because the class I was inheriting from still used @Index annotations.  Commenting those out fixed the issue and my calls works

spring-projects-issues commented 6 years ago

Mark Paluch commented

KJQ – That issue is fixed with 2.1 M3. Have you tried using the new milestone release? (Please upgrade Spring Data Commons and the driver version as well)