use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class RsdrMain method getLogCursor.
private static IOCursor<LogEntry> getLogCursor(FileSystemAbstraction fileSystem, String fname, NeoStores neoStores) throws IOException {
File file = new File(neoStores.getStoreDir(), fname);
StoreChannel fileChannel = fileSystem.open(file, "r");
LogHeader logHeader = readLogHeader(ByteBuffer.allocateDirect(LOG_HEADER_SIZE), fileChannel, false, file);
console.printf("Logical log version: %s with prev committed tx[%s]%n", logHeader.logVersion, logHeader.lastCommittedTxId);
PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(fileChannel, logHeader.logVersion, logHeader.logFormatVersion);
ReadableLogChannel logChannel = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS);
LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
return new LogEntryCursor(logEntryReader, logChannel);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class BackupServiceIT method checkPreviousCommittedTxIdFromLog.
private void checkPreviousCommittedTxIdFromLog(long logVersion, long txId) throws IOException {
// Assert header of specified log version containing correct txId
PhysicalLogFiles logFiles = new PhysicalLogFiles(backupDir, fileSystem);
LogHeader logHeader = LogHeaderReader.readLogHeader(fileSystem, logFiles.getLogFileForVersion(logVersion));
assertEquals(txId, logHeader.lastCommittedTxId);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class PhysicalLogFile method createLogChannelForVersion.
/**
* Creates a new channel for the specified version, creating the backing file if it doesn't already exist.
* If the file exists then the header is verified to be of correct version. Having an existing file there
* could happen after a previous crash in the middle of rotation, where the new file was created,
* but the incremented log version changed hadn't made it to persistent storage.
*
* @param forVersion log version for the file/channel to create.
* @return {@link PhysicalLogVersionedStoreChannel} for newly created/opened log file.
* @throws IOException if there's any I/O related error.
*/
private PhysicalLogVersionedStoreChannel createLogChannelForVersion(long forVersion) throws IOException {
File toOpen = logFiles.getLogFileForVersion(forVersion);
StoreChannel storeChannel = fileSystem.open(toOpen, "rw");
LogHeader header = readLogHeader(headerBuffer, storeChannel, false, toOpen);
if (header == null) {
// Either the header is not there in full or the file was new. Don't care
long lastTxId = lastCommittedId.get();
writeLogHeader(headerBuffer, forVersion, lastTxId);
logHeaderCache.putHeader(forVersion, lastTxId);
storeChannel.writeAll(headerBuffer);
monitor.opened(toOpen, forVersion, lastTxId, true);
}
byte formatVersion = header == null ? CURRENT_LOG_VERSION : header.logFormatVersion;
return new PhysicalLogVersionedStoreChannel(storeChannel, forVersion, formatVersion);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class PhysicalLogFile method openForVersion.
public static PhysicalLogVersionedStoreChannel openForVersion(PhysicalLogFiles logFiles, FileSystemAbstraction fileSystem, long version, boolean write) throws IOException {
final File fileToOpen = logFiles.getLogFileForVersion(version);
if (!fileSystem.fileExists(fileToOpen)) {
throw new FileNotFoundException(String.format("File does not exist [%s]", fileToOpen.getCanonicalPath()));
}
StoreChannel rawChannel = null;
try {
rawChannel = fileSystem.open(fileToOpen, write ? "rw" : "r");
ByteBuffer buffer = ByteBuffer.allocate(LOG_HEADER_SIZE);
LogHeader header = readLogHeader(buffer, rawChannel, true, fileToOpen);
assert header != null && header.logVersion == version;
PhysicalLogVersionedStoreChannel result = new PhysicalLogVersionedStoreChannel(rawChannel, version, header.logFormatVersion);
return result;
} catch (FileNotFoundException cause) {
throw Exceptions.withCause(new FileNotFoundException(String.format("File could not be opened [%s]", fileToOpen.getCanonicalPath())), cause);
} catch (Throwable unexpectedError) {
if (rawChannel != null) {
// If we managed to open the file before failing, then close the channel
try {
rawChannel.close();
} catch (IOException e) {
unexpectedError.addSuppressed(e);
}
}
throw unexpectedError;
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogHeader in project neo4j by neo4j.
the class LogTestUtils method openLogEntryCursor.
private static LogEntryCursor openLogEntryCursor(FileSystemAbstraction fs, File firstFile, LogVersionBridge versionBridge) {
StoreChannel channel = null;
try {
channel = fs.open(firstFile, "r");
ByteBuffer buffer = ByteBuffer.allocate(LogHeader.LOG_HEADER_SIZE);
LogHeader header = LogHeaderReader.readLogHeader(buffer, channel, true, firstFile);
PhysicalLogVersionedStoreChannel logVersionedChannel = new PhysicalLogVersionedStoreChannel(channel, header.logVersion, header.logFormatVersion);
ReadableLogChannel logChannel = new ReadAheadLogChannel(logVersionedChannel, versionBridge, ReadAheadLogChannel.DEFAULT_READ_AHEAD_SIZE);
return new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel);
} catch (Throwable t) {
if (channel != null) {
try {
channel.close();
} catch (IOException e) {
t.addSuppressed(e);
}
}
throw new RuntimeException(t);
}
}
Aggregations