简体   繁体   English

Groovy和Java MongoDB驱动程序批量插入引发异常

[英]Groovy & Java MongoDB Driver bulk insertion throws exception

the following groovy scripts use the Java MongoDB Driver and try to run a bulk insertion in a separate thread by using GPars. 以下groovy脚本使用Java MongoDB驱动程序,并尝试使用GPar在单独的线程中运行批量插入。 The first script mongobulk1.groovy works fine but it runs without the 'BulkWriteOperation'. 第一个脚本mongobulk1.groovy可以正常运行,但是没有'BulkWriteOperation'即可运行。

For a better performance the second script mongobulk2.groovy is using the 'BulkWritOperation' feature but it throws the following exception: 为了获得更好的性能,第二个脚本mongobulk2.groovy使用了'BulkWritOperation'功能,但是它引发以下异常:

Caught: java.lang.IllegalStateException: java.lang.IllegalStateException: no operations
java.lang.IllegalStateException: java.lang.IllegalStateException: no operations
    at jsr166y.ForkJoinTask.getThrowableException(ForkJoinTask.java:504)
    at jsr166y.ForkJoinTask.reportResult(ForkJoinTask.java:567)
    at jsr166y.ForkJoinTask.join(ForkJoinTask.java:611)
    at jsr166y.ForkJoinPool.invoke(ForkJoinPool.java:1492)
    at groovyx.gpars.extra166y.ParallelArrayWithMapping.apply(ParallelArrayWithMapping.java:48)
    at groovyx.gpars.extra166y.ParallelArray.apply(ParallelArray.java:329)
    at groovyx.gpars.pa.GParsPoolUtilHelper.eachParallelPA(GParsPoolUtilHelper.groovy:192)
    at groovyx.gpars.GParsPoolUtil.eachParallel(GParsPoolUtil.java:358)
    at Importer$_main_closure1.doCall(mongobulk2.groovy:107)
    at groovyx.gpars.GParsPool$_withExistingPool_closure1.doCall(GParsPool.groovy:174)
    at groovyx.gpars.GParsPool$_withExistingPool_closure1.doCall(GParsPool.groovy)
    at groovyx.gpars.GParsPool.withExistingPool(GParsPool.groovy:173)
    at groovyx.gpars.GParsPool$withExistingPool$2.callStatic(Unknown Source)
    at groovyx.gpars.GParsPool.withPool(GParsPool.groovy:145)
    at groovyx.gpars.GParsPool$withPool$1.callStatic(Unknown Source)
    at groovyx.gpars.GParsPool.withPool(GParsPool.groovy:121)
    at groovyx.gpars.GParsPool$withPool$0.callStatic(Unknown Source)
    at groovyx.gpars.GParsPool.withPool(GParsPool.groovy:100)
    at groovyx.gpars.GParsPool$withPool.call(Unknown Source)
    at Importer.main(mongobulk2.groovy:106)
Caused by: java.lang.IllegalStateException: no operations
    at org.bson.util.Assertions.isTrue(Assertions.java:36)
    at com.mongodb.DBCollectionImpl.executeBulkWriteOperation(DBCollectionImpl.java:132)
    at com.mongodb.DBCollection.executeBulkWriteOperation(DBCollection.java:1663)
    at com.mongodb.DBCollection.executeBulkWriteOperation(DBCollection.java:1659)
    at com.mongodb.BulkWriteOperation.execute(BulkWriteOperation.java:90)
    at Importer.run(mongobulk2.groovy:82)
    at Importer$run$2.call(Unknown Source)
    at Importer$_main_closure1_closure2.doCall(mongobulk2.groovy:112)
    at groovyx.gpars.pa.GParsPoolUtilHelper$_eachParallelPA_closure8.doCall(GParsPoolUtilHelper.groovy:192)
    at com.sun.proxy.$Proxy9.op(Unknown Source)
    at groovyx.gpars.extra166y.AbstractParallelAnyArray$OUPap.leafApply(AbstractParallelAnyArray.java:640)
    at groovyx.gpars.extra166y.PAS$FJOApply.atLeaf(PAS.java:147)
    at groovyx.gpars.extra166y.PAS$FJBase.compute(PAS.java:108)
    at jsr166y.RecursiveAction.exec(RecursiveAction.java:148)
    at jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:305)
    at jsr166y.ForkJoinWorkerThread.execTask(ForkJoinWorkerThread.java:575)
    at jsr166y.ForkJoinPool.scan(ForkJoinPool.java:755)
    at jsr166y.ForkJoinPool.work(ForkJoinPool.java:617)
    at jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:369)

Any idea? 任何想法?

In fact, your algo is wrong and you trigger builder.execute() at a time when your builder has no request to make (ie 'no operation'). 实际上,您的算法是错误的,并且在您的构建器没有要执行的请求(即“无操作”)时触发了builder.execute() )。

You can check this by adding a sysout before the builder.execute() : 您可以通过在builder.execute()之前添加sysout来进行检查:

println "nb request to execute: $builder.requests.size"
BulkWriteResult result = builder.execute()

Here is the associated mongo client source code: 这是关联的mongo客户端源代码:

Assertions.isTrue("no operations", !writeRequests.isEmpty());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM