Skip to content

Commit

Permalink
Uses Stream instead of added ArrayUtil method
Browse files Browse the repository at this point in the history
and some minor cleanups in RecordFormats capabilities
  • Loading branch information
tinwelint committed Mar 3, 2016
1 parent e83973f commit dcc3d8c
Show file tree
Hide file tree
Showing 16 changed files with 107 additions and 112 deletions.
Expand Up @@ -36,6 +36,8 @@
import org.neo4j.kernel.impl.store.format.InternalRecordFormatSelector;
import org.neo4j.logging.Level;

import static java.lang.String.valueOf;

import static org.neo4j.kernel.configuration.Settings.ANY;
import static org.neo4j.kernel.configuration.Settings.BOOLEAN;
import static org.neo4j.kernel.configuration.Settings.BYTES;
Expand Down Expand Up @@ -367,23 +369,23 @@ private static String defaultPageCacheMemory()
"than the configured block size" )
@Internal
public static final Setting<Integer> string_block_size = setting("string_block_size", INTEGER,
dynamicRecordDataSizeForAligningWith( 128 ), min(1) );
valueOf( dynamicRecordDataSizeForAligningWith( 128 ) ), min( dynamicRecordDataSizeForAligningWith( 16 ) ) );

@Description("Specifies the block size for storing arrays. This parameter is only honored when the store is " +
"created, otherwise it is ignored. " +
"Also note that each block carries a ~10B of overhead so record size on disk will be slightly larger " +
"than the configured block size" )
@Internal
public static final Setting<Integer> array_block_size = setting("array_block_size", INTEGER,
dynamicRecordDataSizeForAligningWith( 128 ), min(1) );
valueOf( dynamicRecordDataSizeForAligningWith( 128 ) ), min( dynamicRecordDataSizeForAligningWith( 16 ) ) );

@Description("Specifies the block size for storing labels exceeding in-lined space in node record. " +
"This parameter is only honored when the store is created, otherwise it is ignored. " +
"Also note that each block carries a ~10B of overhead so record size on disk will be slightly larger " +
"than the configured block size" )
@Internal
public static final Setting<Integer> label_block_size = setting("label_block_size", INTEGER,
dynamicRecordDataSizeForAligningWith( 64 ),min(1) );
valueOf( dynamicRecordDataSizeForAligningWith( 64 ) ), min( dynamicRecordDataSizeForAligningWith( 16 ) ) );

@Description("An identifier that uniquely identifies this graph database instance within this JVM. " +
"Defaults to an auto-generated number depending on how many instance are started in this JVM.")
Expand Down Expand Up @@ -447,8 +449,8 @@ private static String defaultPageCacheMemory()
* to get to the data size, which is the value that the configuration will end up having.
* @return the dynamic record data size based on the desired record size and with the header size in mind.
*/
private static String dynamicRecordDataSizeForAligningWith( int recordSize )
private static int dynamicRecordDataSizeForAligningWith( int recordSize )
{
return String.valueOf( recordSize - InternalRecordFormatSelector.select().dynamic().getRecordHeaderSize() );
return recordSize - InternalRecordFormatSelector.select().dynamic().getRecordHeaderSize();
}
}
23 changes: 0 additions & 23 deletions community/kernel/src/main/java/org/neo4j/helpers/ArrayUtil.java
Expand Up @@ -22,8 +22,6 @@
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.function.Function;
import java.util.function.Predicate;

import static java.util.Arrays.copyOf;

/**
Expand Down Expand Up @@ -486,27 +484,6 @@ public static <T> T[] without( T[] source, T... toRemove )
return length == result.length ? result : Arrays.copyOf( result, length );
}

/**
* Filters an array, only including the items that passes the {@code filter}.
*
* @param array items to filter.
* @param filter {@link Predicate} to match each item.
* @return a new array with the items that passed the filter.
*/
public static <T> T[] filter( T[] array, Predicate<T> filter )
{
T[] result = array.clone();
int cursor = 0;
for ( T item : array )
{
if ( filter.test( item ) )
{
result[cursor++] = item;
}
}
return cursor == result.length ? result : Arrays.copyOf( result, cursor );
}

private ArrayUtil()
{ // No instances allowed
}
Expand Down
Expand Up @@ -19,11 +19,12 @@
*/
package org.neo4j.kernel.impl.store.format;

import org.neo4j.kernel.impl.store.StoreType;
import java.util.Set;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toSet;

import static org.neo4j.helpers.ArrayUtil.contains;
import static org.neo4j.helpers.ArrayUtil.containsAll;
import static org.neo4j.helpers.ArrayUtil.filter;

/**
* Base class for simpler implementation of {@link RecordFormats}.
Expand Down Expand Up @@ -93,12 +94,6 @@ public int generation()
return generation;
}

@Override
public boolean hasStore( StoreType store )
{
return true;
}

@Override
public Capability[] capabilities()
{
Expand All @@ -112,13 +107,13 @@ public boolean hasCapability( Capability capability )
}

@Override
public boolean hasSameCapabilities( RecordFormats other, int types )
public boolean hasSameCapabilities( RecordFormats other, CapabilityType types )
{
Capability[] myFormatCapabilities =
filter( this.capabilities(), capability -> capability.isType( types ) );
Capability[] otherFormatCapabilities =
filter( other.capabilities(), capability -> capability.isType( types ) );
return containsAll( myFormatCapabilities, otherFormatCapabilities ) &&
containsAll( otherFormatCapabilities, myFormatCapabilities );
Set<Capability> myFormatCapabilities = Stream.of( capabilities() )
.filter( capability -> capability.isType( types ) ).collect( toSet() );
Set<Capability> otherFormatCapabilities = Stream.of( other.capabilities() )
.filter( capability -> capability.isType( types ) ).collect( toSet() );

return myFormatCapabilities.equals( otherFormatCapabilities );
}
}
Expand Up @@ -19,6 +19,8 @@
*/
package org.neo4j.kernel.impl.store.format;

import static org.neo4j.helpers.ArrayUtil.contains;

/**
* A collection of high level capabilities a store can have, should not be more granular than necessary
* for differentiating different version from one another.
Expand All @@ -28,42 +30,37 @@ public enum Capability
/**
* Store has schema support
*/
SCHEMA( Capability.TYPE_STORE ),
SCHEMA( CapabilityType.STORE ),

/**
* Store has dense node support
*/
DENSE_NODES( Capability.TYPE_FORMAT | Capability.TYPE_STORE ),
DENSE_NODES( CapabilityType.FORMAT, CapabilityType.STORE ),

/**
* Store has version trailers in the end of cleanly shut down store
*/
VERSION_TRAILERS( Capability.TYPE_STORE ),
VERSION_TRAILERS( CapabilityType.STORE ),

/**
* Lucene version 3.x
*/
LUCENE_3( Capability.TYPE_INDEX ),
LUCENE_3( CapabilityType.INDEX ),

/**
* Lucene version 5.x
*/
LUCENE_5( Capability.TYPE_INDEX );

public static final int TYPE_FORMAT = 0x1;
public static final int TYPE_STORE = 0x2;
public static final int TYPE_INDEX = 0x4;
public static final int ALL_TYPES = TYPE_FORMAT | TYPE_STORE | TYPE_INDEX;
LUCENE_5( CapabilityType.INDEX );

private final int types;
private final CapabilityType[] types;

Capability( int types )
Capability( CapabilityType... types )
{
this.types = types;
}

public boolean isType( int type )
public boolean isType( CapabilityType type )
{
return (types & type) != 0;
return contains( types, type );
}
}
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2002-2016 "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.store.format;

public enum CapabilityType
{
FORMAT,
STORE,
INDEX;
}
Expand Up @@ -20,7 +20,6 @@
package org.neo4j.kernel.impl.store.format;

import org.neo4j.helpers.Service;
import org.neo4j.kernel.impl.store.StoreType;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
Expand Down Expand Up @@ -49,6 +48,13 @@ public Factory( String key, String... altKeys )
String storeVersion();

/**
* Generation of this format, simply an increasing int which should be incrementing along with
* releases, e.g. store version, e.g. official versions of the product. This is for preventing downgrades.
* When implementing a new format or evolving an older format the generation of the new format should
* be higher than the format it evolves from, or in case of a new format - newer than the currently newest format.
* The generation value doesn't need to correlate to any other value, the only thing needed is to
* determine "older" or "newer".
*
* @return format generation, with the intent of usage being that a store can migrate to a newer or
* same generation, but not to an older generation.
*/
Expand All @@ -70,8 +76,6 @@ public Factory( String key, String... altKeys )

RecordFormat<DynamicRecord> dynamic();

boolean hasStore( StoreType store );

/**
* Use when comparing one format to another, for example for migration purposes.
*
Expand All @@ -85,5 +89,12 @@ public Factory( String key, String... altKeys )
*/
boolean hasCapability( Capability capability );

boolean hasSameCapabilities( RecordFormats other, int types );
/**
* Whether or not this format has the same capabilities of the specific {@code type} as the {@code other} format.
*
* @param other {@link RecordFormats} to compare with.
* @param type {@link CapabilityType type} of capability to compare.
* @return true if both formats have the same set of capabilities of the given {@code type}.
*/
boolean hasSameCapabilities( RecordFormats other, CapabilityType type );
}
Expand Up @@ -19,7 +19,6 @@
*/
package org.neo4j.kernel.impl.store.format.lowlimit;

import org.neo4j.kernel.impl.store.StoreType;
import org.neo4j.kernel.impl.store.format.BaseRecordFormats;
import org.neo4j.kernel.impl.store.format.Capability;
import org.neo4j.kernel.impl.store.format.RecordFormat;
Expand Down Expand Up @@ -91,10 +90,4 @@ public RecordFormat<DynamicRecord> dynamic()
{
return new DynamicRecordFormat();
}

@Override
public boolean hasStore( StoreType store )
{
return store != StoreType.RELATIONSHIP_GROUP;
}
}
Expand Up @@ -59,7 +59,7 @@ public DirectRecordStoreMigrator( PageCache pageCache, FileSystemAbstraction fs,
}

public void migrate( File fromStoreDir, RecordFormats fromFormat, File toStoreDir, RecordFormats toFormat,
StoreType[] types, StoreType[] additionalTypesToOpen )
StoreType[] types, StoreType... additionalTypesToOpen )
{
StoreType[] storesToOpen = ArrayUtil.concat( types, additionalTypesToOpen );
try (
Expand All @@ -72,10 +72,8 @@ public void migrate( File fromStoreDir, RecordFormats fromFormat, File toStoreDi
{
for ( StoreType type : types )
{
// This condition will exclude counts store and "neostore" since we don't want to copy its metadata
// into the new migrated store.
if ( type.isRecordStore() &&
toFormat.hasStore( type ) && fromFormat.hasStore( type ) )
// This condition will exclude counts store first and foremost.
if ( type.isRecordStore() )
{
migrate( fromStores.getRecordStore( type ), toStores.getRecordStore( type ) );
}
Expand Down
Expand Up @@ -25,7 +25,7 @@
import java.util.Map;

import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.impl.store.format.Capability;
import org.neo4j.kernel.impl.store.format.CapabilityType;
import org.neo4j.kernel.impl.store.format.InternalRecordFormatSelector;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void migrate( File storeDir, File migrationDir, MigrationProgressMonitor.
{
RecordFormats from = InternalRecordFormatSelector.fromVersion( versionToMigrateFrom );
RecordFormats to = InternalRecordFormatSelector.fromVersion( versionToMigrateTo );
if ( !from.hasSameCapabilities( to, Capability.TYPE_INDEX ) )
if ( !from.hasSameCapabilities( to, CapabilityType.INDEX ) )
{
originalLegacyIndexesRoot = indexImplementation.getIndexImplementationDirectory( storeDir );
migrationLegacyIndexesRoot = indexImplementation.getIndexImplementationDirectory( migrationDir );
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.api.index.SchemaIndexProvider;
import org.neo4j.kernel.impl.api.scan.LabelScanStoreProvider;
import org.neo4j.kernel.impl.store.format.Capability;
import org.neo4j.kernel.impl.store.format.CapabilityType;
import org.neo4j.kernel.impl.store.format.InternalRecordFormatSelector;
import org.neo4j.kernel.impl.store.format.RecordFormats;
import org.neo4j.kernel.impl.storemigration.monitoring.MigrationProgressMonitor;
Expand Down Expand Up @@ -60,7 +60,7 @@ public void migrate( File storeDir, File migrationDir, MigrationProgressMonitor.
{
RecordFormats from = InternalRecordFormatSelector.fromVersion( versionToMigrateFrom );
RecordFormats to = InternalRecordFormatSelector.fromVersion( versionToMigrateTo );
if ( !from.hasSameCapabilities( to, Capability.TYPE_INDEX ) )
if ( !from.hasSameCapabilities( to, CapabilityType.INDEX ) )
{
schemaIndexDirectory = schemaIndexProvider.getSchemaIndexStoreDirectory( storeDir );
labelIndexDirectory = labelScanStoreProvider.getStoreDirectory( storeDir );
Expand Down

0 comments on commit dcc3d8c

Please sign in to comment.