[SERVER-47123] Remove AutoGetOrCreateDb Created: 25/Mar/20  Updated: 29/Oct/23  Resolved: 30/Apr/21

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

Type: Task Priority: Major - P3
Reporter: Gregory Noma Assignee: Benety Goh
Resolution: Fixed Votes: 0
Labels: newgrad
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-56511 use AutoGetOrCreateCollection to crea... Closed
is related to SERVER-37283 View graph cycle on expressive lookup... Closed
is related to SERVER-45955 findAndModify should not take exclusi... Closed
is related to SERVER-53256 Make a new lock helper to encapsulate... Backlog
Backwards Compatibility: Fully Compatible
Sprint: Execution Team 2021-05-03
Participants:

 Description   

With the introduction of AutoGetDb::ensureDbExists() and AutoGetCollection::ensureDbExists() in SERVER-45955, there is no longer a need for AutoGetOrCreateDb and removing it would simplify the codebase. Going through and directly translating the uses should be trivial, however anywhere we use this pattern:

AutoGetOrCreateDb autoDb(opCtx, ns.db(), MODE_IX);
Lock::CollectionLock collLock(opCtx, ns, MODE_IX);
Database* db = autoDb.getDb();

should be changed into

AutoGetCollection autoColl(opCtx, ns, MODE_IX);
Database* db = autoColl.ensureDbExists();

This change leads to implicitly creating the system.views collection hitting this uassert, which we would should investigate whether we can circumvent.



 Comments   
Comment by Benety Goh [ 30/Apr/21 ]

The AutoGetOrCreateDb class has been removed, but there are opportunities for additional code cleanup to be explored in SERVER-56511 and SERVER-53256.

Comment by Githook User [ 30/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 remove AutoGetOrCreateDb class

Use AutoGetDb (and its ensureDbExists() method) instead.
Branch: master
https://github.com/mongodb/mongo/commit/3295126e8a081ca57af1a07c6c582fac7a825efd

Comment by Githook User [ 30/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 remove AutoGetOrCreateDb from implicit collection creation during CRUD operations

This class is deprecated in favor of AutoGetDb which provides the same functonality
in AutoGetDb::ensureDbExists().
Branch: master
https://github.com/mongodb/mongo/commit/be9319f442417777e400b7b11e140675f2ece4e6

Comment by Githook User [ 29/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 remove AutoGetOrCreateDb from collection and view creation

This class is deprecated in favor of AutoGetDb.
Branch: master
https://github.com/mongodb/mongo/commit/7fe73c9955e44c7e99c5c3487454bb2ad64740e1

Comment by Githook User [ 29/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 use collection lock to read FCV doc

This still locks the DB in MODE_IX but conveys the intent of the
FCV function better.
Branch: master
https://github.com/mongodb/mongo/commit/ba92efbdba666465e7ccad076412174bc8673fc9

Comment by Githook User [ 29/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 remove AutoGetOrCreateDb from IndexBuildsManager::_moveRecordToLostAndFound()

This affects repair functionality where we have to save duplicate keys to a local 'lost_and_found'
collection while repairing a unique index.

This commit also includes trivial changes to startup logging and the config.system.indexBuilds helper.
Branch: master
https://github.com/mongodb/mongo/commit/93134ab6b29ddf3a9a31ad497b3f298a8928af7e

Comment by Githook User [ 29/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 remove AutoGetOrCreateDb from repl::StorageInterfaceImpl

StorageInterfaceImpl is used in replication to access the storage
and query execution subsystems.

AutoGetOrCreateDb is deprecated in favor of AutoGetDb and AutoGetCollection.
Branch: master
https://github.com/mongodb/mongo/commit/3aee716a28a8ccc5258316ebbe48e19343f4ee79

Comment by Githook User [ 29/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 remove sharding (and resharding) references to AutoGetOrCreateDb

This RAII type is deprecated in favor of AutoGetDb and AutoGetCollection.
Branch: master
https://github.com/mongodb/mongo/commit/0a211f3d23316f1bfe7af90d92bcdae458510909

Comment by Githook User [ 29/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 remove AutoGetOrCreateDb from test command pinHistoryReplicated
Branch: master
https://github.com/mongodb/mongo/commit/ee6112c32187870232a61b92663092bd8771561b

Comment by Githook User [ 29/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 remove AutoGetOrCreateDb from dbtests
Branch: master
https://github.com/mongodb/mongo/commit/fbc4a0423c4930139b719ed5fee985af52b92e90

Comment by Githook User [ 28/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 remove AutoGetOrCreateDb from non-catalog unit tests
Branch: master
https://github.com/mongodb/mongo/commit/00d3ec0d3a9d7c4077148f528bb1f7293fd1b238

Comment by Githook User [ 28/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 remove AutoGetOrCreateDb from catalog unit tests

AutoGetOrCreateDb is being deprecated in favor or AutoGetDb::ensureDbExists()
and AutoGetCollection.
Branch: master
https://github.com/mongodb/mongo/commit/b46ac14ee3895b8129069c8f1b03e3820ebcea99

Comment by Githook User [ 26/Apr/21 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-47123 remove AutoGetOrCreateDb from importCollection()
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/3ed011f40570fc5e1481534b685916553493545b

Comment by Benety Goh [ 23/Apr/21 ]

Alternative, we could upgrade the lock mode (using this helper function) for system.views to MODE_X in _createCollection().

Comment by Benety Goh [ 23/Apr/21 ]

The _createCollection() uassert mentioned in the description was introduced in SERVER-37283.

Going by the comment above the assertion, we may be able to tell if the collection lock acquisition is requested by UUID or by namespace from the nsOrUUID argument.

For _createCollection(), we can probably convert to a combination of AutoGetDb and CollectionLock for now and defer the work on refining the assertion condition in AutoGetCollection.

Generated at Thu Feb 08 05:13:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.