use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.
the class KernelTransactions method newInstance.
public KernelTransaction newInstance(KernelTransaction.Type type, SecurityContext securityContext, long timeout) {
assertCurrentThreadIsNotBlockingNewTransactions();
SecurityContext frozenSecurityContext = securityContext.freeze();
try {
while (!newTransactionsLock.readLock().tryLock(1, TimeUnit.SECONDS)) {
assertRunning();
}
try {
assertRunning();
TransactionId lastCommittedTransaction = transactionIdStore.getLastCommittedTransaction();
KernelTransactionImplementation tx = localTxPool.acquire();
StatementLocks statementLocks = statementLocksFactory.newInstance();
tx.initialize(lastCommittedTransaction.transactionId(), lastCommittedTransaction.commitTimestamp(), statementLocks, type, frozenSecurityContext, timeout);
return tx;
} finally {
newTransactionsLock.readLock().unlock();
}
} catch (InterruptedException ie) {
Thread.interrupted();
throw new TransactionFailureException("Fail to start new transaction.", ie);
}
}
use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.
the class StoreMigrator method migrate.
@Override
public void migrate(File storeDir, File migrationDir, MigrationProgressMonitor.Section progressMonitor, String versionToMigrateFrom, String versionToMigrateTo) throws IOException {
if (versionToMigrateFrom.equals(StandardV2_0.STORE_VERSION) || versionToMigrateFrom.equals(StandardV2_1.STORE_VERSION) || versionToMigrateFrom.equals(StandardV2_2.STORE_VERSION)) {
// These versions are not supported for block devices.
CustomIOConfigValidator.assertCustomIOConfigNotUsed(config, CUSTOM_IO_EXCEPTION_MESSAGE);
}
// Extract information about the last transaction from legacy neostore
File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
long lastTxId = MetaDataStore.getRecord(pageCache, neoStore, Position.LAST_TRANSACTION_ID);
TransactionId lastTxInfo = extractTransactionIdInformation(neoStore, storeDir, lastTxId);
LogPosition lastTxLogPosition = extractTransactionLogPosition(neoStore, storeDir, lastTxId);
// Write the tx checksum to file in migrationDir, because we need it later when moving files into storeDir
writeLastTxInformation(migrationDir, lastTxInfo);
writeLastTxLogPosition(migrationDir, lastTxLogPosition);
if (versionToMigrateFrom.equals("vE.H.0")) {
// NOTE for 3.0 here is a special case for vE.H.0 "from" record format.
// Legend has it that 3.0.5 enterprise changed store format without changing store version.
// This was done to cheat the migrator to avoid doing store migration since the
// format itself was backwards compatible. Immediately a problem was detected:
// if a user uses 3.0.5 for a while and then goes back to a previous 3.0.x patch release
// the db wouldn't recognize it was an incompatible downgrade and start up normally,
// but read records with scrambled values and pointers, sort of.
//
// This condition has two functions:
// 1. preventing actual store migration between vE.H.0 --> vE.H.0b
// 2. making vE.H.0b used in any migration where either vE.H.0 or vE.H.0b is the existing format,
// this because vE.H.0b is a superset of vE.H.0 and sometimes (for 3.0.5) vE.H.0
// actually means vE.H.0b (in later version).
//
// In later versions of neo4j there are better mechanics in place so that a non-migration like this
// can be performed w/o special casing. To not require backporting that functionality
// this condition is here and should be removed in 3.1.
versionToMigrateFrom = "vE.H.0b";
}
RecordFormats oldFormat = selectForVersion(versionToMigrateFrom);
RecordFormats newFormat = selectForVersion(versionToMigrateTo);
if (FormatFamily.isHigherFamilyFormat(newFormat, oldFormat) || (FormatFamily.isSameFamily(oldFormat, newFormat) && isDifferentCapabilities(oldFormat, newFormat))) {
// TODO if this store has relationship indexes then warn user about that they will be incorrect
// after migration, because now we're rewriting the relationship ids.
// Some form of migration is required (a fallback/catch-all option)
migrateWithBatchImporter(storeDir, migrationDir, lastTxId, lastTxInfo.checksum(), lastTxLogPosition.getLogVersion(), lastTxLogPosition.getByteOffset(), progressMonitor, oldFormat, newFormat);
}
if (versionToMigrateFrom.equals(StandardV2_1.STORE_VERSION)) {
removeDuplicateEntityProperties(storeDir, migrationDir, pageCache, schemaIndexProvider, oldFormat);
}
// DO NOT migrate logs. LegacyLogs is able to migrate logs, but only changes its format, not any
// contents of it, and since the record format has changed there would be a mismatch between the
// commands in the log and the contents in the store. If log migration is to be performed there
// must be a proper translation happening while doing so.
}
use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.
the class StoreMigratorTest method shouldGenerateTransactionInformationWhenLogsAreEmpty.
@Test
public void shouldGenerateTransactionInformationWhenLogsAreEmpty() throws Exception {
// given
long txId = 1;
PageCache pageCache = pageCacheRule.getPageCache(fileSystemRule.get());
File storeDir = directory.graphDbDir();
File neoStore = new File(storeDir, DEFAULT_NAME);
neoStore.createNewFile();
Config config = mock(Config.class);
LogService logService = new SimpleLogService(NullLogProvider.getInstance(), NullLogProvider.getInstance());
LegacyLogs legacyLogs = mock(LegacyLogs.class);
// when
// ... transaction info not in neo store
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_ID));
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_CHECKSUM));
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP));
// ... and transaction not in log
when(legacyLogs.getTransactionInformation(storeDir, txId)).thenReturn(Optional.empty());
// ... and with migrator
StoreMigrator migrator = new StoreMigrator(fileSystemRule.get(), pageCache, config, logService, schemaIndexProvider);
TransactionId actual = migrator.extractTransactionIdInformation(neoStore, storeDir, txId);
// then
assertEquals(txId, actual.transactionId());
assertEquals(TransactionIdStore.BASE_TX_CHECKSUM, actual.checksum());
assertEquals(TransactionIdStore.BASE_TX_COMMIT_TIMESTAMP, actual.commitTimestamp());
}
use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.
the class StoreMigratorTest method shouldGenerateTransactionInformationWhenLogsNotPresent.
@Test
public void shouldGenerateTransactionInformationWhenLogsNotPresent() throws Exception {
// given
long txId = 42;
PageCache pageCache = pageCacheRule.getPageCache(fileSystemRule.get());
File storeDir = directory.graphDbDir();
File neoStore = new File(storeDir, DEFAULT_NAME);
neoStore.createNewFile();
Config config = mock(Config.class);
LogService logService = new SimpleLogService(NullLogProvider.getInstance(), NullLogProvider.getInstance());
LegacyLogs legacyLogs = mock(LegacyLogs.class);
// when
// ... transaction info not in neo store
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_ID));
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_CHECKSUM));
assertEquals(FIELD_NOT_PRESENT, getRecord(pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP));
// ... and transaction not in log
when(legacyLogs.getTransactionInformation(storeDir, txId)).thenReturn(Optional.empty());
// ... and with migrator
StoreMigrator migrator = new StoreMigrator(fileSystemRule.get(), pageCache, config, logService, schemaIndexProvider);
TransactionId actual = migrator.extractTransactionIdInformation(neoStore, storeDir, txId);
// then
assertEquals(txId, actual.transactionId());
assertEquals(TransactionIdStore.UNKNOWN_TX_CHECKSUM, actual.checksum());
assertEquals(TransactionIdStore.UNKNOWN_TX_COMMIT_TIMESTAMP, actual.commitTimestamp());
}
use of org.neo4j.kernel.impl.store.TransactionId in project neo4j by neo4j.
the class StoreMigratorTest method shouldExtractTransactionInformationFromMetaDataStore.
@Test
public void shouldExtractTransactionInformationFromMetaDataStore() throws Exception {
// given
// ... variables
long txId = 42;
long checksum = 123456789123456789L;
long timestamp = 919191919191919191L;
TransactionId expected = new TransactionId(txId, checksum, timestamp);
// ... and files
PageCache pageCache = pageCacheRule.getPageCache(fileSystemRule.get());
File storeDir = directory.graphDbDir();
File neoStore = new File(storeDir, DEFAULT_NAME);
neoStore.createNewFile();
// ... and mocks
Config config = mock(Config.class);
LogService logService = mock(LogService.class);
// when
// ... data in record
setRecord(pageCache, neoStore, LAST_TRANSACTION_ID, txId);
setRecord(pageCache, neoStore, LAST_TRANSACTION_CHECKSUM, checksum);
setRecord(pageCache, neoStore, LAST_TRANSACTION_COMMIT_TIMESTAMP, timestamp);
// ... and with migrator
StoreMigrator migrator = new StoreMigrator(fileSystemRule.get(), pageCache, config, logService, NO_INDEX_PROVIDER);
TransactionId actual = migrator.extractTransactionIdInformation(neoStore, storeDir, txId);
// then
assertEquals(expected, actual);
}
Aggregations