[SERVER-79893] 6.0.x Enterprise Advanced: sharded databases always shows "partitioned: false" Created: 10/Aug/23  Updated: 27/Oct/23  Resolved: 17/Aug/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 6.0.9
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Gary Taylor Assignee: Tommaso Tocci
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-64045 Remove partitioned field from Databas... Closed
is related to SERVER-60926 Make enableSharding command optional Closed
Assigned Teams:
Sharding EMEA
Operating System: ALL
Steps To Reproduce:

MongoDB 6.0.9 Enterprise Advanced (EA) used

(other 6.0.x versions also have same issue - maybe all?)

Run:
db.runCommand( { buildInfo: 1 } ).version 
6.0.9
db.runCommand( { buildInfo: 1 } ).modules 
[ 'enterprise' ]
 

 

Run:
sh.shardCollection("foobar.transmissions", {"pzone":1, "transmission_id":1}, {"unique":true})
Output:
{
  collectionsharded: 'foobar.transmissions',
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1691633612, i: 12 }),
    signature: {
      hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
      keyId: Long("0")
    }
  },
  operationTime: Timestamp({ t: 1691633612, i: 8 })
}
 

 

Run:
db.getSiblingDB('config').databases.find()
Output: (showing "partitioned: false" even though a collection in that database has just been sharded)
 [
  {
    _id: 'foobar',
    primary: 'shard03',
    partitioned: false,
    version: {
      uuid: new UUID("12c22472-03f8-495f-809e-321abbdd8def"),
      timestamp: Timestamp({ t: 1691632589, i: 1 }),
      lastMod: 1
    }
  }
]
 

 

Run:
db.getSiblingDB('config').databases.find({partitioned: true})
Output: 
(FYI: Nothing is returned by the command which is saying NO databases are partitioned)
 

 

 

 

Sprint: Sharding EMEA 2023-08-21
Participants:

 Description   

I understand that enableSharding() for a database is not required in 6.0; However, sharded databases are always showing "partitioned: false" in sh.status(). 

Regardless of whether a database is enabled for sharding explicitly by enableSharding(<dbname>) (which isn't required as mentioned earlier) or by directly sharding the database.collection as described here: https://www.mongodb.com/docs/manual/reference/method/sh.shardCollection/#sh.shardcollection--

The database reports is always reporting "partitioned: false" in sh.status().

Having a database reporting "partitioned: false" when it has actually been sharded prevents some commands from reporting correctly such as:

1) Finding what databases are actually sharded:

db.getSiblingDB('config').databases.find({partitioned: true})

2) Finding number of bytes in unsharded collections across the cluster as shown in this Knowledge Base article:
https://kb.corp.mongodb.com/article/000018993

 

Assuming this is a bug.



 Comments   
Comment by Tommaso Tocci [ 17/Aug/23 ]

Also, what is the best (quickest) way to check to see what databases have sharded collections.

gary.taylor@mongodb.com  you can use the following aggreagation to retrieve the sharded collections grouped by database name:

 db.getSiblingDB('config').collections.aggregate([{
          $group: {
             _id: { dbName: { $arrayElemAt: [{$split: ['$_id', '.']}, 0] }},
             collections: { $push: '$_id'}
          }
     },{
        $sort: { _id: 1 }
 }])

Comment by Gary Taylor [ 10/Aug/23 ]

I found some related tickets that seem to indicate this is known and expected/acceptable starting n 6.0. 

Those tickets are SERVER-60926, MONGOSH-1152.

And this in the documentation: https://www.mongodb.com/docs/manual/reference/method/sh.status/#mongodb-data-sh.status.databases.partitioned

Given the above then I can accept that this ticket can be closed but I wanted to provide some feedback below:

If the flag isn't useful anymore - why still have it?

The documentation links states its still there for backwards compatibility BUT if it doesn't reflect the correct status then any script like in the KB for finding the size of unsharded collections will not give the correct results and the user of that script may not be aware that is the case.

Also, what is the best (quickest) way to check to see what databases have sharded collections.

Would it be the following:

db.getSiblingDB('config').collections.find({}, {_id:1})

 

Or maybe something like this to get just the unique database names:

 

 

// Get the sibling database named 'config'
const siblingDB = db.getSiblingDB('config');
// Query the collections and extract the database names, storing unique names in an array
const uniqueDatabaseNames = [];
const collections = siblingDB.collections.find();
collections.forEach(function(collection) {
  const databaseName = collection._id.split('.')[0];
  if (uniqueDatabaseNames.indexOf(databaseName) === -1) {
    uniqueDatabaseNames.push(databaseName);
  }
});
// Sort the unique database names alphabetically
uniqueDatabaseNames.sort();
// Print the sorted, unique database names
uniqueDatabaseNames.forEach(function(databaseName) {
  print("Sharded DB: " + databaseName);
});

 

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