Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSQLNonBlockingQuery not working #6267

Closed
temilmg opened this issue Jun 7, 2016 · 11 comments
Closed

OSQLNonBlockingQuery not working #6267

temilmg opened this issue Jun 7, 2016 · 11 comments
Assignees
Labels
Milestone

Comments

@temilmg
Copy link

temilmg commented Jun 7, 2016

Steps to reproduce the problem

Expected behavior and actual behavior

I tried using OSQLNonBlockingQuery but i get different errors when actually using the returned odocument (see below).

    OrientGraph graph = graphFactory.getTx();           
    try {

        OSQLNonBlockingQuery<Object> test = new OSQLNonBlockingQuery<Object>("select * from Prod where pid = '421'", new OCommandResultListener() {
              int resultCount = 0;
              @Override
              public boolean result(Object iRecord) {
                resultCount++;

                ODocument odoc = ((ODocument)iRecord);

                for(String name : odoc.fieldNames()) {     //  <----------- PROBLEM
                    System.out.println("Name:"+name);
                }

                System.out.println("callback "+resultCount+" invoked");
                return resultCount > 20 ? false : true;
              }

              @Override
              public void end() {
              }
            });

        Future future = graph.command(test).execute();
            System.out.println("query executed");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {

        if (graph != null) {
            graph.shutdown(); // <------- If i remove this bit it wont throw the last exception but how do I then release resources
        }
    }

java.lang.UnsupportedOperationException: Trying to iterate over a non-blocking query result
at com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery$ONonBlockingQueryFuture.iterator(OSQLNonBlockingQuery.java:102)
at com.tinkerpop.blueprints.impls.orient.OrientGraphCommand.execute(OrientGraphCommand.java:51)
at com.myapp.Endpoint.main(Endpoint.java:57)

May 17, 2016 11:14:40 AM com.orientechnologies.common.log.OLogManager log
WARNING: Error deserializing record with id #38:235 send this data for debugging: ABpEYXRhX1Byb2R1Y3RzRwAAANdNAAAA20kAAADvSwAAASVFAAAC1kMAAALZFGVnZW5za2FiZXIAAAMaCgxncm91cHMAAAM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y00MjFgcHJvZHVrdGthdGFsb2cvYnlnZy90cmFlbGltL3RyYWVsaW0tcHUtbGp1cy00MjEvPkRBTkFMSU1fSU1QT1JUXzIwMTYtMjgtMTIgMTE6MjgGFwwEBwZhbHQAAAPRBwcGdXJsAAAD5AckUHJvZHVrdGluZm9ybWF0aW9uPC9wcm9kdWt0aW5mb3JtYXRpb24vc2UvNDIxLnBkZgwEBwZhbHQAAAQZBwcGdXJsAAAELAckU8Oka2VyaGV0c2RhdGFibGFkPC9zaWtrZXJoZWRzZGF0YWJsYWQvc2UvNDIxLnBkZgwEBwZhbHQAAARhBwcGdXJsAAAEdQcmQnlnZ3ZhcnVkZWtsYXJhdGlvbjovYnlnZ3ZhcnVkZWtsYXRpb24vc2UvNDIxLnBkZgAXAhcMBAcEdjEAAASrBwcEdjIAAATdB2Jwcm9kdWt0a2F0YWxvZy9ieWdnL3RyYWVsaW0vdHJhZWxpbS1wdS1tb2Vyay00MjIvKFRyw6RsaW0gUFUgTcO2cmsgNDIyCGJ5Z2cOdHJhZWxpbQAA
Exception in thread "Thread-3" com.orientechnologies.orient.core.exception.ODatabaseException: Database 'remote:orientdb:2424/mydb' is closed
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.checkOpeness(ODatabaseDocumentTx.java:2920)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.getMetadata(ODatabaseDocumentTx.java:793)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.getMetadata(ODatabaseDocumentTx.java:121)
at com.orientechnologies.orient.core.record.impl.ODocument.setClassNameIfExists(ODocument.java:1917)
at com.orientechnologies.orient.core.record.impl.ODocument.fillClassIfNeed(ODocument.java:2180)
at com.orientechnologies.orient.core.record.impl.ODocumentInternal.fillClassNameIfNeeded(ODocumentInternal.java:64)
at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.deserialize(ORecordSerializerBinaryV0.java:159)
at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinary.fromStream(ORecordSerializerBinary.java:74)
at com.orientechnologies.orient.core.record.impl.ODocument.deserializeFields(ODocument.java:1817)
at com.orientechnologies.orient.core.record.impl.ODocument.checkForFields(ODocument.java:2416)
at com.orientechnologies.orient.core.record.impl.ODocument.fieldNames(ODocument.java:736)
at com.myapp.Endpoint$1.result(Endpoint.java:42)
at com.orientechnologies.orient.client.remote.OStorageRemote.command(OStorageRemote.java:1214)
at com.orientechnologies.orient.client.remote.OStorageRemoteThread.command(OStorageRemoteThread.java:453)
at com.orientechnologies.orient.core.sql.query.OSQLQuery.run(OSQLQuery.java:72)
at com.orientechnologies.orient.core.query.OQueryAbstract.execute(OQueryAbstract.java:33)
at com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery.access$001(OSQLNonBlockingQuery.java:47)
at com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery$1.run(OSQLNonBlockingQuery.java:258)
at java.lang.Thread.run(Thread.java:745)

Important Questions

If I dont do a graph.shutdown() it will print the fieldnames and not throw the last exception but then how do I release my resources?

In the event I get the non-blocking query working is it possible to return results in batches (I suspect otherwise I will get into trouble with latency given Im using a remote connection)?

Runninng Mode

  • Remote

OrientDB Version

  • v2.1.17

Operating System

  • Linux

Java Version

  • 8
@wolf4ood
Copy link
Member

hi @temilmg

about the closed exception,
you cannot release the graph in the finally since the graph is used in the async query.
You could release the graph in the end method

@Override
public void end() {
   graph.makeActive();
   graph.shutdown();
}

Let me know if it works

Thanks

@temilmg
Copy link
Author

temilmg commented Jun 14, 2016

Hi maggiolo00,
Thanks for looking into this.

I get two exceptions when adding your two lines of code, see stack-trace below.
For some reason the end() method is called twice. The exceptions are thrown the second time inside end().

Also the documentations says: "... That means that in the meantime you can close your db instance and keep on receiving callbacks from the query result." Maybe its a silly question but I thought that meant I could release the graph resources right away? Or does it mean I should do graphFactory.getDatabase().close(); in the finally block?

com.orientechnologies.orient.core.exception.ODatabaseException: Database instance is not set in current thread. Assure to set it with: ODatabaseRecordThreadLocal.INSTANCE.set(db);
at com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal.get(ODatabaseRecordThreadLocal.java:51)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.checkIfActive(ODatabaseDocumentTx.java:3130)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.close(ODatabaseDocumentTx.java:1168)
at com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery$1.run(OSQLNonBlockingQuery.java:267)
at java.lang.Thread.run(Thread.java:745)
Exception in thread "Thread-5" com.orientechnologies.orient.core.exception.ODatabaseException: Database 'remote:orientdb:2424/mydb' is closed
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.checkOpeness(ODatabaseDocumentTx.java:2867)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.getMetadata(ODatabaseDocumentTx.java:799)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.getMetadata(ODatabaseDocumentTx.java:121)
at com.orientechnologies.orient.core.sql.query.OSQLQuery.run(OSQLQuery.java:75)
at com.orientechnologies.orient.core.query.OQueryAbstract.execute(OQueryAbstract.java:33)
at com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery.access$001(OSQLNonBlockingQuery.java:47)
at com.orientechnologies.orient.core.sql.query.OSQLNonBlockingQuery$1.run(OSQLNonBlockingQuery.java:258)
at java.lang.Thread.run(Thread.java:745)

@temilmg
Copy link
Author

temilmg commented Jun 23, 2016

Had a peek into the code (OSQLNonBlockingQuery) seems like the db is being closed automatically. So Im thinking I shouldnt do anything to release resources. Can anyone confirm?
Maybe this is not a bug but just slightly misleading documentation.

Actually there is still the problem with the end() method, it probably shouldn't be invoked twice.

@tglman
Copy link
Member

tglman commented Jul 4, 2016

Hi,
This should be fixed now, is going to be out for 2.2.4, closing.

@tglman tglman closed this as completed Jul 4, 2016
@temilmg
Copy link
Author

temilmg commented Nov 21, 2016

I have tried to run it again, the same way as the documentation, and in 2.2.13 its still not working. This time it doesn't call into the method
@OverRide public boolean result(Object iRecord) {}
Could anybody please provide a working code example so I can see how to use nonblocking queries, because I can't get it to work at all?

@tglman
Copy link
Member

tglman commented Nov 24, 2016

hi @temilmg,

I add the proper test cases ad fixed all the related issues, now it should work.

check the commit the test case is a working example now.

Bye

@tglman tglman added this to the 2.2.x (next hotfix) milestone Nov 24, 2016
@temilmg
Copy link
Author

temilmg commented Nov 24, 2016

Hi tglman, thank you for looking into this issue and fixing it.
I did some testing and it seems to work for my purpose. I did wonder about the Object getResult() method, now it never actually calls into it!

@tglman
Copy link
Member

tglman commented Nov 24, 2016

hi @temilmg,

As return of a non blocking query there is a Future if you call the get of the future that will call the getResult()
here is an exampe of future : https://github.com/orientechnologies/orientdb/blob/master/tests/src/test/java/com/orientechnologies/orient/test/database/auto/NonBlockingQueryTest.java#L64

@temilmg
Copy link
Author

temilmg commented Nov 24, 2016

Ok I see, thank you:-)

@tglman
Copy link
Member

tglman commented Nov 24, 2016

hi @temilmg,

Can we close this again ? now there is the test case to prove it works ;)

@temilmg
Copy link
Author

temilmg commented Nov 24, 2016

Yes I think this one can be closed (I did open a related issue for deleting and updating with OSQLNonBlockingQuery)

@robfrank robfrank modified the milestones: 2.2.14, 2.2.x (next hotfix) Dec 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

7 participants