Skip to content

Commit

Permalink
Minor cleanup for the fulltext addon
Browse files Browse the repository at this point in the history
  • Loading branch information
ragadeeshu committed Oct 11, 2017
1 parent 618615c commit 5e57d56
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 27 deletions.
Expand Up @@ -88,7 +88,7 @@ public FulltextProvider( GraphDatabaseService db, Log log, AvailabilityGuard ava
applier = new FulltextUpdateApplier( log, availabilityGuard, scheduler );
applier.start();
factory = new FulltextFactory( fileSystem, storeDir, analyzerClassName );
fulltextTransactionEventUpdater = new FulltextTransactionEventUpdater( this, log, applier );
fulltextTransactionEventUpdater = new FulltextTransactionEventUpdater( this, applier );
nodeProperties = ConcurrentHashMap.newKeySet();
relationshipProperties = ConcurrentHashMap.newKeySet();
writableNodeIndices = new ConcurrentHashMap<>();
Expand Down
Expand Up @@ -30,29 +30,25 @@
import org.neo4j.graphdb.NotFoundException;
import org.neo4j.graphdb.event.TransactionData;
import org.neo4j.graphdb.event.TransactionEventHandler;
import org.neo4j.logging.Log;

class FulltextTransactionEventUpdater implements TransactionEventHandler<Object>
class FulltextTransactionEventUpdater implements TransactionEventHandler<FulltextTransactionEventUpdater.FulltextTransactionContext>
{
private final FulltextProvider fulltextProvider;
private final Log log;
private final FulltextUpdateApplier applier;

FulltextTransactionEventUpdater( FulltextProvider fulltextProvider, Log log,
FulltextUpdateApplier applier )
FulltextTransactionEventUpdater( FulltextProvider fulltextProvider, FulltextUpdateApplier applier )
{
this.fulltextProvider = fulltextProvider;
this.log = log;
this.applier = applier;
}

@Override
public Object beforeCommit( TransactionData data ) throws Exception
public FulltextTransactionContext beforeCommit( TransactionData data ) throws Exception
{
Map<Long,Map<String,Object>> nodeMap = new HashMap<Long,Map<String,Object>>();
Map<Long,Map<String,Object>> relationshipMap = new HashMap<Long,Map<String,Object>>();
Map<Long,Map<String,Object>> nodeMap = new HashMap<>();
Map<Long,Map<String,Object>> relationshipMap = new HashMap<>();
Lock lock = fulltextProvider.readLockIndexConfiguration();
FulltextTransactioncontext fulltextTransactioncontext = new FulltextTransactioncontext( nodeMap, relationshipMap, lock );
FulltextTransactionContext fulltextTransactionContext = new FulltextTransactionContext( nodeMap, relationshipMap, lock );

String[] nodeProperties = fulltextProvider.getNodeProperties();
data.removedNodeProperties().forEach( propertyEntry ->
Expand Down Expand Up @@ -86,21 +82,20 @@ public Object beforeCommit( TransactionData data ) throws Exception
data.assignedRelationshipProperties().forEach(
propertyEntry -> relationshipMap.put( propertyEntry.entity().getId(),
propertyEntry.entity().getProperties( relationshipProperties ) ) );
return fulltextTransactioncontext;
return fulltextTransactionContext;
}

@Override
public void afterCommit( TransactionData data, Object state )
public void afterCommit( TransactionData data, FulltextTransactionContext state )
{
RuntimeException applyException = null;
List<AsyncFulltextIndexOperation> completions = new ArrayList<>();
FulltextTransactioncontext context = (FulltextTransactioncontext) state;
try
{
try
{
Map<Long,Map<String,Object>> nodeMap = context.getNodeMap();
Map<Long,Map<String,Object>> relationshipMap = context.getRelationshipMap();
Map<Long,Map<String,Object>> nodeMap = state.getNodeMap();
Map<Long,Map<String,Object>> relationshipMap = state.getRelationshipMap();

//update node indices
for ( WritableFulltext nodeIndex : fulltextProvider.writableNodeIndices() )
Expand Down Expand Up @@ -143,24 +138,23 @@ public void afterCommit( TransactionData data, Object state )
}
finally
{
context.release();
state.release();
}
}

@Override
public void afterRollback( TransactionData data, Object state )
public void afterRollback( TransactionData data, FulltextTransactionContext state )
{
FulltextTransactioncontext context = (FulltextTransactioncontext) state;
context.release();
state.release();
}

private static class FulltextTransactioncontext
public static class FulltextTransactionContext
{
private final Map<Long,Map<String,Object>> nodeMap;
private final Map<Long,Map<String,Object>> relationshipMap;
private final Lock lock;

private FulltextTransactioncontext( Map<Long,Map<String,Object>> nodeMap, Map<Long,Map<String,Object>> relationshipMap, Lock lock )
private FulltextTransactionContext( Map<Long,Map<String,Object>> nodeMap, Map<Long,Map<String,Object>> relationshipMap, Lock lock )
{
this.nodeMap = nodeMap;
this.relationshipMap = relationshipMap;
Expand Down
Expand Up @@ -41,11 +41,6 @@
*/
public class BloomFulltextConfig implements LoadableConfig
{
public static final String UNSUPPORTED_PROPERTY_KEY_REGEX = "^(?!" + LUCENE_FULLTEXT_ADDON_PREFIX + ").+$";
public static final BiFunction<List<String>,Function<String,String>,List<String>> ILLEGAL_VALUE_CONSTRAINT =
illegalValueMessage( "Must not contain '" + LUCENE_FULLTEXT_ADDON_PREFIX + "'", matchesAny(
UNSUPPORTED_PROPERTY_KEY_REGEX ) );

@Description( "Enable the fulltext addon for bloom." )
@Internal
static final Setting<Boolean> bloom_enabled = setting( "unsupported.dbms.bloom_enabled", BOOLEAN, FALSE );
Expand Down

0 comments on commit 5e57d56

Please sign in to comment.