Search in sources :

Example 6 with SchemaStorage

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();
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaStore(org.neo4j.kernel.impl.store.SchemaStore) ArrayList(java.util.ArrayList) SchemaRule(org.neo4j.storageengine.api.schema.SchemaRule) BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) ConstraintRule(org.neo4j.kernel.impl.store.record.ConstraintRule) RecordStorageEngine(org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine) NeoStores(org.neo4j.kernel.impl.store.NeoStores) Matchers.anyLong(org.mockito.Matchers.anyLong) Test(org.junit.Test)

Example 7 with SchemaStorage

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)");
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Example 8 with SchemaStorage

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;
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) ArrayList(java.util.ArrayList) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)

Example 9 with 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();
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaRuleUtil.constraintIndexRule(org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Example 10 with SchemaStorage

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();
}
Also used : IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaRuleUtil.constraintIndexRule(org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Aggregations

SchemaStorage (org.neo4j.kernel.impl.store.SchemaStorage)11 Test (org.junit.Test)7 IndexRule (org.neo4j.kernel.impl.store.record.IndexRule)7 ArrayList (java.util.ArrayList)3 SchemaRuleUtil.constraintIndexRule (org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule)3 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)3 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)3 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)3 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)2 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 SchemaStore (org.neo4j.kernel.impl.store.SchemaStore)2 ConstraintRule (org.neo4j.kernel.impl.store.record.ConstraintRule)2 DynamicRecord (org.neo4j.kernel.impl.store.record.DynamicRecord)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Matchers.anyLong (org.mockito.Matchers.anyLong)1 PropertyChain (org.neo4j.consistency.checking.PropertyChain)1 SchemaRecordCheck (org.neo4j.consistency.checking.SchemaRecordCheck)1 CacheTask (org.neo4j.consistency.checking.cache.CacheTask)1 IndexEntryProcessor (org.neo4j.consistency.checking.index.IndexEntryProcessor)1