use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class DetectAllRelationshipInconsistenciesIT method shouldDetectSabotagedRelationshipWhereEverItIs.
@Test
public void shouldDetectSabotagedRelationshipWhereEverItIs() throws Exception {
// GIVEN a database which lots of relationships
GraphDatabaseAPI db = getGraphDatabaseAPI();
Sabotage sabotage;
try {
Node[] nodes = new Node[1_000];
Relationship[] relationships = new Relationship[10_000];
try (Transaction tx = db.beginTx()) {
for (int i = 0; i < nodes.length; i++) {
nodes[i] = db.createNode(label("Foo"));
}
for (int i = 0; i < 10_000; i++) {
relationships[i] = random.among(nodes).createRelationshipTo(random.among(nodes), MyRelTypes.TEST);
}
tx.success();
}
// WHEN sabotaging a random relationship
DependencyResolver resolver = db.getDependencyResolver();
PageCache pageCache = resolver.resolveDependency(PageCache.class);
StoreFactory storeFactory = newStoreFactory(pageCache);
try (NeoStores neoStores = storeFactory.openNeoStores(false, StoreType.RELATIONSHIP)) {
RelationshipStore relationshipStore = neoStores.getRelationshipStore();
Relationship sabotagedRelationships = random.among(relationships);
sabotage = sabotage(relationshipStore, sabotagedRelationships.getId());
}
} finally {
db.shutdown();
}
// THEN the checker should find it, where ever it is in the store
db = getGraphDatabaseAPI();
try {
DependencyResolver resolver = db.getDependencyResolver();
PageCache pageCache = resolver.resolveDependency(PageCache.class);
StoreFactory storeFactory = newStoreFactory(pageCache);
try (NeoStores neoStores = storeFactory.openAllNeoStores()) {
StoreAccess storeAccess = new StoreAccess(neoStores).initialize();
DirectStoreAccess directStoreAccess = new DirectStoreAccess(storeAccess, db.getDependencyResolver().resolveDependency(LabelScanStore.class), db.getDependencyResolver().resolveDependency(SchemaIndexProvider.class));
int threads = random.intBetween(2, 10);
FullCheck checker = new FullCheck(getTuningConfiguration(), ProgressMonitorFactory.NONE, Statistics.NONE, threads);
AssertableLogProvider logProvider = new AssertableLogProvider(true);
ConsistencySummaryStatistics summary = checker.execute(directStoreAccess, logProvider.getLog(FullCheck.class));
int relationshipInconsistencies = summary.getInconsistencyCountForRecordType(RecordType.RELATIONSHIP);
assertTrue("Couldn't detect sabotaged relationship " + sabotage, relationshipInconsistencies > 0);
logProvider.assertContainsLogCallContaining(sabotage.after.toString());
}
} finally {
db.shutdown();
}
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class VersionCommand method execute.
@Override
public void execute(String[] args) throws IncorrectUsage, CommandFailed {
final Path storeDir = arguments.parseMandatoryPath("store", args);
Validators.CONTAINS_EXISTING_DATABASE.validate(storeDir.toFile());
try (DefaultFileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
PageCache pageCache = StandalonePageCacheFactory.createPageCache(fileSystem)) {
final String storeVersion = new StoreVersionCheck(pageCache).getVersion(storeDir.resolve(MetaDataStore.DEFAULT_NAME).toFile()).orElseThrow(() -> new CommandFailed(String.format("Could not find version metadata in store '%s'", storeDir)));
final String fmt = "%-25s%s";
out.accept(String.format(fmt, "Store format version:", storeVersion));
RecordFormats format = RecordFormatSelector.selectForVersion(storeVersion);
out.accept(String.format(fmt, "Introduced in version:", format.introductionVersion()));
findSuccessor(format).map(next -> String.format(fmt, "Superseded in version:", next.introductionVersion())).ifPresent(out);
out.accept(String.format(fmt, "Current version:", Version.getNeo4jVersion()));
} catch (IOException e) {
throw new CommandFailed(e.getMessage(), e);
}
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class FormatCompatibilityTest method shouldDetectFormatChange.
@Test
public void shouldDetectFormatChange() throws Throwable {
// GIVEN stored tree
File storeFile = directory.file(STORE);
try {
unzipTo(storeFile);
} catch (FileNotFoundException e) {
// First time this test is run, eh?
createAndZipTree(storeFile);
tellDeveloperToCommitThisFormatVersion();
}
assertTrue(CURRENT_FORMAT_ZIP + " seems to be missing from resources directory", fsRule.get().fileExists(storeFile));
// WHEN reading from the tree
// THEN everything should work, otherwise there has likely been a format change
PageCache pageCache = pageCacheRule.getPageCache(fsRule.get());
try (GBPTree<MutableLong, MutableLong> tree = new GBPTree<>(pageCache, storeFile, new SimpleLongLayout(), 0, NO_MONITOR, NO_HEADER)) {
try {
tree.consistencyCheck();
try (RawCursor<Hit<MutableLong, MutableLong>, IOException> cursor = tree.seek(new MutableLong(0), new MutableLong(KEY_COUNT))) {
for (long expectedKey = 0; cursor.next(); expectedKey++) {
Hit<MutableLong, MutableLong> hit = cursor.get();
assertEquals(expectedKey, hit.key().longValue());
assertEquals(value(expectedKey), hit.value().longValue());
}
assertFalse(cursor.next());
}
} catch (Throwable t) {
throw new AssertionError(format("If this is the single failing test for %s this failure is a strong indication that format " + "has changed without also incrementing %s.FORMAT_VERSION. " + "Please go ahead and increment the format version", TREE_CLASS_NAME, TREE_CLASS_NAME), t);
}
} catch (MetadataMismatchException e) {
// Good actually, or?
assertThat(e.getMessage(), containsString("format version"));
fsRule.get().deleteFile(storeFile);
createAndZipTree(storeFile);
tellDeveloperToCommitThisFormatVersion();
}
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class FormatCompatibilityTest method createAndZipTree.
private void createAndZipTree(File storeFile) throws IOException {
PageCache pageCache = pageCacheRule.getPageCache(fsRule.get());
try (GBPTree<MutableLong, MutableLong> tree = new GBPTree<>(pageCache, storeFile, new SimpleLongLayout(), 0, NO_MONITOR, NO_HEADER)) {
MutableLong insertKey = new MutableLong();
MutableLong insertValue = new MutableLong();
int batchSize = KEY_COUNT / 10;
for (int i = 0, key = 0; i < 10; i++) {
try (Writer<MutableLong, MutableLong> writer = tree.writer()) {
for (int j = 0; j < batchSize; j++, key++) {
insertKey.setValue(key);
insertValue.setValue(value(key));
writer.put(insertKey, insertValue);
}
}
tree.checkpoint(IOLimiter.unlimited());
}
}
zip(storeFile);
}
use of org.neo4j.io.pagecache.PageCache in project neo4j by neo4j.
the class GBPTreeConcurrencyIT method createIndex.
private GBPTree<MutableLong, MutableLong> createIndex(GBPTree.Monitor monitor) throws IOException {
int pageSize = 256;
PageCache pageCache = pageCacheRule.getPageCache(fs.get(), config().withPageSize(pageSize).withAccessChecks(true));
return index = new GBPTree<>(pageCache, directory.file("index"), layout, 0, /*use whatever page cache says*/
monitor, NO_HEADER);
}
Aggregations