Skip to content

Commit

Permalink
Less index updates work sync if no relevant updates
Browse files Browse the repository at this point in the history
by figuring out if there are any potential updates at all and if not
skip creating a couple of update instances and participating in index/label
work sync jobs unnecessarily.
  • Loading branch information
tinwelint committed Jan 22, 2016
1 parent 19a81a1 commit 290c7ad
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.neo4j.storageengine.api.CommandsToApply;

import static org.neo4j.collection.primitive.Primitive.longObjectMap;
import static org.neo4j.kernel.impl.store.NodeLabelsField.fieldPointsToDynamicRecordOfLabels;

/**
* Implements both BatchTransactionApplier and TransactionApplier in order to reduce garbage.
Expand All @@ -44,6 +45,7 @@ public class NodePropertyCommandsExtractor extends TransactionApplier.Adapter
{
private final PrimitiveLongObjectMap<NodeCommand> nodeCommandsById = longObjectMap();
private final PrimitiveLongObjectMap<List<PropertyCommand>> propertyCommandsByNodeIds = longObjectMap();
private boolean hasUpdates;

@Override
public TransactionApplier startTx( CommandsToApply transaction )
Expand All @@ -68,9 +70,24 @@ public void close() throws Exception
public boolean visitNodeCommand( NodeCommand command ) throws IOException
{
nodeCommandsById.put( command.getKey(), command );
if ( !hasUpdates && hasLabelChanges( command ) )
{
hasUpdates = true;
}
return false;
}

private boolean hasLabelChanges( NodeCommand command )
{
long before = command.getBefore().getLabelField();
long after = command.getAfter().getLabelField();
return before != after ||
// Because we don't know here, there may have been changes to a dynamic label record
// even though it still points to the same one
fieldPointsToDynamicRecordOfLabels( before ) || fieldPointsToDynamicRecordOfLabels( after );

}

@Override
public boolean visitPropertyCommand( PropertyCommand command ) throws IOException
{
Expand All @@ -84,13 +101,14 @@ public boolean visitPropertyCommand( PropertyCommand command ) throws IOExceptio
propertyCommandsByNodeIds.put( nodeId, group = new ArrayList<>() );
}
group.add( command );
hasUpdates = true;
}
return false;
}

public boolean containsAnyNodeOrPropertyUpdate()
{
return !nodeCommandsById.isEmpty() || !propertyCommandsByNodeIds.isEmpty();
return hasUpdates;
}

public PrimitiveLongObjectMap<NodeCommand> nodeCommandsById()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public TransactionApplier startTx( CommandsToApply transaction )

private void applyIndexUpdates()
{
if ( indexUpdates != null )
if ( indexUpdates != null && indexUpdates.hasUpdates() )
{
indexUpdatesSync.apply( new IndexUpdatesWork( indexUpdates ) );
indexUpdates = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public void feed( PrimitiveLongObjectMap<List<PropertyCommand>> propCommands,
{
throw new UnsupportedOperationException();
}

@Override
public boolean hasUpdates()
{
return true;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ public void feed( PrimitiveLongObjectMap<List<PropertyCommand>> propCommands,
{
throw new UnsupportedOperationException();
}

@Override
public boolean hasUpdates()
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ void feed( PrimitiveLongObjectMap<List<PropertyCommand>> propCommands,
* @param target to receive these node ids.
*/
void collectUpdatedNodeIds( PrimitiveLongSet target );

boolean hasUpdates();
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ public void feed( PrimitiveLongObjectMap<List<PropertyCommand>> propertyCommands
gatherUpdatesFromNodeCommands( nodeCommands, propertyCommands, propertyChanges );
}

@Override
public boolean hasUpdates()
{
return !updates.isEmpty();
}

private void gatherUpdatesFromPropertyCommands(
PrimitiveLongObjectMap<NodeCommand> nodeCommands,
PrimitiveLongObjectMap<List<PropertyCommand>> propCommands,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ public void feed( PrimitiveLongObjectMap<List<PropertyCommand>> propCommands,
ids.addAll( propCommands.iterator() );
ids.addAll( nodeCommands.iterator() );
}

@Override
public boolean hasUpdates()
{
return !ids.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,12 @@ public void feed( PrimitiveLongObjectMap<List<PropertyCommand>> propCommands,
{
throw new UnsupportedOperationException();
}

@Override
public boolean hasUpdates()
{
return !nodeIds.isEmpty();
}
};
}

Expand Down

0 comments on commit 290c7ad

Please sign in to comment.