Skip to content
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

auto-index-creation will block app to start when one Mongo cluster node is offline #4657

Closed
yxyeip opened this issue Mar 11, 2024 · 6 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@yxyeip
Copy link

yxyeip commented Mar 11, 2024

As title, we find an issue if we enable auto-index-creation as true, it will block app to start, if one of Mongo node offline.

The root cause is default value of commitQuorum is "votingMembers": all data-bearing voting replica set members
while one of voting member is down, so this command will never return. It block whole app to start.
We need set it as 1, look like set it as 1, it will also snyc to offline node when it come to online.

While Spring data Mongo didn't prviode function to override this option "commitQuorum".

refer: https://www.mongodb.com/docs/v5.3/reference/command/createIndexes/

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 11, 2024
@mp911de
Copy link
Member

mp911de commented Mar 11, 2024

That is likely and blocking the application can also happen on application startup if the MongoDB server isn't available. We generally recommend not using auto-index creation because of operational aspects like these and therefore, the feature is deprecated.

@yxyeip
Copy link
Author

yxyeip commented Mar 11, 2024

Hi @mp911de thanks for your reply, do you have any suggestions for replacement if not use auto index feature?

@mp911de
Copy link
Member

mp911de commented Mar 11, 2024

Please either use programmatic index creation or create indexes out of band by running scripts against MongoDB via e.g. the shell.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Mar 11, 2024
@mp911de mp911de added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 11, 2024
@yxyeip
Copy link
Author

yxyeip commented Mar 11, 2024

Programmatic index creation also need spring data mongodb add support to override commitQuorum option.
Currently, looks like there is no way to override it:

template.indexOps(Person.class)
.ensureIndex(new Index().on("age", Order.DESCENDING).unique()); // we need ensureIndex function has ability to pass CreateIndexOptions obj, then we can override commitQuorum on CreateIndexOptions obj

@mp911de
Copy link
Member

mp911de commented Mar 11, 2024

We use MongoCollection.createIndex to run the command. Only the createIndexes(…) command provides access to CreateIndexOptions exposing CreateIndexCommitQuorum and maxTimeMS options.

These aren't typically the options Spring Data is working with.

@yxyeip
Copy link
Author

yxyeip commented Mar 12, 2024

DefaultIndexOperations.ensureIndex called createIndexes(keys, indexOptions), my suggestions is provide other method DefaultIndexOperations.ensureIndex will call createIndexes(indexs, createIndexOptions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants