use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class MetaDataStore method setUpgradeTransaction.
public void setUpgradeTransaction(long id, int checksum, long timestamp, CursorContext cursorContext) {
long pageId = pageIdForRecord(Position.UPGRADE_TRANSACTION_ID.id);
assert pageId == pageIdForRecord(Position.UPGRADE_TRANSACTION_CHECKSUM.id);
synchronized (upgradeTransactionLock) {
try (PageCursor cursor = pagedFile.io(pageId, PF_SHARED_WRITE_LOCK, cursorContext)) {
if (!cursor.next()) {
throw new UnderlyingStorageException("Could not access MetaDataStore page " + pageId);
}
setRecord(cursor, Position.UPGRADE_TRANSACTION_ID, id);
setRecord(cursor, Position.UPGRADE_TRANSACTION_CHECKSUM, checksum);
setRecord(cursor, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, timestamp);
upgradeTxIdField = id;
upgradeTxChecksumField = checksum;
upgradeCommitTimestampField = timestamp;
upgradeTransaction = new TransactionId(id, checksum, timestamp);
} catch (IOException e) {
throw new UnderlyingStorageException(e);
}
}
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class HighestTransactionId method offer.
/**
* Offers a transaction id. Will be accepted if this is higher than the current highest.
* This method is thread-safe.
*
* @param transactionId transaction id to compare for highest.
* @param checksum checksum of the transaction.
* @param commitTimestamp commit time for transaction with {@code transactionId}.
* @return {@code true} if the given transaction id was higher than the current highest,
* {@code false}.
*/
public boolean offer(long transactionId, int checksum, long commitTimestamp) {
TransactionId high = highest.get();
if (transactionId < high.transactionId()) {
// a higher id has already been offered
return false;
}
TransactionId update = new TransactionId(transactionId, checksum, commitTimestamp);
while (!highest.compareAndSet(high, update)) {
high = highest.get();
if (high.transactionId() >= transactionId) {
// apparently someone else set a higher id while we were trying to set this id
return false;
}
}
// we set our id as the highest
return true;
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class NeoStoresTest method shouldAddUpgradeFieldsToTheNeoStoreIfNotPresent.
@Test
void shouldAddUpgradeFieldsToTheNeoStoreIfNotPresent() throws IOException {
StoreFactory factory = newStoreFactory(databaseLayout, pageCache, fs);
long recordVersion = defaultStoreVersion();
try (NeoStores neoStores = factory.openAllNeoStores(true)) {
MetaDataStore metaDataStore = neoStores.getMetaDataStore();
metaDataStore.setCreationTime(3, NULL);
metaDataStore.setRandomNumber(4, NULL);
metaDataStore.setCurrentLogVersion(5, NULL);
metaDataStore.setLastCommittedAndClosedTransactionId(6, 42, BASE_TX_COMMIT_TIMESTAMP, 43, 44, NULL);
metaDataStore.setStoreVersion(recordVersion, NULL);
metaDataStore.setLatestConstraintIntroducingTx(9, NULL);
}
Path file = databaseLayout.metadataStore();
assertNotEquals(10, MetaDataStore.getRecord(pageCache, file, Position.UPGRADE_TRANSACTION_ID, databaseLayout.getDatabaseName(), NULL));
assertNotEquals(11, MetaDataStore.getRecord(pageCache, file, Position.UPGRADE_TRANSACTION_CHECKSUM, databaseLayout.getDatabaseName(), NULL));
MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TRANSACTION_ID, 10, databaseLayout.getDatabaseName(), NULL);
MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TRANSACTION_CHECKSUM, 11, databaseLayout.getDatabaseName(), NULL);
MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TIME, 12, databaseLayout.getDatabaseName(), NULL);
try (NeoStores neoStores = factory.openAllNeoStores()) {
MetaDataStore metaDataStore = neoStores.getMetaDataStore();
assertEquals(3, metaDataStore.getCreationTime());
assertEquals(4, metaDataStore.getRandomNumber());
assertEquals(5, metaDataStore.getCurrentLogVersion());
assertEquals(6, metaDataStore.getLastCommittedTransactionId());
assertEquals(recordVersion, metaDataStore.getStoreVersion());
assertEquals(9, metaDataStore.getLatestConstraintIntroducingTx());
assertEquals(new TransactionId(10, 11, BASE_TX_COMMIT_TIMESTAMP), metaDataStore.getUpgradeTransaction());
assertEquals(12, metaDataStore.getUpgradeTime());
assertArrayEquals(new long[] { 6, 44, 43 }, metaDataStore.getLastClosedTransaction());
}
MetaDataStore.setRecord(pageCache, file, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, 13, databaseLayout.getDatabaseName(), NULL);
try (NeoStores neoStores = factory.openAllNeoStores()) {
MetaDataStore metaDataStore = neoStores.getMetaDataStore();
assertEquals(new TransactionId(10, 11, 13), metaDataStore.getUpgradeTransaction());
}
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class TransactionLogInitializerTest method shouldResetMetaDataStoreWithTransactionId.
@Test
void shouldResetMetaDataStoreWithTransactionId() throws Exception {
// Given
var metaStore = mock(MetadataProvider.class);
var txn = new TransactionId(3, -1322858814, currentTimeMillis());
when(metaStore.getStoreId()).thenReturn(new StoreId(versionStringToLong(LATEST_STORE_VERSION)));
when(metaStore.getLastClosedTransaction()).thenReturn(new long[] { txn.transactionId(), 0, 1613 });
when(metaStore.getLastCommittedTransaction()).thenReturn(txn);
when(metaStore.getLastCommittedTransactionId()).thenReturn(txn.transactionId());
when(metaStore.getLastClosedTransactionId()).thenReturn(txn.transactionId());
DatabaseLayout databaseLayout = Neo4jLayout.of(testDirectory.homePath()).databaseLayout(DEFAULT_DATABASE_NAME);
// When
var initializer = new TransactionLogInitializer(testDirectory.getFileSystem(), metaStore, INSTANCE, PageCacheTracer.NULL);
initializer.initializeEmptyLogFile(databaseLayout, databaseLayout.getTransactionLogsDirectory(), "LostFiles");
// Then
verify(metaStore).resetLastClosedTransaction(eq(txn.transactionId()), eq(txn.transactionId()), eq((long) CURRENT_FORMAT_LOG_HEADER_SIZE), eq(true), any());
}
use of org.neo4j.storageengine.api.TransactionId in project neo4j by neo4j.
the class StoreMigratorTest method writeAndReadLastTxInformation.
@Test
void writeAndReadLastTxInformation() throws IOException {
RecordStorageMigrator migrator = newStoreMigrator();
TransactionId writtenTxId = new TransactionId(random.nextLong(), random.nextInt(), random.nextLong());
migrator.writeLastTxInformation(databaseLayout, writtenTxId);
TransactionId readTxId = migrator.readLastTxInformation(databaseLayout);
assertEquals(writtenTxId, readTxId);
}
Aggregations