use of org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel in project neo4j by neo4j.
the class ReplicatedTransactionFactory method read.
public static TransactionRepresentation read(NetworkReadableClosableChannelNetty4 channel, byte[] extraHeader) throws IOException {
LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
int authorId = channel.getInt();
int masterId = channel.getInt();
long latestCommittedTxWhenStarted = channel.getLong();
long timeStarted = channel.getLong();
long timeCommitted = channel.getLong();
int lockSessionId = channel.getInt();
int headerLength = channel.getInt();
byte[] header;
if (headerLength == 0) {
header = extraHeader;
} else {
header = new byte[headerLength];
}
channel.get(header, headerLength);
LogEntryCommand entryRead;
List<StorageCommand> commands = new LinkedList<>();
while ((entryRead = (LogEntryCommand) reader.readLogEntry(channel)) != null) {
commands.add(entryRead.getXaCommand());
}
PhysicalTransactionRepresentation tx = new PhysicalTransactionRepresentation(commands);
tx.setHeader(header, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, lockSessionId);
return tx;
}
use of org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel in project neo4j by neo4j.
the class ReplicatedTokenRequestSerializer method extractCommands.
static Collection<StorageCommand> extractCommands(byte[] commandBytes) {
ByteBuf txBuffer = Unpooled.wrappedBuffer(commandBytes);
NetworkReadableClosableChannelNetty4 channel = new NetworkReadableClosableChannelNetty4(txBuffer);
LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>(new RecordStorageCommandReaderFactory());
LogEntryCommand entryRead;
List<StorageCommand> commands = new LinkedList<>();
try {
while ((entryRead = (LogEntryCommand) reader.readLogEntry(channel)) != null) {
commands.add(entryRead.getXaCommand());
}
} catch (IOException e) {
// TODO: Handle or throw.
e.printStackTrace();
}
return commands;
}
use of org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel in project neo4j by neo4j.
the class BackupProtocolTest method shouldGatherForensicsInFullBackupRequest.
private void shouldGatherForensicsInFullBackupRequest(boolean forensics) throws Exception {
// GIVEN
Response<Void> response = Response.EMPTY;
StoreId storeId = response.getStoreId();
String host = "localhost";
int port = BackupServer.DEFAULT_PORT;
LifeSupport life = new LifeSupport();
LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
BackupClient client = life.add(new BackupClient(host, port, null, NullLogProvider.getInstance(), storeId, 10_000, mock(ResponseUnpacker.class), mock(ByteCounterMonitor.class), mock(RequestMonitor.class), reader));
ControlledBackupInterface backup = new ControlledBackupInterface();
life.add(new BackupServer(backup, new HostnamePort(host, port), NullLogProvider.getInstance(), mock(ByteCounterMonitor.class), mock(RequestMonitor.class)));
life.start();
try {
// WHEN
StoreWriter writer = mock(StoreWriter.class);
client.fullBackup(writer, forensics);
// THEN
assertEquals(forensics, backup.receivedForensics);
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel in project neo4j by neo4j.
the class UpgradableDatabase method checkCleanShutDownByCheckPoint.
private Result checkCleanShutDownByCheckPoint(File storeDirectory) {
// check version
PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDirectory, fs);
LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>();
LatestCheckPointFinder latestCheckPointFinder = new LatestCheckPointFinder(logFiles, fs, logEntryReader);
try {
LatestCheckPoint latestCheckPoint = latestCheckPointFinder.find(logFiles.getHighestLogVersion());
if (!latestCheckPoint.commitsAfterCheckPoint) {
return new Result(Result.Outcome.ok, null, null);
}
} catch (IOException e) {
// ignore exception and return db not cleanly shutdown
}
return new Result(Result.Outcome.storeNotCleanlyShutDown, null, null);
}
use of org.neo4j.kernel.impl.transaction.log.ReadableClosablePositionAwareChannel 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