use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class RaftLogMetadataCacheTest method shouldClearTheCache.
@Test
public void shouldClearTheCache() {
// given
final RaftLogMetadataCache cache = new RaftLogMetadataCache(2);
final long index = 12L;
final long term = 12L;
final LogPosition position = new LogPosition(3, 4);
// when
cache.cacheMetadata(index, term, position);
cache.clear();
RaftLogMetadataCache.RaftLogEntryMetadata metadata = cache.getMetadata(index);
// then
assertNull(metadata);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class RaftLogMetadataCacheTest method shouldReturnTheTxValueTIfInTheCached.
@Test
public void shouldReturnTheTxValueTIfInTheCached() {
// given
final RaftLogMetadataCache cache = new RaftLogMetadataCache(2);
final long index = 12L;
final long term = 12L;
final LogPosition position = new LogPosition(3, 4);
// when
cache.cacheMetadata(index, term, position);
final RaftLogMetadataCache.RaftLogEntryMetadata metadata = cache.getMetadata(index);
// then
assertEquals(new RaftLogMetadataCache.RaftLogEntryMetadata(term, position), metadata);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class StoreMigrator method updateOrAddNeoStoreFieldsAsPartOfMigration.
private void updateOrAddNeoStoreFieldsAsPartOfMigration(File migrationDir, File storeDir, String versionToMigrateTo) throws IOException {
final File storeDirNeoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TRANSACTION_ID, MetaDataStore.getRecord(pageCache, storeDirNeoStore, Position.LAST_TRANSACTION_ID));
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TIME, System.currentTimeMillis());
// Store the checksum of the transaction id the upgrade is at right now. Store it both as
// LAST_TRANSACTION_CHECKSUM and UPGRADE_TRANSACTION_CHECKSUM. Initially the last transaction and the
// upgrade transaction will be the same, but imagine this scenario:
// - legacy store is migrated on instance A at transaction T
// - upgraded store is copied, via backup or HA or whatever to instance B
// - instance A performs a transaction
// - instance B would like to communicate with A where B's last transaction checksum
// is verified on A. A, at this point not having logs from pre-migration era, will need to
// know the checksum of transaction T to accommodate for this request from B. A will be able
// to look up checksums for transactions succeeding T by looking at its transaction logs,
// but T needs to be stored in neostore to be accessible. Obvioously this scenario is only
// problematic as long as we don't migrate and translate old logs.
TransactionId lastTxInfo = readLastTxInformation(migrationDir);
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_TRANSACTION_CHECKSUM, lastTxInfo.checksum());
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TRANSACTION_CHECKSUM, lastTxInfo.checksum());
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.commitTimestamp());
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.UPGRADE_TRANSACTION_COMMIT_TIMESTAMP, lastTxInfo.commitTimestamp());
// add LAST_CLOSED_TRANSACTION_LOG_VERSION and LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET to the migrated
// NeoStore
LogPosition logPosition = readLastTxLogPosition(migrationDir);
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_CLOSED_TRANSACTION_LOG_VERSION, logPosition.getLogVersion());
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, logPosition.getByteOffset());
// Upgrade version in NeoStore
MetaDataStore.setRecord(pageCache, storeDirNeoStore, Position.STORE_VERSION, MetaDataStore.versionStringToLong(versionToMigrateTo));
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class StoreMigrator method extractTransactionLogPosition.
private LogPosition extractTransactionLogPosition(File neoStore, File storeDir, long lastTxId) throws IOException {
long lastClosedTxLogVersion = MetaDataStore.getRecord(pageCache, neoStore, Position.LAST_CLOSED_TRANSACTION_LOG_VERSION);
long lastClosedTxLogByteOffset = MetaDataStore.getRecord(pageCache, neoStore, Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET);
if (lastClosedTxLogVersion != MetaDataRecordFormat.FIELD_NOT_PRESENT && lastClosedTxLogByteOffset != MetaDataRecordFormat.FIELD_NOT_PRESENT) {
return new LogPosition(lastClosedTxLogVersion, lastClosedTxLogByteOffset);
}
// The legacy store we're migrating doesn't have this record in neostore so try to extract it from tx log
if (lastTxId == TransactionIdStore.BASE_TX_ID) {
return new LogPosition(BASE_TX_LOG_VERSION, BASE_TX_LOG_BYTE_OFFSET);
}
PhysicalLogFiles logFiles = new PhysicalLogFiles(storeDir, fileSystem);
long logVersion = logFiles.getHighestLogVersion();
if (logVersion == -1) {
return new LogPosition(BASE_TX_LOG_VERSION, BASE_TX_LOG_BYTE_OFFSET);
}
long offset = fileSystem.getFileSize(logFiles.getLogFileForVersion(logVersion));
return new LogPosition(logVersion, offset);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class LatestCheckPointFinder method latestCheckPoint.
private LatestCheckPoint latestCheckPoint(long fromVersionBackwards, long version, LogEntryStart latestStartEntry, long oldestVersionFound, CheckPoint latestCheckPoint) throws IOException {
// Is the latest start entry in this log file version later than what the latest check point targets?
LogPosition target = latestCheckPoint.getLogPosition();
boolean startEntryAfterCheckPoint = latestStartEntry != null && latestStartEntry.getStartPosition().compareTo(target) >= 0;
if (!startEntryAfterCheckPoint) {
if (target.getLogVersion() < version) {
// This check point entry targets a previous log file.
// Go there and see if there's a transaction. Reader is capped to that log version.
startEntryAfterCheckPoint = extractFirstTxIdAfterPosition(target, version) != LatestCheckPoint.NO_TRANSACTION_ID;
}
}
// Extract first transaction id after check point target position.
// Reader may continue into log files after the initial version.
long firstTxIdAfterCheckPoint = startEntryAfterCheckPoint ? extractFirstTxIdAfterPosition(target, fromVersionBackwards) : LatestCheckPoint.NO_TRANSACTION_ID;
return new LatestCheckPoint(latestCheckPoint, startEntryAfterCheckPoint, firstTxIdAfterCheckPoint, oldestVersionFound);
}
Aggregations