use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor in project neo4j by neo4j.
the class PhysicalLogicalTransactionStoreTest method shouldOpenCleanStore.
@Test
public void shouldOpenCleanStore() throws Exception {
// GIVEN
TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
TransactionMetadataCache positionCache = new TransactionMetadataCache(1000);
LogHeaderCache logHeaderCache = new LogHeaderCache(10);
LifeSupport life = new LifeSupport();
PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
life.add(new BatchingTransactionAppender(logFile, NO_ROTATION, positionCache, transactionIdStore, BYPASS, DATABASE_HEALTH));
try {
// WHEN
life.start();
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor in project neo4j by neo4j.
the class PhysicalLogicalTransactionStoreTest method shouldOpenAndRecoverExistingData.
@Test
public void shouldOpenAndRecoverExistingData() throws Exception {
// GIVEN
TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
TransactionMetadataCache positionCache = new TransactionMetadataCache(100);
LogHeaderCache logHeaderCache = new LogHeaderCache(10);
final byte[] additionalHeader = new byte[] { 1, 2, 5 };
final int masterId = 2, authorId = 1;
final long timeStarted = 12345, latestCommittedTxWhenStarted = 4545, timeCommitted = timeStarted + 10;
LifeSupport life = new LifeSupport();
final PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
life.start();
try {
addATransactionAndRewind(life, logFile, positionCache, transactionIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
} finally {
life.shutdown();
}
life = new LifeSupport();
final AtomicBoolean recoveryRequired = new AtomicBoolean();
FakeRecoveryVisitor visitor = new FakeRecoveryVisitor(additionalHeader, masterId, authorId, timeStarted, timeCommitted, latestCommittedTxWhenStarted);
logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFile, positionCache, new VersionAwareLogEntryReader<>());
life.add(new BatchingTransactionAppender(logFile, NO_ROTATION, positionCache, transactionIdStore, BYPASS, DATABASE_HEALTH));
life.add(new Recovery(new Recovery.SPI() {
@Override
public void forceEverything() {
}
@Override
public Visitor<CommittedTransactionRepresentation, Exception> startRecovery() {
recoveryRequired.set(true);
return visitor;
}
@Override
public LogPosition getPositionToRecoverFrom() throws IOException {
return LogPosition.start(0);
}
@Override
public TransactionCursor getTransactions(LogPosition position) throws IOException {
return txStore.getTransactions(position);
}
@Override
public void allTransactionsRecovered(CommittedTransactionRepresentation lastRecoveredTransaction, LogPosition positionAfterLastRecoveredTransaction) throws Exception {
}
}, mock(Recovery.Monitor.class)));
// WHEN
try {
life.start();
} finally {
life.shutdown();
}
// THEN
assertEquals(1, visitor.getVisitedTransactions());
assertTrue(recoveryRequired.get());
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor in project neo4j by neo4j.
the class PhysicalLogicalTransactionStoreTest method shouldExtractMetadataFromExistingTransaction.
@Test
public void shouldExtractMetadataFromExistingTransaction() throws Exception {
// GIVEN
TransactionIdStore txIdStore = new DeadSimpleTransactionIdStore();
TransactionMetadataCache positionCache = new TransactionMetadataCache(100);
LogHeaderCache logHeaderCache = new LogHeaderCache(10);
final byte[] additionalHeader = new byte[] { 1, 2, 5 };
final int masterId = 2, authorId = 1;
final long timeStarted = 12345, latestCommittedTxWhenStarted = 4545, timeCommitted = timeStarted + 10;
LifeSupport life = new LifeSupport();
PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, txIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
life.start();
try {
addATransactionAndRewind(life, logFile, positionCache, txIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
} finally {
life.shutdown();
}
life = new LifeSupport();
logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, txIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFile, positionCache, new VersionAwareLogEntryReader<>());
// WHEN
life.start();
try {
verifyTransaction(txIdStore, positionCache, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor in project neo4j by neo4j.
the class PhysicalLogicalTransactionStoreTest method extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader.
@Test
public void extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader() throws IOException {
TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
TransactionMetadataCache positionCache = new TransactionMetadataCache(100);
LogHeaderCache logHeaderCache = new LogHeaderCache(10);
final byte[] additionalHeader = new byte[] { 1, 2, 5 };
final int masterId = 2, authorId = 1;
final long timeStarted = 12345, latestCommittedTxWhenStarted = 4545, timeCommitted = timeStarted + 10;
LifeSupport life = new LifeSupport();
final PhysicalLogFiles logFiles = new PhysicalLogFiles(testDir, DEFAULT_NAME, fileSystemRule.get());
Monitor monitor = new Monitors().newMonitor(PhysicalLogFile.Monitor.class);
LogFile logFile = life.add(new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache));
life.start();
try {
addATransactionAndRewind(life, logFile, positionCache, transactionIdStore, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
} finally {
life.shutdown();
}
PhysicalLogFile emptyLogFile = new PhysicalLogFile(fileSystemRule.get(), logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, mock(LogVersionRepository.class), monitor, logHeaderCache);
// create empty transaction log file and clear transaction cache to force re-read
fileSystemRule.get().create(logFiles.getLogFileForVersion(logFiles.getHighestLogVersion() + 1)).close();
positionCache.clear();
final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(emptyLogFile, positionCache, new VersionAwareLogEntryReader<>());
verifyTransaction(transactionIdStore, positionCache, additionalHeader, masterId, authorId, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFile.Monitor in project neo4j by neo4j.
the class PhysicalLogFileTest method shouldWriteSomeDataIntoTheLog.
@Test
public void shouldWriteSomeDataIntoTheLog() throws Exception {
// GIVEN
String name = "log";
LifeSupport life = new LifeSupport();
FileSystemAbstraction fs = fileSystemRule.get();
PhysicalLogFiles logFiles = new PhysicalLogFiles(directory.directory(), name, fs);
Monitor monitor = mock(Monitor.class);
LogFile logFile = life.add(new PhysicalLogFile(fs, logFiles, 1000, transactionIdStore::getLastCommittedTransactionId, logVersionRepository, monitor, new LogHeaderCache(10)));
// WHEN
try {
life.start();
FlushablePositionAwareChannel writer = logFile.getWriter();
LogPositionMarker positionMarker = new LogPositionMarker();
writer.getCurrentPosition(positionMarker);
int intValue = 45;
long longValue = 4854587;
writer.putInt(intValue);
writer.putLong(longValue);
writer.prepareForFlush().flush();
// THEN
try (ReadableClosableChannel reader = logFile.getReader(positionMarker.newPosition())) {
assertEquals(intValue, reader.getInt());
assertEquals(longValue, reader.getLong());
}
} finally {
life.shutdown();
}
}
Aggregations