Missing '__type__' in relationships

瀏覽次數:20 次
跳到第一則未讀訊息

Chris Walker

未讀,
2015年10月8日 上午8:53:362015/10/8
收件者:Neo4j
Hello,

I am running Spring Data Neo4j version 3.3.1.RELEASE and Neo4j version 2.2.3. I have a multi-threaded program inserting 40 related nodes in a method annotated @Neo4jTransactional. The insertion process is as follows:
  1. Construct the Java object for the node
  2. Call the Spring data repository to save the node
  3. Fetch each of the related nodes (we have a list of keys) and add each to the collection of relationships
  4. Save the node again
I am seeing frequent exceptions like this when fetching the related nodes (step 3 above).

org.springframework.dao.DataRetrievalFailureException: '__type__' on http://neo4j:7474/db/data/relationship/146815; nested exception is org.neo4j.graphdb.NotFo4j:7474/db/data/relationship/146815
        at org.springframework.data.neo4j.support.Neo4jExceptionTranslator.translateExceptionIfPossible(Neo4jExceptionTranslator.java:57)
        at org.springframework.data.neo4j.support.Neo4jTemplate.translateExceptionIfPossible(Neo4jTemplate.java:456)
        at org.springframework.data.neo4j.support.Neo4jTemplate.doExecute(Neo4jTemplate.java:467)
        ...
Caused by: org.neo4j.graphdb.NotFoundException: '__type__' on http://neo4j:7474/db/data/relationship/146815
        at org.neo4j.rest.graphdb.entity.RestEntity.getProperty(RestEntity.java:125)

As an attempt to solve this, I have modified the code to retry the fetch when this exception is caught.  This mostly works, although it sometimes requires 10 retries and over 1 second before the call succeeds.  When all retries are exhausted, the exception-handling code makes an HTTP call to the URL in the exception message so that I can examine the response as JSON.

The initial response is below.  The "__type__" field is indeed missing.

    {
      "extensions" : { },
      "start" : "http://localhost:7474/db/data/node/617",
      "property" : "http://localhost:7474/db/data/relationship/533/properties/{key}",
      "self" : "http://localhost:7474/db/data/relationship/533",
      "properties" : "http://localhost:7474/db/data/relationship/533/properties",
      "type" : "CONTAINS",
      "end" : "http://localhost:7474/db/data/node/650",
      "metadata" : {
        "id" : 533,
        "type" : "CONTAINS"
      },
      "data" : { }
    }


But a few seconds later, the same REST call returns JSON that seems to include the correct "__type__":

    {
      "extensions" : { },
      "start" : "http://localhost:7474/db/data/node/617",
      "property" : "http://localhost:7474/db/data/relationship/533/properties/{key}",
      "self" : "http://localhost:7474/db/data/relationship/533",
      "properties" : "http://localhost:7474/db/data/relationship/533/properties",
      "type" : "CONTAINS",
      "end" : "http://localhost:7474/db/data/node/650",
      "metadata" : {
        "id" : 533,
        "type" : "CONTAINS"
      },
      "data" : {
        "__type__" : "ProductRelationship"
      }
    }


My understanding is that "__type__" is added by SDN.  It seems odd that it is apparently added after the relationship has been inserted to Neo4j, and that the total transaction is not atomic.

Is there some way to specify consistency or transaction isolation in order to prevent this happening?  The retry strategy is unreliable and a serious performance hit.  It's also a very nasty code smell.

Thanks,

Chris
回覆所有人
回覆作者
轉寄
0 則新訊息