Skip to content

Commit

Permalink
Introduced IndexingUpdateService interface
Browse files Browse the repository at this point in the history
  • Loading branch information
fickludd committed Mar 23, 2017
1 parent c511948 commit 5f17c62
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 11 deletions.
Expand Up @@ -84,7 +84,7 @@
* If, however, it is {@link org.neo4j.kernel.api.index.InternalIndexState#ONLINE}, the index provider is required to
* also guarantee that the index had been flushed to disk.
*/
public class IndexingService extends LifecycleAdapter
public class IndexingService extends LifecycleAdapter implements IndexingUpdateService
{
private final IndexSamplingController samplingController;
private final IndexProxyCreator indexProxyCreator;
Expand Down Expand Up @@ -405,6 +405,7 @@ public double indexUniqueValuesPercentage( LabelSchemaDescriptor descriptor ) th
* @throws IOException potentially thrown from index updating.
* @throws IndexEntryConflictException potentially thrown from index updating.
*/
@Override
public void apply( IndexUpdates updates ) throws IOException, IndexEntryConflictException
{
if ( state == State.NOT_STARTED )
Expand Down Expand Up @@ -440,6 +441,12 @@ private void apply( IndexUpdates updates, IndexUpdateMode updateMode )
}
}

@Override
public void loadAdditionalProperties( NodeUpdates nodeUpdates )
{
nodeUpdates.loadAdditionalProperties( indexMapRef.getAllIndexProxies(), storeView );
}

/**
* Creates one or more indexes. They will all be populated by one and the same store scan.
*
Expand Down
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.api.index;

import java.io.IOException;

import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.impl.transaction.state.IndexUpdates;

public interface IndexingUpdateService
{
/**
* Apply updates to the relevant indexes.
*/
void apply( IndexUpdates updates ) throws IOException, IndexEntryConflictException;

/**
* Load eventual additional properties depending on the set of active indexes. This has to happen earlier than
* the actual application of the updates to the indexes, so that the properties reflect the exact state of the
* transaction.
*/
void loadAdditionalProperties( NodeUpdates nodeUpdates );
}
Expand Up @@ -189,6 +189,25 @@ public <INDEX_KEY extends LabelSchemaSupplier> Iterable<IndexEntryUpdate<INDEX_K
return gatherUpdatesForPotentials( potentiallyRelevant );
}

public <INDEX_KEY extends LabelSchemaSupplier> void loadAdditionalProperties(
Iterable<INDEX_KEY> indexKeys, PropertyLoader propertyLoader )
{
PrimitiveIntSet additionalPropertiesToLoad = Primitive.intSet();

for ( INDEX_KEY indexKey : indexKeys )
{
if ( atLeastOneRelevantChange( indexKey ) )
{
gatherPropsToLoad( indexKey.schema(), additionalPropertiesToLoad );
}
}

if ( !additionalPropertiesToLoad.isEmpty() )
{
loadProperties( propertyLoader, additionalPropertiesToLoad );
}
}

private <INDEX_KEY extends LabelSchemaSupplier> Iterable<IndexEntryUpdate<INDEX_KEY>> gatherUpdatesForPotentials(
Iterable<INDEX_KEY> potentiallyRelevant )
{
Expand Down
Expand Up @@ -55,6 +55,7 @@
import org.neo4j.kernel.impl.api.TransactionApplierFacade;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.api.index.IndexingServiceFactory;
import org.neo4j.kernel.impl.api.index.IndexingUpdateService;
import org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter;
import org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider;
import org.neo4j.kernel.impl.api.store.StorageLayer;
Expand Down Expand Up @@ -155,7 +156,7 @@ public class RecordStorageEngine implements StorageEngine, Lifecycle
private final LockService lockService;
private final WorkSync<Supplier<LabelScanWriter>,LabelUpdateWork> labelScanStoreSync;
private final CommandReaderFactory commandReaderFactory;
private final WorkSync<IndexingService,IndexUpdatesWork> indexUpdatesSync;
private final WorkSync<IndexingUpdateService,IndexUpdatesWork> indexUpdatesSync;
private final NeoStoreIndexStoreView indexStoreView;
private final LegacyIndexProviderLookup legacyIndexProviderLookup;
private final PropertyPhysicalToLogicalConverter indexUpdatesConverter;
Expand Down
Expand Up @@ -34,6 +34,7 @@
import org.neo4j.kernel.impl.api.BatchTransactionApplier;
import org.neo4j.kernel.impl.api.TransactionApplier;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.api.index.IndexingUpdateService;
import org.neo4j.kernel.impl.api.index.NodePropertyCommandsExtractor;
import org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter;
import org.neo4j.kernel.impl.store.NodeLabels;
Expand All @@ -58,7 +59,7 @@ public class IndexBatchTransactionApplier extends BatchTransactionApplier.Adapte
{
private final IndexingService indexingService;
private final WorkSync<Supplier<LabelScanWriter>,LabelUpdateWork> labelScanStoreSync;
private final WorkSync<IndexingService,IndexUpdatesWork> indexUpdatesSync;
private final WorkSync<IndexingUpdateService,IndexUpdatesWork> indexUpdatesSync;
private final SingleTransactionApplier transactionApplier;
private final PropertyPhysicalToLogicalConverter indexUpdateConverter;

Expand All @@ -67,7 +68,7 @@ public class IndexBatchTransactionApplier extends BatchTransactionApplier.Adapte

public IndexBatchTransactionApplier( IndexingService indexingService,
WorkSync<Supplier<LabelScanWriter>,LabelUpdateWork> labelScanStoreSync,
WorkSync<IndexingService,IndexUpdatesWork> indexUpdatesSync,
WorkSync<IndexingUpdateService,IndexUpdatesWork> indexUpdatesSync,
NodeStore nodeStore, PropertyLoader propertyLoader,
PropertyPhysicalToLogicalConverter indexUpdateConverter,
TransactionApplicationMode mode )
Expand Down
Expand Up @@ -29,8 +29,8 @@
import org.neo4j.concurrent.Work;
import org.neo4j.helpers.collection.NestingIterator;
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.impl.api.index.IndexingUpdateService;
import org.neo4j.kernel.impl.api.index.NodeUpdates;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.store.UnderlyingStorageException;
import org.neo4j.kernel.impl.transaction.command.Command.NodeCommand;
import org.neo4j.kernel.impl.transaction.command.Command.PropertyCommand;
Expand All @@ -39,7 +39,7 @@
/**
* Combines {@link IndexUpdates} from multiple transactions into one bigger job.
*/
public class IndexUpdatesWork implements Work<IndexingService,IndexUpdatesWork>
public class IndexUpdatesWork implements Work<IndexingUpdateService,IndexUpdatesWork>
{
private final List<IndexUpdates> updates = new ArrayList<>();

Expand All @@ -56,7 +56,7 @@ public IndexUpdatesWork combine( IndexUpdatesWork work )
}

@Override
public void apply( IndexingService material )
public void apply( IndexingUpdateService material )
{
try
{
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.neo4j.kernel.impl.api.TransactionApplier;
import org.neo4j.kernel.impl.api.TransactionToApply;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.api.index.IndexingUpdateService;
import org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter;
import org.neo4j.kernel.impl.store.NodeLabelsField;
import org.neo4j.kernel.impl.store.NodeStore;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void shouldProvideLabelScanStoreUpdatesSortedByNodeId() throws Exception
LabelScanWriter writer = new OrderVerifyingLabelScanWriter( 10, 15, 20 );
WorkSync<Supplier<LabelScanWriter>,LabelUpdateWork> labelScanSync =
spy( new WorkSync<>( singletonProvider( writer ) ) );
WorkSync<IndexingService,IndexUpdatesWork> indexUpdatesSync = new WorkSync<>( indexing );
WorkSync<IndexingUpdateService,IndexUpdatesWork> indexUpdatesSync = new WorkSync<>( indexing );
TransactionToApply tx = mock( TransactionToApply.class );
PropertyStore propertyStore = mock( PropertyStore.class );
try ( IndexBatchTransactionApplier applier = new IndexBatchTransactionApplier( indexing, labelScanSync,
Expand Down
Expand Up @@ -41,6 +41,7 @@
import org.neo4j.kernel.impl.api.BatchTransactionApplierFacade;
import org.neo4j.kernel.impl.api.TransactionToApply;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.api.index.IndexingUpdateService;
import org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter;
import org.neo4j.kernel.impl.core.CacheAccessBackDoor;
import org.neo4j.kernel.impl.core.RelationshipTypeToken;
Expand Down Expand Up @@ -114,7 +115,7 @@ public class NeoStoreTransactionApplierTest
private final WorkSync<Supplier<LabelScanWriter>,LabelUpdateWork>
labelScanStoreSynchronizer = new WorkSync<>( labelScanStore );
private final TransactionToApply transactionToApply = mock( TransactionToApply.class );
private final WorkSync<IndexingService,IndexUpdatesWork> indexUpdatesSync = new WorkSync<>( indexingService );
private final WorkSync<IndexingUpdateService,IndexUpdatesWork> indexUpdatesSync = new WorkSync<>( indexingService );

@Before
public void setup()
Expand Down
Expand Up @@ -33,6 +33,7 @@
import org.neo4j.kernel.impl.api.TransactionApplier;
import org.neo4j.kernel.impl.api.TransactionToApply;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.api.index.IndexingUpdateService;
import org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter;
import org.neo4j.kernel.impl.store.NodeStore;
import org.neo4j.kernel.impl.store.PropertyStore;
Expand All @@ -59,7 +60,7 @@ public class NeoTransactionIndexApplierTest
private final Collection<DynamicRecord> emptyDynamicRecords = Collections.emptySet();
private final WorkSync<Supplier<LabelScanWriter>,LabelUpdateWork> labelScanStoreSynchronizer =
new WorkSync<>( labelScanStore );
private final WorkSync<IndexingService,IndexUpdatesWork> indexUpdatesSync = new WorkSync<>( indexingService );
private final WorkSync<IndexingUpdateService,IndexUpdatesWork> indexUpdatesSync = new WorkSync<>( indexingService );
private final TransactionToApply transactionToApply = mock( TransactionToApply.class );

@Before
Expand Down
Expand Up @@ -32,6 +32,7 @@
import org.neo4j.kernel.impl.api.BatchTransactionApplier;
import org.neo4j.kernel.impl.api.TransactionToApply;
import org.neo4j.kernel.impl.api.index.IndexingService;
import org.neo4j.kernel.impl.api.index.IndexingUpdateService;
import org.neo4j.kernel.impl.api.index.PropertyPhysicalToLogicalConverter;
import org.neo4j.kernel.impl.core.CacheAccessBackDoor;
import org.neo4j.kernel.impl.locking.LockService;
Expand Down Expand Up @@ -84,7 +85,7 @@ public class SchemaRuleCommandTest
mock( CacheAccessBackDoor.class ), LockService.NO_LOCK_SERVICE );
private final WorkSync<Supplier<LabelScanWriter>,LabelUpdateWork> labelScanStoreSynchronizer =
new WorkSync<>( labelScanStore );
private final WorkSync<IndexingService,IndexUpdatesWork> indexUpdatesSync = new WorkSync<>( indexes );
private final WorkSync<IndexingUpdateService,IndexUpdatesWork> indexUpdatesSync = new WorkSync<>( indexes );
private final PropertyStore propertyStore = mock( PropertyStore.class );
private final IndexBatchTransactionApplier indexApplier = new IndexBatchTransactionApplier( indexes,
labelScanStoreSynchronizer, indexUpdatesSync, mock( NodeStore.class ),
Expand Down

0 comments on commit 5f17c62

Please sign in to comment.