use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class PhysicalLogCommandReaderV3_0Test method readRelationshipGroupCommandWithSecondaryUnit.
@Test
public void readRelationshipGroupCommandWithSecondaryUnit() throws IOException {
// Given
InMemoryClosableChannel channel = new InMemoryClosableChannel();
RelationshipGroupRecord before = new RelationshipGroupRecord(42, 3);
RelationshipGroupRecord after = new RelationshipGroupRecord(42, 3, 4, 5, 6, 7, 8, true);
after.setRequiresSecondaryUnit(true);
after.setSecondaryUnitId(17);
after.setCreated();
new Command.RelationshipGroupCommand(before, after).serialize(channel);
// When
PhysicalLogCommandReaderV3_0 reader = new PhysicalLogCommandReaderV3_0();
Command command = reader.read(channel);
assertTrue(command instanceof Command.RelationshipGroupCommand);
Command.RelationshipGroupCommand relationshipGroupCommand = (Command.RelationshipGroupCommand) command;
// Then
assertEquals(before, relationshipGroupCommand.getBefore());
assertEquals(after, relationshipGroupCommand.getAfter());
verifySecondaryUnit(after, relationshipGroupCommand.getAfter());
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class NeoStoreTransactionApplierTest method shouldApplyRelationshipGroupCommandToTheStoreInRecovery.
@Test
public void shouldApplyRelationshipGroupCommandToTheStoreInRecovery() throws Exception {
// given
final BatchTransactionApplier applier = newApplier(true);
// when
final RelationshipGroupRecord before = new RelationshipGroupRecord(42, 1);
final RelationshipGroupRecord after = new RelationshipGroupRecord(42, 1, 2, 3, 4, 5, 6, true);
final Command command = new Command.RelationshipGroupCommand(before, after);
boolean result = apply(applier, command::handle, transactionToApply);
// then
assertFalse(result);
verify(relationshipGroupStore, times(1)).setHighestPossibleIdInUse(after.getId());
verify(relationshipGroupStore, times(1)).updateRecord(after);
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class RelationshipGroupDefragmenter method run.
public void run(long memoryWeCanHoldForCertain, BatchingNeoStores neoStore, long highNodeId) {
try (RelationshipGroupCache groupCache = new RelationshipGroupCache(AUTO, memoryWeCanHoldForCertain, highNodeId)) {
// Read from the temporary relationship group store...
RecordStore<RelationshipGroupRecord> fromStore = neoStore.getTemporaryRelationshipGroupStore();
// and write into the main relationship group store
RecordStore<RelationshipGroupRecord> toStore = neoStore.getRelationshipGroupStore();
// Count all nodes, how many groups each node has each
Configuration groupConfig = withBatchSize(config, neoStore.getRelationshipGroupStore().getRecordsPerPage());
executeStage(new CountGroupsStage(groupConfig, fromStore, groupCache));
long fromNodeId = 0;
long toNodeId = 0;
while (fromNodeId < highNodeId) {
// See how many nodes' groups we can fit into the cache this iteration of the loop.
// Groups that doesn't fit in this round will be included in consecutive rounds.
toNodeId = groupCache.prepare(fromNodeId);
monitor.defragmentingNodeRange(fromNodeId, toNodeId);
// Cache those groups
executeStage(new ScanAndCacheGroupsStage(groupConfig, fromStore, groupCache));
// And write them in sequential order in the store
executeStage(new WriteGroupsStage(groupConfig, groupCache, toStore));
// Make adjustments for the next iteration
fromNodeId = toNodeId;
}
// Now update nodes to point to the new groups
ByteArray groupCountCache = groupCache.getGroupCountCache();
groupCountCache.clear();
Configuration nodeConfig = withBatchSize(config, neoStore.getNodeStore().getRecordsPerPage());
executeStage(new NodeFirstGroupStage(nodeConfig, toStore, neoStore.getNodeStore(), groupCountCache));
}
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class EncodeGroupsStep method process.
@Override
protected void process(RelationshipGroupRecord[] batch, BatchSender sender) throws Throwable {
int groupStartIndex = 0;
for (int i = 0; i < batch.length; i++) {
RelationshipGroupRecord group = batch[i];
// The iterator over the groups will not produce real next pointers, they are instead
// a count meaning how many groups come after it. This encoder will set the real group ids.
long count = group.getNext();
boolean lastInChain = count == 0;
group.setId(nextId == -1 ? nextId = store.nextId() : nextId);
if (!lastInChain) {
group.setNext(nextId = store.nextId());
} else {
group.setNext(nextId = -1);
// secondary units ends up very close by.
for (int j = groupStartIndex; j <= i; j++) {
store.prepareForCommit(batch[j]);
}
groupStartIndex = i + 1;
}
}
assert groupStartIndex == batch.length;
sender.send(batch);
}
use of org.neo4j.kernel.impl.store.record.RelationshipGroupRecord in project neo4j by neo4j.
the class NodeFirstRelationshipProcessor method visit.
@Override
public long visit(long nodeId, long next, long out, long in, long loop) {
// Here we'll use the already generated id (below) from the previous visit, if that so happened
long id = relGroupStore.nextId();
RelationshipGroupRecord groupRecord = new RelationshipGroupRecord(id);
groupRecord.setType(relationshipType);
groupRecord.setInUse(true);
groupRecord.setFirstOut(out);
groupRecord.setFirstIn(in);
groupRecord.setFirstLoop(loop);
groupRecord.setOwningNode(nodeId);
groupRecord.setNext(next);
relGroupStore.prepareForCommit(groupRecord);
relGroupStore.updateRecord(groupRecord);
return id;
}
Aggregations