use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class StoreMigratorTest method shouldGenerateTransactionInformationWhenLogsAreEmpty.
@Test
void shouldGenerateTransactionInformationWhenLogsAreEmpty() throws Exception {
// given
long txId = 1;
Path neoStore = databaseLayout.metadataStore();
Files.createFile(neoStore);
Config config = mock(Config.class);
LogService logService = new SimpleLogService(NullLogProvider.getInstance(), NullLogProvider.getInstance());
// when
// ... transaction info not in neo store
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_ID, databaseLayout.getDatabaseName(), NULL));
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_CHECKSUM, databaseLayout.getDatabaseName(), NULL));
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP, databaseLayout.getDatabaseName(), NULL));
// ... and with migrator
RecordStorageMigrator migrator = new RecordStorageMigrator(fileSystem, pageCache, config, logService, jobScheduler, PageCacheTracer.NULL, batchImporterFactory, INSTANCE);
TransactionId actual = migrator.extractTransactionIdInformation(neoStore, txId, databaseLayout, NULL);
// then
assertEquals(txId, actual.transactionId());
assertEquals(TransactionIdStore.BASE_TX_CHECKSUM, actual.checksum());
assertEquals(TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP, actual.commitTimestamp());
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class NeoStoresTest method shouldNotSetHighestTransactionIdWhenNeeded.
@Test
void shouldNotSetHighestTransactionIdWhenNeeded() {
// GIVEN
StoreFactory factory = getStoreFactory(Config.defaults(), databaseLayout, fs, LOG_PROVIDER);
try (NeoStores neoStore = factory.openAllNeoStores(true)) {
MetaDataStore store = neoStore.getMetaDataStore();
store.setLastCommittedAndClosedTransactionId(40, 4444, BASE_TX_COMMIT_TIMESTAMP, CURRENT_FORMAT_LOG_HEADER_SIZE, 0, NULL);
// WHEN
store.transactionCommitted(39, 3333, BASE_TX_COMMIT_TIMESTAMP, NULL);
// THEN
assertEquals(new TransactionId(40, 4444, BASE_TX_COMMIT_TIMESTAMP), store.getLastCommittedTransaction());
assertArrayEquals(new long[] { 40, 0, CURRENT_FORMAT_LOG_HEADER_SIZE }, store.getLastClosedTransaction());
}
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class BatchingTransactionAppenderTest method shouldNotCallTransactionClosedOnFailedAppendedTransaction.
@Test
void shouldNotCallTransactionClosedOnFailedAppendedTransaction() throws Exception {
// GIVEN
long txId = 3;
String failureMessage = "Forces a failure";
FlushablePositionAwareChecksumChannel channel = spy(new PositionAwarePhysicalFlushableChecksumChannel(mock(PhysicalLogVersionedStoreChannel.class), new HeapScopedBuffer(Long.BYTES * 2, INSTANCE)));
IOException failure = new IOException(failureMessage);
when(channel.putLong(anyLong())).thenThrow(failure);
when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(txId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
Mockito.reset(databaseHealth);
TransactionAppender appender = life.add(createTransactionAppender());
// WHEN
TransactionRepresentation transaction = mock(TransactionRepresentation.class);
when(transaction.additionalHeader()).thenReturn(new byte[0]);
var e = assertThrows(IOException.class, () -> appender.append(new TransactionToApply(transaction, NULL), logAppendEvent));
assertSame(failure, e);
verify(transactionIdStore).nextCommittingTransactionId();
verify(transactionIdStore, never()).transactionClosed(eq(txId), anyLong(), anyLong(), any(CursorContext.class));
verify(databaseHealth).panic(failure);
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class BatchingTransactionAppenderTest method shouldNotCallTransactionClosedOnFailedForceLogToDisk.
@Test
void shouldNotCallTransactionClosedOnFailedForceLogToDisk() throws Exception {
// GIVEN
long txId = 3;
String failureMessage = "Forces a failure";
FlushablePositionAwareChecksumChannel channel = spy(new InMemoryClosableChannel());
IOException failure = new IOException(failureMessage);
final Flushable flushable = mock(Flushable.class);
doAnswer(invocation -> {
invocation.callRealMethod();
return flushable;
}).when(channel).prepareForFlush();
when(logFile.forceAfterAppend(any())).thenThrow(failure);
when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
TransactionMetadataCache metadataCache = new TransactionMetadataCache();
TransactionIdStore transactionIdStore = mock(TransactionIdStore.class);
when(transactionIdStore.nextCommittingTransactionId()).thenReturn(txId);
when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(txId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, NO_ROTATION, metadataCache, transactionIdStore, databaseHealth));
// WHEN
TransactionRepresentation transaction = mock(TransactionRepresentation.class);
when(transaction.additionalHeader()).thenReturn(new byte[0]);
var e = assertThrows(IOException.class, () -> appender.append(new TransactionToApply(transaction, NULL), logAppendEvent));
assertSame(failure, e);
verify(transactionIdStore).nextCommittingTransactionId();
verify(transactionIdStore, never()).transactionClosed(eq(txId), anyLong(), anyLong(), any(CursorContext.class));
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class SimpleTransactionIdStore method setLastCommittedAndClosedTransactionId.
@Override
public void setLastCommittedAndClosedTransactionId(long transactionId, int checksum, long commitTimestamp, long byteOffset, long logVersion, CursorContext cursorContext) {
committingTransactionId.set(transactionId);
committedTransactionId.set(new TransactionId(transactionId, checksum, commitTimestamp));
closedTransactionId.set(transactionId, new long[] { logVersion, byteOffset });
}
Aggregations