Skip to content

Commit

Permalink
Merge pull request #9250 from MishaDemianenko/3.2-index-update-tx-state
Browse files Browse the repository at this point in the history
Avoid duplicated work in transaction state when doing index updates.
  • Loading branch information
MishaDemianenko committed May 15, 2017
2 parents 0e957c2 + fbd1780 commit 3a8d8c5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,7 @@ public void pageCursorCloseWithClosedLinkedCursorShouldNotReturnSameObjectToCurs
{
File file = file( "a" );
generateFileWithRecords( file, recordsPerFilePage * 2, recordSize );
getPageCache( fs, maxPages, pageCachePageSize, PageCacheTracer.NULL );
getPageCache( fs, maxPages, pageCachePageSize, PageCacheTracer.NULL, DefaultPageCursorTracerSupplier.INSTANCE );
try ( PagedFile pf = pageCache.map( file, filePageSize ) )
{
PageCursor a = pf.io( 0, PF_SHARED_WRITE_LOCK );
Expand All @@ -2947,7 +2947,7 @@ public void pageCursorCloseMustNotClosePreviouslyLinkedCursorThatGotReused() thr
{
File file = file( "a" );
generateFileWithRecords( file, recordsPerFilePage * 2, recordSize );
getPageCache( fs, maxPages, pageCachePageSize, PageCacheTracer.NULL );
getPageCache( fs, maxPages, pageCachePageSize, PageCacheTracer.NULL, DefaultPageCursorTracerSupplier.INSTANCE );
try ( PagedFile pf = pageCache.map( file, filePageSize ) )
{
PageCursor a = pf.io( 0, PF_SHARED_WRITE_LOCK );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1192,39 +1192,62 @@ private TreeMap<OrderedPropertyValues, DiffSets<Long>> getSortedIndexUpdates( La
public void indexDoUpdateEntry( LabelSchemaDescriptor descriptor, long nodeId,
OrderedPropertyValues propertiesBefore, OrderedPropertyValues propertiesAfter )
{
NodeStateImpl nodeState = getOrCreateNodeState( nodeId );
Map<OrderedPropertyValues,DiffSets<Long>> updates = getIndexUpdatesByDescriptor( descriptor, true);
if ( propertiesBefore != null )
{
DiffSets<Long> before = getIndexUpdatesForSeek( descriptor, propertiesBefore, true );
DiffSets<Long> before = getIndexUpdatesForSeek( updates, propertiesBefore, true );
//noinspection ConstantConditions
before.remove( nodeId );
if ( before.getRemoved().contains( nodeId ) )
{
getOrCreateNodeState( nodeId ).addIndexDiff( before );
nodeState.addIndexDiff( before );
}
else
{
getOrCreateNodeState( nodeId ).removeIndexDiff( before );
nodeState.removeIndexDiff( before );
}
}

if ( propertiesAfter != null )
{
DiffSets<Long> after = getIndexUpdatesForSeek( descriptor, propertiesAfter, true );
DiffSets<Long> after = getIndexUpdatesForSeek( updates, propertiesAfter, true );
//noinspection ConstantConditions
after.add( nodeId );
if ( after.getAdded().contains( nodeId ) )
{
getOrCreateNodeState( nodeId ).addIndexDiff( after );
nodeState.addIndexDiff( after );
}
else
{
getOrCreateNodeState( nodeId ).removeIndexDiff( after );
nodeState.removeIndexDiff( after );
}
}
}

private DiffSets<Long> getIndexUpdatesForSeek(
LabelSchemaDescriptor schema, OrderedPropertyValues values, boolean create )
{
Map<OrderedPropertyValues,DiffSets<Long>> updates = getIndexUpdatesByDescriptor( schema, create );
if ( updates != null )
{
return getIndexUpdatesForSeek( updates, values, create );
}
return null;
}

private DiffSets<Long> getIndexUpdatesForSeek( Map<OrderedPropertyValues,DiffSets<Long>> updates,
OrderedPropertyValues values, boolean create )
{
DiffSets<Long> diffs = updates.get( values );
if ( diffs == null && create )
{
updates.put( values, diffs = new DiffSets<>() );
}
return diffs;
}

private Map<OrderedPropertyValues,DiffSets<Long>> getIndexUpdatesByDescriptor( LabelSchemaDescriptor schema,
boolean create )
{
if ( indexUpdates == null )
{
Expand All @@ -1243,12 +1266,7 @@ private DiffSets<Long> getIndexUpdatesForSeek(
}
indexUpdates.put( schema, updates = new HashMap<>() );
}
DiffSets<Long> diffs = updates.get( values );
if ( diffs == null && create )
{
updates.put( values, diffs = new DiffSets<>() );
}
return diffs;
return updates;
}

private DiffSets<Long> getIndexUpdatesForScan( LabelSchemaDescriptor schema )
Expand Down

0 comments on commit 3a8d8c5

Please sign in to comment.