我有一个分片集合,其中分片键是一个名为“uuid”的字段。该字段的值是字符串类型,表示十六进制值,即十六进制字符串。对于每个文档,这个“uuid”字段是唯一的。
数据由 MongoDB 自动划分为块。我无法弄清楚 MongoDB 是如何将此十六进制字符串划分为连续范围的。没有文件可以解释 Mongo 如何形成这些范围
你能帮我理解这些范围是如何形成的吗?
作为示例,我插入了 3025357 个具有上述十六进制值的文档。与它们相关的块和范围是,
{
"_id" : "database.sha_shard-uuid_MinKey",
"lastmod" : Timestamp(2, 0),
"lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
"ns" : "database.sha_shard",
"min" : {
"uuid" : { "$minKey" : 1 }
},
"max" : {
"uuid" : "000043c071f23fc889275f77f950c649faac92e0"
},
"shard" : "shardRpSet2",
"history" : [
{
"validAfter" : Timestamp(1577632842, 37),
"shard" : "shardRpSet2"
}
]
},{
"_id" : "database.sha_shard-uuid_\"5b935a89d91977490d04f740a86bccc2b3cc2bfb\"",
"lastmod" : Timestamp(3, 5),
"lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
"ns" : "database.sha_shard",
"min" : {
"uuid" : "5b935a89d91977490d04f740a86bccc2b3cc2bfb"
},
"max" : {
"uuid" : "7a25fa7aa3a86ed259f646d7890db370e8b43ae7"
},
"shard" : "shardRpSet1",
"history" : [
{
"validAfter" : Timestamp(1577632856, 21509),
"shard" : "shardRpSet1"
}
]
},{
"_id" : "database.sha_shard-uuid_\"7a25fa7aa3a86ed259f646d7890db370e8b43ae7\"",
"lastmod" : Timestamp(3, 6),
"lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
"ns" : "database.sha_shard",
"min" : {
"uuid" : "7a25fa7aa3a86ed259f646d7890db370e8b43ae7"
},
"max" : {
"uuid" : "810b573464d4894fc40b428ec82ec54d9a681bf6"
},
"shard" : "shardRpSet1",
"history" : [
{
"validAfter" : Timestamp(1577632856, 21509),
"shard" : "shardRpSet1"
}
]
},{
"_id" : "database.sha_shard-uuid_\"000043c071f23fc889275f77f950c649faac92e0\"",
"lastmod" : Timestamp(4, 0),
"lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
"ns" : "database.sha_shard",
"min" : {
"uuid" : "000043c071f23fc889275f77f950c649faac92e0"
},
"max" : {
"uuid" : "1e8421c5d4f3eb45a82c2785bccc81fa7abfbfc7"
},
"shard" : "shardRpSet2",
"history" : [
{
"validAfter" : Timestamp(1577635896, 15268),
"shard" : "shardRpSet2"
}
]
},{
"_id" : "database.sha_shard-uuid_\"1e8421c5d4f3eb45a82c2785bccc81fa7abfbfc7\"",
"lastmod" : Timestamp(5, 0),
"lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
"ns" : "database.sha_shard",
"min" : {
"uuid" : "1e8421c5d4f3eb45a82c2785bccc81fa7abfbfc7"
},
"max" : {
"uuid" : "3d165990d2969bbaf79b6b0d790080b46ca5f056"
},
"shard" : "shardRpSet",
"history" : [
{
"validAfter" : Timestamp(1577635906, 26457),
"shard" : "shardRpSet"
}
]
},{
"_id" : "database.sha_shard-uuid_\"3d165990d2969bbaf79b6b0d790080b46ca5f056\"",
"lastmod" : Timestamp(5, 1),
"lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
"ns" : "database.sha_shard",
"min" : {
"uuid" : "3d165990d2969bbaf79b6b0d790080b46ca5f056"
},
"max" : {
"uuid" : "5b935a89d91977490d04f740a86bccc2b3cc2bfb"
},
"shard" : "shardRpSet1",
"history" : [
{
"validAfter" : Timestamp(1577632856, 21509),
"shard" : "shardRpSet1"
}
]
},{
"_id" : "database.sha_shard-uuid_\"c1788722a31a5a5a5caa00816ad85aeeda26e581\"",
"lastmod" : Timestamp(5, 2),
"lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
"ns" : "database.sha_shard",
"min" : {
"uuid" : "c1788722a31a5a5a5caa00816ad85aeeda26e581"
},
"max" : {
"uuid" : "dcbd245e03d425aa14a85b51befde274856fc5f3"
},
"shard" : "shardRpSet",
"history" : [
{
"validAfter" : Timestamp(1577630416, 3),
"shard" : "shardRpSet"
}
]
},{
"_id" : "database.sha_shard-uuid_\"dcbd245e03d425aa14a85b51befde274856fc5f3\"",
"lastmod" : Timestamp(5, 3),
"lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
"ns" : "database.sha_shard",
"min" : {
"uuid" : "dcbd245e03d425aa14a85b51befde274856fc5f3"
},
"max" : {
"uuid" : "fffff8c5e160711fb48f0d38ce01a98880e869e2"
},
"shard" : "shardRpSet",
"history" : [
{
"validAfter" : Timestamp(1577630416, 3),
"shard" : "shardRpSet"
}
]
},{
"_id" : "database.sha_shard-uuid_\"fffff8c5e160711fb48f0d38ce01a98880e869e2\"",
"lastmod" : Timestamp(6, 0),
"lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
"ns" : "database.sha_shard",
"min" : {
"uuid" : "fffff8c5e160711fb48f0d38ce01a98880e869e2"
},
"max" : {
"uuid" : { "$maxKey" : 1 }
},
"shard" : "shardRpSet2",
"history" : [
{
"validAfter" : Timestamp(1577636268, 67),
"shard" : "shardRpSet2"
}
]
},{
"_id" : "database.sha_shard-uuid_\"810b573464d4894fc40b428ec82ec54d9a681bf6\"",
"lastmod" : Timestamp(6, 1),
"lastmodEpoch" : ObjectId("5e08bad0b5e6b931087f0871"),
"ns" : "database.sha_shard",
"min" : {
"uuid" : "810b573464d4894fc40b428ec82ec54d9a681bf6"
},
"max" : {
"uuid" : "c1788722a31a5a5a5caa00816ad85aeeda26e581"
},
"shard" : "shardRpSet",
"history" : [
{
"validAfter" : Timestamp(1577630416, 3),
"shard" : "shardRpSet"
}
]
}
有关分片块如何工作的参考:https ://docs.mongodb.com/v4.0/core/sharding-data-partitioning/
现在,要了解块内将包含哪些记录,我们需要了解“每个块具有基于分片键的包含下限和互斥上限”部分,从现在开始,我们应该将其称为块范围。
例如,这个块:
字段
min
和max
是块范围:该范围定义了块内的内容,您可以通过阅读 BSON 参考了解该范围的工作原理:https ://docs.mongodb.com/v4.0/reference/bson-type-comparison-order/
在您的情况下,如果该
UUID
字段仅包含字符串,这就是记录将被评估为在块范围内的方式: