由于会话事务集合丢失

由于会话事务集合丢失

本文介绍了由于会话事务集合丢失,因此无法保持事务状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心从mongo数据库中删除了所有数据库.然后,我尝试在新数据库中插入文档.它将引发错误由于缺少会话事务集合而无法持久化事务状态.这表明config.transactions集合已被手动删除."

I have accidentally dropped all databases from my mongo db. Then i tried to insert a document in new database. It throws error "Unable to persist transaction state because the session transaction collection is missing. This indicates that the config.transactions collection has been manually deleted."

我的示例代码:

doc_client = MongoClient(host=host,
                         port=port,
                         connect=True,  # Connect on first operation to avoid multi-threading related errors
                         j=True,  # Requests only return once write has hit the DB journal
                         )
print(doc_client.database_names()) # It works fine
doc_client['test'].insert({'a': 'ss'}) # Throws Error

推荐答案

您可能还删除了 config.transactions 集合.这是内部使用的集合,用于存储用于支持可重试写入的记录用于副本集和分片群集.另请参见配置数据库.

It is likely that you have also dropped config.transactions collection. This is a collection for internal usage that stores records used to support retryable writes for replica sets and sharded clusters. See also Config Databases.

自MongoDB v3.6 +起,用户将无法从 mongo 外壳.尽管如果使用v3.6之前的mongo Shell连接,您仍然可以这样做,但请确保升级Shell以使其与服务器版本匹配.

Since MongoDB v3.6+, users won't be able to drop the config database in replica set from mongo shell. Although if you are connecting using mongo shell prior to v3.6, you're still able to do so, please ensure to upgrade the shell to match the server version.

您可以在主节点上手动重新创建集合:

You can manually re-create the collection on the primary node:

use config
db.createCollection("transactions");

或者,副本集选择也将自动重新创建它.这是因为config.transactions集合的创建是副本集节点升级的一部分. session_catalog_mongod.cpp#L156

Alternatively, a replica set election would also automatically re-creates it. This is because the creation of config.transactions collection is part of a replica set node step up. session_catalog_mongod.cpp#L156

新的config.transactions集合将在主数据库完成追赶阶段后复制到辅助数据库.

The new config.transactions collection will be replicated to the secondaries after the primary completed the catch up phase.

这篇关于由于会话事务集合丢失,因此无法保持事务状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 00:04