Skip to content

Commit

Permalink
Fixed a leak of stale versions of the properties array in Primitive.
Browse files Browse the repository at this point in the history
Conflicts:

	kernel/src/main/java/org/neo4j/kernel/impl/core/ArrayBasedPrimitive.java
  • Loading branch information
thobe committed Jan 29, 2012
1 parent 5d0cbdc commit 9c68896
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions kernel/src/main/java/org/neo4j/kernel/impl/core/Primitive.java
Expand Up @@ -567,6 +567,7 @@ protected void commitPropertyMaps(

synchronized ( this )
{
// Dereference the volatile once to avoid multiple barriers
PropertyData[] newArray = properties;

/*
Expand All @@ -582,13 +583,22 @@ protected void commitPropertyMaps(
extraLength += cowPropertyAddMap.size();
}

int newArraySize = newArray.length;

// make sure that we don't make inplace modifications to the existing array
// TODO: Refactor this to guarantee only one copy,
// currently it can do two copies in the clone() case if it also compacts
if ( extraLength > 0 )
{
newArray = new PropertyData[properties.length + extraLength];
System.arraycopy( properties, 0, newArray, 0, properties.length );
PropertyData[] oldArray = newArray;
newArray = new PropertyData[oldArray.length + extraLength];
System.arraycopy( oldArray, 0, newArray, 0, oldArray.length );
}
else
{
newArray = newArray.clone();
}

int newArraySize = properties.length;
if ( cowPropertyRemoveMap != null )
{
for ( Integer keyIndex : cowPropertyRemoveMap.keySet() )
Expand All @@ -614,8 +624,7 @@ protected void commitPropertyMaps(
for ( int i = 0; i < newArray.length; i++ )
{
PropertyData existingProperty = newArray[i];
if ( existingProperty == null
|| addedProperty.getIndex() == existingProperty.getIndex() )
if ( existingProperty == null || addedProperty.getIndex() == existingProperty.getIndex() )
{
newArray[i] = addedProperty;
if ( existingProperty == null )
Expand All @@ -631,8 +640,7 @@ protected void commitPropertyMaps(
if ( newArraySize < newArray.length )
{
PropertyData[] compactedNewArray = new PropertyData[newArraySize];
System.arraycopy( newArray, 0, compactedNewArray, 0,
newArraySize );
System.arraycopy( newArray, 0, compactedNewArray, 0, newArraySize );
properties = compactedNewArray;
}
else
Expand Down Expand Up @@ -728,4 +736,4 @@ protected Object getCommittedPropertyValue( NodeManager nodeManager, String key
}
return null;
}
}
}

0 comments on commit 9c68896

Please sign in to comment.