Ejemplo n.º 1
0
 private void convertNodeToDenseNode(
     NodeRecord node,
     RelationshipRecord firstRel,
     RecordAccess<Long, RelationshipRecord, Void> relRecords,
     RecordAccess<Long, RelationshipGroupRecord, Integer> relGroupRecords) {
   firstRel = relRecords.getOrLoad(firstRel.getId(), null).forChangingLinkage();
   node.setDense(true);
   node.setNextRel(Record.NO_NEXT_RELATIONSHIP.intValue());
   long relId = firstRel.getId();
   RelationshipRecord relRecord = firstRel;
   while (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
     locker.getWriteLock(relId);
     relId = relChain(relRecord, node.getId()).get(relRecord);
     connectRelationshipToDenseNode(node, relRecord, relRecords, relGroupRecords);
     if (relId == Record.NO_NEXT_RELATIONSHIP.intValue()) {
       break;
     }
     relRecord = relRecords.getOrLoad(relId, null).forChangingLinkage();
   }
   if (upgradedDenseNodes == null) {
     upgradedDenseNodes = new ArrayList<>();
   }
   upgradedDenseNodes.add(node);
 }
Ejemplo n.º 2
0
 private void convertNodeToDenseIfNecessary(
     NodeRecord node,
     RecordAccess<Long, RelationshipRecord, Void> relRecords,
     RecordAccess<Long, RelationshipGroupRecord, Integer> relGroupRecords) {
   if (node.isDense()) {
     return;
   }
   long relId = node.getNextRel();
   if (relId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
     RecordProxy<Long, RelationshipRecord, Void> relChange = relRecords.getOrLoad(relId, null);
     RelationshipRecord rel = relChange.forReadingLinkage();
     if (RelationshipCounter.relCount(node.getId(), rel) >= neoStore.getDenseNodeThreshold()) {
       convertNodeToDenseNode(node, relChange.forChangingLinkage(), relRecords, relGroupRecords);
     }
   }
 }
Ejemplo n.º 3
0
  private void connect(
      long nodeId,
      long firstRelId,
      RelationshipRecord rel,
      RecordAccess<Long, RelationshipRecord, Void> relRecords) {
    long newCount = 1;
    if (firstRelId != Record.NO_NEXT_RELATIONSHIP.intValue()) {
      locker.getWriteLock(firstRelId);
      RelationshipRecord firstRel = relRecords.getOrLoad(firstRelId, null).forChangingLinkage();
      boolean changed = false;
      if (firstRel.getFirstNode() == nodeId) {
        newCount = firstRel.getFirstPrevRel() + 1;
        firstRel.setFirstPrevRel(rel.getId());
        firstRel.setFirstInFirstChain(false);
        changed = true;
      }
      if (firstRel.getSecondNode() == nodeId) {
        newCount = firstRel.getSecondPrevRel() + 1;
        firstRel.setSecondPrevRel(rel.getId());
        firstRel.setFirstInSecondChain(false);
        changed = true;
      }
      if (!changed) {
        throw new InvalidRecordException(nodeId + " doesn't match " + firstRel);
      }
    }

    // Set the relationship count
    if (rel.getFirstNode() == nodeId) {
      rel.setFirstPrevRel(newCount);
      rel.setFirstInFirstChain(true);
    }
    if (rel.getSecondNode() == nodeId) {
      rel.setSecondPrevRel(newCount);
      rel.setFirstInSecondChain(true);
    }
  }