use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.
the class StoreMigratorTest method extractTransactionalInformationFromLogs.
private void extractTransactionalInformationFromLogs(Path customLogsLocation) throws IOException {
Config config = Config.defaults(transaction_logs_root_path, customLogsLocation);
LogService logService = new SimpleLogService(NullLogProvider.getInstance(), NullLogProvider.getInstance());
DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(databaseLayout).setConfig(transaction_logs_root_path, customLogsLocation).build();
GraphDatabaseAPI database = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
StorageEngineFactory storageEngineFactory = database.getDependencyResolver().resolveDependency(StorageEngineFactory.class);
for (int i = 0; i < 10; i++) {
try (Transaction transaction = database.beginTx()) {
transaction.createNode();
transaction.commit();
}
}
DatabaseLayout databaseLayout = database.databaseLayout();
Path neoStore = databaseLayout.metadataStore();
managementService.shutdown();
MetaDataStore.setRecord(pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, MetaDataRecordFormat.FIELD_NOT_PRESENT, databaseLayout.getDatabaseName(), NULL);
RecordStorageMigrator migrator = new RecordStorageMigrator(fileSystem, pageCache, config, logService, jobScheduler, PageCacheTracer.NULL, batchImporterFactory, INSTANCE);
LogPosition logPosition = migrator.extractTransactionLogPosition(neoStore, databaseLayout, 100, NULL);
LogFiles logFiles = LogFilesBuilder.activeFilesBuilder(databaseLayout, fileSystem, pageCache).withConfig(config).withCommandReaderFactory(storageEngineFactory.commandReaderFactory()).build();
assertEquals(0, logPosition.getLogVersion());
assertEquals(Files.size(logFiles.getLogFile().getHighestLogFile()), logPosition.getByteOffset());
}
use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.
the class StoreMigratorTest method shouldNotMigrateFilesForVersionsWithSameCapability.
@Test
void shouldNotMigrateFilesForVersionsWithSameCapability() throws Exception {
// Prepare migrator and file
RecordStorageMigrator migrator = newStoreMigrator();
DatabaseLayout dbLayout = databaseLayout;
Path neoStore = dbLayout.metadataStore();
Files.createFile(neoStore);
// Monitor what happens
MyProgressReporter progressReporter = new MyProgressReporter();
// Migrate with two storeversions that have the same FORMAT capabilities
DatabaseLayout migrationLayout = neo4jLayout.databaseLayout("migrationDir");
fileSystem.mkdirs(migrationLayout.databaseDirectory());
migrator.migrate(dbLayout, migrationLayout, progressReporter, StandardV4_0.STORE_VERSION, StandardV4_0.STORE_VERSION, IndexImporterFactory.EMPTY);
// Should not have started any migration
assertFalse(progressReporter.started);
}
use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.
the class StoreUpgraderTest method failToMoveTransactionLogsIfTheyAlreadyExist.
@ParameterizedTest
@MethodSource("versions")
void failToMoveTransactionLogsIfTheyAlreadyExist(RecordFormats formats) throws IOException {
init(formats);
Path txRoot = testDirectory.directory("customTxRoot");
AssertableLogProvider logProvider = new AssertableLogProvider();
StoreVersionCheck check = getVersionCheck(pageCache);
Config config = Config.newBuilder().fromConfig(allowMigrateConfig).set(neo4j_home, testDirectory.homePath()).set(GraphDatabaseSettings.transaction_logs_root_path, txRoot.toAbsolutePath()).set(default_database, databaseLayout.getDatabaseName()).build();
DatabaseLayout migrationLayout = DatabaseLayout.of(config);
Path databaseTransactionLogsHome = txRoot.resolve(migrationLayout.getDatabaseName());
fileSystem.mkdir(databaseTransactionLogsHome);
createDummyTxLogFiles(databaseTransactionLogsHome);
assertThrows(StoreUpgrader.TransactionLogsRelocationException.class, () -> newUpgrader(check, pageCache, config, new VisibleMigrationProgressMonitor(logProvider.getLog("test"))).migrateIfNeeded(migrationLayout, false));
}
use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.
the class StoreUpgraderTest method upgradeMoveTransactionLogs.
@ParameterizedTest
@MethodSource("versions")
void upgradeMoveTransactionLogs(RecordFormats formats) throws IOException {
init(formats);
Path txRoot = testDirectory.directory("customTxRoot");
AssertableLogProvider logProvider = new AssertableLogProvider();
StoreVersionCheck check = getVersionCheck(pageCache);
Config config = Config.newBuilder().fromConfig(allowMigrateConfig).set(neo4j_home, testDirectory.homePath()).set(GraphDatabaseSettings.transaction_logs_root_path, txRoot.toAbsolutePath()).set(default_database, databaseLayout.getDatabaseName()).build();
DatabaseLayout migrationLayout = DatabaseLayout.of(config);
newUpgrader(check, pageCache, config, new VisibleMigrationProgressMonitor(logProvider.getLog("test"))).migrateIfNeeded(migrationLayout, false);
assertThat(logProvider).containsMessages("Starting transaction logs migration.", "Transaction logs migration completed.");
assertThat(getLogFiles(migrationLayout.databaseDirectory())).isEmpty();
Path databaseTransactionLogsHome = txRoot.resolve(migrationLayout.getDatabaseName());
assertTrue(fileSystem.fileExists(databaseTransactionLogsHome));
Set<String> logFileNames = getLogFileNames(databaseTransactionLogsHome);
assertThat(logFileNames).isNotEmpty();
assertThat(logFileNames).containsAll(getLogFileNames(prepareDatabaseDirectory));
}
use of org.neo4j.io.layout.DatabaseLayout in project neo4j by neo4j.
the class LogsUpgrader method assertCleanlyShutDown.
public void assertCleanlyShutDown(DatabaseLayout layout) {
Throwable suppressibleException = null;
try {
// we should not use provided database layout here since transaction log location is different compare to previous versions
// and that's why we need to use custom transaction logs locator and database layout
DatabaseLayout oldDatabaseLayout = buildLegacyLogsLayout(layout);
LogFiles logFiles = buildLogFiles(oldDatabaseLayout);
LogTailInformation tail = logFiles.getTailInformation();
if (!tail.isRecoveryRequired()) {
// All good
return;
}
if (tail.logsMissing()) {
// There are no log files in the legacy logs location.
// Either log files are missing entirely, or they are already in their correct place.
logFiles = buildLogFiles(layout);
tail = logFiles.getTailInformation();
if (!tail.isRecoveryRequired()) {
// Log file is already in its new location, and looks good.
return;
}
if (tail.logsMissing() && !config.get(fail_on_missing_files)) {
// We don't have any log files, but we were told to ignore this.
return;
}
}
} catch (Throwable throwable) {
// ignore exception and throw db not cleanly shutdown
suppressibleException = throwable;
}
StoreUpgrader.DatabaseNotCleanlyShutDownException exception = new StoreUpgrader.DatabaseNotCleanlyShutDownException();
if (suppressibleException != null) {
exception.addSuppressed(suppressibleException);
}
throw exception;
}
Aggregations