use of org.neo4j.kernel.impl.store.record.IndexRule 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.record.IndexRule in project neo4j by neo4j.
the class IndexLookup method getAnyIndexOrNull.
public Index getAnyIndexOrNull(final long[] labelIds, final int propertyKeyId) throws IOException {
List<IndexRule> indexRules = indexRuleIndex.get(propertyKeyId);
if (indexRules == null) {
return null;
}
IndexRule rule = findIndexRuleWithOneOfLabels(indexRules, labelIds);
if (rule == null) {
return null;
}
final IndexReader reader = getIndexReader(rule);
return (nodeId, propertyValue) -> reader.countIndexedNodes(nodeId, propertyValue) > 0;
}
use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportNodesThatAreNotIndexed.
@Test
public void shouldReportNodesThatAreNotIndexed() 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.remove(asPrimitiveLongSet(indexedNodes));
updater.close();
accessor.close();
}
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.NODE, 1).andThatsAllFolks();
}
use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class FullCheckIntegrationTest method shouldReportDuplicateConstraintReferences.
@Test
public void shouldReportDuplicateConstraintReferences() throws Exception {
// given
fixture.apply(new GraphStoreFixture.Transaction() {
@Override
protected void transactionData(GraphStoreFixture.TransactionDataBuilder tx, GraphStoreFixture.IdGenerator next) {
int ruleId1 = (int) next.schema();
int ruleId2 = (int) next.schema();
int labelId = next.label();
int propertyKeyId = next.propertyKey();
DynamicRecord record1 = new DynamicRecord(ruleId1);
DynamicRecord record2 = new DynamicRecord(ruleId2);
DynamicRecord record1Before = record1.clone();
DynamicRecord record2Before = record2.clone();
IndexRule rule1 = constraintIndexRule(ruleId1, labelId, propertyKeyId, DESCRIPTOR, (long) ruleId1);
IndexRule rule2 = constraintIndexRule(ruleId2, labelId, propertyKeyId, DESCRIPTOR, (long) ruleId1);
Collection<DynamicRecord> records1 = serializeRule(rule1, record1);
Collection<DynamicRecord> records2 = serializeRule(rule2, record2);
assertEquals(asList(record1), records1);
assertEquals(asList(record2), records2);
tx.nodeLabel(labelId, "label");
tx.propertyKey(propertyKeyId, "property");
tx.createSchema(asList(record1Before), records1, rule1);
tx.createSchema(asList(record2Before), records2, rule2);
}
});
// when
ConsistencySummaryStatistics stats = check();
// then
on(stats).verify(RecordType.SCHEMA, 4).andThatsAllFolks();
}
use of org.neo4j.kernel.impl.store.record.IndexRule in project neo4j by neo4j.
the class SchemaRecordCheckTest method shouldReportTwoConstraintIndexesReferencingSameConstraint.
@Test
public void shouldReportTwoConstraintIndexesReferencingSameConstraint() throws Exception {
// given
int ruleId1 = 0;
int ruleId2 = 1;
DynamicRecord record1 = inUse(dynamicRecord(ruleId1));
DynamicRecord record2 = inUse(dynamicRecord(ruleId2));
SchemaIndexProvider.Descriptor providerDescriptor = new SchemaIndexProvider.Descriptor("in-memory", "1.0");
IndexRule rule1 = constraintIndexRule(ruleId1, labelId, propertyKeyId, providerDescriptor, (long) ruleId1);
IndexRule rule2 = constraintIndexRule(ruleId2, labelId, propertyKeyId, providerDescriptor, (long) ruleId1);
when(checker().ruleAccess.loadSingleSchemaRule(ruleId1)).thenReturn(rule1);
when(checker().ruleAccess.loadSingleSchemaRule(ruleId2)).thenReturn(rule2);
add(inUse(new LabelTokenRecord(labelId)));
add(inUse(new PropertyKeyTokenRecord(propertyKeyId)));
// when
check(record1);
ConsistencyReport.SchemaConsistencyReport report = check(record2);
// then
verify(report).duplicateObligation(record1);
}
Aggregations