use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class LogEntryParserDispatcherV6Test method failToParseCheckpointWithLatestFormat.
@Test
void failToParseCheckpointWithLatestFormat() {
var checkPoint = new LogEntryInlinedCheckPoint(version, new LogPosition(43, 44));
var channel = new InMemoryClosableChannel();
channel.putLong(checkPoint.getLogPosition().getLogVersion());
channel.putLong(checkPoint.getLogPosition().getByteOffset());
channel.putChecksum();
channel.getCurrentPosition(marker);
assertThrows(Exception.class, () -> parserSet(LATEST).select(LEGACY_CHECK_POINT));
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class VersionAwareLogEntryReader method readLogEntry.
@Override
public LogEntry readLogEntry(ReadableClosablePositionAwareChecksumChannel channel) throws IOException {
try {
while (true) {
channel.getCurrentPosition(positionMarker);
byte versionCode = channel.get();
if (versionCode == 0) {
// and we report that we reach end of record stream from our point of view
if (channel instanceof PositionableChannel) {
resetChannelPosition(channel);
} else {
throw new IllegalStateException("Log reader expects positionable channel to be able to reset offset. Current channel: " + channel);
}
return null;
}
if (parserSet == null || parserSet.getIntroductionVersion().version() != versionCode) {
try {
parserSet = LogEntryParserSets.parserSet(KernelVersion.getForVersion(versionCode));
} catch (IllegalArgumentException e) {
throw new UnsupportedLogVersionException(String.format("Log file contains entries with prefix %d, and the lowest supported prefix is %s. This " + "indicates that the log files originates from an older version of neo4j, which we don't support " + "migrations from.", versionCode, KernelVersion.V2_3));
}
// a new checksum segment if we change version parser.
if (channel instanceof PositionableChannel) {
resetChannelPosition(channel);
channel.beginChecksum();
channel.get();
}
}
byte typeCode = channel.get();
LogEntryParser entryReader;
LogEntry entry;
try {
entryReader = parserSet.select(typeCode);
entry = entryReader.parse(parserSet.getIntroductionVersion(), channel, positionMarker, commandReaderFactory);
} catch (ReadPastEndException e) {
// Make these exceptions slip by straight out to the outer handler
throw e;
} catch (Exception e) {
// Tag all other exceptions with log position and other useful information
LogPosition position = positionMarker.newPosition();
withMessage(e, e.getMessage() + ". At position " + position + " and entry version " + versionCode);
throwIfInstanceOf(e, UnsupportedLogVersionException.class);
throw new IOException(e);
}
verifyChecksumChain(entry);
return entry;
}
} catch (ReadPastEndException e) {
return null;
}
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition 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);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition 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.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CheckTxLogsTest method shouldDetectAnInconsistentCheckPointPointingToALogFileGreaterThanMaxLogVersion.
@Test
public void shouldDetectAnInconsistentCheckPointPointingToALogFileGreaterThanMaxLogVersion() throws Exception {
// given
File log = logFile(1);
writeCheckPoint(log, 2, LOG_HEADER_SIZE);
CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
// when
checker.validateCheckPoints(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler);
// then
assertEquals(1, handler.checkPointInconsistencies.size());
assertEquals(1, handler.checkPointInconsistencies.get(0).logVersion);
assertEquals(new LogPosition(2, LOG_HEADER_SIZE), handler.checkPointInconsistencies.get(0).logPosition);
assertThat(handler.checkPointInconsistencies.get(0).size, lessThan(0L));
}
Aggregations