Search in sources :

Example 1 with StoreId

use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.

the class LogHeaderReaderTest method setUp.

@BeforeEach
void setUp() {
    expectedLogVersion = random.nextLong(0, LOG_VERSION_MASK);
    expectedTxId = random.nextLong();
    expectedStoreId = new StoreId(random.nextLong(), random.nextLong(), random.nextLong(), random.nextLong(), random.nextLong());
}
Also used : StoreId(org.neo4j.storageengine.api.StoreId) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with StoreId

use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.

the class LogHeaderWriterTest method setUp.

@BeforeEach
void setUp() {
    expectedLogVersion = random.nextLong(0, LOG_VERSION_MASK);
    expectedTxId = random.nextLong(0, Long.MAX_VALUE);
    expectedStoreId = new StoreId(random.nextLong(), random.nextLong(), random.nextLong(), random.nextLong(), random.nextLong());
    logHeader = new LogHeader(expectedLogVersion, expectedTxId, expectedStoreId);
}
Also used : StoreId(org.neo4j.storageengine.api.StoreId) LogHeaderWriter.writeLogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeaderWriter.writeLogHeader) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with StoreId

use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.

the class LogHeaderWriterTest method shouldWriteALogHeaderInAStoreChannel.

@Test
void shouldWriteALogHeaderInAStoreChannel() throws IOException {
    // given
    final Path file = testDirectory.file("WriteLogHeader");
    final StoreChannel channel = fileSystem.write(file);
    // when
    writeLogHeader(channel, logHeader, INSTANCE);
    channel.close();
    // then
    final byte[] array = new byte[CURRENT_FORMAT_LOG_HEADER_SIZE];
    try (InputStream stream = fileSystem.openAsInputStream(file)) {
        int read = stream.read(array);
        assertEquals(CURRENT_FORMAT_LOG_HEADER_SIZE, read);
    }
    final ByteBuffer result = ByteBuffer.wrap(array);
    long encodedLogVersions = result.getLong();
    assertEquals(encodeLogVersion(expectedLogVersion, CURRENT_LOG_FORMAT_VERSION), encodedLogVersions);
    byte logFormatVersion = decodeLogFormatVersion(encodedLogVersions);
    assertEquals(CURRENT_LOG_FORMAT_VERSION, logFormatVersion);
    long logVersion = decodeLogVersion(encodedLogVersions);
    assertEquals(expectedLogVersion, logVersion);
    long txId = result.getLong();
    assertEquals(expectedTxId, txId);
    StoreId storeId = new StoreId(result.getLong(), result.getLong(), result.getLong(), result.getLong(), result.getLong());
    assertEquals(expectedStoreId, storeId);
}
Also used : Path(java.nio.file.Path) StoreId(org.neo4j.storageengine.api.StoreId) InputStream(java.io.InputStream) StoreChannel(org.neo4j.io.fs.StoreChannel) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 4 with StoreId

use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.

the class LogFilesBuilder method buildContext.

TransactionLogFilesContext buildContext() throws IOException {
    if (logEntryReader == null) {
        requireNonNull(commandReaderFactory);
        logEntryReader = new VersionAwareLogEntryReader(commandReaderFactory);
    }
    if (config == null) {
        config = Config.defaults();
    }
    requireNonNull(fileSystem);
    Supplier<StoreId> storeIdSupplier = getStoreId();
    Supplier<LogVersionRepository> logVersionRepositorySupplier = getLogVersionRepositorySupplier();
    LongSupplier lastCommittedIdSupplier = lastCommittedIdSupplier();
    LongSupplier committingTransactionIdSupplier = committingIdSupplier();
    Supplier<LogPosition> lastClosedTransactionPositionSupplier = closePositionSupplier();
    // Register listener for rotation threshold
    AtomicLong rotationThreshold = getRotationThresholdAndRegisterForUpdates();
    AtomicBoolean tryPreallocateTransactionLogs = getTryToPreallocateTransactionLogs();
    var nativeAccess = getNativeAccess();
    var monitors = getMonitors();
    var health = getDatabaseHealth();
    var clock = getClock();
    // Or the latest version if we can't find the system db version.
    if (kernelVersionRepository == null) {
        kernelVersionRepository = () -> KernelVersion.LATEST;
        if (dependencies != null) {
            try {
                this.kernelVersionRepository = dependencies.resolveDependency(KernelVersionRepository.class);
            } catch (UnsatisfiedDependencyException e) {
            // Use latest version if can't find version repository.
            }
        }
    }
    return new TransactionLogFilesContext(rotationThreshold, tryPreallocateTransactionLogs, logEntryReader, lastCommittedIdSupplier, committingTransactionIdSupplier, lastClosedTransactionPositionSupplier, logVersionRepositorySupplier, fileSystem, logProvider, databaseTracers, storeIdSupplier, nativeAccess, memoryTracker, monitors, config.get(fail_on_corrupted_log_files), health, kernelVersionRepository, clock, config);
}
Also used : LogVersionRepository(org.neo4j.storageengine.api.LogVersionRepository) KernelVersionRepository(org.neo4j.storageengine.api.KernelVersionRepository) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) UnsatisfiedDependencyException(org.neo4j.exceptions.UnsatisfiedDependencyException) StoreId(org.neo4j.storageengine.api.StoreId) VersionAwareLogEntryReader(org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader) LongSupplier(java.util.function.LongSupplier) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Example 5 with StoreId

use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.

the class DetachedLogTailScanner method isValidCheckpoint.

/**
 * Valid checkpoint points to valid location in a file, which exists and header store id matches with checkpoint store id.
 * Otherwise checkpoint is not considered valid and we need to recover.
 */
private boolean isValidCheckpoint(LogFile logFile, CheckpointInfo checkpointInfo) throws IOException {
    LogPosition logPosition = checkpointInfo.getTransactionLogPosition();
    long logVersion = logPosition.getLogVersion();
    if (!logFile.versionExists(logVersion)) {
        return false;
    }
    Path logFileForVersion = logFile.getLogFileForVersion(logVersion);
    if (fileSystem.getFileSize(logFileForVersion) < logPosition.getByteOffset()) {
        return false;
    }
    LogHeader logHeader = logFile.extractHeader(logVersion);
    StoreId headerStoreId = logHeader.getStoreId();
    return StoreId.UNKNOWN.equals(headerStoreId) || headerStoreId.equalsIgnoringVersion(checkpointInfo.storeId());
}
Also used : Path(java.nio.file.Path) StoreId(org.neo4j.storageengine.api.StoreId) LogHeader(org.neo4j.kernel.impl.transaction.log.entry.LogHeader) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition)

Aggregations

StoreId (org.neo4j.storageengine.api.StoreId)20 Test (org.junit.jupiter.api.Test)9 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)9 ExternalStoreId (org.neo4j.storageengine.api.ExternalStoreId)3 Path (java.nio.file.Path)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 InMemoryClosableChannel (org.neo4j.kernel.impl.transaction.log.InMemoryClosableChannel)2 LogEntryDetachedCheckpoint (org.neo4j.kernel.impl.transaction.log.entry.LogEntryDetachedCheckpoint)2 LogEntryInlinedCheckPoint (org.neo4j.kernel.impl.transaction.log.entry.LogEntryInlinedCheckPoint)2 LogHeader (org.neo4j.kernel.impl.transaction.log.entry.LogHeader)2 TransactionId (org.neo4j.storageengine.api.TransactionId)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 LongSupplier (java.util.function.LongSupplier)1 UnsatisfiedDependencyException (org.neo4j.exceptions.UnsatisfiedDependencyException)1 StoreChannel (org.neo4j.io.fs.StoreChannel)1