Groovy & Java MongoDB 驱动程序批量插入抛出异常
Groovy & Java MongoDB Driver bulk insertion throws exception
以下 groovy 脚本使用 Java MongoDB 驱动程序并尝试使用 GPars 运行 在单独的线程中进行批量插入。
第一个脚本 mongobulk1.groovy 工作正常但是它 运行s 没有 'BulkWriteOperation'.
为了获得更好的性能,第二个脚本 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.callStatic(Unknown Source)
at groovyx.gpars.GParsPool.withPool(GParsPool.groovy:145)
at groovyx.gpars.GParsPool$withPool.callStatic(Unknown Source)
at groovyx.gpars.GParsPool.withPool(GParsPool.groovy:121)
at groovyx.gpars.GParsPool$withPool[=13=].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.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)
有什么想法吗?
事实上,您的算法是错误的,您在构建器没有请求时触发了 builder.execute()
(即 'no operation')。
您可以通过在 builder.execute()
:
之前添加系统输出来检查这一点
println "nb request to execute: $builder.requests.size"
BulkWriteResult result = builder.execute()
这是相关的 mongo 客户端源代码:
Assertions.isTrue("no operations", !writeRequests.isEmpty());
以下 groovy 脚本使用 Java MongoDB 驱动程序并尝试使用 GPars 运行 在单独的线程中进行批量插入。 第一个脚本 mongobulk1.groovy 工作正常但是它 运行s 没有 'BulkWriteOperation'.
为了获得更好的性能,第二个脚本 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.callStatic(Unknown Source)
at groovyx.gpars.GParsPool.withPool(GParsPool.groovy:145)
at groovyx.gpars.GParsPool$withPool.callStatic(Unknown Source)
at groovyx.gpars.GParsPool.withPool(GParsPool.groovy:121)
at groovyx.gpars.GParsPool$withPool[=13=].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.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)
有什么想法吗?
事实上,您的算法是错误的,您在构建器没有请求时触发了 builder.execute()
(即 'no operation')。
您可以通过在 builder.execute()
:
println "nb request to execute: $builder.requests.size"
BulkWriteResult result = builder.execute()
这是相关的 mongo 客户端源代码:
Assertions.isTrue("no operations", !writeRequests.isEmpty());