Skip to content

Commit

Permalink
Collapses Layout classes a bit further
Browse files Browse the repository at this point in the history
Since they no longer need to be split into unique/non-unique
  • Loading branch information
tinwelint committed Mar 14, 2018
1 parent b191eae commit aacecf8
Show file tree
Hide file tree
Showing 39 changed files with 92 additions and 447 deletions.

This file was deleted.

This file was deleted.

Expand Up @@ -21,24 +21,15 @@

import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor;

/**
* {@link Layout} for dates.
*/
class DateLayout extends BaseLayout<DateSchemaKey>
class DateLayout extends SchemaLayout<DateSchemaKey>
{
public static Layout<DateSchemaKey,NativeSchemaValue> of( SchemaIndexDescriptor descriptor )
DateLayout()
{
return descriptor.type() == SchemaIndexDescriptor.Type.UNIQUE ? DateLayout.UNIQUE : DateLayout.NON_UNIQUE;
}

private static DateLayout UNIQUE = new DateLayout( "UTda", 0, 1 );
private static DateLayout NON_UNIQUE = new DateLayout( "NTda", 0, 1 );

private DateLayout( String layoutName, int majorVersion, int minorVersion )
{
super( layoutName, majorVersion, minorVersion );
super( "Tda", 0, 1 );
}

@Override
Expand Down
Expand Up @@ -27,7 +27,7 @@
/**
* Includes value and entity id (to be able to handle non-unique values). A value can be any {@link DateValue}.
*/
class DateSchemaKey extends ComparableNativeSchemaKey<DateSchemaKey>
class DateSchemaKey extends NativeSchemaKey<DateSchemaKey>
{
static final int SIZE =
Long.BYTES + /* epochDay */
Expand Down
Expand Up @@ -21,24 +21,15 @@

import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor;

/**
* {@link Layout} for durations.
*/
class DurationLayout extends BaseLayout<DurationSchemaKey>
class DurationLayout extends SchemaLayout<DurationSchemaKey>
{
public static Layout<DurationSchemaKey,NativeSchemaValue> of( SchemaIndexDescriptor descriptor )
DurationLayout()
{
return descriptor.type() == SchemaIndexDescriptor.Type.UNIQUE ? DurationLayout.UNIQUE : DurationLayout.NON_UNIQUE;
}

private static DurationLayout UNIQUE = new DurationLayout( "UTdu", 0, 1 );
private static DurationLayout NON_UNIQUE = new DurationLayout( "NTdu", 0, 1 );

private DurationLayout( String layoutName, int majorVersion, int minorVersion )
{
super( layoutName, majorVersion, minorVersion );
super( "Tdu", 0, 1 );
}

@Override
Expand Down
Expand Up @@ -30,7 +30,7 @@
* Durations are tricky, because exactly how long a duration is depends on the start date. We therefore sort them by
* average total time in seconds, but keep the original months and days so we can reconstruct the value.
*/
class DurationSchemaKey extends ComparableNativeSchemaKey<DurationSchemaKey>
class DurationSchemaKey extends NativeSchemaKey<DurationSchemaKey>
{
/**
* An average month is 30 days, 10 hours and 30 minutes.
Expand Down
Expand Up @@ -21,24 +21,15 @@

import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor;

/**
* {@link Layout} for local date times.
*/
class LocalDateTimeLayout extends BaseLayout<LocalDateTimeSchemaKey>
class LocalDateTimeLayout extends SchemaLayout<LocalDateTimeSchemaKey>
{
public static Layout<LocalDateTimeSchemaKey,NativeSchemaValue> of( SchemaIndexDescriptor descriptor )
LocalDateTimeLayout()
{
return descriptor.type() == SchemaIndexDescriptor.Type.UNIQUE ? LocalDateTimeLayout.UNIQUE : LocalDateTimeLayout.NON_UNIQUE;
}

private static LocalDateTimeLayout UNIQUE = new LocalDateTimeLayout( "UTld", 0, 1 );
private static LocalDateTimeLayout NON_UNIQUE = new LocalDateTimeLayout( "NTld", 0, 1 );

private LocalDateTimeLayout( String layoutName, int majorVersion, int minorVersion )
{
super( layoutName, majorVersion, minorVersion );
super( "Tld", 0, 1 );
}

@Override
Expand Down
Expand Up @@ -27,7 +27,7 @@
/**
* Includes value and entity id (to be able to handle non-unique values). A value can be any {@link LocalDateTimeValue}.
*/
class LocalDateTimeSchemaKey extends ComparableNativeSchemaKey<LocalDateTimeSchemaKey>
class LocalDateTimeSchemaKey extends NativeSchemaKey<LocalDateTimeSchemaKey>
{
static final int SIZE =
Long.BYTES + /* epochSecond */
Expand Down
Expand Up @@ -21,24 +21,15 @@

import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor;

/**
* {@link Layout} for local times.
*/
class LocalTimeLayout extends BaseLayout<LocalTimeSchemaKey>
class LocalTimeLayout extends SchemaLayout<LocalTimeSchemaKey>
{
public static Layout<LocalTimeSchemaKey,NativeSchemaValue> of( SchemaIndexDescriptor descriptor )
LocalTimeLayout()
{
return descriptor.type() == SchemaIndexDescriptor.Type.UNIQUE ? LocalTimeLayout.UNIQUE : LocalTimeLayout.NON_UNIQUE;
}

private static LocalTimeLayout UNIQUE = new LocalTimeLayout( "UTlt", 0, 1 );
private static LocalTimeLayout NON_UNIQUE = new LocalTimeLayout( "NTlt", 0, 1 );

private LocalTimeLayout( String layoutName, int majorVersion, int minorVersion )
{
super( layoutName, majorVersion, minorVersion );
super( "Tlt", 0, 1 );
}

@Override
Expand Down
Expand Up @@ -27,7 +27,7 @@
/**
* Includes value and entity id (to be able to handle non-unique values). A value can be any {@link LocalTimeValue}.
*/
class LocalTimeSchemaKey extends ComparableNativeSchemaKey<LocalTimeSchemaKey>
class LocalTimeSchemaKey extends NativeSchemaKey<LocalTimeSchemaKey>
{
static final int SIZE =
Long.BYTES + /* nanoOfDay */
Expand Down
Expand Up @@ -50,8 +50,8 @@ abstract class NativeIndexProvider<KEY extends NativeSchemaKey,VALUE extends Nat
protected final RecoveryCleanupWorkCollector recoveryCleanupWorkCollector;
protected final boolean readOnly;

protected NativeIndexProvider( Descriptor descriptor, int priority, Factory directoryStructureFactory, PageCache pageCache,
FileSystemAbstraction fs, Monitor monitor, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, boolean readOnly )
protected NativeIndexProvider( Descriptor descriptor, int priority, Factory directoryStructureFactory, PageCache pageCache, FileSystemAbstraction fs,
Monitor monitor, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, boolean readOnly )
{
super( descriptor, priority, directoryStructureFactory );
this.pageCache = pageCache;
Expand All @@ -61,6 +61,8 @@ protected NativeIndexProvider( Descriptor descriptor, int priority, Factory dire
this.readOnly = readOnly;
}

abstract Layout<KEY,VALUE> layout( SchemaIndexDescriptor descriptor );

@Override
public IndexPopulator getPopulator( long indexId, SchemaIndexDescriptor descriptor, IndexSamplingConfig samplingConfig )
{
Expand All @@ -70,8 +72,7 @@ public IndexPopulator getPopulator( long indexId, SchemaIndexDescriptor descript
}

File storeFile = nativeIndexFileFromIndexId( indexId );
Layout<KEY,VALUE> layout = layout( descriptor );
return newIndexPopulator( storeFile, layout, descriptor, indexId, samplingConfig );
return newIndexPopulator( storeFile, layout( descriptor ), descriptor, indexId, samplingConfig );
}

protected abstract IndexPopulator newIndexPopulator( File storeFile, Layout<KEY, VALUE> layout, SchemaIndexDescriptor descriptor, long indexId,
Expand All @@ -82,8 +83,7 @@ public IndexAccessor getOnlineAccessor(
long indexId, SchemaIndexDescriptor descriptor, IndexSamplingConfig samplingConfig ) throws IOException
{
File storeFile = nativeIndexFileFromIndexId( indexId );
Layout<KEY,VALUE> layout = layout( descriptor );
return newIndexAccessor( storeFile, layout, descriptor, indexId, samplingConfig );
return newIndexAccessor( storeFile, layout( descriptor ), descriptor, indexId, samplingConfig );
}

protected abstract IndexAccessor newIndexAccessor( File storeFile, Layout<KEY,VALUE> layout, SchemaIndexDescriptor descriptor,
Expand Down Expand Up @@ -129,23 +129,6 @@ public StoreMigrationParticipant storeMigrationParticipant( FileSystemAbstractio
return StoreMigrationParticipant.NOT_PARTICIPATING;
}

private Layout<KEY,VALUE> layout( SchemaIndexDescriptor descriptor )
{
switch ( descriptor.type() )
{
case GENERAL:
return layoutNonUnique();
case UNIQUE:
return layoutUnique();
default:
throw new UnsupportedOperationException( "Can not create index accessor of type " + descriptor.type() );
}
}

protected abstract Layout<KEY,VALUE> layoutUnique();

protected abstract Layout<KEY,VALUE> layoutNonUnique();

private File nativeIndexFileFromIndexId( long indexId )
{
return new File( directoryStructure().directoryForIndex( indexId ), indexFileName( indexId ) );
Expand Down
Expand Up @@ -28,7 +28,7 @@
* This is the abstraction of what NativeSchemaIndex with friends need from a schema key.
* Note that it says nothing about how keys are compared, serialized, read, written, etc. That is the job of Layout.
*/
abstract class NativeSchemaKey extends ValueWriter.Adapter<RuntimeException>
abstract class NativeSchemaKey<SELF extends NativeSchemaKey> extends ValueWriter.Adapter<RuntimeException>
{
static final boolean DEFAULT_COMPARE_ID = true;

Expand Down Expand Up @@ -109,4 +109,13 @@ final void initAsHighest()
}

abstract void initValueAsHighest();

/**
* Compares the value of this key to that of another key.
* This method is expected to be called in scenarios where inconsistent reads may happen (and later retried).
*
* @param other the key to compare to.
* @return comparison against the {@code other} key.
*/
abstract int compareValueTo( SELF other );
}
Expand Up @@ -54,15 +54,18 @@ public NumberIndexProvider( PageCache pageCache, FileSystemAbstraction fs,
}

@Override
protected NumberLayoutUnique layoutUnique()
Layout<NumberSchemaKey,NativeSchemaValue> layout( SchemaIndexDescriptor descriptor )
{
return new NumberLayoutUnique();
}

@Override
protected NumberLayoutNonUnique layoutNonUnique()
{
return new NumberLayoutNonUnique();
// split like this due to legacy reasons, there are old stores out there with these different identifiers
switch ( descriptor.type() )
{
case GENERAL:
return new NumberLayoutNonUnique();
case UNIQUE:
return new NumberLayoutUnique();
default:
throw new IllegalArgumentException( "Unknown index type " + descriptor.type() );
}
}

@Override
Expand Down
Expand Up @@ -27,9 +27,9 @@
*/
abstract class NumberLayout extends SchemaLayout<NumberSchemaKey>
{
NumberLayout( long identifier, int majorVersion, int minorVersion )
NumberLayout( String identifierName, int majorVersion, int minorVersion )
{
super( identifier, majorVersion, minorVersion );
super( identifierName, majorVersion, minorVersion );
}

@Override
Expand Down

0 comments on commit aacecf8

Please sign in to comment.