I have 1 mongodb cluster im am backing up and attempting to restore into another mongodb cluster. The data seems to all restore successfully, but we are having a problem with restoring the indexes.
2023-04-28T12:48:43.064+0000 Failed: <redacted>.games: error creating indexes for redacted.games: createIndex error: connection(mongo.redacted-test.com:27017[-6]) socket was unexpectedly closed: EOF
Hi @Kay_Khan and welcome to MongoDB community forums!!
Based on the above posts, it seems you are trying to do a mongodump and mongorestore between version 5.0 and 6.0
I tried to replicate the issue in my local environment with a sample dataset between the latest patch version for version 5.0 and version 6.0 which are version 5.0.17 and version 6.0.5 respectively.
I tried the following mongodump and mongorestore with index being created in the collection.
Your example is quite small. If we are dealing with gb’s in size of data. The index takes long to complete and maybe thats why we are getting an error socket was unexpectedly closed ? What would be the solution to this problem?
Based on the error logs provided, I tried to replicate the issue in my local environment.
Firstly, I tested the scenario with a dataset for ~ 3 GB and tried to follow the steps mentioned above with a change during the mongorestore.
While the restore was creating the index, I tried to kill the mongod process using kill -9 <PID> and I could see the similar error logs as:
2023-05-04T12:33:42.648+0530 Failed: test.samplerestore2: error creating indexes for test.samplerestore2: createIndex error: connection(localhost:27018[-7]) socket was unexpectedly closed: EOF
2023-05-04T12:33:42.648+0530 24000000 document(s) restored successfully. 0 document(s) failed to restore.
Can you confirm if there has been any termination in the mongod process while the index was restored.
I tried to replicate using the latest patch versions of mongoDB (5.0.17 and 6.0.5), could you help with the versions of mongod, mongodump and mongorestore ?
If you find that the mongod process was shut down unexpectedly by the Linux OOMkiller, you might be seeing the effect of SERVER-68125: Index build on multi-key fields can consume more memory than limit especially if you have a lot of data and multi-key indexes. This was fixed in MongoDB 6.0.4, so if you’re not using the latest version, please upgrade to the latest one for bug fixes and improvements
Lastly, this issue mainly would effect on the large collections and one possible workaround we could suggest would be to pre-create the collection and indexes before mongorestore. This would avoid large index building process.
Also, --drop parameter should not be used in the mongorestore command if you decide to pre-create the collection and indexes.