Search in sources :

Example 61 with LogPosition

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);
}
Also used : LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 62 with LogPosition

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);
}
Also used : LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.Test)

Example 63 with LogPosition

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));
}
Also used : PagedFile(org.neo4j.io.pagecache.PagedFile) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File) TransactionId(org.neo4j.kernel.impl.store.TransactionId) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 64 with LogPosition

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);
}
Also used : LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) PhysicalLogFiles(org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)

Example 65 with LogPosition

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);
}
Also used : LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Aggregations

LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)115 Test (org.junit.jupiter.api.Test)50 File (java.io.File)16 Test (org.junit.Test)16 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)15 Path (java.nio.file.Path)14 IOException (java.io.IOException)11 LogPositionMarker (org.neo4j.kernel.impl.transaction.log.LogPositionMarker)10 LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)10 CheckpointFile (org.neo4j.kernel.impl.transaction.log.files.checkpoint.CheckpointFile)10 StoreId (org.neo4j.storageengine.api.StoreId)10 PhysicalLogFiles (org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles)9 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)8 PhysicalLogFile (org.neo4j.kernel.impl.transaction.log.PhysicalLogFile)8 LogEntryWriter (org.neo4j.kernel.impl.transaction.log.entry.LogEntryWriter)8 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)8 LogTailInformation (org.neo4j.kernel.impl.transaction.log.files.LogTailInformation)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 CommittedTransactionRepresentation (org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation)7 LogEntry (org.neo4j.kernel.impl.transaction.log.entry.LogEntry)7