use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.
the class LogHeaderReader method readLogHeader.
/**
* Reads the header of a log. Data will be read from {@code channel} using supplied {@code buffer}
* as to allow more controlled allocation.
*
* @param buffer {@link ByteBuffer} to read into. Passed in to allow control over allocation.
* @param channel {@link ReadableByteChannel} to read from, typically a channel over a file containing the data.
* @param strict if {@code true} then will fail with {@link IncompleteLogHeaderException} on incomplete
* header, i.e. if there's not enough data in the channel to even read the header. If {@code false} then
* the return value will instead be {@code null}.
* @param fileForAdditionalErrorInformationOrNull when in {@code strict} mode the exception can be
* amended with information about which file the channel represents, if any. Purely for better forensics
* ability.
* @return {@link LogHeader} containing the log header data from the {@code channel}.
* @throws IOException if unable to read from {@code channel}
* @throws IncompleteLogHeaderException if {@code strict} and not enough data could be read
*/
public static LogHeader readLogHeader(ByteBuffer buffer, ReadableByteChannel channel, boolean strict, Path fileForAdditionalErrorInformationOrNull) throws IOException {
// Decode first part of the header that contains the version
if (!safeRead(buffer, channel, LOG_HEADER_VERSION_SIZE, strict, fileForAdditionalErrorInformationOrNull)) {
return null;
}
long encodedLogVersions = buffer.getLong();
if (encodedLogVersions == 0) {
// Since the format version is a non-zero number, we know we are reading a pre-allocated file
return null;
}
byte logFormatVersion = decodeLogFormatVersion(encodedLogVersions);
long logVersion = decodeLogVersion(encodedLogVersions);
// The header's total length differs from versions
if (logFormatVersion == LOG_VERSION_3_5) {
if (!safeRead(buffer, channel, Long.BYTES, strict, fileForAdditionalErrorInformationOrNull)) {
return null;
}
long previousCommittedTx = buffer.getLong();
return new LogHeader(logFormatVersion, logVersion, previousCommittedTx, LOG_HEADER_SIZE_3_5);
}
if (logFormatVersion == LOG_VERSION_4_0) {
if (!safeRead(buffer, channel, LOG_HEADER_SIZE_4_0 - LOG_HEADER_VERSION_SIZE, strict, fileForAdditionalErrorInformationOrNull)) {
return null;
}
long previousCommittedTx = buffer.getLong();
StoreId storeId = new StoreId(buffer.getLong(), buffer.getLong(), buffer.getLong(), buffer.getLong(), buffer.getLong());
// reserved
buffer.getLong();
return new LogHeader(logFormatVersion, logVersion, previousCommittedTx, storeId, LOG_HEADER_SIZE_4_0);
}
throw new IOException("Unrecognized transaction log format version: " + logFormatVersion);
}
use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.
the class TransactionRangeDiagnosticsTest method shouldLogCorrectTransactionLogDiagnosticsForTransactionsAndCheckpointLogs.
@Test
void shouldLogCorrectTransactionLogDiagnosticsForTransactionsAndCheckpointLogs() throws Exception {
// GIVEN
long txLogLowVersion = 2;
long txLogHighVersion = 10;
long checkpointLogLowVersion = 0;
long checkpointLogHighVersion = 3;
StoreId storeId = new StoreId(12345);
LogPosition checkpointLogPosition = new LogPosition(checkpointLogHighVersion, 34);
Database database = databaseWithLogFilesContainingLowestTxId(logs(transactionLogsWithTransaction(txLogLowVersion, txLogHighVersion, 42), checkpointLogsWithLastCheckpoint(checkpointLogLowVersion, checkpointLogHighVersion, new CheckpointInfo(new LogEntryDetachedCheckpoint(KernelVersion.LATEST, checkpointLogPosition, 1234, storeId, "testing"), checkpointLogPosition))));
AssertableLogProvider logProvider = new AssertableLogProvider();
Log logger = logProvider.getLog(getClass());
// WHEN
new TransactionRangeDiagnostics(database).dump(logger::info);
// THEN
assertThat(logProvider).containsMessages("existing transaction log versions " + txLogLowVersion + "-" + txLogHighVersion).containsMessages("existing checkpoint log versions " + checkpointLogLowVersion + "-" + checkpointLogHighVersion);
}
use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.
the class CheckpointInfoTest method checkpointInfoOfLegacyCheckpointEntry.
@Test
void checkpointInfoOfLegacyCheckpointEntry() {
var logPosition = new LogPosition(0, 1);
StoreId storeId = new StoreId(1, 2, 3, 4, 5);
LogPosition position = new LogPosition(1, 2);
var checkpointInfo = new CheckpointInfo(new LogEntryInlinedCheckPoint(logPosition), storeId, position);
assertSame(logPosition, checkpointInfo.getTransactionLogPosition());
assertSame(storeId, checkpointInfo.storeId());
assertSame(position, checkpointInfo.getCheckpointEntryPosition());
}
use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.
the class MetaDataStore method initialiseNewStoreFile.
@Override
protected void initialiseNewStoreFile(CursorContext cursorContext) throws IOException {
super.initialiseNewStoreFile(cursorContext);
long storeVersionAsLong = MetaDataStore.versionStringToLong(storeVersion);
StoreId storeId = new StoreId(storeVersionAsLong);
setCreationTime(storeId.getCreationTime(), cursorContext);
setRandomNumber(storeId.getRandomId(), cursorContext);
// If metaDataStore.creationTime == metaDataStore.upgradeTime && metaDataStore.upgradeTransactionId == BASE_TX_ID
// then store has never been upgraded
setUpgradeTime(storeId.getCreationTime(), cursorContext);
setUpgradeTransaction(BASE_TX_ID, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP, cursorContext);
setCurrentLogVersion(0, cursorContext);
setLastCommittedAndClosedTransactionId(BASE_TX_ID, BASE_TX_CHECKSUM, BASE_TX_COMMIT_TIMESTAMP, BASE_TX_LOG_BYTE_OFFSET, BASE_TX_LOG_VERSION, cursorContext);
setStoreVersion(storeVersionAsLong, cursorContext);
setLatestConstraintIntroducingTx(0, cursorContext);
setExternalStoreUUID(UUID.randomUUID(), cursorContext);
setCheckpointLogVersion(0, cursorContext);
setKernelVersion(KernelVersion.LATEST, cursorContext);
setDatabaseIdUuid(NOT_INITIALIZED_UUID, cursorContext);
flush(cursorContext);
}
use of org.neo4j.storageengine.api.StoreId in project neo4j by neo4j.
the class DetachedCheckpointLogEntryWriterTest method writeCheckpoint.
private static void writeCheckpoint(DetachedCheckpointLogEntryWriter checkpointLogEntryWriter, String reason) throws IOException {
var storeId = new StoreId(3, 4, 5, 6, 7);
LogPosition logPosition = new LogPosition(1, 2);
checkpointLogEntryWriter.writeCheckPointEntry(logPosition, Instant.ofEpochMilli(1), storeId, reason);
}
Aggregations