zoukankan      html  css  js  c++  java
  • mongo异常com.mongodb.MongoCursorNotFoundException

    昨天晚上跑脚本,删除历史无用数据,查询200万条记录数据做遍历,遍历一次做一次查询并删除列表操作

    今天早上一看,报了异常:org.springframework.dao.DataAccessResourceFailureException: Query failed with error code -5 and error message 'Cursor 2300197310076874624 not found on server

    看下代码:

          // 删除已回收(21)或删除的标客任务对应的markTaskFile
            CloseableIterator<Map> iterator = markerTaskRepository.findMarkTasks();
            while (iterator.hasNext()){
                Map m = iterator.next();
                String taskId = (String) m.get("taskId");
                String markTaskId = (String) m.get("markTaskId");
                if (collectionNames.contains(taskId)) {
                    markerTaskRepository.removeDeletedOrRecyclingMarkTaskFiles(taskId, markTaskId);
                }
            }
            iterator.close();

    异常信息:

    org.springframework.dao.DataAccessResourceFailureException: Query failed with error code -5 and error message 'Cursor 2300197310076874624 not found on server mongo.mongodb-m801-1zd89f.svc.bja.ipaas.cn:30000' on server mongo.mongodb-m801-1zd89f.svc.bja.ipaas.cn:30000; nested exception is com.mongodb.MongoCursorNotFoundException: Query failed with error code -5 and error message 'Cursor 2300197310076874624 not found on server mongo.mongodb-m801-1zd89f.svc.bja.ipaas.cn:30000' on server mongo.mongodb-m801-1zd89f.svc.bja.ipaas.cn:30000
    
        at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:90)
        at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2793)
        at org.springframework.data.mongodb.core.MongoTemplate$CloseableIterableCursorAdapter.hasNext(MongoTemplate.java:3295)
        at com.iflytek.datahub.ainote.service.MongoDiskTest.deleteMarkTask(MongoDiskTest.java:72)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
        at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
        at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
        at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
        at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
        at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    Caused by: com.mongodb.MongoCursorNotFoundException: Query failed with error code -5 and error message 'Cursor 2300197310076874624 not found on server mongo.mongodb-m801-1zd89f.svc.bja.ipaas.cn:30000' on server mongo.mongodb-m801-1zd89f.svc.bja.ipaas.cn:30000
        at com.mongodb.operation.QueryHelper.translateCommandException(QueryHelper.java:27)
        at com.mongodb.operation.QueryBatchCursor.getMore(QueryBatchCursor.java:229)
        at com.mongodb.operation.QueryBatchCursor.hasNext(QueryBatchCursor.java:115)
        at com.mongodb.client.internal.MongoBatchCursorAdapter.hasNext(MongoBatchCursorAdapter.java:54)
        at org.springframework.data.mongodb.core.MongoTemplate$CloseableIterableCursorAdapter.hasNext(MongoTemplate.java:3293)
        ... 31 more

    原因是因为集群有多节点,查询数据过大时可能出现。A节点查到的游标到了B节点找不到,所以报异常

  • 相关阅读:
    第四周作业
    jsp第二次作业
    jsp第一次作业
    软件测试1
    activity
    listview
    sql
    登录
    第二次安卓作业
    安卓第一周作业
  • 原文地址:https://www.cnblogs.com/mabiao008/p/14665783.html
Copyright © 2011-2022 走看看