-
Type: Task
-
Resolution: Won't Do
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Replication
-
Labels:
-
Sharding
-
Sharding 2020-07-13, Sharding 2020-06-29, Sharding 2020-07-27
Original ticket name: Make Database have a shared_ptr<MigratingTenantAccessBlocker> decoration
See this gist for an explanation of the decorator pattern and how decorations are used in MongoDB.
Make Database have a shared_ptr<MigratingTenantAccessBlocker> decoration. (The decoration should default to nullptr.) See example of a shared_ptr decoration on another object.
EDIT:
Using a decoration on Database is difficult because there is no good way to synchronize access to it (besides using a database-level LockManager lock).
Instead, let's create a MigratingTenantAccessBlockerByName class with standalone map from dbName -> shared_ptr<MigratingTenantAccessBlocker> that is protected by a member mutex, analogous to the CollectionShardingStateMap.
The class should be a decoration on ServiceContext (similarly to how CollectionShardingStateMap is) and should go in migrating_tenant_access_blocker.cpp.
The class should have the following methods:
// Returns the MigratingTenantAccessBlocker for 'dbName' if one exists, else returns nullptr. shared_ptr<MigratingTenantAccessBlocker> get(StringData dbName); // Adds an entry for 'dbName' with 'mtab'. void add(StringData dbName, shared_ptr<MigratingTenantAccessBlocker> mtab); // Removes all entries for which 'dbPrefix' is a prefix of the entry's 'dbName'. void removeAllWithPrefix(StringData dbPrefix);
and should have a private StringMap<std::shared_ptr<MigratingTenantAccessBlocker>>.
EDIT 2:
This ticket is more of an optimization, since we could have user reads/writes just check the byPrefix map. Getting an mtab by dbName from the byPrefix map will be slightly more expensive (if it's a tree map, the lookup will be O(log n) where n is the number of concurrent tenant migrations that have started blocking). But I don't expect there to ever be many concurrent tenant migrations, so that lookup should still be cheap.
If we decide having an O(1) lookup is important or otherwise want to optimize for concurrency, we can revisit this ticket.
- is depended on by
-
SERVER-49184 Make new database creation set the database's MigratingTenantAccessBlocker to the corresponding one in MigratingTenantAccessBlockerByPrefix
- Closed
-
SERVER-49185 Add function to DatabaseHolder to iterate existing databases matching a prefix and set their MigratingTenantAccessBlocker decorations
- Closed