use of org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator in project neo4j by neo4j.
the class NodeRecordCheckTest method shouldReportDynamicLabelsNotInUse.
@Test
public void shouldReportDynamicLabelsNotInUse() throws Exception {
// given
long[] labelIds = createLabels(100);
LabelTokenRecord labelRecordNotInUse = notInUse(new LabelTokenRecord(labelIds.length));
add(labelRecordNotInUse);
NodeRecord node = inUse(new NodeRecord(42, false, NONE, NONE));
add(node);
DynamicRecord labelsRecord1 = inUse(array(new DynamicRecord(1)));
DynamicRecord labelsRecord2 = inUse(array(new DynamicRecord(2)));
Collection<DynamicRecord> labelRecords = asList(labelsRecord1, labelsRecord2);
labelIds[12] = labelIds.length;
DynamicArrayStore.allocateFromNumbers(new ArrayList<>(), labelIds, new ReusableRecordsAllocator(52, labelRecords));
assertDynamicRecordChain(labelsRecord1, labelsRecord2);
node.setLabelField(DynamicNodeLabels.dynamicPointer(labelRecords), labelRecords);
addNodeDynamicLabels(labelsRecord1);
addNodeDynamicLabels(labelsRecord2);
// when
ConsistencyReport.NodeConsistencyReport report = check(node);
// then
verify(report).labelNotInUse(labelRecordNotInUse);
}
use of org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportNodeDynamicLabelContainingDuplicateLabelAsNodeInconsistency.
@Test
public void shouldReportNodeDynamicLabelContainingDuplicateLabelAsNodeInconsistency() throws Exception {
// given
fixture.apply(new GraphStoreFixture.Transaction() {
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
tx.nodeLabel(42, "Label");
NodeRecord nodeRecord = new NodeRecord(next.node(), false, -1, -1);
DynamicRecord record = inUse(new DynamicRecord(next.nodeLabel()));
Collection<DynamicRecord> newRecords = new ArrayList<>();
allocateFromNumbers(newRecords, prependNodeId(nodeRecord.getId(), new long[] { 42L, 42L }), new ReusableRecordsAllocator(60, record));
nodeRecord.setLabelField(dynamicPointer(newRecords), newRecords);
tx.create(nodeRecord);
}
});
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.NODE, 1).verify(RecordType.COUNTS, 1).andThatsAllFolks();
}
use of org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator in project neo4j by neo4j.
the class FullCheckIntegrationTest method chainOfDynamicRecordsWithLabelsForANode.
private Pair<List<DynamicRecord>, List<Integer>> chainOfDynamicRecordsWithLabelsForANode(int labelCount) throws TransactionFailureException {
// allocate enough labels to need three records
final long[] labels = new long[labelCount + 1];
final List<Integer> createdLabels = new ArrayList<>();
try (Applier applier = fixture.createApplier()) {
for (int i = 1; /*leave space for the node id*/
i < labels.length; i++) {
final int offset = i;
applier.apply(new GraphStoreFixture.Transaction() {
// Neo4j can create no more than one label per transaction...
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
Integer label = next.label();
tx.nodeLabel((int) (labels[offset] = label), "label:" + offset);
createdLabels.add(label);
}
});
}
}
final List<DynamicRecord> chain = new ArrayList<>();
fixture.apply(new GraphStoreFixture.Transaction() {
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
NodeRecord nodeRecord = new NodeRecord(next.node(), false, -1, -1);
DynamicRecord record1 = inUse(new DynamicRecord(next.nodeLabel()));
DynamicRecord record2 = inUse(new DynamicRecord(next.nodeLabel()));
DynamicRecord record3 = inUse(new DynamicRecord(next.nodeLabel()));
// the first id should not be a label id, but the id of the node
labels[0] = nodeRecord.getId();
ReusableRecordsAllocator allocator = new ReusableRecordsAllocator(60, record1, record2, record3);
allocateFromNumbers(chain, labels, allocator);
nodeRecord.setLabelField(dynamicPointer(chain), chain);
tx.create(nodeRecord);
}
});
return Pair.of(chain, createdLabels);
}
use of org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator in project neo4j by neo4j.
the class NodeInUseWithCorrectLabelsCheckTest method withDynamicLabels.
private NodeRecord withDynamicLabels(RecordAccessStub recordAccess, NodeRecord nodeRecord, long... labelIds) {
List<DynamicRecord> preAllocatedRecords = new ArrayList<>();
for (int i = 0; i < 10; i++) {
preAllocatedRecords.add(inUse(new DynamicRecord(i)));
}
Collection<DynamicRecord> dynamicRecords = new ArrayList<>();
DynamicArrayStore.allocateFromNumbers(dynamicRecords, prependNodeId(nodeRecord.getId(), labelIds), new ReusableRecordsAllocator(4, preAllocatedRecords));
for (DynamicRecord dynamicRecord : dynamicRecords) {
recordAccess.addNodeDynamicLabels(dynamicRecord);
}
nodeRecord.setLabelField(dynamicPointer(dynamicRecords), dynamicRecords);
return nodeRecord;
}
use of org.neo4j.kernel.impl.store.allocator.ReusableRecordsAllocator in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportNodeDynamicLabelContainingUnknownLabelAsNodeInconsistency.
@Test
public void shouldReportNodeDynamicLabelContainingUnknownLabelAsNodeInconsistency() throws Exception {
// given
fixture.apply(new GraphStoreFixture.Transaction() {
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
NodeRecord nodeRecord = new NodeRecord(next.node(), false, -1, -1);
DynamicRecord record = inUse(new DynamicRecord(next.nodeLabel()));
Collection<DynamicRecord> newRecords = new ArrayList<>();
allocateFromNumbers(newRecords, prependNodeId(nodeRecord.getId(), new long[] { 42L }), new ReusableRecordsAllocator(60, record));
nodeRecord.setLabelField(dynamicPointer(newRecords), newRecords);
tx.create(nodeRecord);
}
});
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.NODE, 1).andThatsAllFolks();
}
Aggregations