use of org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation in project neo4j by neo4j.
the class RecoverIndexDropIT method extractLastTransaction.
private static CommittedTransactionRepresentation extractLastTransaction(GraphDatabaseAPI db) throws IOException {
LogicalTransactionStore txStore = db.getDependencyResolver().resolveDependency(LogicalTransactionStore.class);
CommittedTransactionRepresentation transaction = null;
try (TransactionCursor cursor = txStore.getTransactions(TransactionIdStore.BASE_TX_ID + 1)) {
while (cursor.next()) {
transaction = cursor.get();
}
}
return transaction;
}
use of org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation in project neo4j by neo4j.
the class ParallelRecoveryVisitor method apply.
private void apply(CommittedTransactionRepresentation transaction) throws Exception {
try (CursorContext cursorContext = new CursorContext(cacheTracer.createPageCursorTracer(tracerTag))) {
TransactionRepresentation txRepresentation = transaction.getTransactionRepresentation();
long txId = transaction.getCommitEntry().getTxId();
TransactionToApply tx = new TransactionToApply(txRepresentation, txId, cursorContext);
tx.commitment(NO_COMMITMENT, txId);
tx.logPosition(transaction.getStartEntry().getStartPosition());
storageEngine.apply(tx, mode);
}
}
use of org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation in project neo4j by neo4j.
the class TransactionLogsRecoveryTest method shouldRecoverExistingData.
@Test
void shouldRecoverExistingData() throws Exception {
LogFile logFile = logFiles.getLogFile();
Path file = logFile.getLogFileForVersion(logVersion);
writeSomeData(file, pair -> {
LogEntryWriter writer = pair.first();
Consumer<LogPositionMarker> consumer = pair.other();
LogPositionMarker marker = new LogPositionMarker();
// last committed tx
int previousChecksum = BASE_TX_CHECKSUM;
consumer.accept(marker);
LogPosition lastCommittedTxPosition = marker.newPosition();
writer.writeStartEntry(2L, 3L, previousChecksum, new byte[0]);
lastCommittedTxStartEntry = new LogEntryStart(2L, 3L, previousChecksum, new byte[0], lastCommittedTxPosition);
previousChecksum = writer.writeCommitEntry(4L, 5L);
lastCommittedTxCommitEntry = new LogEntryCommit(4L, 5L, previousChecksum);
// check point pointing to the previously committed transaction
var checkpointFile = logFiles.getCheckpointFile();
var checkpointAppender = checkpointFile.getCheckpointAppender();
checkpointAppender.checkPoint(LogCheckPointEvent.NULL, lastCommittedTxPosition, Instant.now(), "test");
// tx committed after checkpoint
consumer.accept(marker);
writer.writeStartEntry(6L, 4L, previousChecksum, new byte[0]);
expectedStartEntry = new LogEntryStart(6L, 4L, previousChecksum, new byte[0], marker.newPosition());
previousChecksum = writer.writeCommitEntry(5L, 7L);
expectedCommitEntry = new LogEntryCommit(5L, 7L, previousChecksum);
return true;
});
LifeSupport life = new LifeSupport();
var recoveryRequired = new AtomicBoolean();
var recoveredTransactions = new MutableInt();
RecoveryMonitor monitor = new RecoveryMonitor() {
@Override
public void recoveryRequired(LogPosition recoveryPosition) {
recoveryRequired.set(true);
}
@Override
public void recoveryCompleted(int numberOfRecoveredTransactions, long recoveryTimeInMilliseconds) {
recoveredTransactions.setValue(numberOfRecoveredTransactions);
}
};
try {
StorageEngine storageEngine = mock(StorageEngine.class);
final LogEntryReader reader = logEntryReader();
TransactionMetadataCache metadataCache = new TransactionMetadataCache();
LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore(logFiles, metadataCache, reader, monitors, false);
CorruptedLogsTruncator logPruner = new CorruptedLogsTruncator(storeDir, logFiles, fileSystem, INSTANCE);
monitors.addMonitorListener(monitor);
life.add(new TransactionLogsRecovery(new DefaultRecoveryService(storageEngine, transactionIdStore, txStore, versionRepository, logFiles, NO_MONITOR, mock(Log.class), false) {
private int nr;
@Override
public RecoveryApplier getRecoveryApplier(TransactionApplicationMode mode, PageCacheTracer cacheTracer, String tracerTag) {
RecoveryApplier actual = super.getRecoveryApplier(mode, cacheTracer, tracerTag);
if (mode == TransactionApplicationMode.REVERSE_RECOVERY) {
return actual;
}
return new RecoveryApplier() {
@Override
public void close() throws Exception {
actual.close();
}
@Override
public boolean visit(CommittedTransactionRepresentation tx) throws Exception {
actual.visit(tx);
switch(nr++) {
case 0:
assertEquals(lastCommittedTxStartEntry, tx.getStartEntry());
assertEquals(lastCommittedTxCommitEntry, tx.getCommitEntry());
break;
case 1:
assertEquals(expectedStartEntry, tx.getStartEntry());
assertEquals(expectedCommitEntry, tx.getCommitEntry());
break;
default:
fail("Too many recovered transactions");
}
return false;
}
};
}
}, logPruner, schemaLife, monitor, ProgressReporter.SILENT, false, EMPTY_CHECKER, NULL));
life.start();
assertTrue(recoveryRequired.get());
assertEquals(2, recoveredTransactions.getValue());
} finally {
life.shutdown();
}
}
use of org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation in project neo4j by neo4j.
the class RecoveryProgressIndicatorTest method reportProgressOnRecovery.
@Test
void reportProgressOnRecovery() throws Throwable {
RecoveryService recoveryService = mock(RecoveryService.class, Answers.RETURNS_MOCKS);
CorruptedLogsTruncator logsTruncator = mock(CorruptedLogsTruncator.class);
RecoveryMonitor recoveryMonitor = mock(RecoveryMonitor.class);
TransactionCursor reverseTransactionCursor = mock(TransactionCursor.class);
TransactionCursor transactionCursor = mock(TransactionCursor.class);
CommittedTransactionRepresentation transactionRepresentation = mock(CommittedTransactionRepresentation.class);
int transactionsToRecover = 5;
int expectedMax = transactionsToRecover * 2;
int lastCommittedTransactionId = 14;
LogPosition transactionLogPosition = new LogPosition(0, CURRENT_FORMAT_LOG_HEADER_SIZE);
LogPosition checkpointLogPosition = new LogPosition(0, CURRENT_FORMAT_LOG_HEADER_SIZE);
int firstTxIdAfterLastCheckPoint = 10;
RecoveryStartInformation startInformation = new RecoveryStartInformation(transactionLogPosition, checkpointLogPosition, firstTxIdAfterLastCheckPoint);
when(reverseTransactionCursor.next()).thenAnswer(new NextTransactionAnswer(transactionsToRecover));
when(transactionCursor.next()).thenAnswer(new NextTransactionAnswer(transactionsToRecover));
when(reverseTransactionCursor.get()).thenReturn(transactionRepresentation);
when(transactionCursor.get()).thenReturn(transactionRepresentation);
when(transactionRepresentation.getCommitEntry()).thenReturn(new LogEntryCommit(lastCommittedTransactionId, 1L, BASE_TX_CHECKSUM));
when(recoveryService.getRecoveryStartInformation()).thenReturn(startInformation);
when(recoveryService.getTransactionsInReverseOrder(transactionLogPosition)).thenReturn(reverseTransactionCursor);
when(recoveryService.getTransactions(transactionLogPosition)).thenReturn(transactionCursor);
AssertableProgressReporter progressReporter = new AssertableProgressReporter(expectedMax);
TransactionLogsRecovery recovery = new TransactionLogsRecovery(recoveryService, logsTruncator, new LifecycleAdapter(), recoveryMonitor, progressReporter, true, EMPTY_CHECKER, PageCacheTracer.NULL);
recovery.init();
progressReporter.verify();
}
use of org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation in project neo4j by neo4j.
the class ReversedSingleFileTransactionCursorTest method assertTransactionRange.
private static void assertTransactionRange(CommittedTransactionRepresentation[] readTransactions, long highTxId, long lowTxId) {
long expectedTxId = highTxId;
for (CommittedTransactionRepresentation tx : readTransactions) {
assertEquals(expectedTxId, tx.getCommitEntry().getTxId());
expectedTxId--;
}
assertEquals(expectedTxId, lowTxId);
}
Aggregations