通过Grails域条件在活动游标中使用Mongo CursorNotFound异常

时间:2015-04-14 10:07:26

标签: mongodb grails grails-2.4 gmongo

我使用Grails 2.4.4,mongo插件3.0.2,MongoDB 2.4.10使用远程数据库连接。

grails {
    mongo {
        host = "11.12.13.14"    // A remote server IP
        port = 27017
        databaseName = "blogger"
        username = "blog"
        password = "xyz"
        options {
            autoConnectRetry = true
            connectTimeout = 3000
            connectionsPerHost = 40
            socketTimeout = 120000
            threadsAllowedToBlockForConnectionMultiplier = 5
            maxAutoConnectRetryTime=5
            maxWaitTime=120000
        }
    }
}

在我们的应用程序的一部分中,服务方法迭代超过20,000个用户并向他们发送电子邮件:

Person.withCriteria {       // Line 323
    eq("active", true)
    order("dateJoined", "asc")
}.each { personInstance ->
   // Code to send an email which takes an average of 1 second
}

对大约6000个用户执行此操作后,我收到MongoDB游标异常:

2015-04-11 07:31:14,218 [quartzScheduler_Worker-1] ERROR listeners.ExceptionPrinterJobListener  - Exception occurred in job: Grails Job
org.quartz.JobExecutionException: com.mongodb.MongoException$CursorNotFound: Cursor 1337814790631604331 not found on server 11.12.13.14:27017 [See nested exception: com.mongodb.MongoException$CursorNotFound: Cursor 1337814790631604331 not found on server 11.12.13.14:27017]
        at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:111)
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: com.mongodb.MongoException$CursorNotFound: Cursor 1337814790631604331 not found on server 11.12.13.14:27017
        at com.mongodb.QueryResultIterator.throwOnQueryFailure(QueryResultIterator.java:218)
        at com.mongodb.QueryResultIterator.init(QueryResultIterator.java:198)
        at com.mongodb.QueryResultIterator.initFromQueryResponse(QueryResultIterator.java:176)
        at com.mongodb.QueryResultIterator.getMore(QueryResultIterator.java:141)
        at com.mongodb.QueryResultIterator.hasNext(QueryResultIterator.java:127)
        at com.mongodb.DBCursor._hasNext(DBCursor.java:551)
        at com.mongodb.DBCursor.hasNext(DBCursor.java:571)
        at org.grails.datastore.mapping.mongo.query.MongoQuery$MongoResultList$1.hasNext(MongoQuery.java:1893)
        at com.test.person.PersonService.sendWeeklyEmail(PersonService.groovy:323)
        at com.test.WeeklyJob.execute(WeeklyJob.groovy:41)
        at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:104)
        ... 2 more

我找了文档,发现光标会在20分钟后自动关闭,当我用日志确认时,这个异常就在20分钟后完成。

但是这种在20分钟内自动关闭的行为适用于非活动光标,但此处光标处于活动状态。

更新

我读了一些文章,发现这可能是TCP keepalive超时的问题。所以我们将TCP keepalive超时从默认的2小时改为2分钟,但它仍然没有解决问题。

1 个答案:

答案 0 :(得分:1)

在此服务器上看起来与MonoDB存在兼容性问题。有关详细信息,请阅读Jira的更多信息https://jira.mongodb.org/browse/SERVER-18439

希望这有助于其他人!