Beispiel #1
0
 private void setCorrectNextRel(NodeRecord node, RelationshipRecord rel, long nextRel) {
   if (node.getId() == rel.getFirstNode()) {
     rel.setFirstNextRel(nextRel);
   }
   if (node.getId() == rel.getSecondNode()) {
     rel.setSecondNextRel(nextRel);
   }
 }
Beispiel #2
0
  @Override
  public Collection<DynamicRecord> put(long[] labelIds, NodeStore nodeStore) {
    long existingLabelsField = node.getLabelField();
    long existingLabelsBits = parseLabelsBody(existingLabelsField);

    Collection<DynamicRecord> changedDynamicRecords = node.getDynamicLabelRecords();

    if (labelField != 0) {
      // There are existing dynamic label records, get them
      nodeStore.ensureHeavy(node, existingLabelsBits);
      changedDynamicRecords = node.getDynamicLabelRecords();
      setNotInUse(changedDynamicRecords);
    }

    if (!new InlineNodeLabels(labelField, node)
        .tryInlineInNodeRecord(labelIds, changedDynamicRecords)) {
      Set<DynamicRecord> allRecords = new HashSet<>(changedDynamicRecords);
      Collection<DynamicRecord> allocatedRecords =
          nodeStore.allocateRecordsForDynamicLabels(
              node.getId(), labelIds, changedDynamicRecords.iterator());
      allRecords.addAll(allocatedRecords);
      node.setLabelField(dynamicPointer(allocatedRecords), allocatedRecords);
      changedDynamicRecords = allRecords;
    }

    return changedDynamicRecords;
  }
Beispiel #3
0
 @Override
 public Collection<DynamicRecord> remove(long labelId, NodeStore nodeStore) {
   nodeStore.ensureHeavy(node, parseLabelsBody(labelField));
   Collection<DynamicRecord> existingRecords = node.getDynamicLabelRecords();
   long[] existingLabelIds = nodeStore.getDynamicLabelsArray(existingRecords);
   long[] newLabelIds = filter(existingLabelIds, labelId);
   if (new InlineNodeLabels(labelField, node)
       .tryInlineInNodeRecord(newLabelIds, existingRecords)) {
     setNotInUse(existingRecords);
   } else {
     Collection<DynamicRecord> newRecords =
         nodeStore.allocateRecordsForDynamicLabels(
             node.getId(), newLabelIds, existingRecords.iterator());
     node.setLabelField(dynamicPointer(newRecords), existingRecords);
     if (!newRecords.equals(
         existingRecords)) { // One less dynamic record, mark that one as not in use
       for (DynamicRecord record : existingRecords) {
         if (!newRecords.contains(record)) {
           record.setInUse(false);
           record.setLength(0); // so that it will not be made heavy again...
         }
       }
     }
   }
   return existingRecords;
 }
Beispiel #4
0
 private void connect(NodeRecord node, RelationshipRecord rel) {
   if (node.getNextRel() != Record.NO_NEXT_RELATIONSHIP.intValue()) {
     RelationshipRecord nextRel = getRelationshipStore().getRecord(node.getNextRel());
     boolean changed = false;
     if (nextRel.getFirstNode() == node.getId()) {
       nextRel.setFirstPrevRel(rel.getId());
       changed = true;
     }
     if (nextRel.getSecondNode() == node.getId()) {
       nextRel.setSecondPrevRel(rel.getId());
       changed = true;
     }
     if (!changed) {
       throw new InvalidRecordException(node + " dont match " + nextRel);
     }
     getRelationshipStore().updateRecord(nextRel);
   }
 }
  @Test
  public void shouldNotReportMissingPropertyForDeletedNodeWithProperty() {
    // given
    PropertyRecord oldProperty = add(inUse(new PropertyRecord(10)));
    NodeRecord oldNode = add(inUse(new NodeRecord(20, false, 0, 0)));
    oldProperty.setNodeId(oldNode.getId());
    oldNode.setNextProp(oldProperty.getId());

    PropertyRecord newProperty = add(notInUse(new PropertyRecord(10)));
    NodeRecord newNode = add(notInUse(new NodeRecord(20, false, 0, 0)));
    newProperty.setNodeId(newNode.getId());
    newNode.setNextProp(newProperty.getId());

    // when
    ConsistencyReport.PropertyConsistencyReport report = checkChange(oldProperty, newProperty);

    // then
    verifyNoMoreInteractions(report);
  }
Beispiel #6
0
  private void connectRelationship(
      NodeRecord firstNode,
      NodeRecord secondNode,
      RelationshipRecord rel,
      RecordAccess<Long, RelationshipRecord, Void> relRecords,
      RecordAccess<Long, RelationshipGroupRecord, Integer> relGroupRecords) {
    // Assertion interpreted: if node is a normal node and we're trying to create a
    // relationship that we already have as first rel for that node --> error
    assert firstNode.getNextRel() != rel.getId() || firstNode.isDense();
    assert secondNode.getNextRel() != rel.getId() || secondNode.isDense();

    if (!firstNode.isDense()) {
      rel.setFirstNextRel(firstNode.getNextRel());
    }
    if (!secondNode.isDense()) {
      rel.setSecondNextRel(secondNode.getNextRel());
    }

    if (!firstNode.isDense()) {
      connect(firstNode, rel, relRecords);
    } else {
      connectRelationshipToDenseNode(firstNode, rel, relRecords, relGroupRecords);
    }

    if (!secondNode.isDense()) {
      if (firstNode.getId() != secondNode.getId()) {
        connect(secondNode, rel, relRecords);
      } else {
        rel.setFirstInFirstChain(true);
        rel.setSecondPrevRel(rel.getFirstPrevRel());
      }
    } else if (firstNode.getId() != secondNode.getId()) {
      connectRelationshipToDenseNode(secondNode, rel, relRecords, relGroupRecords);
    }

    if (!firstNode.isDense()) {
      firstNode.setNextRel(rel.getId());
    }
    if (!secondNode.isDense()) {
      secondNode.setNextRel(rel.getId());
    }
  }
 private void migrateNodes(NodeStore nodeStore, PropertyWriter propertyWriter)
     throws IOException {
   Iterable<NodeRecord> records = legacyStore.getNodeStoreReader().readNodeStore();
   // estimate total number of nodes using file size then calc number of dots or percentage
   // complete
   for (NodeRecord nodeRecord : records) {
     reportProgress(nodeRecord.getId());
     nodeStore.setHighId(nodeRecord.getId() + 1);
     if (nodeRecord.inUse()) {
       long startOfPropertyChain = nodeRecord.getNextProp();
       if (startOfPropertyChain != Record.NO_NEXT_RELATIONSHIP.intValue()) {
         long propertyRecordId = migrateProperties(startOfPropertyChain, propertyWriter);
         nodeRecord.setNextProp(propertyRecordId);
       }
       nodeStore.updateRecord(nodeRecord);
     } else {
       nodeStore.freeId(nodeRecord.getId());
     }
   }
   legacyStore.getNodeStoreReader().close();
 }
Beispiel #8
0
 @Override
 public Collection<DynamicRecord> add(long labelId, NodeStore nodeStore) {
   nodeStore.ensureHeavy(node, parseLabelsBody(labelField));
   Collection<DynamicRecord> existingRecords = node.getDynamicLabelRecords();
   long[] existingLabelIds = nodeStore.getDynamicLabelsArray(existingRecords);
   long[] newLabelIds = LabelIdArray.concatAndSort(existingLabelIds, labelId);
   Collection<DynamicRecord> changedDynamicRecords =
       nodeStore.allocateRecordsForDynamicLabels(
           node.getId(), newLabelIds, existingRecords.iterator());
   node.setLabelField(dynamicPointer(changedDynamicRecords), changedDynamicRecords);
   return changedDynamicRecords;
 }
Beispiel #9
0
 private void connectRelationshipToDenseNode(
     NodeRecord node,
     RelationshipRecord rel,
     RecordAccess<Long, RelationshipRecord, Void> relRecords,
     RecordAccess<Long, RelationshipGroupRecord, Integer> relGroupRecords) {
   RelationshipGroupRecord group =
       relGroupGetter
           .getOrCreateRelationshipGroup(node, rel.getType(), relGroupRecords)
           .forChangingData();
   RelIdArray.DirectionWrapper dir = DirectionIdentifier.wrapDirection(rel, node);
   long nextRel = dir.getNextRel(group);
   setCorrectNextRel(node, rel, nextRel);
   connect(node.getId(), nextRel, rel, relRecords);
   dir.setNextRel(group, rel.getId());
 }
Beispiel #10
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);
     }
   }
 }
Beispiel #11
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);
 }
Beispiel #12
0
 private void connect(
     NodeRecord node,
     RelationshipRecord rel,
     RecordAccess<Long, RelationshipRecord, Void> relRecords) {
   connect(node.getId(), node.getNextRel(), rel, relRecords);
 }
 public void updateFirstRelationships() {
   for (RecordProxy<Long, NodeRecord, Void> change : recordChangeSet.getNodeRecords().changes()) {
     NodeRecord record = change.forReadingLinkage();
     txState.setFirstIds(record.getId(), record.getNextRel(), record.getNextProp());
   }
 }
Beispiel #14
0
 public NodeCommand init(NodeRecord before, NodeRecord after) {
   setup(after.getId(), Mode.fromRecordState(after));
   this.before = before;
   this.after = after;
   return this;
 }