@Override public void close() throws IOException { accessor.close(); }
@Override public IndexUpdater newUpdater( IndexUpdateMode mode ) { return delegate.newUpdater( mode ); }
@Override public void force( IOLimiter ioLimiter ) { delegate.force( ioLimiter ); }
private void addUpdates( SpatialIndexProvider provider, StoreIndexDescriptor schemaIndexDescriptor, ValueCreatorUtil<SpatialIndexKey,NativeIndexValue> layoutUtil ) throws IOException, IndexEntryConflictException { IndexAccessor accessor = provider.getOnlineAccessor( schemaIndexDescriptor, samplingConfig() ); try ( IndexUpdater updater = accessor.newUpdater( ONLINE ) ) { // when for ( IndexEntryUpdate<IndexDescriptor> update : layoutUtil.someUpdates( randomRule ) ) { updater.process( update ); } } accessor.force( IOLimiter.UNLIMITED ); accessor.close(); }
@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(); }
@Override public IndexReader newReader() { return accessor.newReader(); }
@Test public void shouldRefreshIndexesOnStart() throws Exception { // given StoreIndexDescriptor rule = index.withId( 0 ); newIndexingServiceWithMockedDependencies( populator, accessor, withData(), rule ); IndexAccessor accessor = mock( IndexAccessor.class ); IndexUpdater updater = mock( IndexUpdater.class ); when( accessor.newUpdater( any( IndexUpdateMode.class ) ) ).thenReturn( updater ); when( indexProvider.getOnlineAccessor( any( StoreIndexDescriptor.class ), any( IndexSamplingConfig.class ) ) ).thenReturn( accessor ); life.init(); verify( accessor, never() ).refresh(); life.start(); // Then verify( accessor, times( 1 ) ).refresh(); }
@Override public BoundedIterable<Long> newAllEntriesReader() { return delegate.newAllEntriesReader(); }
@Override public void drop() { delegate.drop(); }
@Test public void shouldPopulateAndUpdate() throws Exception { // GIVEN withPopulator( indexProvider.getPopulator( descriptor, indexSamplingConfig ), p -> p.add( updates( valueSet1 ) ) ); try ( IndexAccessor accessor = indexProvider.getOnlineAccessor( descriptor, indexSamplingConfig ) ) { // WHEN try ( IndexUpdater updater = accessor.newUpdater( IndexUpdateMode.ONLINE ) ) { List<IndexEntryUpdate<?>> updates = updates( valueSet2 ); for ( IndexEntryUpdate<?> update : updates ) { updater.process( update ); } } // THEN try ( IndexReader reader = new QueryResultComparingIndexReader( accessor.newReader() ) ) { int propertyKeyId = descriptor.schema().getPropertyId(); for ( NodeAndValue entry : Iterables.concat( valueSet1, valueSet2 ) ) { NodeValueIterator nodes = new NodeValueIterator(); reader.query( nodes, IndexOrder.NONE, false , IndexQuery.exact( propertyKeyId, entry.value ) ); assertEquals( entry.nodeId, nodes.next() ); assertFalse( nodes.hasNext() ); } } } }
@Override public boolean isDirty() { return delegate.isDirty(); }
@Override public ResourceIterator<File> snapshotFiles() { return delegate.snapshotFiles(); }
@Override public void refresh() { accessor.refresh(); }
@Override public void validateBeforeCommit( Value[] tuple ) { accessor.validateBeforeCommit( tuple ); }
@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(); }
@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(); }
@Override public IndexReader newReader() { return delegate.newReader(); }
@Override public BoundedIterable<Long> newAllEntriesReader() { return actual.newAllEntriesReader(); }
@Override public void drop() { accessor.drop(); }