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());
}
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);
}
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);
}
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);
}
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());
}
Aggregations