[SERVER-83236] Create index with hidden:true succeeds when a hidden:false index already exists Created: 14/Nov/23  Updated: 18/Dec/23  Resolved: 18/Dec/23

Status: Closed
Project: Core Server
Component/s: Catalog
Affects Version/s: None
Fix Version/s: 7.3.0-rc0

Type: Bug Priority: Major - P3
Reporter: Kaloian Manassiev Assignee: David Dominguez Sal
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Assigned Teams:
Catalog and Routing
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: CAR Team 2023-12-11, CAR Team 2023-12-25
Participants:
Linked BF Score: 0
Story Points: 1

 Description   

From looking at BF-30486 it appears that creating a hidden:true index when the same hidden:false index already exists doesn't actually report an error.

From looking at the logs, it can be seen that on one of the shards, the index indeed got dropped successfully, but a concurrent incoming migration of a first chunk from a collection managed to re-create it with the options it had from before the drop (relevant log lines posted below).

Because the index is now existent, the create statement (which creates it with hidden:true) just became a no-op.

This ticket is just to improve the createIndex command to report an error in this case.



 Comments   
Comment by Githook User [ 18/Dec/23 ]

Author:

{'name': 'David Dominguez-Sal', 'email': 'david.dominguez@mongodb.com', 'username': 'david-dominguez-sal'}

Message: SERVER-83236: Check if createIndex hidden parameter is incompatible with an already existing index

GitOrigin-RevId: 8b3714f014d464a8fa2145cee22716869c9f028a
Branch: master
https://github.com/mongodb/mongo/commit/74f5f0aca38c3b949d370038aaf05e856b12db38

Comment by David Dominguez Sal [ 05/Dec/23 ]

After some discussions, we agree that the current behavior, which converts the new createIndex to a no-op, is not intuitive. It makes sense to update the behavior of createIndex to return an error when the hidden status does not match. 

Comment by David Dominguez Sal [ 30/Nov/23 ]

According to the createIndex documentation, implementing the description would change the command behavior.

Recreating an Existing Index

If you call db.collection.createIndex() for an index that already exists, MongoDB does not recreate the index.

Index Options

Non-Collation and Non-Hidden Options

With the exception of the collation option, if you create an index with one set of index options and then try to recreate the same index but with different index options, MongoDB will not change the options nor recreate the index.

The hidden option can be changed without dropping and recreating the index. See Hidden Option.

To change the other index options, drop the existing index with db.collection.dropIndex() before running db.collection.createIndex() with the new options.

Generated at Thu Feb 08 06:51:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.