Skip to content

Commit

Permalink
Primitive sets and maps used for recovered node ids and grouping of c…
Browse files Browse the repository at this point in the history
…ommands
  • Loading branch information
lutovich committed Mar 6, 2015
1 parent eb96272 commit 601d6a5
Show file tree
Hide file tree
Showing 26 changed files with 350 additions and 188 deletions.
Expand Up @@ -19,17 +19,6 @@
*/
package org.neo4j.consistency.checking.full;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -41,6 +30,19 @@
import org.junit.runners.Parameterized.Parameters;
import org.junit.runners.model.Statement;

import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.neo4j.collection.primitive.PrimitiveLongCollections;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.consistency.RecordType;
import org.neo4j.consistency.checking.GraphStoreFixture;
import org.neo4j.consistency.report.ConsistencySummaryStatistics;
Expand Down Expand Up @@ -90,10 +92,8 @@
import org.neo4j.unsafe.batchinsert.LabelScanWriter;

import static java.util.Arrays.asList;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import static org.neo4j.consistency.checking.RecordCheckTestBase.inUse;
import static org.neo4j.consistency.checking.RecordCheckTestBase.notInUse;
import static org.neo4j.consistency.checking.full.ExecutionOrderIntegrationTest.config;
Expand Down Expand Up @@ -424,7 +424,7 @@ protected void transactionData( GraphStoreFixture.TransactionDataBuilder tx,
.andThatsAllFolks();
}

private long[] asArray( List<Integer> in )
private long[] asArray( List<? extends Number> in )
{
long[] longs = new long[in.size()];
for ( int i = 0; i < in.size(); i++ )
Expand All @@ -434,6 +434,11 @@ private long[] asArray( List<Integer> in )
return longs;
}

private PrimitiveLongSet asPrimitiveLongSet( List<? extends Number> in )
{
return PrimitiveLongCollections.setOf( asArray( in ) );
}

@Test
public void shouldReportMismatchedInlinedLabels() throws Exception
{
Expand Down Expand Up @@ -471,7 +476,7 @@ public void shouldReportNodesThatAreNotIndexed() throws Exception
IndexAccessor accessor = fixture.directStoreAccess().indexes().getOnlineAccessor(
indexRule.getId(), new IndexConfiguration( indexRule.isConstraintIndex() ), samplingConfig );
IndexUpdater updater = accessor.newUpdater( IndexUpdateMode.ONLINE );
updater.remove( indexedNodes );
updater.remove( asPrimitiveLongSet( indexedNodes ) );
updater.close();
accessor.close();
}
Expand Down
Expand Up @@ -20,8 +20,8 @@
package org.neo4j.kernel.api.index;

import java.io.IOException;
import java.util.Collection;

import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.kernel.api.exceptions.index.IndexCapacityExceededException;

public interface IndexUpdater extends AutoCloseable
Expand All @@ -34,5 +34,5 @@ void process( NodePropertyUpdate update )
@Override
void close() throws IOException, IndexEntryConflictException, IndexCapacityExceededException;

void remove( Collection<Long> nodeIds ) throws IOException;
void remove( PrimitiveLongSet nodeIds ) throws IOException;
}
Expand Up @@ -20,8 +20,8 @@
package org.neo4j.kernel.impl.api.index;

import java.io.IOException;
import java.util.Collection;

import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.kernel.api.exceptions.index.IndexCapacityExceededException;
import org.neo4j.kernel.api.index.IndexEntryConflictException;
import org.neo4j.kernel.api.index.IndexUpdater;
Expand Down Expand Up @@ -52,7 +52,7 @@ public void process( NodePropertyUpdate update )
}

@Override
public void remove( Collection<Long> nodeIds ) throws IOException
public void remove( PrimitiveLongSet nodeIds ) throws IOException
{
delegate.remove( nodeIds );
}
Expand Down
Expand Up @@ -21,12 +21,12 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveLongObjectMap;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.collection.primitive.PrimitiveLongVisitor;
import org.neo4j.helpers.collection.Visitor;
import org.neo4j.kernel.api.index.NodePropertyUpdate;
import org.neo4j.kernel.impl.api.TransactionApplicationMode;
Expand Down Expand Up @@ -82,12 +82,12 @@ public ValidatedIndexUpdates validate( TransactionRepresentation transaction, Tr
}

Iterable<NodePropertyUpdate> updates = new LazyIndexUpdates( nodeStore, propertyStore, propertyLoader,
extractor.nodeCommandsById, extractor.propertyCommandsByNodeIds );
extractor.propertyCommandsByNodeIds, extractor.nodeCommandsById );

return indexing.validate( updates );
}

private static ValidatedIndexUpdates newValidatedRecoveredUpdates( final Set<Long> nodeIds,
private static ValidatedIndexUpdates newValidatedRecoveredUpdates( final PrimitiveLongSet nodeIds,
final IndexingService indexing )
{
return new ValidatedIndexUpdates()
Expand All @@ -108,8 +108,8 @@ public void close()
private static class NodePropertyCommandsExtractor
extends NeoCommandHandler.Adapter implements Visitor<Command,IOException>
{
final Map<Long,NodeCommand> nodeCommandsById = new HashMap<>();
final Map<Long,List<PropertyCommand>> propertyCommandsByNodeIds = new HashMap<>();
final PrimitiveLongObjectMap<NodeCommand> nodeCommandsById = Primitive.longObjectMap( 16 );
final PrimitiveLongObjectMap<List<PropertyCommand>> propertyCommandsByNodeIds = Primitive.longObjectMap( 16 );

@Override
public boolean visit( Command element ) throws IOException
Expand Down Expand Up @@ -147,12 +147,25 @@ boolean noCommandsExtracted()
return nodeCommandsById.isEmpty() && propertyCommandsByNodeIds.isEmpty();
}

Set<Long> changedNodeIds()
PrimitiveLongSet changedNodeIds()
{
Set<Long> nodeIds = new HashSet<>( nodeCommandsById.size() + propertyCommandsByNodeIds.size(), 1 );
nodeIds.addAll( nodeCommandsById.keySet() );
nodeIds.addAll( propertyCommandsByNodeIds.keySet() );
PrimitiveLongSet nodeIds = Primitive.longSet( nodeCommandsById.size() + propertyCommandsByNodeIds.size() );
nodeCommandsById.visitKeys( copyTo( nodeIds ) );
propertyCommandsByNodeIds.visitKeys( copyTo( nodeIds ) );
return nodeIds;
}

PrimitiveLongVisitor<RuntimeException> copyTo( final PrimitiveLongSet set )
{
return new PrimitiveLongVisitor<RuntimeException>()
{
@Override
public boolean visited( long value )
{
set.add( value );
return false;
}
};
}
}
}
Expand Up @@ -30,6 +30,9 @@
import java.util.Set;
import java.util.concurrent.Future;

import org.neo4j.collection.primitive.Primitive;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.collection.primitive.PrimitiveLongVisitor;
import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.helpers.BiConsumer;
import org.neo4j.helpers.Pair;
Expand Down Expand Up @@ -94,7 +97,7 @@ public class IndexingService extends LifecycleAdapter
private final StringLogger logger;
private final TokenNameLookup tokenNameLookup;
private final Monitor monitor;
private final Set<Long> recoveredNodeIds = new HashSet<>();
private final PrimitiveLongSet recoveredNodeIds = Primitive.longSet( 20 );

enum State
{
Expand All @@ -106,7 +109,7 @@ enum State

public interface Monitor
{
void applyingRecoveredData( Set<Long> recoveredNodeIds );
void applyingRecoveredData( PrimitiveLongSet recoveredNodeIds );

void appliedRecoveredData( Iterable<NodePropertyUpdate> updates );

Expand All @@ -123,7 +126,7 @@ public void appliedRecoveredData( Iterable<NodePropertyUpdate> updates )
}

@Override
public void applyingRecoveredData( Set<Long> recoveredNodeIds )
public void applyingRecoveredData( PrimitiveLongSet recoveredNodeIds )
{ // Do nothing
}

Expand Down Expand Up @@ -382,15 +385,15 @@ public void createIndex( IndexRule rule )
indexMapRef.setIndexMap( indexMap );
}

public void addRecoveredNodeIds( Set<Long> nodeIds )
public void addRecoveredNodeIds( PrimitiveLongSet nodeIds )
{
if ( state != State.NOT_STARTED )
{
throw new IllegalStateException(
"Can't queue recovered node ids " + nodeIds + " while indexing service is " + state );
}

recoveredNodeIds.addAll( nodeIds );
recoveredNodeIds.addAll( nodeIds.iterator() );
}

public ValidatedIndexUpdates validate( Iterable<NodePropertyUpdate> updates )
Expand Down Expand Up @@ -529,11 +532,7 @@ private void applyRecoveredUpdates() throws IOException
}
}

List<NodePropertyUpdate> recoveredUpdates = new ArrayList<>();
for ( long nodeId : recoveredNodeIds )
{
Iterables.addAll( recoveredUpdates, storeView.nodeAsUpdates( nodeId ) );
}
List<NodePropertyUpdate> recoveredUpdates = readRecoveredUpdatesFromStore();

try ( ValidatedIndexUpdates validatedUpdates = validate( recoveredUpdates ) )
{
Expand All @@ -548,6 +547,23 @@ private void applyRecoveredUpdates() throws IOException
recoveredNodeIds.clear();
}

private List<NodePropertyUpdate> readRecoveredUpdatesFromStore()
{
final List<NodePropertyUpdate> recoveredUpdates = new ArrayList<>();

recoveredNodeIds.visitKeys( new PrimitiveLongVisitor<RuntimeException>()
{
@Override
public boolean visited( long nodeId )
{
Iterables.addAll( recoveredUpdates, storeView.nodeAsUpdates( nodeId ) );
return false;
}
} );

return recoveredUpdates;
}

private static Map<IndexDescriptor,List<NodePropertyUpdate>> groupUpdatesByIndexDescriptor(
Iterable<NodePropertyUpdate> updates, IndexUpdaterMap updaterMap )
{
Expand Down
Expand Up @@ -21,9 +21,9 @@

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.Future;

import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.helpers.ThisShouldNotHappenError;
import org.neo4j.kernel.api.exceptions.index.IndexActivationFailedKernelException;
Expand Down Expand Up @@ -222,7 +222,7 @@ public void close() throws IOException, IndexEntryConflictException
}

@Override
public void remove( Collection<Long> nodeIds )
public void remove( PrimitiveLongSet nodeIds )
{
throw new UnsupportedOperationException( "Should not remove() from populating index." );
}
Expand Down
Expand Up @@ -20,8 +20,8 @@
package org.neo4j.kernel.impl.api.index;

import java.io.IOException;
import java.util.Collection;

import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.kernel.api.index.IndexEntryConflictException;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.api.index.NodePropertyUpdate;
Expand Down Expand Up @@ -54,7 +54,7 @@ public void close() throws IOException, IndexEntryConflictException
}

@Override
public void remove( Collection<Long> nodeIds )
public void remove( PrimitiveLongSet nodeIds )
{
// intentionally swallow these removals
}
Expand Down
Expand Up @@ -20,8 +20,8 @@
package org.neo4j.kernel.impl.api.index;

import java.io.IOException;
import java.util.Collection;

import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.kernel.api.exceptions.index.IndexCapacityExceededException;
import org.neo4j.kernel.api.index.IndexDescriptor;
import org.neo4j.kernel.api.index.IndexEntryConflictException;
Expand Down Expand Up @@ -67,7 +67,7 @@ public void close() throws IOException, IndexEntryConflictException, IndexCapaci
}

@Override
public void remove( Collection<Long> nodeIds ) throws IOException
public void remove( PrimitiveLongSet nodeIds ) throws IOException
{
delegate.remove( nodeIds );
updates += nodeIds.size();
Expand Down
Expand Up @@ -25,8 +25,8 @@
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.neo4j.collection.primitive.PrimitiveLongObjectMap;
import org.neo4j.helpers.Pair;
import org.neo4j.helpers.UTF8;
import org.neo4j.helpers.collection.IteratorUtil;
Expand Down Expand Up @@ -667,7 +667,7 @@ public Collection<PropertyRecord> getPropertyRecordChain( long firstRecordId )
return toReturn;
}

public Collection<PropertyRecord> getPropertyRecordChain( long firstRecordId, Map<Long,PropertyRecord> propertyLookup )
public Collection<PropertyRecord> getPropertyRecordChain( long firstRecordId, PrimitiveLongObjectMap<PropertyRecord> propertyLookup )
{
long nextProp = firstRecordId;
List<PropertyRecord> toReturn = new ArrayList<>();
Expand Down

0 comments on commit 601d6a5

Please sign in to comment.