@Override public RecordReference<DynamicRecord> schema( long id ) { return referenceTo( access.getSchemaStore(), id ); }
public MandatoryProperties( StoreAccess storeAccess ) { this.storeAccess = storeAccess; SchemaStorage schemaStorage = new SchemaStorage( storeAccess.getSchemaStore() ); for ( ConstraintRule rule : constraintsIgnoringMalformed( schemaStorage ) ) { if ( rule.getConstraintDescriptor().enforcesPropertyExistence() ) { rule.schema().processWith( constraintRecorder ); } } }
private void createRelationshipPropertyExistenceConstraint( int relTypeId, int propertyKeyId ) { SchemaStore schemaStore = (SchemaStore) fixture.directStoreAccess().nativeStores().getSchemaStore(); ConstraintRule rule = relPropertyExistenceConstraintRule( schemaStore.nextId(), relTypeId, propertyKeyId ); writeToSchemaStore( schemaStore, rule ); }
private void createNodePropertyExistenceConstraint( int labelId, int propertyKeyId ) { SchemaStore schemaStore = (SchemaStore) fixture.directStoreAccess().nativeStores().getSchemaStore(); ConstraintRule rule = nodePropertyExistenceConstraintRule( schemaStore.nextId(), labelId, propertyKeyId ); writeToSchemaStore( schemaStore, rule ); }
tasks.add( create( "SchemaStore", nativeStores.getSchemaStore(), ROUND_ROBIN ) ); new SchemaRecordCheck( new SchemaStorage( nativeStores.getSchemaStore() ), indexes ); tasks.add( new SchemaStoreProcessorTask<>( "SchemaStoreProcessor-check_rules", statistics, numberOfThreads, nativeStores.getSchemaStore(), nativeStores, "check_rules", schemaCheck, multiPartBuilder, cacheAccess, defaultProcessor, ROUND_ROBIN ) ); numberOfThreads, nativeStores.getSchemaStore(), nativeStores, "check_obligations", schemaCheck.forObligationChecking(), multiPartBuilder, cacheAccess, defaultProcessor, ROUND_ROBIN ) );
void execute( final DirectStoreAccess directStoreAccess, final CheckDecorator decorator, final RecordAccess recordAccess, final InconsistencyReport report, CacheAccess cacheAccess, Monitor reportMonitor ) throws ConsistencyCheckIncompleteException { final ConsistencyReporter reporter = new ConsistencyReporter( recordAccess, report, reportMonitor ); StoreProcessor processEverything = new StoreProcessor( decorator, reporter, Stage.SEQUENTIAL_FORWARD, cacheAccess ); ProgressMonitorFactory.MultiPartBuilder progress = progressFactory.multipleParts( "Full Consistency Check" ); final StoreAccess nativeStores = directStoreAccess.nativeStores(); try ( IndexAccessors indexes = new IndexAccessors( directStoreAccess.indexes(), nativeStores.getSchemaStore(), samplingConfig ) ) { MultiPassStore.Factory multiPass = new MultiPassStore.Factory( decorator, recordAccess, cacheAccess, report, reportMonitor ); ConsistencyCheckTasks taskCreator = new ConsistencyCheckTasks( progress, processEverything, nativeStores, statistics, cacheAccess, directStoreAccess.labelScanStore(), indexes, multiPass, reporter, threads ); List<ConsistencyCheckerTask> tasks = taskCreator.createTasksForFullCheck( checkLabelScanStore, checkIndexes, checkGraph ); TaskExecutor.execute( tasks, decorator::prepare ); } catch ( Exception e ) { throw new ConsistencyCheckIncompleteException( e ); } }
private void createUniquenessConstraintRule( final int labelId, final int... propertyKeyIds ) { SchemaStore schemaStore = (SchemaStore) fixture.directStoreAccess().nativeStores().getSchemaStore(); long ruleId1 = schemaStore.nextId(); long ruleId2 = schemaStore.nextId(); StoreIndexDescriptor indexRule = uniqueForSchema( forLabel( labelId, propertyKeyIds ), DESCRIPTOR ).withIds( ruleId1, ruleId2 ); ConstraintRule uniqueRule = ConstraintRule.constraintRule( ruleId2, ConstraintDescriptorFactory.uniqueForLabel( labelId, propertyKeyIds ), ruleId1 ); writeToSchemaStore( schemaStore, indexRule ); writeToSchemaStore( schemaStore, uniqueRule ); }
private void createNodeKeyConstraintRule( final int labelId, final int... propertyKeyIds ) { SchemaStore schemaStore = (SchemaStore) fixture.directStoreAccess().nativeStores().getSchemaStore(); long ruleId1 = schemaStore.nextId(); long ruleId2 = schemaStore.nextId(); StoreIndexDescriptor indexRule = uniqueForSchema( forLabel( labelId, propertyKeyIds ), DESCRIPTOR ).withIds( ruleId1, ruleId2 ); ConstraintRule nodeKeyRule = ConstraintRule.constraintRule( ruleId2, ConstraintDescriptorFactory.nodeKeyForLabel( labelId, propertyKeyIds ), ruleId1 ); writeToSchemaStore( schemaStore, indexRule ); writeToSchemaStore( schemaStore, nodeKeyRule ); }
@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<StoreIndexDescriptor> rules = new SchemaStorage( storeAccess.nativeStores().getSchemaStore() ).indexesGetAll(); while ( rules.hasNext() ) { StoreIndexDescriptor rule = rules.next(); IndexSamplingConfig samplingConfig = new IndexSamplingConfig( Config.defaults() ); IndexPopulator populator = storeAccess.indexes().lookup( rule.providerDescriptor() ) .getPopulator( rule, 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, 2 ) // the label scan is pointing to 2 nodes not in use .verify( RecordType.COUNTS, 3 ) .andThatsAllFolks(); }
@Test public void shouldReportNodesWithDuplicatePropertyValueInUniqueIndex() throws Exception { // given IndexSamplingConfig samplingConfig = new IndexSamplingConfig( Config.defaults() ); Iterator<StoreIndexDescriptor> indexRuleIterator = new SchemaStorage( fixture.directStoreAccess().nativeStores().getSchemaStore() ).indexesGetAll(); while ( indexRuleIterator.hasNext() ) { StoreIndexDescriptor indexRule = indexRuleIterator.next(); IndexAccessor accessor = fixture.directStoreAccess().indexes().lookup( indexRule.providerDescriptor() ) .getOnlineAccessor( indexRule, samplingConfig ); IndexUpdater updater = accessor.newUpdater( IndexUpdateMode.ONLINE ); updater.process( IndexEntryUpdate.add( 42, indexRule.schema(), values( indexRule ) ) ); updater.close(); accessor.force( IOLimiter.UNLIMITED ); accessor.close(); } // when ConsistencySummaryStatistics stats = check(); // then on( stats ).verify( RecordType.NODE, 1 ) // the duplicate in unique index .verify( RecordType.INDEX, 3 ) // the index entries pointing to non-existent node 42 .andThatsAllFolks(); }
new SchemaStorage( fixture.directStoreAccess().nativeStores().getSchemaStore() ).indexesGetAll(); NeoStoreIndexStoreView storeView = new NeoStoreIndexStoreView( LockService.NO_LOCK_SERVICE, fixture.directStoreAccess().nativeStores().getRawNeoStores() );
StoreAccess stores = new StoreAccess( graphDb.getDependencyResolver() .resolveDependency( RecordStorageEngine.class ).testAccessNeoStores() ).initialize(); schemaId = stores.getSchemaStore().getHighId(); nodeId = stores.getNodeStore().getHighId(); labelId = (int) stores.getLabelTokenStore().getHighId();
private void createNodePropertyExistenceConstraint( int labelId, int propertyKeyId ) { SchemaStore schemaStore = (SchemaStore) fixture.directStoreAccess().nativeStores().getSchemaStore(); SchemaRule rule = nodePropertyExistenceConstraintRule( schemaStore.nextId(), labelId, propertyKeyId ); Collection<DynamicRecord> records = schemaStore.allocateFrom( rule ); for ( DynamicRecord record : records ) { schemaStore.updateRecord( record ); } }
private void createRelationshipPropertyExistenceConstraint( int relTypeId, int propertyKeyId ) { SchemaStore schemaStore = (SchemaStore) fixture.directStoreAccess().nativeStores().getSchemaStore(); SchemaRule rule = relPropertyExistenceConstraintRule( schemaStore.nextId(), relTypeId, propertyKeyId ); Collection<DynamicRecord> records = schemaStore.allocateFrom( rule ); for ( DynamicRecord record : records ) { schemaStore.updateRecord( record ); } }
Iterator<IndexRule> rules = new SchemaStorage( storeAccess.nativeStores().getSchemaStore() ).allIndexRules(); while ( rules.hasNext() )
@Test public void shouldReportNodesWithDuplicatePropertyValueInUniqueIndex() throws Exception { // given IndexConfiguration indexConfig = new IndexConfiguration( false ); IndexSamplingConfig samplingConfig = new IndexSamplingConfig( new Config() ); for ( IndexRule indexRule : loadAllIndexRules( fixture.directStoreAccess().nativeStores().getSchemaStore() ) ) { IndexAccessor accessor = fixture.directStoreAccess() .indexes() .getOnlineAccessor( indexRule.getId(), indexConfig, samplingConfig ); IndexUpdater updater = accessor.newUpdater( IndexUpdateMode.ONLINE ); updater.process( NodePropertyUpdate.add( 42, 0, "value", new long[]{3} ) ); updater.close(); accessor.close(); } // when ConsistencySummaryStatistics stats = check(); // then on( stats ).verify( RecordType.NODE, 1 ) .verify( RecordType.INDEX, 2 ) .andThatsAllFolks(); }
@Test public void shouldReportNodesThatAreNotIndexed() throws Exception { // given IndexSamplingConfig samplingConfig = new IndexSamplingConfig( new Config() ); for ( IndexRule indexRule : loadAllIndexRules( fixture.directStoreAccess().nativeStores().getSchemaStore() ) ) { IndexAccessor accessor = fixture.directStoreAccess().indexes().getOnlineAccessor( indexRule.getId(), new IndexConfiguration( indexRule.isConstraintIndex() ), 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(); }
private void generateInitialData() { GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( directory ); GraphDatabaseAPI graphDb = (GraphDatabaseAPI) builder.newGraphDatabase(); try { generateInitialData( graphDb ); StoreAccess stores = new StoreAccess( graphDb ).initialize(); schemaId = stores.getSchemaStore().getHighId(); nodeId = stores.getNodeStore().getHighId(); labelId = (int) stores.getLabelTokenStore().getHighId(); nodeLabelsId = stores.getNodeDynamicLabelStore().getHighId(); relId = stores.getRelationshipStore().getHighId(); relGroupId = stores.getRelationshipGroupStore().getHighId(); propId = (int) stores.getPropertyStore().getHighId(); stringPropId = stores.getStringStore().getHighId(); arrayPropId = stores.getArrayStore().getHighId(); relTypeId = (int) stores.getRelationshipTypeTokenStore().getHighId(); propKeyId = (int) stores.getPropertyKeyNameStore().getHighId(); } finally { graphDb.shutdown(); } }