2011-11-19 21 views
1

這似乎是一個非常奇怪的問題。我正在測試我的neo4j圖形數據庫,因此我的一個測試需要創建大量的用戶(在這個特定的測試中,1000)。因此,對於該代碼如下,在neo4j索引中創建第128個節點後,無法訪問更多節點

// Creates a n users and measures the time taken to add another 
      n = 1000; 
      tx = graphDb.beginTx(); 
      try { 
       for(int i = 0; i < n; i++){ 
        dataService.createUser(BigInteger.valueOf(i)); 
       } 

       start = System.nanoTime(); 
       dataService.createUser(BigInteger.valueOf(n)); 
       end = System.nanoTime(); 

       time = end - start; 

       System.out.println("The time taken for createUser with " + n + " users is " + time +" nanoseconds."); 

       tx.success(); 
      } 
      finally 
      { 
       tx.finish(); 
      } 

而對於dataService.createUser()是代碼,

public User createUser(BigInteger identifier) throws ExistsException { 
     // Verify that user doesn't already exist. 
     if (this.nodeIndex.get(UserWrapper.KEY_IDENTIFIER, identifier) 
       .getSingle() != null) { 
      throw new ExistsException("User with identifier '" 
        + identifier.toString() + "' already exists."); 
     } 

     // Create new user. 
     final Node userNode = graphDb.createNode(); 
     final User user = new UserWrapper(userNode); 
     user.setIdentifier(identifier); 

     userParent.getNode().createRelationshipTo(userNode, NodeRelationships.PARENT); 

     return user; 
    } 

現在我需要調用dataService.getUser()我做了這些之後,用戶。 getUser()的代碼如下,

public User getUser(BigInteger identifier) throws DoesNotExistException { 
     // Search for the user. 
     Node userNode = this.nodeIndex.get(UserWrapper.KEY_IDENTIFIER, 
       identifier).getSingle(); 
     // Return the wrapped user, if found. 
     if (userNode != null) { 
      return new UserWrapper(userNode); 
     } else { 
      throw new DoesNotExistException("User with identifier '" 
        + identifier.toString() + "' was not found."); 
     } 
    } 

所以一切都很好,直到我創建第129個用戶。我在調試器中觀察dataService.getUser(BigInteger.valueOf(1))(它是第二個節點)的值,dataService.getUser(BigInteger.valueOf(127))(它是第128個節點)和dataService。 getUser(BigInteger.valueOf(i-1))這是最後創建的節點。調試器告訴我,節點128創建後,節點129及以上不會創建,因爲getUser()爲這些節點拋出DoesNotExistException異常,但仍給出節點2和節點128的值。

用戶標識我傳遞給createUser()是autoindexed。

任何想法爲什麼它沒有更多的節點(或不索引這些節點)?

回答

2

它聽起來很像128字節的字節值轉換。你能確定在你的代碼中沒有類似的東西嗎?

+0

好,我應該意識到這一點。我的用戶ID存儲爲字節數組。我將它們轉換爲多頭,一切正常。 – gsingh2011