use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CheckTxLogs method validateCheckPoints.
boolean validateCheckPoints(PhysicalLogFiles logFiles, InconsistenciesHandler handler) throws IOException {
final long lowestLogVersion = logFiles.getLowestLogVersion();
final long highestLogVersion = logFiles.getHighestLogVersion();
boolean success = true;
try (PrimitiveLongLongMap logFileSizes = Primitive.offHeapLongLongMap()) {
for (long i = lowestLogVersion; i <= highestLogVersion; i++) {
logFileSizes.put(i, fs.getFileSize(logFiles.getLogFileForVersion(i)));
}
LogEntryCursor logEntryCursor = LogTestUtils.openLogs(fs, logFiles);
while (logEntryCursor.next()) {
LogEntry logEntry = logEntryCursor.get();
if (logEntry instanceof CheckPoint) {
LogPosition logPosition = logEntry.<CheckPoint>as().getLogPosition();
// if the file has been pruned we cannot validate the check point
if (logPosition.getLogVersion() >= lowestLogVersion) {
long size = logFileSizes.get(logPosition.getLogVersion());
if (logPosition.getByteOffset() < 0 || size < 0 || logPosition.getByteOffset() > size) {
long currentLogVersion = logEntryCursor.getCurrentLogVersion();
handler.reportInconsistentCheckPoint(currentLogVersion, logPosition, size);
success = false;
}
}
}
}
}
return success;
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CheckTxLogsTest method writeCheckPoint.
private void writeCheckPoint(File log, long logVersion, long byteOffset) throws IOException {
LogPosition logPosition = new LogPosition(logVersion, byteOffset);
writeContent(log, (txWriter) -> txWriter.checkPoint(logPosition));
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class CheckTxLogsTest method shouldDetectAnInconsistentCheckPointPointingToAByteOffsetNotInTheFile.
@Test
public void shouldDetectAnInconsistentCheckPointPointingToAByteOffsetNotInTheFile() throws Exception {
// given
ensureLogExists(logFile(1));
writeCheckPoint(logFile(2), 1, 42);
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(2, handler.checkPointInconsistencies.get(0).logVersion);
assertEquals(new LogPosition(1, 42), handler.checkPointInconsistencies.get(0).logPosition);
assertEquals(LOG_HEADER_SIZE, handler.checkPointInconsistencies.get(0).size);
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class TransactionLogCatchUpWriter method close.
@Override
public synchronized void close() throws IOException {
if (asPartOfStoreCopy) {
/* A checkpoint which points to the beginning of the log file, meaning that
all the streamed transactions will be applied as part of recovery. */
long logVersion = logFiles.getHighestLogVersion();
writer.checkPoint(new LogPosition(logVersion, LOG_HEADER_SIZE));
// * comment copied from old StoreCopyClient *
// since we just create new log and put checkpoint into it with offset equals to
// LOG_HEADER_SIZE we need to update last transaction offset to be equal to this newly defined max
// offset otherwise next checkpoint that use last transaction offset will be created for non
// existing offset that is in most of the cases bigger than new log size.
// Recovery will treat that as last checkpoint and will not try to recover store till new
// last closed transaction offset will not overcome old one. Till that happens it will be
// impossible for recovery process to restore the store
File neoStore = new File(storeDir, MetaDataStore.DEFAULT_NAME);
MetaDataStore.setRecord(pageCache, neoStore, MetaDataStore.Position.LAST_CLOSED_TRANSACTION_LOG_BYTE_OFFSET, LOG_HEADER_SIZE);
}
lifespan.close();
if (lastTxId != -1) {
File neoStoreFile = new File(storeDir, MetaDataStore.DEFAULT_NAME);
MetaDataStore.setRecord(pageCache, neoStoreFile, LAST_TRANSACTION_ID, lastTxId);
}
}
use of org.neo4j.kernel.impl.transaction.log.LogPosition in project neo4j by neo4j.
the class RaftLogMetadataCacheTest method shouldRemoveUpTo.
@Test
public void shouldRemoveUpTo() throws Exception {
// given
int cacheSize = 100;
RaftLogMetadataCache cache = new RaftLogMetadataCache(cacheSize);
for (int i = 0; i < cacheSize; i++) {
cache.cacheMetadata(i, i, new LogPosition(i, i));
}
// when
int upTo = 30;
cache.removeUpTo(upTo);
// then
long i = 0;
for (; i <= upTo; i++) {
assertNull(cache.getMetadata(i));
}
for (; i < cacheSize; i++) {
RaftLogMetadataCache.RaftLogEntryMetadata metadata = cache.getMetadata(i);
assertNotNull(metadata);
assertEquals(i, metadata.getEntryTerm());
}
}
Aggregations