use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class RebuildFromLogs method rebuild.
public void rebuild(File source, File target, long txId) throws Exception, InconsistentStoreException {
try (PageCache pageCache = StandalonePageCacheFactory.createPageCache(fs)) {
PhysicalLogFiles logFiles = new PhysicalLogFiles(source, fs);
long highestVersion = logFiles.getHighestLogVersion();
if (highestVersion < 0) {
printUsage("Inconsistent number of log files found in " + source);
return;
}
long txCount = findLastTransactionId(logFiles, highestVersion);
ProgressMonitorFactory progress;
if (txCount < 0) {
progress = ProgressMonitorFactory.NONE;
System.err.println("Unable to report progress, cannot find highest txId, attempting rebuild anyhow.");
} else {
progress = ProgressMonitorFactory.textual(System.err);
}
progress.singlePart(format("Rebuilding store from %s transactions ", txCount), txCount);
long lastTxId;
try (TransactionApplier applier = new TransactionApplier(fs, target, pageCache)) {
lastTxId = applier.applyTransactionsFrom(source, txId);
}
// set last tx id in neostore otherwise the db is not usable
MetaDataStore.setRecord(pageCache, new File(target, MetaDataStore.DEFAULT_NAME), MetaDataStore.Position.LAST_TRANSACTION_ID, lastTxId);
checkConsistency(target, pageCache);
}
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class CheckTxLogsTest method shouldReportNoInconsistenciesIfTxIdSequenceIsStriclyIncreasingAndHasNoGaps.
@Test
public void shouldReportNoInconsistenciesIfTxIdSequenceIsStriclyIncreasingAndHasNoGaps() throws Exception {
// given
Function<Long, Command.NodeCommand> newNodeCommandFunction = (i) -> new Command.NodeCommand(new NodeRecord(i, false, false, -1, -1, -1), new NodeRecord(i, true, false, -1, -1, -1));
writeTxContent(logFile(1), 40L, newNodeCommandFunction.apply(1L));
writeTxContent(logFile(1), 41L, newNodeCommandFunction.apply(2L));
writeTxContent(logFile(1), 42L, newNodeCommandFunction.apply(3L));
writeTxContent(logFile(2), 43L, newNodeCommandFunction.apply(4L));
writeTxContent(logFile(2), 44L, newNodeCommandFunction.apply(5L));
writeTxContent(logFile(2), 45L, newNodeCommandFunction.apply(6L));
CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
// when
checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, CHECK_TYPES);
// then
assertTrue(handler.txIdSequenceInconsistencies.isEmpty());
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class CheckTxLogsTest method shouldReportNeoStoreInconsistenciesFromDifferentLogs.
@Test
public void shouldReportNeoStoreInconsistenciesFromDifferentLogs() throws IOException {
// Given
File log1 = logFile(1);
File log2 = logFile(2);
File log3 = logFile(3);
writeTxContent(log1, 0, new Command.NeoStoreCommand(new NeoStoreRecord(), createNeoStoreRecord(42)), new Command.PropertyCommand(propertyRecord(5, false, -1, -1), propertyRecord(5, true, -1, -1, 777)), new Command.NeoStoreCommand(createNeoStoreRecord(42), createNeoStoreRecord(21)));
writeTxContent(log2, 0, new Command.NeoStoreCommand(createNeoStoreRecord(12), createNeoStoreRecord(21)));
writeTxContent(log3, 0, new Command.NeoStoreCommand(createNeoStoreRecord(13), createNeoStoreRecord(21)));
CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
// When
checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, NEO_STORE);
// Then
assertEquals(2, handler.recordInconsistencies.size());
NeoStoreRecord seenRecord1 = (NeoStoreRecord) handler.recordInconsistencies.get(0).committed.record();
NeoStoreRecord currentRecord1 = (NeoStoreRecord) handler.recordInconsistencies.get(0).current.record();
assertEquals(21, seenRecord1.getNextProp());
assertEquals(12, currentRecord1.getNextProp());
NeoStoreRecord seenRecord2 = (NeoStoreRecord) handler.recordInconsistencies.get(1).committed.record();
NeoStoreRecord currentRecord2 = (NeoStoreRecord) handler.recordInconsistencies.get(1).current.record();
assertEquals(21, seenRecord2.getNextProp());
assertEquals(13, currentRecord2.getNextProp());
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class CheckTxLogsTest method shouldReportNodeInconsistenciesFromDifferentLogs.
@Test
public void shouldReportNodeInconsistenciesFromDifferentLogs() throws IOException {
// Given
File log1 = logFile(1);
File log2 = logFile(2);
File log3 = logFile(3);
writeTxContent(log1, 0, new Command.NodeCommand(new NodeRecord(42, false, false, -1, -1, 1), new NodeRecord(42, true, false, 42, -1, 1)), new Command.PropertyCommand(propertyRecord(5, true, -1, -1, 777), propertyRecord(5, true, -1, -1, 777, 888)), new Command.NodeCommand(new NodeRecord(1, true, true, 2, -1, 1), new NodeRecord(1, true, false, -1, -1, 1)));
writeTxContent(log2, 0, new Command.NodeCommand(new NodeRecord(2, false, false, -1, -1, 1), new NodeRecord(2, true, false, -1, -1, 1)));
writeTxContent(log3, 0, new Command.NodeCommand(new NodeRecord(42, true, true, 42, -1, 1), new NodeRecord(42, true, true, 42, 10, 1)), new Command.NodeCommand(new NodeRecord(2, true, false, -1, -1, 5), new NodeRecord(2, false, false, -1, -1, 5)));
CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
// When
boolean success = checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, NODE);
// Then
assertFalse(success);
assertEquals(2, handler.recordInconsistencies.size());
NodeRecord seenRecord1 = (NodeRecord) handler.recordInconsistencies.get(0).committed.record();
NodeRecord currentRecord1 = (NodeRecord) handler.recordInconsistencies.get(0).current.record();
assertEquals(42, seenRecord1.getId());
assertFalse(seenRecord1.isDense());
assertEquals(42, currentRecord1.getId());
assertTrue(currentRecord1.isDense());
NodeRecord seenRecord2 = (NodeRecord) handler.recordInconsistencies.get(1).committed.record();
NodeRecord currentRecord2 = (NodeRecord) handler.recordInconsistencies.get(1).current.record();
assertEquals(2, seenRecord2.getId());
assertEquals(1, seenRecord2.getLabelField());
assertEquals(2, currentRecord2.getId());
assertEquals(5, currentRecord2.getLabelField());
}
use of org.neo4j.kernel.impl.transaction.log.PhysicalLogFiles in project neo4j by neo4j.
the class CheckTxLogsTest method shouldReportRelationshipInconsistenciesFromSingleLog.
@Test
public void shouldReportRelationshipInconsistenciesFromSingleLog() throws IOException {
// Given
File log = logFile(1);
writeTxContent(log, 0, new Command.RelationshipCommand(new RelationshipRecord(42, false, -1, -1, -1, -1, -1, -1, -1, false, false), new RelationshipRecord(42, true, 1, 2, 3, 4, 5, 6, 7, true, true)), new Command.PropertyCommand(propertyRecord(5, false, -1, -1), propertyRecord(5, true, -1, -1, 777)), new Command.RelationshipCommand(new RelationshipRecord(21, true, 1, 2, 3, 4, 5, 6, 7, true, true), new RelationshipRecord(21, false, -1, -1, -1, -1, -1, -1, -1, false, false)));
writeTxContent(log, 0, new Command.RelationshipCommand(new RelationshipRecord(53, true, 1, 2, 3, 4, 5, 6, 7, true, true), new RelationshipRecord(53, true, 1, 2, 30, 4, 14, 6, 7, true, true)), new Command.RelationshipCommand(new RelationshipRecord(42, true, 1, 2, 3, 9, 5, 6, 7, true, true), new RelationshipRecord(42, true, 1, 2, 3, 4, 5, 6, 7, true, true)));
CapturingInconsistenciesHandler handler = new CapturingInconsistenciesHandler();
CheckTxLogs checker = new CheckTxLogs(System.out, fsRule.get());
// When
checker.scan(new PhysicalLogFiles(storeDirectory, fsRule.get()), handler, RELATIONSHIP);
// Then
assertEquals(1, handler.recordInconsistencies.size());
RelationshipRecord seenRecord = (RelationshipRecord) handler.recordInconsistencies.get(0).committed.record();
RelationshipRecord currentRecord = (RelationshipRecord) handler.recordInconsistencies.get(0).current.record();
assertEquals(42, seenRecord.getId());
assertEquals(4, seenRecord.getFirstPrevRel());
assertEquals(42, currentRecord.getId());
assertEquals(9, currentRecord.getFirstPrevRel());
}
Aggregations