use of org.neo4j.kernel.impl.transaction.log.files.LogFiles 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.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class VersionAwareLogEntryReaderIT method correctlyResetPositionOfObservedZeroWhenChannelSwitchOnExactlyCheckedByte.
@Test
void correctlyResetPositionOfObservedZeroWhenChannelSwitchOnExactlyCheckedByte() throws IOException {
LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fs).withLogEntryReader(entryReader).withLogVersionRepository(new SimpleLogVersionRepository()).withTransactionIdStore(new SimpleTransactionIdStore()).withStoreId(StoreId.UNKNOWN).withKernelVersionProvider(() -> KernelVersion.V4_0).build();
try (Lifespan lifespan = new Lifespan(logFiles)) {
LogPositionMarker positionMarker = new LogPositionMarker();
LogFile logFile = logFiles.getLogFile();
long initialPosition = getLastReadablePosition(logFiles);
long checkpointsEndDataOffset = DEFAULT_READ_AHEAD_SIZE + initialPosition;
TransactionLogWriter logWriter = logFile.getTransactionLogWriter();
do {
logWriter.legacyCheckPoint(new LogPosition(4, 5));
logWriter.getCurrentPosition(positionMarker);
} while (positionMarker.getByteOffset() <= checkpointsEndDataOffset);
logFile.flush();
logFiles.getLogFile().rotate();
fs.truncate(logFiles.getLogFile().getLogFileForVersion(0), checkpointsEndDataOffset);
try (StoreChannel storeChannel = fs.write(logFiles.getLogFile().getLogFileForVersion(1))) {
storeChannel.position(CURRENT_FORMAT_LOG_HEADER_SIZE);
storeChannel.writeAll(ByteBuffer.wrap(new byte[] { 0 }));
}
try (ReadableLogChannel logChannel = logFiles.getLogFile().getReader(new LogPosition(0, initialPosition))) {
LogEntry logEntry = entryReader.readLogEntry(logChannel);
// we reading expected checkpoint records
assertThat(logEntry).isInstanceOf(LogEntryInlinedCheckPoint.class);
LogEntryInlinedCheckPoint checkPoint = (LogEntryInlinedCheckPoint) logEntry;
LogPosition logPosition = checkPoint.getLogPosition();
assertEquals(4, logPosition.getLogVersion());
assertEquals(5, logPosition.getByteOffset());
// set position to the end of the buffer to cause channel switch on next byte read
((PositionableChannel) logChannel).setCurrentPosition(checkpointsEndDataOffset);
while (entryReader.readLogEntry(logChannel) != null) {
// read to the end
}
// channel should be switched now and position should be just after the header
LogPosition position = entryReader.lastPosition();
assertEquals(CURRENT_FORMAT_LOG_HEADER_SIZE, position.getByteOffset());
assertEquals(1, position.getLogVersion());
}
}
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class CheckPointerIntegrationTest method checkPointInTxLog.
private static List<CheckpointInfo> checkPointInTxLog(GraphDatabaseService db) throws IOException {
DependencyResolver dependencyResolver = ((GraphDatabaseAPI) db).getDependencyResolver();
LogFiles logFiles = dependencyResolver.resolveDependency(LogFiles.class);
return logFiles.getCheckpointFile().reachableCheckpoints();
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFiles in project neo4j by neo4j.
the class StoreUpgraderTest method removeCheckPointFromTxLog.
public static void removeCheckPointFromTxLog(FileSystemAbstraction fileSystem, Path databaseDirectory) throws IOException {
LogFiles logFiles = LogFilesBuilder.logFilesBasedOnlyBuilder(databaseDirectory, fileSystem).withCommandReaderFactory(RecordStorageCommandReaderFactory.INSTANCE).build();
LogTailInformation logTailInformation = logFiles.getTailInformation();
if (logTailInformation.commitsAfterLastCheckpoint()) {
// done already
return;
}
// let's assume there is at least a checkpoint
assertNotNull(logTailInformation.lastCheckPoint);
LogPosition logPosition = logTailInformation.lastCheckPoint.getTransactionLogPosition();
Path logFile = logFiles.getLogFile().getLogFileForVersion(logPosition.getLogVersion());
long byteOffset = logPosition.getByteOffset();
fileSystem.truncate(logFile, byteOffset);
}
use of org.neo4j.kernel.impl.transaction.log.files.LogFiles 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