use of org.neo4j.kernel.impl.store.RecordCursors in project neo4j by neo4j.
the class StorePropertyCursorTest method newStorePropertyCursor.
private static StorePropertyCursor newStorePropertyCursor(PropertyStore propertyStore, Consumer<StorePropertyCursor> cache) {
RecordCursor<PropertyRecord> propertyRecordCursor = propertyStore.newRecordCursor(propertyStore.newRecord());
propertyRecordCursor.acquire(0, NORMAL);
DynamicStringStore stringStore = propertyStore.getStringStore();
RecordCursor<DynamicRecord> dynamicStringCursor = stringStore.newRecordCursor(stringStore.nextRecord());
dynamicStringCursor.acquire(0, NORMAL);
DynamicArrayStore arrayStore = propertyStore.getArrayStore();
RecordCursor<DynamicRecord> dynamicArrayCursor = arrayStore.newRecordCursor(arrayStore.nextRecord());
dynamicArrayCursor.acquire(0, NORMAL);
RecordCursors cursors = mock(RecordCursors.class);
when(cursors.property()).thenReturn(propertyRecordCursor);
when(cursors.propertyString()).thenReturn(dynamicStringCursor);
when(cursors.propertyArray()).thenReturn(dynamicArrayCursor);
return new StorePropertyCursor(cursors, cache);
}
use of org.neo4j.kernel.impl.store.RecordCursors in project neo4j by neo4j.
the class StoreIteratorRelationshipCursorTest method newRecordCursorsWithMockedNeoStores.
private static RecordCursors newRecordCursorsWithMockedNeoStores(RelationshipStore relationshipStore) {
NeoStores neoStores = mock(NeoStores.class);
NodeStore nodeStore = newStoreMockWithRecordCursor(NodeStore.class);
RelationshipGroupStore relGroupStore = newStoreMockWithRecordCursor(RelationshipGroupStore.class);
PropertyStore propertyStore = newStoreMockWithRecordCursor(PropertyStore.class);
DynamicStringStore dynamicStringStore = newStoreMockWithRecordCursor(DynamicStringStore.class);
DynamicArrayStore dynamicArrayStore = newStoreMockWithRecordCursor(DynamicArrayStore.class);
DynamicArrayStore dynamicLabelStore = newStoreMockWithRecordCursor(DynamicArrayStore.class);
when(neoStores.getNodeStore()).thenReturn(nodeStore);
when(neoStores.getRelationshipStore()).thenReturn(relationshipStore);
when(neoStores.getRelationshipGroupStore()).thenReturn(relGroupStore);
when(neoStores.getPropertyStore()).thenReturn(propertyStore);
when(propertyStore.getStringStore()).thenReturn(dynamicStringStore);
when(propertyStore.getArrayStore()).thenReturn(dynamicArrayStore);
when(nodeStore.getDynamicLabelStore()).thenReturn(dynamicLabelStore);
return new RecordCursors(neoStores);
}
use of org.neo4j.kernel.impl.store.RecordCursors in project neo4j by neo4j.
the class StoreMigrator method propertyDecorator.
private <ENTITY extends InputEntity, RECORD extends PrimitiveRecord> BiConsumer<ENTITY, RECORD> propertyDecorator(boolean requiresPropertyMigration, RecordCursors cursors) {
if (!requiresPropertyMigration) {
return (a, b) -> {
};
}
final StorePropertyCursor cursor = new StorePropertyCursor(cursors, ignored -> {
});
final List<Object> scratch = new ArrayList<>();
return (ENTITY entity, RECORD record) -> {
cursor.init(record.getNextProp(), LockService.NO_LOCK);
scratch.clear();
while (cursor.next()) {
// add key as int here as to have the importer use the token id
scratch.add(cursor.propertyKeyId());
scratch.add(cursor.value());
}
entity.setProperties(scratch.isEmpty() ? InputEntity.NO_PROPERTIES : scratch.toArray());
cursor.close();
};
}
use of org.neo4j.kernel.impl.store.RecordCursors in project neo4j by neo4j.
the class StoreMigrator method migrateWithBatchImporter.
private void migrateWithBatchImporter(File storeDir, File migrationDir, long lastTxId, long lastTxChecksum, long lastTxLogVersion, long lastTxLogByteOffset, MigrationProgressMonitor.Section progressMonitor, RecordFormats oldFormat, RecordFormats newFormat) throws IOException {
prepareBatchImportMigration(storeDir, migrationDir, oldFormat, newFormat);
boolean requiresDynamicStoreMigration = !newFormat.dynamic().equals(oldFormat.dynamic());
boolean requiresPropertyMigration = !newFormat.property().equals(oldFormat.property()) || requiresDynamicStoreMigration;
File badFile = new File(storeDir, Configuration.BAD_FILE_NAME);
try (NeoStores legacyStore = instantiateLegacyStore(oldFormat, storeDir);
RecordCursors nodeInputCursors = new RecordCursors(legacyStore);
RecordCursors relationshipInputCursors = new RecordCursors(legacyStore);
OutputStream badOutput = new BufferedOutputStream(new FileOutputStream(badFile, false))) {
Configuration importConfig = new Configuration.Overridden(config);
AdditionalInitialIds additionalInitialIds = readAdditionalIds(lastTxId, lastTxChecksum, lastTxLogVersion, lastTxLogByteOffset);
// We have to make sure to keep the token ids if we're migrating properties/labels
BatchImporter importer = new ParallelBatchImporter(migrationDir.getAbsoluteFile(), fileSystem, pageCache, importConfig, logService, withDynamicProcessorAssignment(migrationBatchImporterMonitor(legacyStore, progressMonitor, importConfig), importConfig), additionalInitialIds, config, newFormat);
InputIterable<InputNode> nodes = legacyNodesAsInput(legacyStore, requiresPropertyMigration, nodeInputCursors);
InputIterable<InputRelationship> relationships = legacyRelationshipsAsInput(legacyStore, requiresPropertyMigration, relationshipInputCursors);
importer.doImport(Inputs.input(nodes, relationships, IdMappers.actual(), IdGenerators.fromInput(), Collectors.badCollector(badOutput, 0)));
// During migration the batch importer doesn't necessarily writes all entities, depending on
// which stores needs migration. Node, relationship, relationship group stores are always written
// anyways and cannot be avoided with the importer, but delete the store files that weren't written
// (left empty) so that we don't overwrite those in the real store directory later.
Collection<StoreFile> storesToDeleteFromMigratedDirectory = new ArrayList<>();
storesToDeleteFromMigratedDirectory.add(StoreFile.NEO_STORE);
if (!requiresPropertyMigration) {
// We didn't migrate properties, so the property stores in the migrated store are just empty/bogus
storesToDeleteFromMigratedDirectory.addAll(asList(StoreFile.PROPERTY_STORE, StoreFile.PROPERTY_STRING_STORE, StoreFile.PROPERTY_ARRAY_STORE));
}
if (!requiresDynamicStoreMigration) {
// We didn't migrate labels (dynamic node labels) or any other dynamic store
storesToDeleteFromMigratedDirectory.addAll(asList(StoreFile.NODE_LABEL_STORE, StoreFile.LABEL_TOKEN_STORE, StoreFile.LABEL_TOKEN_NAMES_STORE, StoreFile.RELATIONSHIP_TYPE_TOKEN_STORE, StoreFile.RELATIONSHIP_TYPE_TOKEN_NAMES_STORE, StoreFile.PROPERTY_KEY_TOKEN_STORE, StoreFile.PROPERTY_KEY_TOKEN_NAMES_STORE, StoreFile.SCHEMA_STORE));
}
StoreFile.fileOperation(DELETE, fileSystem, migrationDir, null, storesToDeleteFromMigratedDirectory, true, null, StoreFileType.values());
// When migrating on a block device there might be some files only accessible via the page cache.
try {
Predicate<FileHandle> fileHandlePredicate = fileHandle -> storesToDeleteFromMigratedDirectory.stream().anyMatch(storeFile -> storeFile.fileName(StoreFileType.STORE).equals(fileHandle.getFile().getName()));
pageCache.streamFilesRecursive(migrationDir).filter(fileHandlePredicate).forEach(FileHandle.HANDLE_DELETE);
} catch (NoSuchFileException e) {
// This means that we had no files only present in the page cache, this is fine.
}
}
}
use of org.neo4j.kernel.impl.store.RecordCursors in project neo4j by neo4j.
the class StorageLayerRelTypesAndDegreeTest method newCursor.
@SuppressWarnings("unchecked")
private StoreSingleNodeCursor newCursor(long nodeId) {
StoreSingleNodeCursor cursor = new StoreSingleNodeCursor(new NodeRecord(-1), mock(Consumer.class), new RecordCursors(resolveNeoStores()), NO_LOCK_SERVICE);
cursor.init(nodeId);
assertTrue(cursor.next());
return cursor;
}
Aggregations