Mongo CursorNotFound在通过Grails域标准的活动光标中发生异常 [英] Mongo CursorNotFound exception in active cursor via Grails domain criteria

查看:170
本文介绍了Mongo CursorNotFound在通过Grails域标准的活动光标中发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  grails {
mongo {
host =11.12.13.14//远程服务器IP
端口= 27017
databaseName =blogger
username =博客
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 - &g吨;
//代码发送平均需要1秒的电子邮件
}



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

  2015-04-11 07: 31:14,218 [quartzScheduler_Worker-1] ERROR listeners.ExceptionPrinterJobListener  - 在作业中发生异常:Grails作业
org.quartz.JobExecutionException:com.mongodb.MongoException $ CursorNotFound:光标1337814790631604331未在服务器上找到11.12.13.14:27017 [请参阅嵌套异常:com.mongodb.MongoException $ CursorNotFound:在服务器上找不到1337814790631604331的光标11.12.13.14:27017]
在grails.plugins.quartz.GrailsJobFactory $ GrailsJob.execute(GrailsJobFactory.java:111)
在org.quartz.core.JobRunShell.run(JobRunShell.java:202)
在org.quartz.simpl.SimpleThreadPool $ WorkerThread.run(SimpleThreadPool.java:573)
引起:com。 mongodb.MongoException $ CursorNotFound:未找到光标1337814790631604331 ver 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 )
在com.mongodb.DBCursor._hasNext(DBCursor.java:551)
在com.mongodb.DBCursor.hasNext(DBCursor.java:571)
在org.grails.datastore。 $ com.test.WeeklyJob
(PersonService.groovy:323)
.execute(WeeklyJob.groovy:41)
at grails.plugins.quartz.GrailsJobFactory $ GrailsJob.execute(GrailsJobFactory.java:104)
... 2 more

我查找了文档,发现游标在20分钟内自动关闭,当我用日志确认它时,



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



更新

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

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



希望这对其他人有帮助!


I'm using Grails 2.4.4, mongo plugin 3.0.2, MongoDB 2.4.10 using a remote database connection.

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
        }
    }
}

In a part of our application, a service method iterates over a 20,000 user's and sends them an email:

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

After executing this for some 6000 user, I'm getting a MongoDB cursor exception:

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

I looked for documentation and found that cursor automatically get closed in 20 minutes and when I confirmed it with the logs, this exception came exactly after 20 minutes.

But this behaviour of auto-close in 20 minutes is applicable for inactive cursor but here the cursor is active.

UPDATE:

I read some articles and found that, this could be an issue of TCP keepalive timeout. So we changed the TCP keepalive timeout to 2 minutes from default 2 hours, but it still doesn't solve the problem.

解决方案

Looks like a compatibility issue with MonoDB on this server. Read more on the Jira for details https://jira.mongodb.org/browse/SERVER-18439

Hope this helps to someone else!

这篇关于Mongo CursorNotFound在通过Grails域标准的活动光标中发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆