@Override public IndexUpdater newUpdater( IndexUpdateMode mode ) { return delegate.newUpdater( mode ); }
@Override public IndexUpdater newUpdater( IndexUpdateMode mode ) { return accessor.newUpdater( mode ); }
@Override public IndexUpdater newUpdater( final IndexUpdateMode mode ) { IndexUpdater actual = accessor.newUpdater( escalateModeIfNecessary( mode ) ); return started ? updateCountingUpdater( actual ) : actual; }
@Override public IndexUpdater newUpdater( IndexUpdateMode mode ) { return wrap( actual.newUpdater( mode ) ); }
private void updateAndCommit( IndexAccessor accessor, Iterable<IndexEntryUpdate<?>> updates ) throws IOException, IndexEntryConflictException { try ( IndexUpdater updater = accessor.newUpdater( IndexUpdateMode.ONLINE ) ) { for ( IndexEntryUpdate<?> update : updates ) { updater.process( update ); } } } }
@Override public IndexUpdater newUpdater( IndexUpdateMode mode ) { LazyInstanceSelector<IndexUpdater> updaterSelector = new LazyInstanceSelector<>( slot -> instanceSelector.select( slot ).newUpdater( mode ) ); return new FusionIndexUpdater( slotSelector, updaterSelector ); }
@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(); }
when( accessor1.newUpdater( any( IndexUpdateMode.class ) ) ).thenReturn( updater1 ); when( accessor2.newUpdater( any( IndexUpdateMode.class ) ) ).thenReturn( updater2 );
/** * Commit these updates to the index. Also store the values, which currently are stored for all types except geometry, * so therefore it's done explicitly here so that we can filter on them later. */ void updateAndCommit( Collection<IndexEntryUpdate<?>> updates ) throws IndexEntryConflictException { try ( IndexUpdater updater = accessor.newUpdater( IndexUpdateMode.ONLINE ) ) { for ( IndexEntryUpdate<?> update : updates ) { updater.process( update ); switch ( update.updateMode() ) { case ADDED: case CHANGED: committedValues.put( update.getEntityId(), update.values() ); break; case REMOVED: committedValues.remove( update.getEntityId() ); break; default: throw new IllegalArgumentException( "Unknown update mode of " + update ); } } } } }
@Test public void indexCreationShouldBeIdempotent() throws Exception { // given when( accessor.newUpdater( any( IndexUpdateMode.class ) ) ).thenReturn( updater ); IndexingService indexingService = newIndexingServiceWithMockedDependencies( populator, accessor, withData() ); life.start(); // when indexingService.createIndexes( index.withId( 0 ) ); indexingService.createIndexes( index.withId( 0 ) ); // We are asserting that the second call to createIndex does not throw an exception. waitForIndexesToComeOnline( indexingService, 0 ); }
@Test public void shouldBringIndexOnlineAndFlipOverToIndexAccessor() throws Exception { // given when( accessor.newUpdater( any( IndexUpdateMode.class ) ) ).thenReturn(updater); IndexingService indexingService = newIndexingServiceWithMockedDependencies( populator, accessor, withData() ); life.start(); // when indexingService.createIndexes( index.withId( 0 ) ); IndexProxy proxy = indexingService.getIndexProxy( 0 ); waitForIndexesToComeOnline( indexingService, 0 ); verify( populator, timeout( 10000 ) ).close( true ); try ( IndexUpdater updater = proxy.newUpdater( IndexUpdateMode.ONLINE ) ) { updater.process( add( 10, "foo" ) ); } // then assertEquals( InternalIndexState.ONLINE, proxy.getState() ); InOrder order = inOrder( populator, accessor, updater); order.verify( populator ).create(); order.verify( populator ).close( true ); order.verify( accessor ).newUpdater( IndexUpdateMode.ONLINE_IDEMPOTENT ); order.verify( updater ).process( add( 10, "foo" ) ); order.verify( updater ).close(); }
@Test public void shouldStillReportInternalIndexStateAsPopulatingWhenConstraintIndexIsDonePopulating() throws Exception { // given when( accessor.newUpdater( any( IndexUpdateMode.class ) ) ).thenReturn( updater ); IndexingService indexingService = newIndexingServiceWithMockedDependencies( populator, accessor, withData() ); life.start(); // when indexingService.createIndexes( constraintIndexRule( 0, labelId, propertyKeyId, PROVIDER_DESCRIPTOR ) ); IndexProxy proxy = indexingService.getIndexProxy( 0 ); // don't wait for index to come ONLINE here since we're testing that it doesn't verify( populator, timeout( 20000 ) ).close( true ); try ( IndexUpdater updater = proxy.newUpdater( IndexUpdateMode.ONLINE ) ) { updater.process( add( 10, "foo" ) ); } // then assertEquals( InternalIndexState.POPULATING, proxy.getState() ); InOrder order = inOrder( populator, accessor, updater ); order.verify( populator ).create(); order.verify( populator ).close( true ); order.verify( accessor ).newUpdater( IndexUpdateMode.ONLINE ); order.verify( updater ).process( add( 10, "foo" ) ); order.verify( updater ).close(); }
@Test public void applicationOfUpdatesShouldFlush() throws Exception { // Given when( accessor.newUpdater( any( IndexUpdateMode.class ) ) ).thenReturn( updater ); IndexingService indexing = newIndexingServiceWithMockedDependencies( populator, accessor, withData() ); life.start(); indexing.createIndexes( index.withId( 0 ) ); waitForIndexesToComeOnline( indexing, 0 ); verify( populator, timeout( 10000 ) ).close( true ); // When indexing.apply( updates( asList( add( 1, "foo" ), add( 2, "bar" ) ) ) ); // Then InOrder inOrder = inOrder( updater ); inOrder.verify( updater ).process( add( 1, "foo" ) ); inOrder.verify( updater ).process( add( 2, "bar" ) ); inOrder.verify( updater ).close(); inOrder.verifyNoMoreInteractions(); }
verify( accessor ).newUpdater( RECOVERY );
@Test void indexUpdateNotAllowedInReadOnlyMode() throws Exception { Config readOnlyConfig = Config.defaults( GraphDatabaseSettings.read_only, Settings.TRUE ); LuceneIndexProvider readOnlyIndexProvider = getLuceneIndexProvider( readOnlyConfig, new DirectoryFactory.InMemoryDirectoryFactory(), fileSystem, graphDbDir ); assertThrows( UnsupportedOperationException.class, () -> getIndexAccessor( readOnlyConfig, readOnlyIndexProvider ).newUpdater( IndexUpdateMode.ONLINE ) ); }
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 shouldNotCheckConflictsWhenApplyingUpdatesInOnlineAccessor() throws IOException, IndexEntryConflictException { // given provider = newProvider(); // when StoreIndexDescriptor descriptor = descriptorUnique(); try ( IndexAccessor accessor = provider.getOnlineAccessor( descriptor, samplingConfig() ); IndexUpdater indexUpdater = accessor.newUpdater( IndexUpdateMode.ONLINE ) ) { Value value = someValue(); indexUpdater.process( IndexEntryUpdate.add( 1, descriptor.schema(), value ) ); // then // ... expect no failure on duplicate value indexUpdater.process( IndexEntryUpdate.add( 2, descriptor.schema(), value ) ); } }
@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(); }
IndexAccessor accessor = fixture.directStoreAccess().indexes(). lookup( indexDescriptor.providerDescriptor() ).getOnlineAccessor( indexDescriptor, samplingConfig ); try ( IndexUpdater updater = accessor.newUpdater( IndexUpdateMode.ONLINE ) )
@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() ); } } } }