Skip to content

Commit

Permalink
Revert "Merge pull request #11 from davidegrohmann/3.3-fix-regression"
Browse files Browse the repository at this point in the history
This reverts commit 9608c17, reversing
changes made to 126c31b.
  • Loading branch information
MishaDemianenko committed May 25, 2017
1 parent c60ea27 commit 19359c0
Show file tree
Hide file tree
Showing 29 changed files with 280 additions and 358 deletions.
Expand Up @@ -87,7 +87,6 @@
import org.neo4j.kernel.impl.logging.LogService;
import org.neo4j.kernel.impl.proc.Procedures;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.StorageStatementFactory;
import org.neo4j.kernel.impl.store.MetaDataStore;
import org.neo4j.kernel.impl.store.StoreId;
import org.neo4j.kernel.impl.store.format.RecordFormatPropertyConfigurator;
Expand Down Expand Up @@ -264,7 +263,6 @@ boolean applicable( DiagnosticsPhase phase )
private final Map<String,IndexImplementation> indexProviders = new HashMap<>();
private final LegacyIndexProviderLookup legacyIndexProviderLookup;
private final ConstraintSemantics constraintSemantics;
private final StorageStatementFactory storageStatementFactory;
private final Procedures procedures;
private final IOLimiter ioLimiter;
private final AvailabilityGuard availabilityGuard;
Expand Down Expand Up @@ -318,7 +316,6 @@ public NeoStoreDataSource(
AutoIndexing autoIndexing,
PageCache pageCache,
ConstraintSemantics constraintSemantics,
StorageStatementFactory storageStatementFactory,
Monitors monitors,
Tracers tracers,
Procedures procedures,
Expand Down Expand Up @@ -356,7 +353,6 @@ public NeoStoreDataSource(
this.startupStatistics = startupStatistics;
this.guard = guard;
this.constraintSemantics = constraintSemantics;
this.storageStatementFactory = storageStatementFactory;
this.monitors = monitors;
this.tracers = tracers;
this.procedures = procedures;
Expand Down Expand Up @@ -585,10 +581,10 @@ private StorageEngine buildStorageEngine(
() -> kernelModule.kernelTransactions().get();
RecordStorageEngine storageEngine = new RecordStorageEngine( storeDir, config, idGeneratorFactory,
eligibleForReuse, idTypeConfigurationProvider, pageCache, fs, logProvider, propertyKeyTokenHolder,
labelTokens, relationshipTypeTokens, schemaStateChangeCallback, constraintSemantics,
storageStatementFactory, scheduler, tokenNameLookup, lockService, schemaIndexProvider,
indexingServiceMonitor, databaseHealth, labelScanStoreProvider, legacyIndexProviderLookup,
indexConfigStore, legacyIndexTransactionOrdering, transactionSnapshotSupplier );
labelTokens, relationshipTypeTokens, schemaStateChangeCallback, constraintSemantics, scheduler,
tokenNameLookup, lockService, schemaIndexProvider, indexingServiceMonitor, databaseHealth,
labelScanStoreProvider, legacyIndexProviderLookup, indexConfigStore, legacyIndexTransactionOrdering,
transactionSnapshotSupplier );

// We pretend that the storage engine abstract hides all details within it. Whereas that's mostly
// true it's not entirely true for the time being. As long as we need this call below, which
Expand Down
Expand Up @@ -34,7 +34,6 @@
import org.neo4j.storageengine.api.txstate.ReadableTransactionState;
import org.neo4j.storageengine.api.txstate.TxStateVisitor;

import static org.neo4j.function.Predicates.ALWAYS_TRUE_INT;
import static org.neo4j.kernel.api.ReadOperations.ANY_LABEL;
import static org.neo4j.kernel.api.ReadOperations.ANY_RELATIONSHIP_TYPE;

Expand Down Expand Up @@ -80,7 +79,7 @@ private void decrementCountForLabelsAndRelationships( NodeItem node )
} );

storeLayer.degrees( statement, node,
( type, out, in ) -> updateRelationshipsCountsFromDegrees( labelIds, type, -out, -in ) );
( type, out, in, loop ) -> updateRelationshipsCountsFromDegrees( labelIds, type, -out, -in, -loop ) );
}

@Override
Expand Down Expand Up @@ -125,37 +124,39 @@ public void visitNodeLabelChanges( long id, final Set<Integer> added, final Set<
// get the relationship counts from *before* this transaction,
// the relationship changes will compensate for what happens during the transaction
storeLayer.nodeCursor( statement, id, null )
.forAll( node -> storeLayer.degrees( statement, node, ( type, out, in ) ->
.forAll( node -> storeLayer.degrees( statement, node, ( type, out, in, loop ) ->
{
added.forEach( label -> updateRelationshipsCountsFromDegrees( type, label, out, in ) );
removed.forEach(
label -> updateRelationshipsCountsFromDegrees( type, label, -out, -in ) );
added.forEach( label -> updateRelationshipsCountsFromDegrees( type, label, out, in, loop ) );
removed.forEach( label -> updateRelationshipsCountsFromDegrees( type, label, -out, -in, -loop ) );
return true;
} ) );
}
super.visitNodeLabelChanges( id, added, removed );
}

private void updateRelationshipsCountsFromDegrees( PrimitiveIntCollection labels, int type, long out, long in )
private boolean updateRelationshipsCountsFromDegrees( PrimitiveIntCollection labels, int type, long outgoing,
long incoming, long loop )
{
labels.visitKeys( label -> updateRelationshipsCountsFromDegrees( type, label, out, in ) );
labels.visitKeys( label -> updateRelationshipsCountsFromDegrees( type, label, outgoing, incoming, loop ) );
return true;
}

private boolean updateRelationshipsCountsFromDegrees( int type, int label, long out, long in )
private boolean updateRelationshipsCountsFromDegrees( int type, int label, long out, long in, long loop )
{
// untyped
counts.incrementRelationshipCount( label, ANY_RELATIONSHIP_TYPE, ANY_LABEL, out );
counts.incrementRelationshipCount( ANY_LABEL, ANY_RELATIONSHIP_TYPE, label, in );
counts.incrementRelationshipCount( label, ANY_RELATIONSHIP_TYPE, ANY_LABEL, out + loop );
counts.incrementRelationshipCount( ANY_LABEL, ANY_RELATIONSHIP_TYPE, label, in + loop );
// typed
counts.incrementRelationshipCount( label, type, ANY_LABEL, out );
counts.incrementRelationshipCount( ANY_LABEL, type, label, in );
counts.incrementRelationshipCount( label, type, ANY_LABEL, out + loop );
counts.incrementRelationshipCount( ANY_LABEL, type, label, in + loop );
return false;
}

private void updateRelationshipCount( long startNode, int type, long endNode, int delta )
{
updateRelationshipsCountsFromDegrees( type, ANY_LABEL, delta, 0 );
visitLabels( startNode, ( labelId ) -> updateRelationshipsCountsFromDegrees( type, labelId, delta, 0) );
visitLabels( endNode, ( labelId ) -> updateRelationshipsCountsFromDegrees( type, labelId, 0, delta ) );
updateRelationshipsCountsFromDegrees( type, ANY_LABEL, delta, 0, 0 );
visitLabels( startNode, ( labelId ) -> updateRelationshipsCountsFromDegrees( type, labelId, delta, 0, 0 ) );
visitLabels( endNode, ( labelId ) -> updateRelationshipsCountsFromDegrees( type, labelId, 0, delta, 0 ) );
}

private void visitLabels( long nodeId, PrimitiveIntVisitor<RuntimeException> visitor )
Expand Down
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2002-2017 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.api;

import org.neo4j.storageengine.api.Direction;

public class CountingDegreeVisitor implements DegreeVisitor
{
private final Direction direction;
private final int relType;
private final boolean dense;

private int count;

public CountingDegreeVisitor( Direction direction, boolean dense )
{
this( direction, -1, dense );
}

public CountingDegreeVisitor( Direction direction, int relType, boolean dense )
{
this.direction = direction;
this.relType = relType;
this.dense = dense;
}

@Override
public boolean visitDegree( int type, long outgoing, long incoming, long loop )
{
if ( relType == -1 || type == relType )
{
switch ( direction )
{
case OUTGOING:
count += outgoing + loop;
break;
case INCOMING:
count += incoming + loop;
break;
case BOTH:
count += outgoing + incoming + loop;
break;
default:
throw new IllegalStateException( "Unknown direction: " + direction );
}
// continue only if we are counting all types or the node is not dense (i.e., we visit one rel at the time)
return relType == -1 || !dense;
}
return true;
}

public int count()
{
return count;
}
}
Expand Up @@ -22,5 +22,25 @@
@FunctionalInterface
public interface DegreeVisitor
{
void visitDegree( int type, long outgoing, long incoming );
interface Visitable extends AutoCloseable
{
void accept( DegreeVisitor visitor );

@Override
void close();

default void once( DegreeVisitor visitor )
{
try
{
accept( visitor );
}
finally
{
close();
}
}
}

boolean visitDegree( int type, long outgoing, long incoming, long loop );
}
Expand Up @@ -1653,14 +1653,30 @@ public PrimitiveIntSet relationshipTypes( KernelStatement statement, NodeItem no
@Override
public int degree( KernelStatement statement, NodeItem node, Direction direction )
{
ReadableTransactionState state = statement.hasTxStateWithChanges() ? statement.txState() : null;
return storeLayer.countDegrees( statement.getStoreStatement(), node, direction, state );
int degree = statement.hasTxStateWithChanges() && statement.txState().nodeIsAddedInThisTx( node.id() )
? 0
: visitDegrees( statement, node, new CountingDegreeVisitor( direction, node.isDense() ) ).count();

return statement.hasTxStateWithChanges()
? statement.txState().getNodeState( node.id() ).augmentDegree( direction, degree )
: degree;
}

@Override
public int degree( KernelStatement statement, NodeItem node, Direction direction, int relType )
{
ReadableTransactionState state = statement.hasTxStateWithChanges() ? statement.txState() : null;
return storeLayer.countDegrees( statement.getStoreStatement(), node, direction, relType, state );
int degree = statement.hasTxStateWithChanges() && statement.txState().nodeIsAddedInThisTx( node.id() )
? 0
: visitDegrees( statement, node, new CountingDegreeVisitor( direction, relType, node.isDense() ) ).count();

return statement.hasTxStateWithChanges()
? statement.txState().getNodeState( node.id() ).augmentDegree( direction, degree, relType )
: degree;
}

private <T extends DegreeVisitor> T visitDegrees( KernelStatement statement, NodeItem node, T visitor )
{
storeLayer.degrees( statement.getStoreStatement(), node, visitor );
return visitor;
}
}
Expand Up @@ -372,6 +372,12 @@ private DiffSets<Long> getOrCreateLabelStateNodeDiffSets( int labelId )
return LABEL_STATE.getOrCreate( this, labelId ).getOrCreateNodeDiffSets();
}

@Override
public ReadableDiffSets<Integer> nodeStateLabelDiffSets( long nodeId )
{
return NODE_STATE.get( this, nodeId ).labelDiffSets();
}

private DiffSets<Integer> getOrCreateNodeStateLabelDiffSets( long nodeId )
{
return getOrCreateNodeState( nodeId ).getOrCreateLabelDiffSets();
Expand Down Expand Up @@ -468,6 +474,12 @@ public boolean nodeIsDeletedInThisTx( long nodeId )
return nodesDeletedInTx != null && nodesDeletedInTx.contains( nodeId );
}

@Override
public boolean nodeModifiedInThisTx( long nodeId )
{
return nodeIsAddedInThisTx( nodeId ) || nodeIsDeletedInThisTx( nodeId ) || hasNodeState( nodeId );
}

@Override
public void relationshipDoDelete( long id, int type, long startNodeId, long endNodeId )
{
Expand Down Expand Up @@ -720,6 +732,24 @@ private DiffSets<Long> nodes()
return nodes;
}

@Override
public int augmentNodeDegree( long nodeId, int degree, Direction direction )
{
return NODE_STATE.get( this, nodeId ).augmentDegree( direction, degree );
}

@Override
public int augmentNodeDegree( long nodeId, int degree, Direction direction, int typeId )
{
return NODE_STATE.get( this, nodeId ).augmentDegree( direction, degree, typeId );
}

@Override
public PrimitiveIntSet nodeRelationshipTypes( long nodeId )
{
return NODE_STATE.get( this, nodeId ).relationshipTypes();
}

@Override
public ReadableRelationshipDiffSets<Long> addedAndRemovedRelationships()
{
Expand Down

0 comments on commit 19359c0

Please sign in to comment.