use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class BatchingTransactionAppenderTest method shouldAppendCommittedTransactions.
@Test
void shouldAppendCommittedTransactions() throws Exception {
// GIVEN
when(logFile.getTransactionLogWriter()).thenReturn(new TransactionLogWriter(channel, new DbmsLogEntryWriterFactory(() -> LATEST)));
long nextTxId = 15;
when(transactionIdStore.nextCommittingTransactionId()).thenReturn(nextTxId);
when(transactionIdStore.getLastCommittedTransaction()).thenReturn(new TransactionId(nextTxId, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP));
TransactionAppender appender = life.add(new BatchingTransactionAppender(logFiles, NO_ROTATION, positionCache, transactionIdStore, databaseHealth));
// WHEN
final byte[] additionalHeader = new byte[] { 1, 2, 5 };
final long timeStarted = 12345;
long latestCommittedTxWhenStarted = nextTxId - 5;
long timeCommitted = timeStarted + 10;
PhysicalTransactionRepresentation transactionRepresentation = new PhysicalTransactionRepresentation(singleTestCommand());
transactionRepresentation.setHeader(additionalHeader, timeStarted, latestCommittedTxWhenStarted, timeCommitted, -1, ANONYMOUS);
LogEntryStart start = new LogEntryStart(0L, latestCommittedTxWhenStarted, 0, null, LogPosition.UNSPECIFIED);
LogEntryCommit commit = new LogEntryCommit(nextTxId, 0L, BASE_TX_CHECKSUM);
CommittedTransactionRepresentation transaction = new CommittedTransactionRepresentation(start, transactionRepresentation, commit);
appender.append(new TransactionToApply(transactionRepresentation, transaction.getCommitEntry().getTxId(), NULL), logAppendEvent);
// THEN
LogEntryReader logEntryReader = logEntryReader();
try (PhysicalTransactionCursor reader = new PhysicalTransactionCursor(channel, logEntryReader)) {
reader.next();
TransactionRepresentation result = reader.get().getTransactionRepresentation();
assertArrayEquals(additionalHeader, result.additionalHeader());
assertEquals(timeStarted, result.getTimeStarted());
assertEquals(timeCommitted, result.getTimeCommitted());
assertEquals(latestCommittedTxWhenStarted, result.getLatestCommittedTxWhenStarted());
}
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class NeoStoresTest method shouldSetHighestTransactionIdWhenNeeded.
@Test
void shouldSetHighestTransactionIdWhenNeeded() {
// 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(42, 6666, BASE_TX_COMMIT_TIMESTAMP, NULL);
// THEN
assertEquals(new TransactionId(42, 6666, 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 HighestTransactionIdTest method shouldHardSetHighest.
@Test
void shouldHardSetHighest() {
// GIVEN
HighestTransactionId highest = new HighestTransactionId(10, 10, 10);
// WHEN
highest.set(8, 1299128, 42);
// THEN
assertEquals(new TransactionId(8, 1299128, 42), highest.get());
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class MetaDataStoreTest method setStoreIdShouldSetAllRelatedFields.
@Test
void setStoreIdShouldSetAllRelatedFields() throws IOException {
// given
int creationTime = 1;
int randomId = 2;
long storeVersion = versionStringToLong(LATEST_STORE_VERSION);
int upgradeTime = 4;
int upgradeTxId = 5;
int upgradeTxChecksum = 6;
long upgradeTxCommitTimestamp = 7;
StoreId storeId = new StoreId(creationTime, randomId, storeVersion, upgradeTime, upgradeTxId);
// when
try (MetaDataStore store = newMetaDataStore()) {
MetaDataStore.setStoreId(pageCache, store.getStorageFile(), storeId, upgradeTxChecksum, upgradeTxCommitTimestamp, databaseLayout.getDatabaseName(), NULL);
}
// then
try (MetaDataStore store = newMetaDataStore()) {
assertEquals(creationTime, store.getCreationTime());
assertEquals(randomId, store.getRandomNumber());
assertEquals(storeVersion, store.getStoreVersion());
assertEquals(upgradeTime, store.getUpgradeTime());
TransactionId expectedTx = new TransactionId(upgradeTxId, upgradeTxChecksum, upgradeTxCommitTimestamp);
assertEquals(expectedTx, store.getUpgradeTransaction());
}
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class MetaDataStoreTest method setUpgradeTransactionMustBeAtomic.
@Test
void setUpgradeTransactionMustBeAtomic() throws Throwable {
try (MetaDataStore store = newMetaDataStore()) {
PagedFile pf = store.pagedFile;
store.setUpgradeTransaction(0, 0, 0, NULL);
AtomicLong writeCount = new AtomicLong();
AtomicLong fileReadCount = new AtomicLong();
AtomicLong apiReadCount = new AtomicLong();
int upperLimit = 10_000;
int lowerLimit = 100;
long endTime = currentTimeMillis() + SECONDS.toMillis(10);
Race race = new Race();
race.withEndCondition(() -> writeCount.get() >= upperLimit && fileReadCount.get() >= upperLimit && apiReadCount.get() >= upperLimit);
race.withEndCondition(() -> writeCount.get() >= lowerLimit && fileReadCount.get() >= lowerLimit && apiReadCount.get() >= lowerLimit && currentTimeMillis() >= endTime);
// writers
race.addContestants(3, () -> {
long count = writeCount.incrementAndGet();
store.setUpgradeTransaction(count, (int) count, count, NULL);
});
// file readers
race.addContestants(3, throwing(() -> {
try (PageCursor cursor = pf.io(0, PagedFile.PF_SHARED_READ_LOCK, NULL)) {
assertTrue(cursor.next());
long id;
long checksum;
do {
id = store.getRecordValue(cursor, MetaDataStore.Position.UPGRADE_TRANSACTION_ID);
checksum = store.getRecordValue(cursor, MetaDataStore.Position.UPGRADE_TRANSACTION_CHECKSUM);
} while (cursor.shouldRetry());
assertIdEqualsChecksum(id, checksum, "file");
fileReadCount.incrementAndGet();
}
}));
race.addContestants(3, () -> {
TransactionId transaction = store.getUpgradeTransaction();
assertIdEqualsChecksum(transaction.transactionId(), transaction.checksum(), "API");
apiReadCount.incrementAndGet();
});
race.go();
}
}
Aggregations