mongodb setFeatureCompatibilityVersion 为 5.0 在分片集群中失败,并显示“BSON 字段‘ShardCollectionType.uuid’缺失,但为必填字段”

问题描述 投票:0回答:1

我们有 MongoDB 社区版,从 4.4.18 升级到 5.0.19。 升级的最后一步,将 CFV 更改为 5.0 失败,似乎元数据已损坏:

mongos> db.adminCommand( { setFeatureCompatibilityVersion: "5.0" } )
{
    "ok" : 0,
    "errmsg" : "Failed command { _flushRoutingTableCacheUpdatesWithWriteConcern: \"9a79fb83-7c4e-4927-88ec-b462438b8471.galileo.prepared_data\", syncFromConfig: true, writeConcern: { w: \"majority\", wtimeout: 60000 } } for database 'admin' on shard 'SRS_4' :: caused by :: Failed to read persisted collections entry for collection '9a79fb83-7c4e-4927-88ec-b462438b8471.galileo.prepared_data'. :: caused by :: Failed to read the '9a79fb83-7c4e-4927-88ec-b462438b8471.galileo.prepared_data' entry locally from config.collections :: caused by :: BSON field 'ShardCollectionType.uuid' is missing but a required field",
    "code" : 40414,
    "codeName" : "Location40414",
    "$clusterTime" : {
        "clusterTime" : Timestamp(1694101525, 7),
        "signature" : {
            "hash" : BinData(0,"kAq76gd44IS7c0NMCUBdZSxmJns="),
            "keyId" : NumberLong("7225622669759086594")
        }
    },
    "operationTime" : Timestamp(1694101518, 3)
}

我们有 4 个分片,并且该集合在 SRS_4 中似乎没有任何块。 sh.status() 显示:

                9a79fb83-7c4e-4927-88ec-b462438b8471.galileo.prepared_data
                        shard key: { "correlationId" : "hashed" }
                        unique: false
                        balancing: true
                        chunks:
                                SRS_1   2
                                SRS_2   2
                                SRS_3   2
                        { "correlationId" : { "$minKey" : 1 } } -->> { "correlationId" : NumberLong("-6148914691236517204") } on : SRS_1 Timestamp(5, 0)
                        { "correlationId" : NumberLong("-6148914691236517204") } -->> { "correlationId" : NumberLong("-3074457345618258602") } on : SRS_1 Timestamp(6, 0)
                        { "correlationId" : NumberLong("-3074457345618258602") } -->> { "correlationId" : NumberLong(0) } on : SRS_2 Timestamp(7, 0)
                        { "correlationId" : NumberLong(0) } -->> { "correlationId" : NumberLong("3074457345618258602") } on : SRS_2 Timestamp(8, 0)
                        { "correlationId" : NumberLong("3074457345618258602") } -->> { "correlationId" : NumberLong("6148914691236517204") } on : SRS_3 Timestamp(9, 0)
                        { "correlationId" : NumberLong("6148914691236517204") } -->> { "correlationId" : { "$maxKey" : 1 } } on : SRS_3 Timestamp(10, 0)

所有副本集成员(所有分片和配置)现在显示:

    "featureCompatibilityVersion" : {
        "version" : "4.4",
        "targetVersion" : "5.0"
    },

知道如何解决这个问题吗? 谢谢

我尝试重做setFeatureCompatibilityVersion。我还尝试重新启动 SRS_4 副本集成员。 结果没有变化,仍然是同样的错误。

mongodb upgrade
1个回答
0
投票

这不是最终答案,但您可以使用以下方法查询所有临时集合:

db.getSiblingDB('config').databases.find({ _id: { $nin: ['admin', 'local', 'config'] } }).forEach(doc => {
   let collections = db.getSiblingDB(doc._id).getCollectionNames();
   for (let col of collections.filter(x => x.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\./))) {
      print(`db.getSiblingDB('${doc._id}').getCollection('${col}').drop()`);
   }
})

然后执行打印的命令。但请注意,其中一些临时集合当前可能正在使用。我建议停止应用程序,然后所有临时集合将被释放。

注意,临时集合的名称模式取决于 MongoDB 版本。例如,在版本 6.0 上,名称类似于

tmp.agg_out.620aa2ca-4a35-45ec-829e-2e7ca3d823bc

您可能会调查为什么这些临时集合不会自动删除。查看应用程序代码。通常,集合

9a79fb83-7c4e-4927-88ec-b462438b8471.galileo.prepared_data
将由聚合管道创建,如下所示:

db.collection.aggregate([
   ...
   { $out: 'galileo.prepared_data' }
])
© www.soinside.com 2019 - 2024. All rights reserved.