Skip to content

Commit

Permalink
Revert "Merge pull request #9373 from davidegrohmann/3.3-small-improv…
Browse files Browse the repository at this point in the history
…ements"

This reverts commit febeb00, reversing
changes made to bd34af2.
  • Loading branch information
MishaDemianenko committed May 25, 2017
1 parent ecc3e3d commit 3cc94c7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 58 deletions.
15 changes: 15 additions & 0 deletions community/common/src/main/java/org/neo4j/function/Predicates.java
Expand Up @@ -271,4 +271,19 @@ public static <T> Predicate<T> in( final Iterable<T> allowed )
} }


public static IntPredicate ALWAYS_TRUE_INT = v -> true; public static IntPredicate ALWAYS_TRUE_INT = v -> true;

public static IntPredicate any( int[] values )
{
return v ->
{
for ( int value : values )
{
if ( v == value )
{
return true;
}
}
return false;
};
}
} }
Expand Up @@ -20,6 +20,7 @@
package org.neo4j.kernel.impl.api.store; package org.neo4j.kernel.impl.api.store;


import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.IntPredicate;


import org.neo4j.collection.primitive.PrimitiveLongIterator; import org.neo4j.collection.primitive.PrimitiveLongIterator;
import org.neo4j.io.pagecache.PageCursor; import org.neo4j.io.pagecache.PageCursor;
Expand All @@ -33,6 +34,8 @@
import org.neo4j.storageengine.api.Direction; import org.neo4j.storageengine.api.Direction;
import org.neo4j.storageengine.api.txstate.ReadableTransactionState; import org.neo4j.storageengine.api.txstate.ReadableTransactionState;


import static org.neo4j.function.Predicates.ALWAYS_TRUE_INT;
import static org.neo4j.function.Predicates.any;
import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP; import static org.neo4j.kernel.impl.store.record.Record.NO_NEXT_RELATIONSHIP;
import static org.neo4j.kernel.impl.store.record.Record.NULL_REFERENCE; import static org.neo4j.kernel.impl.store.record.Record.NULL_REFERENCE;
import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE; import static org.neo4j.kernel.impl.store.record.RecordLoad.FORCE;
Expand All @@ -53,7 +56,7 @@ public class NodeRelationshipCursor extends AbstractIteratorRelationshipCursor
private long relationshipId; private long relationshipId;
private long fromNodeId; private long fromNodeId;
private Direction direction; private Direction direction;
private int[] allowedTypes; private IntPredicate allowedTypes;
private int groupChainIndex; private int groupChainIndex;
private boolean end; private boolean end;


Expand All @@ -73,19 +76,19 @@ public NodeRelationshipCursor init( boolean isDense, long firstRelId, long fromN
ReadableTransactionState state ) ReadableTransactionState state )
{ {
PrimitiveLongIterator addedNodeRelationships = addedNodeRelationships( fromNodeId, direction, null, state ); PrimitiveLongIterator addedNodeRelationships = addedNodeRelationships( fromNodeId, direction, null, state );
return init( isDense, firstRelId, fromNodeId, direction, null, state, addedNodeRelationships ); return init( isDense, firstRelId, fromNodeId, direction, ALWAYS_TRUE_INT, state, addedNodeRelationships );
} }


public NodeRelationshipCursor init( boolean isDense, long firstRelId, long fromNodeId, Direction direction, public NodeRelationshipCursor init( boolean isDense, long firstRelId, long fromNodeId, Direction direction,
int[] allowedTypes, ReadableTransactionState state ) int[] allowedTypes, ReadableTransactionState state )
{ {
PrimitiveLongIterator addedNodeRelationships = PrimitiveLongIterator addedNodeRelationships =
addedNodeRelationships( fromNodeId, direction, allowedTypes, state ); addedNodeRelationships( fromNodeId, direction, allowedTypes, state );
return init( isDense, firstRelId, fromNodeId, direction, allowedTypes, state, addedNodeRelationships ); return init( isDense, firstRelId, fromNodeId, direction, any( allowedTypes ), state, addedNodeRelationships );
} }


private NodeRelationshipCursor init( boolean isDense, long firstRelId, long fromNodeId, Direction direction, private NodeRelationshipCursor init( boolean isDense, long firstRelId, long fromNodeId, Direction direction,
int[] allowedTypes, ReadableTransactionState state, PrimitiveLongIterator addedNodeRelationships ) IntPredicate allowedTypes, ReadableTransactionState state, PrimitiveLongIterator addedNodeRelationships )
{ {
internalInitTxState( state, addedNodeRelationships ); internalInitTxState( state, addedNodeRelationships );
this.isDense = isDense; this.isDense = isDense;
Expand All @@ -111,6 +114,11 @@ private NodeRelationshipCursor init( boolean isDense, long firstRelId, long from
private PrimitiveLongIterator addedNodeRelationships( long fromNodeId, Direction direction, private PrimitiveLongIterator addedNodeRelationships( long fromNodeId, Direction direction,
int[] allowedTypes, ReadableTransactionState state ) int[] allowedTypes, ReadableTransactionState state )
{ {
if ( state == null )
{
return null;
}

return allowedTypes == null ? state.getNodeState( fromNodeId ).getAddedRelationships( direction ) return allowedTypes == null ? state.getNodeState( fromNodeId ).getAddedRelationships( direction )
: state.getNodeState( fromNodeId ).getAddedRelationships( direction, allowedTypes ); : state.getNodeState( fromNodeId ).getAddedRelationships( direction, allowedTypes );
} }
Expand All @@ -129,17 +137,13 @@ protected boolean doFetchNext()
// to chase a used record down the line. // to chase a used record down the line.
try try
{ {
// Direction check
if ( record.inUse() ) if ( record.inUse() )
{ {
// direction is checked while reading the group chain, no need to check it here again if ( direction != Direction.BOTH )
if ( !isDense )
{ {
// Direction check
switch ( direction ) switch ( direction )
{ {
case BOTH:
break;

case INCOMING: case INCOMING:
{ {
if ( record.getSecondNode() != fromNodeId ) if ( record.getSecondNode() != fromNodeId )
Expand All @@ -163,11 +167,12 @@ protected boolean doFetchNext()
} }
} }


// Type check, for dense nodes it is checked while traversing the group records // Type check
if ( isDense || checkType( record.getType() ) ) if ( !allowedTypes.test( record.getType() ) )
{ {
return true; continue;
} }
return true;
} }
} }
finally finally
Expand Down Expand Up @@ -202,23 +207,6 @@ else if ( record.getSecondNode() == fromNodeId )
return false; return false;
} }


private boolean checkType( int type )
{
if ( allowedTypes == null )
{
return true;
}

for ( int allowedType : allowedTypes )
{
if ( type == allowedType )
{
return true;
}
}
return false;
}

@Override @Override
public void close() public void close()
{ {
Expand All @@ -232,7 +220,7 @@ private long nextChainStart()
{ {
// We check inUse flag here since we can actually follow pointers in unused records // We check inUse flag here since we can actually follow pointers in unused records
// to guard for and overcome concurrent deletes in the relationship group chain // to guard for and overcome concurrent deletes in the relationship group chain
if ( groupRecord.inUse() && checkType( groupRecord.getType() ) ) if ( groupRecord.inUse() && allowedTypes.test( groupRecord.getType() ) )
{ {
// Go to the next chain (direction) within this group // Go to the next chain (direction) within this group
while ( groupChainIndex < GROUP_CHAINS.length ) while ( groupChainIndex < GROUP_CHAINS.length )
Expand Down
Expand Up @@ -55,13 +55,13 @@ protected boolean loadNextFromDisk()
} }


// go to disk if the state does not contain the keyId we are looking for // go to disk if the state does not contain the keyId we are looking for
return !state.hasChanges() || state.getAddedProperty( propertyKeyId ) == null; return state.getAddedProperty( propertyKeyId ) == null;
} }


@Override @Override
protected DefinedProperty nextAdded() protected DefinedProperty nextAdded()
{ {
return fetched ? null : (DefinedProperty) state.getAddedProperty( propertyKeyId ); return !fetched ? (DefinedProperty) state.getAddedProperty( propertyKeyId ) : null;
} }


@Override @Override
Expand Down
Expand Up @@ -27,7 +27,6 @@
import java.time.Clock; import java.time.Clock;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.function.Predicate; import java.util.function.Predicate;


import org.neo4j.function.IOFunction; import org.neo4j.function.IOFunction;
Expand Down Expand Up @@ -375,31 +374,16 @@ public void shouldNotEndUpInBrokenStateAfterRotationFailure() throws Exception
{ {
tx.incrementNodeCount( labelId, 1 ); // now at 2 tx.incrementNodeCount( labelId, 1 ); // now at 2
} }

clock.forward( Config.empty().get( GraphDatabaseSettings.counts_store_rotation_timeout ) * 2, MILLISECONDS );
while ( true ) try
{ {
/* rotation.get();
* There is a race between forwarding the clock and the thread calling rotate, in case the call to forward fail( "Should've failed rotation due to timeout" );
* the clock happens before the thread calls rotate, then this test hangs. In order to solve this issue, }
* a timeout is set on the future and if the timeout is trigger the clock is forwarded again and we try catch ( ExecutionException e )
* again. {
*/ // good
clock.forward( Config.empty().get( GraphDatabaseSettings.counts_store_rotation_timeout ) * 2, MILLISECONDS ); assertTrue( e.getCause() instanceof RotationTimeoutException );
try
{
rotation.get( 100, MILLISECONDS );
fail( "Should've failed rotation due to timeout" );
}
catch ( TimeoutException e )
{
// ignore try again
}
catch ( ExecutionException e )
{
// good
assertTrue( e.getCause() instanceof RotationTimeoutException );
break;
}
} }


// THEN // THEN
Expand Down

0 comments on commit 3cc94c7

Please sign in to comment.