[ 
https://issues.apache.org/jira/browse/CAMEL-11977?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16237811#comment-16237811
 ] 

Ihor Paliichuk edited comment on CAMEL-11977 at 11/3/17 4:00 PM:
-----------------------------------------------------------------

I have found some info about this topic. Some time ago mongodb java driver team 
reworked hasNext() to wait for tailable cursors. 
https://jira.mongodb.org/browse/JAVA-1091 And added tryNext() to allow old 
behavior https://jira.mongodb.org/browse/JAVA-1255. As you see in current 
driver code 


{code:java}
    public boolean hasNext() {
        if (closed) {
            throw new IllegalStateException("Cursor has been closed");
        }

        if (nextBatch != null) {
            return true;
        }

        if (limitReached()) {
            return false;
        }

        while (serverCursor != null) {
            getMore();
            if (nextBatch != null) {
                return true;
            }
        }

        return false;
    }
{code}

hasNext() has infinite loop, which also is bad for performance, as in case we 
would use tryNext() and open/close cursor each time on camel side. I propose to 
request another "is closed" check inside loop before getMore() to mongodb 
driver team. Thjis should allow to exit from hasNext() when we will close 
cursor from another thread. If this solution sounds ok, I will request change 
on driver side.


was (Author: igorko):
I have found some info about this topic. Somw time ago mongodb java driver team 
reworked hasNext() to wait for tailable cursors. 
https://jira.mongodb.org/browse/JAVA-1091 And added tryNext() to allow old 
behavior https://jira.mongodb.org/browse/JAVA-1255. As you see in current 
driver code 


{code:java}
    public boolean hasNext() {
        if (closed) {
            throw new IllegalStateException("Cursor has been closed");
        }

        if (nextBatch != null) {
            return true;
        }

        if (limitReached()) {
            return false;
        }

        while (serverCursor != null) {
            getMore();
            if (nextBatch != null) {
                return true;
            }
        }

        return false;
    }
{code}

hasNext() has infinite loop, which also is bad for performance, as in case we 
would use tryNext() and open/close cursor each time on camel side. I propose to 
request another "is closed" check inside loop before getMore() to mongodb 
driver team. Thjis should allow to exit from hasNext() when we will close 
cursor from another thread. If this solution sounds ok, I will request change 
on driver side.

> MongoDB Tailable cursor consumer fails to stop on shutdown
> ----------------------------------------------------------
>
>                 Key: CAMEL-11977
>                 URL: https://issues.apache.org/jira/browse/CAMEL-11977
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-mongodb, camel-mongodb3
>    Affects Versions: 2.20.0
>         Environment: Windows 10, Java 1.8
>            Reporter: Ihor Paliichuk
>            Priority: Major
>             Fix For: 2.20.1, 2.21.0
>
>
> MongoDB Tailable cursor consumer fails to stop on shutdown(when using Ctrl+C) 
> if collection is not empty. Routes are described in xml file.
> [Camel (...) thread #8 - ShutdownTask] INFO  o.a.c.c.m.MongoDbTailingProcess 
> - Stopping MongoDB Tailable Cursor consumer, bound to collection: db: ..., 
> col: ... 
> [Camel (...) thread #8 - ShutdownTask] INFO  o.a.c.c.m.MongoDbTailingProcess 
> - Going to wait for stopping
> When collection is empty, all is ok and I see next line
> [Camel (...) thread #8 - ShutdownTask] INFO  o.a.c.c.m.MongoDbTailingProcess 
> - Stopped MongoDB Tailable Cursor consumer, bound to collection: db: ..., 
> col: ...



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to