use of org.neo4j.kernel.impl.transaction.log.ReadableLogChannel 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);
}
use of org.neo4j.kernel.impl.transaction.log.ReadableLogChannel in project neo4j by neo4j.
the class CheckPointerIntegrationTest method checkPointInTxLog.
private boolean checkPointInTxLog(GraphDatabaseService db) throws IOException {
LogFile logFile = ((GraphDatabaseAPI) db).getDependencyResolver().resolveDependency(LogFile.class);
try (ReadableLogChannel reader = logFile.getReader(new LogPosition(0, LOG_HEADER_SIZE))) {
LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
LogEntry entry = null;
while ((entry = logEntryReader.readLogEntry(reader)) != null) {
if (entry instanceof CheckPoint) {
return true;
}
}
return false;
}
}
use of org.neo4j.kernel.impl.transaction.log.ReadableLogChannel in project neo4j by neo4j.
the class LatestCheckPointFinder method find.
public LatestCheckPoint find(long fromVersionBackwards) throws IOException {
long version = fromVersionBackwards;
long versionToSearchForCommits = fromVersionBackwards;
LogEntryStart latestStartEntry = null;
LogEntryStart oldestStartEntry = null;
long oldestVersionFound = -1;
while (version >= INITIAL_LOG_VERSION) {
LogVersionedStoreChannel channel = PhysicalLogFile.tryOpenForVersion(logFiles, fileSystem, version, false);
if (channel == null) {
break;
}
oldestVersionFound = version;
CheckPoint latestCheckPoint = null;
ReadableLogChannel recoveredDataChannel = new ReadAheadLogChannel(channel, NO_MORE_CHANNELS);
boolean firstStartEntry = true;
try (LogEntryCursor cursor = new LogEntryCursor(logEntryReader, recoveredDataChannel)) {
LogEntry entry;
while (cursor.next()) {
entry = cursor.get();
if (entry instanceof CheckPoint) {
latestCheckPoint = entry.as();
}
if (entry instanceof LogEntryStart) {
LogEntryStart startEntry = entry.as();
if (version == versionToSearchForCommits) {
latestStartEntry = startEntry;
}
// Oldest start entry will be the first in the last log version scanned.
if (firstStartEntry) {
oldestStartEntry = startEntry;
firstStartEntry = false;
}
}
}
}
if (latestCheckPoint != null) {
return latestCheckPoint(fromVersionBackwards, version, latestStartEntry, oldestVersionFound, latestCheckPoint);
}
version--;
// if we have found no commits in the latest log, keep searching in the next one
if (latestStartEntry == null) {
versionToSearchForCommits--;
}
}
boolean commitsAfterCheckPoint = oldestStartEntry != null;
long firstTxAfterPosition = commitsAfterCheckPoint ? extractFirstTxIdAfterPosition(oldestStartEntry.getStartPosition(), fromVersionBackwards) : LatestCheckPoint.NO_TRANSACTION_ID;
return new LatestCheckPoint(null, commitsAfterCheckPoint, firstTxAfterPosition, oldestVersionFound);
}
use of org.neo4j.kernel.impl.transaction.log.ReadableLogChannel in project neo4j by neo4j.
the class TransactionLogCatchUpWriterTest method verifyTransactionsInLog.
private void verifyTransactionsInLog(long fromTxId, long endTxId) throws IOException {
long expectedTxId = fromTxId;
PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fs);
LogVersionedStoreChannel versionedStoreChannel = PhysicalLogFile.openForVersion(logFiles, fs, 0, false);
try (ReadableLogChannel channel = new ReadAheadLogChannel(versionedStoreChannel, LogVersionBridge.NO_MORE_CHANNELS, 1024)) {
try (PhysicalTransactionCursor<ReadableLogChannel> txCursor = new PhysicalTransactionCursor<>(channel, new VersionAwareLogEntryReader<>())) {
while (txCursor.next()) {
CommittedTransactionRepresentation tx = txCursor.get();
long txId = tx.getCommitEntry().getTxId();
assertThat(expectedTxId, lessThanOrEqualTo(endTxId));
assertEquals(expectedTxId, txId);
expectedTxId++;
}
}
}
}
use of org.neo4j.kernel.impl.transaction.log.ReadableLogChannel in project neo4j by neo4j.
the class RebuildFromLogs method findLastTransactionId.
private long findLastTransactionId(PhysicalLogFiles logFiles, long highestVersion) throws IOException {
ReadableLogChannel logChannel = new ReadAheadLogChannel(PhysicalLogFile.openForVersion(logFiles, fs, highestVersion, false), NO_MORE_CHANNELS);
long lastTransactionId = -1;
LogEntryReader<ReadableClosablePositionAwareChannel> entryReader = new VersionAwareLogEntryReader<>();
try (IOCursor<CommittedTransactionRepresentation> cursor = new PhysicalTransactionCursor<>(logChannel, entryReader)) {
while (cursor.next()) {
lastTransactionId = cursor.get().getCommitEntry().getTxId();
}
}
return lastTransactionId;
}
Aggregations