use of org.neo4j.kernel.impl.store.SchemaStorage in project neo4j by neo4j.
the class BatchInsertTest method shouldCreateConsistentUniquenessConstraint.
@Test
public void shouldCreateConsistentUniquenessConstraint() throws Exception {
// given
BatchInserter inserter = newBatchInserter();
// when
inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
// then
GraphDatabaseAPI graphdb = (GraphDatabaseAPI) switchToEmbeddedGraphDatabaseService(inserter);
try {
NeoStores neoStores = graphdb.getDependencyResolver().resolveDependency(RecordStorageEngine.class).testAccessNeoStores();
SchemaStore store = neoStores.getSchemaStore();
SchemaStorage storage = new SchemaStorage(store);
List<Long> inUse = new ArrayList<>();
DynamicRecord record = store.nextRecord();
for (long i = 1, high = store.getHighestPossibleIdInUse(); i <= high; i++) {
store.getRecord(i, record, RecordLoad.FORCE);
if (record.inUse() && record.isStartRecord()) {
inUse.add(i);
}
}
assertEquals("records in use", 2, inUse.size());
SchemaRule rule0 = storage.loadSingleSchemaRule(inUse.get(0));
SchemaRule rule1 = storage.loadSingleSchemaRule(inUse.get(1));
IndexRule indexRule;
ConstraintRule constraintRule;
if (rule0 instanceof IndexRule) {
indexRule = (IndexRule) rule0;
constraintRule = (ConstraintRule) rule1;
} else {
constraintRule = (ConstraintRule) rule0;
indexRule = (IndexRule) rule1;
}
assertEquals("index should reference constraint", constraintRule.getId(), indexRule.getOwningConstraint().longValue());
assertEquals("constraint should reference index", indexRule.getId(), constraintRule.getOwnedIndex());
} finally {
graphdb.shutdown();
}
}
use of org.neo4j.kernel.impl.store.SchemaStorage in project neo4j by neo4j.
the class IndexStatisticsIT method shouldRecoverIndexCountsBySamplingThemOnStartup.
@Test
public void shouldRecoverIndexCountsBySamplingThemOnStartup() {
// given some aliens in a database
createAliens();
// that have been indexed
awaitIndexOnline(indexAliensBySpecimen());
// where ALIEN and SPECIMEN are both the first ids of their kind
NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel(labelId(ALIEN), pkId(SPECIMEN));
SchemaStorage storage = new SchemaStorage(neoStores().getSchemaStore());
long indexId = storage.indexGetForSchema(index).getId();
// for which we don't have index counts
resetIndexCounts(indexId);
// when we shutdown the database and restart it
restart();
// then we should have re-sampled the index
CountsTracker tracker = neoStores().getCounts();
assertEqualRegisters("Unexpected updates and size for the index", newDoubleLongRegister(0, 32), tracker.indexUpdatesAndSize(indexId, newDoubleLongRegister()));
assertEqualRegisters("Unexpected sampling result", newDoubleLongRegister(16, 32), tracker.indexSample(indexId, newDoubleLongRegister()));
// and also
assertLogExistsForRecoveryOn(":Alien(specimen)");
}
use of org.neo4j.kernel.impl.store.SchemaStorage in project neo4j by neo4j.
the class DumpCountsStoreTest method createSchemaStorage.
private SchemaStorage createSchemaStorage() {
SchemaStorage schemaStorage = mock(SchemaStorage.class);
SchemaIndexProvider.Descriptor providerDescriptor = new SchemaIndexProvider.Descriptor("in-memory", "1.0");
IndexRule rule = IndexRule.indexRule(indexId, descriptor, providerDescriptor);
ArrayList<IndexRule> rules = new ArrayList<>();
rules.add(rule);
when(schemaStorage.indexesGetAll()).thenReturn(rules.iterator());
return schemaStorage;
}
use of org.neo4j.kernel.impl.store.SchemaStorage in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldNotReportIndexInconsistenciesIfIndexIsFailed.
@Test
public void shouldNotReportIndexInconsistenciesIfIndexIsFailed() throws Exception {
// this test fails all indexes, and then destroys a record and makes sure we only get a failure for
// the label scan store but not for any index
// given
DirectStoreAccess storeAccess = fixture.directStoreAccess();
// fail all indexes
Iterator<IndexRule> rules = new SchemaStorage(storeAccess.nativeStores().getSchemaStore()).indexesGetAll();
while (rules.hasNext()) {
IndexRule rule = rules.next();
IndexSamplingConfig samplingConfig = new IndexSamplingConfig(Config.empty());
IndexPopulator populator = storeAccess.indexes().getPopulator(rule.getId(), rule.getIndexDescriptor(), samplingConfig);
populator.markAsFailed("Oh noes! I was a shiny index and then I was failed");
populator.close(false);
}
for (Long indexedNodeId : indexedNodes) {
storeAccess.nativeStores().getNodeStore().updateRecord(notInUse(new NodeRecord(indexedNodeId, false, -1, -1)));
}
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.LABEL_SCAN_DOCUMENT, 1).verify(RecordType.COUNTS, 3).andThatsAllFolks();
}
use of org.neo4j.kernel.impl.store.SchemaStorage in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportNodesWithDuplicatePropertyValueInUniqueIndex.
@Test
public void shouldReportNodesWithDuplicatePropertyValueInUniqueIndex() throws Exception {
// given
IndexSamplingConfig samplingConfig = new IndexSamplingConfig(Config.empty());
Iterator<IndexRule> indexRuleIterator = new SchemaStorage(fixture.directStoreAccess().nativeStores().getSchemaStore()).indexesGetAll();
while (indexRuleIterator.hasNext()) {
IndexRule indexRule = indexRuleIterator.next();
IndexAccessor accessor = fixture.directStoreAccess().indexes().getOnlineAccessor(indexRule.getId(), indexRule.getIndexDescriptor(), samplingConfig);
IndexUpdater updater = accessor.newUpdater(IndexUpdateMode.ONLINE);
updater.process(IndexEntryUpdate.add(42, indexRule.getIndexDescriptor().schema(), "value"));
updater.close();
accessor.close();
}
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.NODE, 1).verify(RecordType.INDEX, 2).andThatsAllFolks();
}
Aggregations