1
votes

I tried to make neo4j REST batching work via org.neo4j.rest.graphdb , but I have no clue, how it should work. Something I did:

final RestAPIFacade rest = new RestAPIFacade("http://localhost:7474/db/data");
BatchTransaction tx = BatchTransaction.begin(rest);
BatchRestAPI newrest = new BatchRestAPI("http://localhost:7474/db/data",rest);

try {
    for (int i = 0; i < 1000; i++) {
        newrest.createNode(null);
    }
    tx.success();
} finally {
    tx.finish();
}

I understand that I could write my own rest requests constructor but it's not appropriate solution for what I need. Maybe someone has worked with this library and knows the right way. The problem is nothing changes in database, and no error appears.

Update: if I use a usual RestAPIFacade transaction and set

System.setProperty("org.neo4j.rest.batch_transaction", "true");

I get Premature EOF error.

Caused by: java.io.IOException: Premature EOF
    at sun.net.www.http.ChunkedInputStream.readAheadBlocking(ChunkedInputStream.java:565)
    at sun.net.www.http.ChunkedInputStream.readAhead(ChunkedInputStream.java:609)
    at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:696)
    at java.io.FilterInputStream.read(FilterInputStream.java:133)

So, one transaction seems to be limited to some size(nearly 700 empty nodes). So, is there a way increasing transaction size, or I should divide my data portions on many many transactions(so the performance, obviously, suffers)?

Thank you!

1

1 Answers

0
votes

Try changing your code to construct a RestGraphDatabase instance and then get the transactions from it instead of constructing them yourself. The same goes for the RestAPI if you want to use it. Something like

GraphDatabaseService graphDb = new RestGraphDatabase("http://localhost:7474/db/data");
...
Transaction tx = graphDb.beginTx();
...
RestAPI restApi = graphDb.getRestAPI();

If you want the transactions to be executed in batch you should also set the corresponding system property

System.setProperty("org.neo4j.rest.batch_transaction", "true");