use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.
the class DetachedCheckpointLogEntryParser method parse.
@Override
LogEntry parse(KernelVersion version, ReadableChecksumChannel channel, LogPositionMarker marker, CommandReaderFactory commandReaderFactory) throws IOException {
long logVersion = channel.getLong();
long byteOffset = channel.getLong();
long checkpointTimeMillis = channel.getLong();
StoreId storeId = new StoreId(channel.getLong(), channel.getLong(), channel.getLong(), channel.getLong(), channel.getLong());
short reasonBytesLength = channel.getShort();
byte[] bytes = new byte[MAX_DESCRIPTION_LENGTH];
channel.get(bytes, MAX_DESCRIPTION_LENGTH);
String reason = new String(bytes, 0, reasonBytesLength, UTF_8);
channel.endChecksumAndValidate();
return new LogEntryDetachedCheckpoint(version, new LogPosition(logVersion, byteOffset), checkpointTimeMillis, storeId, reason);
}
use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.
the class TransactionLogInitializerTest method shouldResetMetaDataStoreWithTransactionId.
@Test
void shouldResetMetaDataStoreWithTransactionId() throws Exception {
// Given
var metaStore = mock(MetadataProvider.class);
var txn = new TransactionId(3, -1322858814, currentTimeMillis());
when(metaStore.getStoreId()).thenReturn(new StoreId(versionStringToLong(LATEST_STORE_VERSION)));
when(metaStore.getLastClosedTransaction()).thenReturn(new long[] { txn.transactionId(), 0, 1613 });
when(metaStore.getLastCommittedTransaction()).thenReturn(txn);
when(metaStore.getLastCommittedTransactionId()).thenReturn(txn.transactionId());
when(metaStore.getLastClosedTransactionId()).thenReturn(txn.transactionId());
DatabaseLayout databaseLayout = Neo4jLayout.of(testDirectory.homePath()).databaseLayout(DEFAULT_DATABASE_NAME);
// When
var initializer = new TransactionLogInitializer(testDirectory.getFileSystem(), metaStore, INSTANCE, PageCacheTracer.NULL);
initializer.initializeEmptyLogFile(databaseLayout, databaseLayout.getTransactionLogsDirectory(), "LostFiles");
// Then
verify(metaStore).resetLastClosedTransaction(eq(txn.transactionId()), eq(txn.transactionId()), eq((long) CURRENT_FORMAT_LOG_HEADER_SIZE), eq(true), any());
}
use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.
the class DetachedCheckpointLogEntryParserTest method parseDetachedCheckpointRecord.
@Test
void parseDetachedCheckpointRecord() throws IOException {
KernelVersion version = KernelVersion.V4_3_D4;
var storeId = new StoreId(4, 5, 6, 7, 8);
var channel = new InMemoryClosableChannel();
int checkpointMillis = 3;
String checkpointDescription = "checkpoint";
byte[] bytes = Arrays.copyOf(checkpointDescription.getBytes(), 120);
// For version confusion, please read LogEntryParserSetV4_3 comments
var checkpoint = new LogEntryDetachedCheckpoint(version, new LogPosition(1, 2), checkpointMillis, storeId, checkpointDescription);
channel.putLong(checkpoint.getLogPosition().getLogVersion()).putLong(checkpoint.getLogPosition().getByteOffset()).putLong(checkpointMillis).putLong(storeId.getCreationTime()).putLong(storeId.getRandomId()).putLong(storeId.getStoreVersion()).putLong(storeId.getUpgradeTime()).putLong(storeId.getUpgradeTxId()).putShort((short) checkpointDescription.getBytes().length).put(bytes, bytes.length);
channel.putChecksum();
var checkpointParser = LogEntryParserSets.parserSet(version).select(DETACHED_CHECK_POINT);
LogEntry logEntry = checkpointParser.parse(version, channel, positionMarker, commandReader);
assertEquals(checkpoint, logEntry);
}
use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.
the class InlinedLogTailScanner method findLogTail.
protected LogTailInformation findLogTail() throws IOException {
LogFile logFile = logFiles.getLogFile();
final long highestLogVersion = logFile.getHighestLogVersion();
long version = highestLogVersion;
long versionToSearchForCommits = highestLogVersion;
LogEntryStart latestStartEntry = null;
long oldestStartEntryTransaction = NO_TRANSACTION_ID;
long oldestVersionFound = -1;
byte latestLogEntryVersion = 0;
boolean startRecordAfterCheckpoint = false;
boolean corruptedTransactionLogs = false;
while (version >= logFile.getLowestLogVersion() && version >= INITIAL_LOG_VERSION) {
log.info("Scanning log file with version %d for checkpoint entries", version);
oldestVersionFound = version;
CheckpointInfo latestCheckPoint = null;
StoreId storeId = StoreId.UNKNOWN;
try (LogVersionedStoreChannel channel = logFile.openForVersion(version);
var readAheadChannel = new ReadAheadLogChannel(channel, memoryTracker);
LogEntryCursor cursor = new LogEntryCursor(logEntryReader, readAheadChannel)) {
LogHeader logHeader = logFile.extractHeader(version);
storeId = logHeader.getStoreId();
LogEntry entry;
long position = logHeader.getStartPosition().getByteOffset();
long channelVersion = version;
while (cursor.next()) {
entry = cursor.get();
// Collect data about latest checkpoint
if (entry instanceof LogEntryInlinedCheckPoint) {
latestCheckPoint = new CheckpointInfo((LogEntryInlinedCheckPoint) entry, storeId, new LogPosition(channelVersion, position));
} else if (entry instanceof LogEntryCommit) {
if (oldestStartEntryTransaction == NO_TRANSACTION_ID) {
oldestStartEntryTransaction = ((LogEntryCommit) entry).getTxId();
}
} else if (entry instanceof LogEntryStart) {
LogEntryStart startEntry = (LogEntryStart) entry;
if (version == versionToSearchForCommits) {
latestStartEntry = startEntry;
}
startRecordAfterCheckpoint = true;
}
// Collect data about latest entry version, only in first log file
if (version == versionToSearchForCommits || latestLogEntryVersion == 0) {
latestLogEntryVersion = entry.getVersion().version();
}
position = channel.position();
channelVersion = channel.getVersion();
}
verifyReaderPosition(version, logEntryReader.lastPosition());
} catch (Error | ClosedByInterruptException e) {
// These should not be parsing errors
throw e;
} catch (Throwable t) {
monitor.corruptedLogFile(version, t);
if (failOnCorruptedLogFiles) {
throwUnableToCleanRecover(t);
}
corruptedTransactionLogs = true;
}
if (latestCheckPoint != null) {
return checkpointTailInformation(highestLogVersion, latestStartEntry, oldestVersionFound, latestLogEntryVersion, latestCheckPoint, corruptedTransactionLogs, storeId);
}
version--;
// if we have found no commits in the latest log, keep searching in the next one
if (latestStartEntry == null) {
versionToSearchForCommits--;
}
}
return new LogTailInformation(corruptedTransactionLogs || startRecordAfterCheckpoint, oldestStartEntryTransaction, oldestVersionFound == UNKNOWN, highestLogVersion, latestLogEntryVersion);
}
use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.
the class LogHeaderWriter method writeLogHeader.
public static void writeLogHeader(StoreChannel channel, LogHeader logHeader, MemoryTracker memoryTracker) throws IOException {
try (var scopedBuffer = new HeapScopedBuffer(CURRENT_FORMAT_LOG_HEADER_SIZE, memoryTracker)) {
var buffer = scopedBuffer.getBuffer();
buffer.putLong(encodeLogVersion(logHeader.getLogVersion(), logHeader.getLogFormatVersion()));
buffer.putLong(logHeader.getLastCommittedTxId());
StoreId storeId = logHeader.getStoreId();
buffer.putLong(storeId.getCreationTime());
buffer.putLong(storeId.getRandomId());
buffer.putLong(storeId.getStoreVersion());
buffer.putLong(storeId.getUpgradeTime());
buffer.putLong(storeId.getUpgradeTxId());
buffer.putLong(0);
buffer.flip();
channel.writeAll(buffer);
}
}
Aggregations