【问题标题】:MongoDB 2.4 not allow to create collection after fileSize~=2GB but dataSize~1MBMongoDB 2.4 不允许在文件大小~=2GB 但数据大小~1MB 之后创建集合
【发布时间】:2019-01-10 21:07:29
【问题描述】:

我在 ARM 处理器上使用 MongoDB 2.4 32 位。我正在我的数据库中创建动态集合。我浏览了 MongoDB 文档,其中指出 - 存储引擎 MMAP 为文件系统预先分配高达 2GB 的磁盘空间。 32-bit MongoDB processes are limited to about 2 gb of data

这是 db.stats() 的输出

{ 
    "db" : "admin", 
    "collections" : NumberInt(40), 
    "objects" : NumberInt(998), 
    "avgObjSize" : 196.9498997995992, 
    "dataSize" : NumberInt(196556), #~1MB
    "storageSize" : 1478905856.0, 
    "numExtents" : NumberInt(42), 
    "indexes" : NumberInt(50), 
    "indexSize" : NumberInt(433328), 
    "fileSize" : 2197028864.0, #2GB
    "nsSizeMB" : NumberInt(16), 
    "dataFileVersion" : {
    "major" : NumberInt(4), 
    "minor" : NumberInt(5)
    }, 
    "ok" : 1.0
}

在这里您可以看到数据大小为 1MB,但文件大小为 ~=2GB。达到 2GB 文件大小限制后,它不允许我创建新集合。

du -sh /data/db
2.1G    /data/db/

当我尝试使用 --repairpath 选项修复数据库时,它仍然给出错误

mongod --repair --repairpath /data/db2

错误

[initandlisten] ERROR:   mmap() failed for /data/db/admin.7 len:536608768 errno:12 Cannot allocate memory
[initandlisten] ERROR: mmap failed with out of memory. You are using a 32-bit build and probably need to upgrade to 64

[initandlisten] ERROR:   mmap() failed for /data/db2/_tmp_repairDatabase_0/admin.2 len:134217728 errno:12 Cannot allocate memory
[initandlisten] ERROR: mmap failed with out of memory. You are using a 32-bit build and probably need to upgrade to 64
[initandlisten] exception in initAndListen: 10084 can't map file memory - mongo requires 64 bit build for larger datasets, terminating
dbexit: 

关于如何解决此问题的任何建议,

【问题讨论】:

标签: mongodb mmap


【解决方案1】:

我终于找到了这个问题的根本原因,fileSize 为 ~=2GB,dataSize 为几 MB 及其解决方案。

根本原因 - 如果数据库使用 capped collection,Mongodb 2.4 MMAP 存储引擎会为这些 capped collection 分配固定数量的磁盘空间。达到数据文件大小后任何创建新集合的尝试都会导致 Mongodb 2.4 抛出错误。

cant map file memory-mongo requires 64 bit build for larger datasets

在我的例子中,我是动态创建有上限的集合。

解决方案 - 使用mongod 命令修复数据库的任何操作都将失败,因为它需要额外的内存来执行这些操作。
所以使用mongodump--repair 一起获取数据库转储,这将为所有上限集合创建一个没有“上限”限制的转储,然后mongorestore

第 1 步 - Take the dump of database alongwith --repair

mongodump --username <username> --password <password> --dbpath <path> --db <db> --out <path> --repair

第 2 步 - Drop database

db.dropDatabase()

第 3 步 - Restore the dump

mongorestore --username <username> --password <password> --dbpath <path> --db <db> <path>

第 4 步 - Convert a Collection to Capped(Optional)

db.runCommand({"convertToCapped": "mycoll", size: 100000});

希望这会有所帮助。

干杯

【讨论】:

    猜你喜欢
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    相关资源
    最近更新 更多