在尝试了将近 2 天后,我找到了自己的答案。
问题在于 MongoDb。MongoDb 以某种奇怪的方式使数据损坏,导致我的问题出现错误。我为解决它所做的就是自己启动 MongoDb。首先,我杀死了所有与 MongoDb 相关的进程并手动启动了 MongoD:
./mongod --dbpath /Users/jeroen/.opa/mongo/data/ -v
我必须启动 Opa 而无需通过以下方式启动 MongoDb 实例:
./CollabTextEditor.exe --db-remote localhost:27017
(CollabTextEditor.exe 是编译我的 Opa 代码的结果)。然后我浏览到 localhost:8080(运行 Opa 的地方),在 MongoD 中得到以下输出:
Jeroens-MacBook-Pro:bin jeroen$ ./mongod --dbpath /Users/jeroen/.opa/mongo/data/ -v
Fri Jan 4 10:03:05 BackgroundJob starting: DataFileSync
Fri Jan 4 10:03:05 versionCmpTest passed
Fri Jan 4 10:03:05 versionArrayTest passed
Fri Jan 4 10:03:05 shardObjTest passed
Fri Jan 4 10:03:05 shardKeyTest passed
Fri Jan 4 10:03:05 isInRangeTest passed
Fri Jan 4 10:03:05 [initandlisten] MongoDB starting : pid=15654 port=27017 dbpath=/Users/jeroen/.opa/mongo/data/ 64-bit host=Jeroens-MacBook-Pro.local
Fri Jan 4 10:03:05 [initandlisten] db version v2.0.2, pdfile version 4.5
Fri Jan 4 10:03:05 [initandlisten] git version: 514b122d308928517f5841888ceaa4246a7f18e3
Fri Jan 4 10:03:05 [initandlisten] build info: Darwin erh2.10gen.cc 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008; root:xnu-1228.9.59~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_40
Fri Jan 4 10:03:05 [initandlisten] options: { dbpath: "/Users/jeroen/.opa/mongo/data/", verbose: true }
Fri Jan 4 10:03:05 [initandlisten] journal dir=/Users/jeroen/.opa/mongo/data/journal
Fri Jan 4 10:03:05 [initandlisten] recover : no journal files present, no recovery needed
Fri Jan 4 10:03:05 [initandlisten] Accessing: local for the first time
Fri Jan 4 10:03:05 [initandlisten] query local.system.namespaces reslen:20 0ms
Fri Jan 4 10:03:05 [initandlisten] enter repairDatabases (to check pdfile version #)
Fri Jan 4 10:03:05 [initandlisten] CollabTextEditor
Fri Jan 4 10:03:05 [initandlisten] Accessing: CollabTextEditor for the first time
Fri Jan 4 10:03:05 [initandlisten] done repairDatabases
Fri Jan 4 10:03:05 BackgroundJob starting: snapshot
Fri Jan 4 10:03:05 BackgroundJob starting: ClientCursorMonitor
Fri Jan 4 10:03:05 BackgroundJob starting: PeriodicTask::Runner
Fri Jan 4 10:03:05 [initandlisten] fd limit hard:9223372036854775807 soft:256 max conn: 204
Fri Jan 4 10:03:05 [websvr] fd limit hard:9223372036854775807 soft:256 max conn: 204
Fri Jan 4 10:03:05 [websvr] admin web console waiting for connections on port 28017
Fri Jan 4 10:03:05 [initandlisten] waiting for connections on port 27017
Fri Jan 4 10:03:46 [initandlisten] connection accepted from 127.0.0.1:54604 #1
Fri Jan 4 10:03:46 [conn1] Accessing: CollabTextEditor for the first time
Fri Jan 4 10:03:46 [conn1] query CollabTextEditor.user reslen:20 0ms
Fri Jan 4 10:03:46 [conn1] query CollabTextEditor.room nreturned:1 reslen:3379 0ms
Fri Jan 4 10:04:05 [DataFileSync] flushing mmap took 2ms for 3 files
Fri Jan 4 10:04:05 [PeriodicTask::Runner] task: DBConnectionPool-cleaner took: 0ms
Fri Jan 4 10:04:05 [PeriodicTask::Runner] task: DBConnectionPool-cleaner took: 0ms
Fri Jan 4 10:04:05 [PeriodicTask::Runner] task: WriteBackManager::cleaner took: 0ms
Fri Jan 4 10:04:05 [clientcursormon] mem (MB) res:30 virt:2594 mapped:80
Fri Jan 4 10:04:32 [conn1] query CollabTextEditor.user idhack:1 reslen:20 0ms
Fri Jan 4 10:04:32 [conn1] update CollabTextEditor.user query: { _id: "test" } update: { $set: { value: { some: { name: "test" } } } } fastmodinsert:1 0ms
Fri Jan 4 10:04:32 [conn1] run command CollabTextEditor.$cmd { getlasterror: 1 }
Fri Jan 4 10:04:32 [conn1] command CollabTextEditor.$cmd command: { getlasterror: 1 } ntoreturn:1 reslen:85 0ms
Fri Jan 4 10:04:32 [conn1] query CollabTextEditor.room nreturned:1 reslen:3379 0ms
Fri Jan 4 10:04:32 [journal] lsn set 55971
Fri Jan 4 10:05:01 [conn1] end connection 127.0.0.1:54604
有些查询似乎返回nreturned:1
了(查看输出中的最后几行),有些并不意味着我的数据可能有问题。这导致了我的问题中的错误。
我实际解决它的方法是分别连接到 Mongo 并在 mongod 实例已经运行后删除数据库:
Jeroens-MacBook-Pro:bin jeroen$ ./mongo localhost:27017
MongoDB shell version: 2.0.2
connecting to: localhost:27017/test
> use CollabTextEditor
switched to db CollabTextEditor
> db.dropDatabase()
{ "dropped" : "CollabTextEditor", "ok" : 1 }
> exit
bye
在此之后,脚本不再返回任何错误。所以我可以得出结论,MongoDB 可能崩溃了(原因未知),导致数据损坏,导致滚雪球效应。相当愚蠢的错误,如果在 MongoDb 和 Opa 中有更好的错误报告,我可能不会浪费这么多宝贵的时间。希望这对其他人有帮助:)