@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; }
@Override public long[] getIfLoaded() { if (node.isLight()) { return null; } for (DynamicRecord dynamic : node.getDynamicLabelRecords()) { if (dynamic.isLight()) { return null; } } return stripNodeId( (long[]) getRightArray(readFullByteArrayFromHeavyRecords(node.getDynamicLabelRecords(), ARRAY))); }
@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; }
@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; }
@Override public long[] get(NodeStore nodeStore) { nodeStore.ensureHeavy(node, getFirstDynamicRecordId()); return nodeStore.getDynamicLabelsArray(node.getDynamicLabelRecords()); }