Does fetch plan actually have any effect when working with OrientVertex/ODocument in remote mode?

81 views
Skip to first unread message

Jan Plaček

unread,
Sep 23, 2015, 5:52:13 PM9/23/15
to orient-...@googlegroups.com
Consider tree like graph represented by "Node" verticies and "childOf" edges (oriented from child to parent) and command:

Iterable<OrientVertex> roots = (Iterable<OrientVertex>) graph.command(new OCommandSQL("select from Node where key = 'root'  fetchplan in_childOf:-1")).execute();


Now when I traverse the tree by Vertex.getVerticies(Direction.IN, "childOf")/ODocument.field("in_childOf") I expect there won't be any further remote lookup calls, because verticies have been already fetched by fetch plan.
But is it really the case?

I was trying to find out how accessing related records (edges) works:

The edges are represented as ORidBag:
ORidBag ridBag = (ORidBag) root.getRecord().field("in_childOf");

The ORidBag is a collection of OIdentifiable implemented by ORecordId:
ORecordId rid = (ORecordId) ridBag.iterator().next();

Now I can access the record (implemented by ODocument) representing the edge:
ODocument inChild = (ODocument) rid.getRecord();

The implementation of ORecordId.getRecord() is quite simple. It basically delegates the record retrieval to current ODatabaseDocument implemented by ODatabaseDocumentTx:
return (T) db.load(this);

There the things are getting complicated, but if I summarize my foundings, the record is either taken from local cache or requested to be fetched by OStorageRemote.

As you can see I was able to find out only one place where the related record is not requested from the storage again and that is obtaining a record from local cache by ODatabaseDocumentTx.
However I checked that the related records are not present in local cache after the command is executed, so local cache also isn't responsible for accessing eagerly fetched records.

So am I really working with fetched records or are they fetched again when traversing graph with Document/Graph API in remote mode?
Which component (ODocument/ORidBag/ODatabase/OStorage) is responsible for obtaining a record which is possibly loaded eagerly via fetch plan? 
And is there a way to tell if the related record (represented for example by ORecordId) is already fetched?

UPDATE:
According to some forum posts the eagerly fetched records should be stored in 2nd level client cache, I wonder how do I access that cache?
UPDATE2:
Since orientdb 2.0, there is only one local cache, but as I mentioned earlier, it does not contain the verticies/edges after the command is executed (they are present in the cache only after I visit them manually - via traversal methods), is this unexpected behavior?

Jan Plaček

unread,
Sep 25, 2015, 10:20:21 AM9/25/15
to orient-...@googlegroups.com
Can someone please test and confirm that using fetchplan does not place any additional records into a local cache? (with transacational database in remote mode).

You can test for record presence in a local cache like this:
graph.getRawGraph().getLocalCache().findRecord(new ORecordId("#11:0")) != null;



Dne středa 23. září 2015 23:52:13 UTC+2 Jan Plaček napsal(a):
Consider tree like graph represented by "Node" verticies and "childOf" edges (oriented from child to parent) and command:

Iterable<OrientVertex> roots = (Iterable<OrientVertex>) graph.command(new OCommandSQL("select from Node where key = 'root'  fetchplan in_childOf:-1")).execute();


Now when I traverse the tree by Vertex.getVerticies(Direction.IN, "childOf")/ODocument.field("in_childOf") I expect there won't be any further remote lookup calls, because verticies have been already fetched by fetch plan.
But is it really the case?

I was trying to find out how accessing related records (edges) works:

The edges are represented as ORidBag:
ORidBag ridBag = (ORidBag) root.getRecord().field("in_childOf");

The ORidBag is a collection of OIdentifiable implemented by ORecordId:
ORecordId rid = (ORecordId) ridBag.iterator().next();

Now I can access the record (implemented by ODocument) representing the edge:
ODocument inChild = (ODocument) rid.getRecord();

The implementation of ORecordId.getRecord() is quite simple. It basically delegates the record retrieval to current ODatabaseDocument implemented by ODatabaseDocumentTx:
return (T) db.load(this);

There the things are getting complicated, but if I summarize my foundings, the record is either taken from local cache or requested to be fetched by OStorageRemote.

As you can see I was able to find out only one place where the related record is not requested from the storage again and that is obtaining a record from local cache by ODatabaseDocumentTx.
However I checked that the related records are not present in local cache after the command is executed, so local cache also isn't responsible for accessing eagerly fetched records.

So am I really working with fetched records or are they fetched again when traversing graph with Document/Graph API in remote mode?
If yes, which component (ODocument/ORidBag/ODatabase/OStorage) is responsible for obtaining a record which is possibly loaded eagerly via fetch plan? 
Reply all
Reply to author
Forward
0 new messages