pymongo.errors.BulkWriteError: batch op errors occurred (MongoDB 3.4.2, pymongo 3.4.0, python 2.7.13)

爷,独闯天下 提交于 2019-12-07 16:57:52

问题


I am migrating several hundred million tweets of the format {'id_str': , 'created_at': , 'text': } from text files into MongoDB using pymongo. A collection is created for each user to store his/her tweets. The insertion method I am using is insert_many(). It often runs into BulkWriteError.

Traceback (most recent call last):
  File "pipeline.py", line 105, in <module>
    timeline_db, meta_db, negative_db, log_col, dir_path)
  File "/media/haitao/Storage/twitter_pipeline/migrate_old.py", line 134, in migrate_dir
    timeline_db[user_id].insert_many(utility.temporal_sort(statuses))
  File "/home/haitao/anaconda3/envs/py27/lib/python2.7/site-packages/pymongo/collection.py", line 711, in insert_many
    blk.execute(self.write_concern.document)
  File "/home/haitao/anaconda3/envs/py27/lib/python2.7/site-packages/pymongo/bulk.py", line 493, in execute
    return self.execute_command(sock_info, generator, write_concern)
  File "/home/haitao/anaconda3/envs/py27/lib/python2.7/site-packages/pymongo/bulk.py", line 331, in execute_command
    raise BulkWriteError(full_result)
pymongo.errors.BulkWriteError: batch op errors occurred

This error seems to occur when there are duplicates of keys, which should not be the case for here. Are there other things that I can check to solve this issue?

Thanks in advance!


回答1:


sorry for the delay.

1) I replicated the error. The following is close to the end of the mongod.log.

I -        [ftdc] Assertion: 13538:couldn't open [/proc/5774/stat] errno:24 Too many open
files
W FTDC     [ftdc] Uncaught exception in 'Location13538: couldn't open [/proc/5774/stat] 
errno:24 Too many open files' in full-time diagnostic data capture subsystem. Shutting down 
the full-time diagnostic data capture subsystem.
E STORAGE  [conn2] WiredTiger (24) [1491020356:127332][5774:0x7f6f30e9d700], WT_SESSION
.create: /var/lib/mongodb/: directory-sync: open: Too many open files
I COMMAND  [conn2] command timeline_db.231731006 command: insert { insert: "231731006", 
ordered: true, documents: 1000 } ninserted:0 keyUpdates:0 writeConflicts:0 exception: 24: 
Too many open files code:8 numYields:0 reslen:123 locks:{ Global: { acquireCount: { r: 2, 
w: 2 } }, Database: { acquireCount: { w: 1, W: 1 } }, Collection: { acquireCount: { w: 1, 
W: 1 } } } protocol:op_query 511ms```

2) Yes, only one instance of MongoClient() is passed around.

3) No multi-processing was run.

After I posted the initial question, I started to use insert_one() which explicitly raised open file limit error. I changed the design of the database (mainly, reduced the number of collections) and solved the issue about open file limit. I am not sure, but the log seems to suggest that the actual cause of the BulkWriteError is also open file limit.



来源:https://stackoverflow.com/questions/43073956/pymongo-errors-bulkwriteerror-batch-op-errors-occurred-mongodb-3-4-2-pymongo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!