use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class CheckTxLogs method validateCheckPoints.
boolean validateCheckPoints(PhysicalLogFiles logFiles, InconsistenciesHandler handler) throws IOException {
final long lowestLogVersion = logFiles.getLowestLogVersion();
final long highestLogVersion = logFiles.getHighestLogVersion();
boolean success = true;
try (PrimitiveLongLongMap logFileSizes = Primitive.offHeapLongLongMap()) {
for (long i = lowestLogVersion; i <= highestLogVersion; i++) {
logFileSizes.put(i, fs.getFileSize(logFiles.getLogFileForVersion(i)));
}
LogEntryCursor logEntryCursor = LogTestUtils.openLogs(fs, logFiles);
while (logEntryCursor.next()) {
LogEntry logEntry = logEntryCursor.get();
if (logEntry instanceof CheckPoint) {
LogPosition logPosition = logEntry.<CheckPoint>as().getLogPosition();
// if the file has been pruned we cannot validate the check point
if (logPosition.getLogVersion() >= lowestLogVersion) {
long size = logFileSizes.get(logPosition.getLogVersion());
if (logPosition.getByteOffset() < 0 || size < 0 || logPosition.getByteOffset() > size) {
long currentLogVersion = logEntryCursor.getCurrentLogVersion();
handler.reportInconsistentCheckPoint(currentLogVersion, logPosition, size);
success = false;
}
}
}
}
}
return success;
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class IndexCreationTest method verifyThatIndexCreationTransactionIsTheFirstOne.
private void verifyThatIndexCreationTransactionIsTheFirstOne() throws Exception {
PhysicalLogFile pLogFile = db.getDependencyResolver().resolveDependency(PhysicalLogFile.class);
long version = db.getDependencyResolver().resolveDependency(LogVersionRepository.class).getCurrentLogVersion();
db.getDependencyResolver().resolveDependency(LogRotation.class).rotateLogFile();
db.getDependencyResolver().resolveDependency(CheckPointer.class).forceCheckPoint(new SimpleTriggerInfo("test"));
ReadableLogChannel logChannel = pLogFile.getReader(LogPosition.start(version));
final AtomicBoolean success = new AtomicBoolean(false);
try (IOCursor<LogEntry> cursor = new LogEntryCursor(new VersionAwareLogEntryReader<>(), logChannel)) {
List<StorageCommand> commandsInFirstEntry = new ArrayList<>();
boolean startFound = false;
while (cursor.next()) {
LogEntry entry = cursor.get();
if (entry instanceof LogEntryStart) {
if (startFound) {
throw new IllegalArgumentException("More than one start entry");
}
startFound = true;
}
if (startFound && entry instanceof LogEntryCommand) {
commandsInFirstEntry.add(entry.<LogEntryCommand>as().getXaCommand());
}
if (entry instanceof LogEntryCommit) {
// The first COMMIT
assertTrue(startFound);
assertFalse("Index creation transaction wasn't the first one", commandsInFirstEntry.isEmpty());
List<StorageCommand> createCommands = Iterators.asList(new FilteringIterator<>(commandsInFirstEntry.iterator(), item -> item instanceof IndexDefineCommand));
assertEquals(1, createCommands.size());
success.set(true);
break;
}
}
}
assertTrue("Didn't find any commit record in log " + version, success.get());
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class LogTestUtils method assertLogContains.
public static void assertLogContains(FileSystemAbstraction fileSystem, String logPath, LogEntry... expectedEntries) throws IOException {
try (LogEntryCursor cursor = openLog(fileSystem, new File(logPath))) {
int entryNo = 0;
while (cursor.next()) {
assertTrue("The log contained more entries than we expected!", entryNo < expectedEntries.length);
LogEntry expectedEntry = expectedEntries[entryNo];
assertEquals("Unexpected entry at entry number " + entryNo, cursor.get(), expectedEntry);
entryNo++;
}
if (entryNo < expectedEntries.length) {
fail("Log ended prematurely. Expected to find '" + expectedEntries[entryNo].toString() + "' as log entry number " + entryNo + ", instead there were no more log entries.");
}
}
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class LegacyLogEntryReader method openReadableChannel.
public Pair<LogHeader, IOCursor<LogEntry>> openReadableChannel(File logFile) throws IOException {
final StoreChannel rawChannel = fs.open(logFile, "r");
final LogHeader header = readLogHeader(ByteBuffer.allocate(LOG_HEADER_SIZE), rawChannel, false, logFile);
LogEntryReader<ReadableLogChannel> reader = readerFactory.apply(header);
// this ensures that the last committed txId field in the header is initialized properly
long lastCommittedTxId = Math.max(BASE_TX_ID, header.lastCommittedTxId);
final PhysicalLogVersionedStoreChannel channel = new PhysicalLogVersionedStoreChannel(rawChannel, header.logVersion, header.logFormatVersion);
final ReadableLogChannel readableChannel = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS);
final IOCursor<LogEntry> cursor = new LogEntrySortingCursor(reader, readableChannel);
return Pair.of(new LogHeader(CURRENT_LOG_VERSION, header.logVersion, lastCommittedTxId), cursor);
}
use of org.neo4j.kernel.impl.transaction.log.entry.LogEntry in project neo4j by neo4j.
the class NeoStoreDataSource method buildTransactionLogs.
private NeoStoreTransactionLogModule buildTransactionLogs(File storeDir, Config config, LogProvider logProvider, JobScheduler scheduler, FileSystemAbstraction fileSystemAbstraction, StorageEngine storageEngine, LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader, SynchronizedArrayIdOrderingQueue legacyIndexTransactionOrdering, TransactionIdStore transactionIdStore, LogVersionRepository logVersionRepository) {
TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache(100_000);
LogHeaderCache logHeaderCache = new LogHeaderCache(1000);
final PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, PhysicalLogFile.DEFAULT_NAME, fileSystemAbstraction);
final PhysicalLogFile logFile = life.add(new PhysicalLogFile(fileSystemAbstraction, logFiles, config.get(GraphDatabaseSettings.logical_log_rotation_threshold), transactionIdStore::getLastCommittedTransactionId, logVersionRepository, physicalLogMonitor, logHeaderCache));
final PhysicalLogFileInformation.LogVersionToTimestamp logInformation = version -> {
LogPosition position = LogPosition.start(version);
try (ReadableLogChannel channel = logFile.getReader(position)) {
LogEntry entry;
while ((entry = logEntryReader.readLogEntry(channel)) != null) {
if (entry instanceof LogEntryStart) {
return entry.<LogEntryStart>as().getTimeWritten();
}
}
}
return -1;
};
final LogFileInformation logFileInformation = new PhysicalLogFileInformation(logFiles, logHeaderCache, transactionIdStore::getLastCommittedTransactionId, logInformation);
if (config.get(GraphDatabaseFacadeFactory.Configuration.ephemeral)) {
config = config.withDefaults(stringMap(GraphDatabaseSettings.keep_logical_logs.name(), "1 files"));
}
String pruningConf = config.get(GraphDatabaseSettings.keep_logical_logs);
LogPruneStrategy logPruneStrategy = fromConfigValue(fs, logFileInformation, logFiles, pruningConf);
final LogPruning logPruning = new LogPruningImpl(logPruneStrategy, logProvider);
final LogRotation logRotation = new LogRotationImpl(monitors.newMonitor(LogRotation.Monitor.class), logFile, databaseHealth);
final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFile, logRotation, transactionMetadataCache, transactionIdStore, legacyIndexTransactionOrdering, databaseHealth));
final LogicalTransactionStore logicalTransactionStore = new PhysicalLogicalTransactionStore(logFile, transactionMetadataCache, logEntryReader);
int txThreshold = config.get(GraphDatabaseSettings.check_point_interval_tx);
final CountCommittedTransactionThreshold countCommittedTransactionThreshold = new CountCommittedTransactionThreshold(txThreshold);
long timeMillisThreshold = config.get(GraphDatabaseSettings.check_point_interval_time);
TimeCheckPointThreshold timeCheckPointThreshold = new TimeCheckPointThreshold(timeMillisThreshold, clock);
CheckPointThreshold threshold = CheckPointThresholds.or(countCommittedTransactionThreshold, timeCheckPointThreshold);
final CheckPointerImpl checkPointer = new CheckPointerImpl(transactionIdStore, threshold, storageEngine, logPruning, appender, databaseHealth, logProvider, tracers.checkPointTracer, ioLimiter, storeCopyCheckPointMutex);
long recurringPeriod = Math.min(timeMillisThreshold, TimeUnit.SECONDS.toMillis(10));
CheckPointScheduler checkPointScheduler = new CheckPointScheduler(checkPointer, scheduler, recurringPeriod, databaseHealth);
life.add(checkPointer);
life.add(checkPointScheduler);
return new NeoStoreTransactionLogModule(logicalTransactionStore, logFileInformation, logFiles, logFile, logRotation, checkPointer, appender, legacyIndexTransactionOrdering);
}
Aggregations