use of org.neo4j.unsafe.impl.batchimport.cache.ByteArray 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));
}
}
Aggregations