use of org.neo4j.storageengine.api.TransactionIdStore in project neo4j by neo4j.
the class DatabaseServiceBookmarkTest method throwsWhenTxAwaitDurationExpires.
@Test
void throwsWhenTxAwaitDurationExpires() {
long lastClosedTransactionId = 100;
TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
var txAwaitDuration = Duration.ofSeconds(42);
var clock = new FakeClock();
var guard = new DatabaseAvailabilityGuard(DATABASE_ID, clock, NullLog.getInstance(), 0, mock(CompositeDatabaseAvailabilityGuard.class));
var databaseAvailabilityGuard = spy(guard);
when(databaseAvailabilityGuard.isAvailable()).then(invocation -> {
// move clock forward on avery availability check
// this check is executed on every tx id polling iteration
clock.forward(1, SECONDS);
return true;
});
var dbSpi = createDbSpi(txIdStore, txAwaitDuration, databaseAvailabilityGuard, clock);
var resultFuture = executor.submit(() -> {
begin(dbSpi, List.of(new BookmarkWithPrefix(lastClosedTransactionId + 42)));
return null;
});
var e = assertThrows(ExecutionException.class, () -> resultFuture.get(20, SECONDS));
assertThat(e.getCause()).isInstanceOf(TransactionIdTrackerException.class);
}
use of org.neo4j.storageengine.api.TransactionIdStore in project neo4j by neo4j.
the class DatabaseServiceBookmarkTest method doesNotWaitWhenTxIdUpToDate.
@Test
void doesNotWaitWhenTxIdUpToDate() throws Exception {
long lastClosedTransactionId = 100;
TransactionIdStore txIdStore = fixedTxIdStore(lastClosedTransactionId);
var dbSpi = createDbSpi(txIdStore, Duration.ofSeconds(1), Clocks.fakeClock());
var resultFuture = executor.submit(() -> {
begin(dbSpi, List.of(new BookmarkWithPrefix(lastClosedTransactionId - 42)));
return null;
});
assertNull(resultFuture.get(20, SECONDS));
}
use of org.neo4j.storageengine.api.TransactionIdStore in project neo4j by neo4j.
the class TransactionLogAppendAndRotateIT method shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending.
@Test
void shouldKeepTransactionsIntactWhenConcurrentlyRotationAndAppending() throws Throwable {
// GIVEN
LogVersionRepository logVersionRepository = new SimpleLogVersionRepository();
LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fileSystem).withLogVersionRepository(logVersionRepository).withRotationThreshold(ByteUnit.mebiBytes(1)).withTransactionIdStore(new SimpleTransactionIdStore()).withLogEntryReader(logEntryReader()).withStoreId(StoreId.UNKNOWN).build();
life.add(logFiles);
final AtomicBoolean end = new AtomicBoolean();
AllTheMonitoring monitoring = new AllTheMonitoring(end, 100);
TransactionIdStore txIdStore = new SimpleTransactionIdStore();
TransactionMetadataCache metadataCache = new TransactionMetadataCache();
monitoring.setLogFile(logFiles.getLogFile());
Health health = new DatabaseHealth(mock(DatabasePanicEventGenerator.class), NullLog.getInstance());
LogRotation rotation = transactionLogRotation(logFiles, Clock.systemUTC(), health, monitoring);
final TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, rotation, metadataCache, txIdStore, health));
// WHEN
Race race = new Race();
for (int i = 0; i < 4; i++) {
race.addContestant(() -> {
while (!end.get()) {
try {
appender.append(new TransactionToApply(sillyTransaction(1_000), CursorContext.NULL), LogAppendEvent.NULL);
} catch (Exception e) {
e.printStackTrace(System.out);
end.set(true);
fail(e.getMessage(), e);
}
}
});
}
race.addContestant(endAfterMax(250, MILLISECONDS, end, monitoring));
race.go();
// THEN
assertTrue(monitoring.numberOfRotations() > 0);
}
use of org.neo4j.storageengine.api.TransactionIdStore in project neo4j by neo4j.
the class PhysicalLogicalTransactionStoreTest method shouldExtractMetadataFromExistingTransaction.
@Test
void shouldExtractMetadataFromExistingTransaction() throws Exception {
// GIVEN
TransactionIdStore transactionIdStore = new SimpleTransactionIdStore();
TransactionMetadataCache positionCache = new TransactionMetadataCache();
final byte[] additionalHeader = new byte[] { 1, 2, 5 };
final long timeStarted = 12345;
long latestCommittedTxWhenStarted = 4545;
long timeCommitted = timeStarted + 10;
LifeSupport life = new LifeSupport();
final LogFiles logFiles = buildLogFiles(transactionIdStore);
life.start();
life.add(logFiles);
try {
addATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
} finally {
life.shutdown();
}
life = new LifeSupport();
life.add(logFiles);
final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFiles, positionCache, logEntryReader(), monitors, true);
// WHEN
life.start();
try {
verifyTransaction(positionCache, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
} finally {
life.shutdown();
}
}
use of org.neo4j.storageengine.api.TransactionIdStore in project neo4j by neo4j.
the class PhysicalLogicalTransactionStoreTest method extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader.
@Test
void extractTransactionFromLogFilesSkippingLastLogFileWithoutHeader() throws IOException {
TransactionIdStore transactionIdStore = new SimpleTransactionIdStore();
TransactionMetadataCache positionCache = new TransactionMetadataCache();
final byte[] additionalHeader = new byte[] { 1, 2, 5 };
final long timeStarted = 12345;
long latestCommittedTxWhenStarted = 4545;
long timeCommitted = timeStarted + 10;
LifeSupport life = new LifeSupport();
final LogFiles logFiles = buildLogFiles(transactionIdStore);
life.add(logFiles);
life.start();
try {
addATransactionAndRewind(life, logFiles, positionCache, transactionIdStore, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted);
} finally {
life.shutdown();
}
// create empty transaction log file and clear transaction cache to force re-read
LogFile logFile = logFiles.getLogFile();
fileSystem.write(logFile.getLogFileForVersion(logFile.getHighestLogVersion() + 1)).close();
positionCache.clear();
final LogicalTransactionStore store = new PhysicalLogicalTransactionStore(logFiles, positionCache, logEntryReader(), monitors, true);
verifyTransaction(positionCache, additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, store);
}
Aggregations