Skip to content

Commit

Permalink
Set of small cleanups
Browse files Browse the repository at this point in the history
Make some classes static, close file reader, use entry set iterators
  • Loading branch information
MishaDemianenko committed Feb 10, 2018
1 parent 6e33ef6 commit 9dd7c60
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 24 deletions.
Expand Up @@ -21,6 +21,7 @@


import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Properties; import java.util.Properties;
Expand Down Expand Up @@ -109,7 +110,7 @@ public static String neo4jVersion()
Properties props = new Properties(); Properties props = new Properties();
try try
{ {
props.load( Util.class.getResourceAsStream( "/org/neo4j/commandline/build.properties" ) ); loadProperties( props );
return props.getProperty( "neo4jVersion" ); return props.getProperty( "neo4jVersion" );
} }
catch ( IOException e ) catch ( IOException e )
Expand All @@ -118,4 +119,12 @@ public static String neo4jVersion()
throw new RuntimeException( e ); throw new RuntimeException( e );
} }
} }

private static void loadProperties( Properties props ) throws IOException
{
try ( InputStream resource = Util.class.getResourceAsStream( "/org/neo4j/commandline/build.properties" ) )
{
props.load( resource );
}
}
} }
Expand Up @@ -66,11 +66,11 @@ public void dump( Set<String> classifiers, Path destination, DiagnosticsReporter
} }


// Add additional sources // Add additional sources
for ( String classifier : additionalSources.keySet() ) for ( Map.Entry<String,List<DiagnosticsReportSource>> classifier : additionalSources.entrySet() )
{ {
if ( classifiers.contains( "all" ) || classifiers.contains( classifier ) ) if ( classifiers.contains( "all" ) || classifiers.contains( classifier.getKey() ) )
{ {
sources.addAll( additionalSources.get( classifier ) ); sources.addAll( classifier.getValue() );
} }
} }


Expand Down
Expand Up @@ -40,8 +40,8 @@
import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.exceptions.EntityNotFoundException; import org.neo4j.kernel.api.exceptions.EntityNotFoundException;
import org.neo4j.kernel.impl.api.KernelTransactionImplementation; import org.neo4j.kernel.impl.api.KernelTransactionImplementation;
import org.neo4j.kernel.impl.core.NodeProxy;
import org.neo4j.kernel.impl.core.EmbeddedProxySPI; import org.neo4j.kernel.impl.core.EmbeddedProxySPI;
import org.neo4j.kernel.impl.core.NodeProxy;
import org.neo4j.kernel.impl.core.RelationshipProxy; import org.neo4j.kernel.impl.core.RelationshipProxy;
import org.neo4j.kernel.impl.locking.Lock; import org.neo4j.kernel.impl.locking.Lock;
import org.neo4j.storageengine.api.NodeItem; import org.neo4j.storageengine.api.NodeItem;
Expand Down Expand Up @@ -465,7 +465,7 @@ public String toString()
} }
} }


private class RelationshipPropertyEntryView implements PropertyEntry<Relationship> private static class RelationshipPropertyEntryView implements PropertyEntry<Relationship>
{ {
private final Relationship relationship; private final Relationship relationship;
private final String key; private final String key;
Expand Down
Expand Up @@ -102,7 +102,7 @@ public void close()
toClose.clear(); toClose.clear();
} }


private class IdAndSource implements Comparable<IdAndSource> private static class IdAndSource implements Comparable<IdAndSource>
{ {
private long latestReturned; private long latestReturned;
private final PrimitiveLongIterator source; private final PrimitiveLongIterator source;
Expand Down
Expand Up @@ -40,15 +40,12 @@
class NativeNonUniqueSchemaIndexPopulator<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue> class NativeNonUniqueSchemaIndexPopulator<KEY extends NativeSchemaKey, VALUE extends NativeSchemaValue>
extends NativeSchemaIndexPopulator<KEY,VALUE> extends NativeSchemaIndexPopulator<KEY,VALUE>
{ {
private final IndexSamplingConfig samplingConfig;
private boolean updateSampling;
private NonUniqueIndexSampler sampler; private NonUniqueIndexSampler sampler;


NativeNonUniqueSchemaIndexPopulator( PageCache pageCache, FileSystemAbstraction fs, File storeFile, Layout<KEY,VALUE> layout, NativeNonUniqueSchemaIndexPopulator( PageCache pageCache, FileSystemAbstraction fs, File storeFile, Layout<KEY,VALUE> layout,
IndexSamplingConfig samplingConfig, SchemaIndexProvider.Monitor monitor, IndexDescriptor descriptor, long indexId ) IndexSamplingConfig samplingConfig, SchemaIndexProvider.Monitor monitor, IndexDescriptor descriptor, long indexId )
{ {
super( pageCache, fs, storeFile, layout, monitor, descriptor, indexId ); super( pageCache, fs, storeFile, layout, monitor, descriptor, indexId );
this.samplingConfig = samplingConfig;
this.sampler = new DefaultNonUniqueIndexSampler( samplingConfig.sampleSizeLimit() ); this.sampler = new DefaultNonUniqueIndexSampler( samplingConfig.sampleSizeLimit() );
} }


Expand Down
Expand Up @@ -176,7 +176,7 @@ public boolean hasFullNumberPrecision( IndexQuery... predicates )
/** /**
* Combine multiple progressor to act like one single logical progressor seen from clients perspective. * Combine multiple progressor to act like one single logical progressor seen from clients perspective.
*/ */
private class BridgingIndexProgressor implements IndexProgressor.NodeValueClient, IndexProgressor private static class BridgingIndexProgressor implements IndexProgressor.NodeValueClient, IndexProgressor
{ {
private final NodeValueClient client; private final NodeValueClient client;
private final int[] keys; private final int[] keys;
Expand Down
Expand Up @@ -74,7 +74,7 @@ public IdGenerator get( IdType idType )
return idGenerators.get( idType ); return idGenerators.get( idType );
} }


class ReadOnlyIdGenerator implements IdGenerator static class ReadOnlyIdGenerator implements IdGenerator
{ {
private final long highId; private final long highId;
private final long defragCount; private final long defragCount;
Expand Down
Expand Up @@ -160,7 +160,7 @@ private static File getLuceneStoreDirectory( File storeRootDir )
return new File( new File( new File( storeRootDir, "schema" ), "label" ), "lucene" ); return new File( new File( new File( storeRootDir, "schema" ), "label" ), "lucene" );
} }


private class MonitoredFullLabelStream extends FullLabelStream private static class MonitoredFullLabelStream extends FullLabelStream
{ {


private final ProgressReporter progressReporter; private final ProgressReporter progressReporter;
Expand Down
Expand Up @@ -740,7 +740,7 @@ private void copyWithPageCache( File sourceFile, File targetFile ) throws IOExce
} }
} }


private class BatchImporterProgressMonitor extends CoarseBoundedProgressExecutionMonitor private static class BatchImporterProgressMonitor extends CoarseBoundedProgressExecutionMonitor
{ {
private final ProgressReporter progressReporter; private final ProgressReporter progressReporter;


Expand Down
Expand Up @@ -49,8 +49,8 @@ public void apply( long iteration ) throws AcquireLockTimeoutException
}, },
INCREMENTAL_BACKOFF INCREMENTAL_BACKOFF
{ {
private final int spinIterations = 1000; private static final int spinIterations = 1000;
private final long multiplyUntilIteration = spinIterations + 2; private static final long multiplyUntilIteration = spinIterations + 2;


@Override @Override
public void apply( long iteration ) throws AcquireLockTimeoutException public void apply( long iteration ) throws AcquireLockTimeoutException
Expand Down
Expand Up @@ -331,7 +331,7 @@ public int hashCode()
} }
} }


private class IndexStatistics private static class IndexStatistics
{ {
private final double uniqueValuesPercentage; private final double uniqueValuesPercentage;
private final long size; private final long size;
Expand Down
Expand Up @@ -59,8 +59,6 @@
import org.neo4j.io.pagecache.tracing.PageCacheTracer; import org.neo4j.io.pagecache.tracing.PageCacheTracer;
import org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier; import org.neo4j.io.pagecache.tracing.cursor.PageCursorTracerSupplier;
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.exceptions.schema.AlreadyConstrainedException;
import org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException;
import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexPopulator; import org.neo4j.kernel.api.index.IndexPopulator;
import org.neo4j.kernel.api.index.PropertyAccessor; import org.neo4j.kernel.api.index.PropertyAccessor;
Expand Down Expand Up @@ -1303,7 +1301,7 @@ public void forceFlush()


private static class IndexPopulatorWithSchema extends IndexPopulator.Adapter implements LabelSchemaSupplier private static class IndexPopulatorWithSchema extends IndexPopulator.Adapter implements LabelSchemaSupplier
{ {
private final int batchSize = 1_000; private static final int batchSize = 1_000;
private final IndexPopulator populator; private final IndexPopulator populator;
private final IndexDescriptor index; private final IndexDescriptor index;
private Collection<IndexEntryUpdate<?>> batchedUpdates = new ArrayList<>( batchSize ); private Collection<IndexEntryUpdate<?>> batchedUpdates = new ArrayList<>( batchSize );
Expand Down
Expand Up @@ -36,7 +36,7 @@ public class StringEncoder implements Encoder


// fixed values // fixed values
private final int numCodes; private final int numCodes;
private final int encodingThreshold = 7; private static final int encodingThreshold = 7;


// data changing over time, potentially with each encoding // data changing over time, potentially with each encoding
private final byte[] reMap = new byte[256]; private final byte[] reMap = new byte[256];
Expand Down
Expand Up @@ -23,11 +23,11 @@
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;


import org.neo4j.internal.kernel.api.InternalIndexState;
import org.neo4j.kernel.api.impl.fulltext.FulltextProvider; import org.neo4j.kernel.api.impl.fulltext.FulltextProvider;
import org.neo4j.kernel.api.impl.fulltext.ReadOnlyFulltext; import org.neo4j.kernel.api.impl.fulltext.ReadOnlyFulltext;
import org.neo4j.kernel.api.impl.fulltext.ScoreEntityIterator; import org.neo4j.kernel.api.impl.fulltext.ScoreEntityIterator;
import org.neo4j.kernel.api.impl.fulltext.ScoreEntityIterator.ScoreEntry; import org.neo4j.kernel.api.impl.fulltext.ScoreEntityIterator.ScoreEntry;
import org.neo4j.internal.kernel.api.InternalIndexState;
import org.neo4j.procedure.Context; import org.neo4j.procedure.Context;
import org.neo4j.procedure.Description; import org.neo4j.procedure.Description;
import org.neo4j.procedure.Name; import org.neo4j.procedure.Name;
Expand Down Expand Up @@ -156,7 +156,7 @@ public static class PropertyOutput
} }
} }


public class StatusOutput public static class StatusOutput
{ {
public final String state; public final String state;


Expand Down
Expand Up @@ -87,7 +87,7 @@ public void stop()
monitors.removeMonitorListener( boltMonitor ); monitors.removeMonitorListener( boltMonitor );
} }


private class BoltMetricsMonitor implements MonitoredWorkerFactory.SessionMonitor private static class BoltMetricsMonitor implements MonitoredWorkerFactory.SessionMonitor
{ {
final AtomicLong sessionsStarted = new AtomicLong(); final AtomicLong sessionsStarted = new AtomicLong();


Expand Down

0 comments on commit 9dd7c60

Please sign in to comment.