Skip to content

fix(mongodb): log an index creation failure on one line, the stack trace at debug - #16981

Open
borinquenkid wants to merge 1 commit into
7.0.xfrom
fix/mongo-index-failure-log-7.0.x
Open

borinquenkid wants to merge 1 commit into
7.0.xfrom
fix/mongo-index-failure-log-7.0.x

Conversation

@borinquenkid

Copy link
Copy Markdown
Member

Fixes #15667 (a merge to 7.0.x does not close it, so it is closed by hand once the merge-ups land).

MongoDatastore.initializeIndices logged a MongoCommandException from createIndex at ERROR together with the exception. A server error such as 86 IndexKeySpecsConflict then printed a very long stack trace at every startup, for a condition the operator has to fix in the mapping or in the database.

Change: the ERROR event carries only the entity, the index definition (or property) and the server message, as before. The stack trace goes to a separate DEBUG event. This covers the three paths: a single index, a compound index and a property index.

Only the 7.x line. On 8.0.x and 8.1.x the reported case goes through reconcileIndexConflict (#15747, #16208), which logs a one-line "Index conflict ..." message and does not attach the exception, so nothing changes there. 7.1.x and 7.2.x do not have that code; the merge-ups carry this fix.

Tests: MongoDatastoreIndexFailureLogSpec creates name_1 with the driver in a MongoDB Testcontainer, then starts a MongoDatastore whose entity maps name as a unique index, which makes the server answer 86. It asserts one ERROR event with the entity name and the server message and no throwable, and a DEBUG event that carries the MongoCommandException. It failed before the change (the ERROR event carried the exception) and passes after. All 569 tests of grails-data-mongodb-core pass (0 failures, 19 skipped); CodeNarc and Checkstyle are clean.

Test dependency: the module's tests ran on slf4j-nop, which cannot capture log events. logback-classic (version managed by the BOM) replaces it as the single SLF4J binding of the tests, so the spec can attach a ListAppender; testRuntimeClasspath shows no second binding.

Two of the three reviewers (matrei, codeconsole, jdaugherty), as 7.0.x is released. The run ci label is set because 7.0.x skips the tests otherwise and the new spec needs the container.

https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL

…ace at debug

MongoDatastore.initializeIndices logged a MongoCommandException from
createIndex at ERROR together with the exception, so a server error such
as 86 IndexKeySpecsConflict printed a huge stack trace at every startup
for a condition the operator must fix in the mapping or the database.

The ERROR event now carries only the entity, the index definition and the
server message; the stack trace goes to a separate DEBUG event. This
covers the single, compound and property index paths.

The module's tests ran on slf4j-nop, which cannot capture log events, so
logback-classic (managed by the BOM) replaces it as the single SLF4J
binding for the tests, and a new spec provokes a real index conflict
against a MongoDB container and asserts on the captured events.

Fixes #15667

Claude-Session: https://claude.ai/code/session_01Dmki4RzWwreEC2GkkyFnvL
Copilot AI balanced review requested due to automatic review settings November 13, 2026 21:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@testlens-app

testlens-app Bot commented Nov 13, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: ac591ef
▶️ Tests: 51576 executed
⚪️ Checks: 58/58 completed


Learn more about TestLens at testlens.app/docs.

@jamesfredley jamesfredley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An index creation failure is still logged with the entity, the index, and the reason. The stack trace is at debug, and a success is not logged as a failure.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants