Skip to content

Commit

Permalink
Basic implementation of native schema string indexing layer
Browse files Browse the repository at this point in the history
Much of the changes in here are about making test classes and utilities
generic to value type as well as copy type-specific indexing code from
number schema index classes.

Here's also a basic, non-optimized implementation of the string schema
index accessor, string layout and friends which focuses on getting the
functionality in place first and foremost.
  • Loading branch information
tinwelint authored and burqen committed Feb 15, 2018
1 parent 21e71a6 commit 4a6e91c
Show file tree
Hide file tree
Showing 22 changed files with 1,249 additions and 259 deletions.
Expand Up @@ -514,6 +514,11 @@ public String from()
return (String)from.asObject();
}

public Value fromAsValue()
{
return from;
}

public boolean fromInclusive()
{
return fromInclusive;
Expand All @@ -524,6 +529,11 @@ public String to()
return (String)to.asObject();
}

public Value toAsValue()
{
return to;
}

public boolean toInclusive()
{
return toInclusive;
Expand Down
7 changes: 7 additions & 0 deletions community/kernel/pom.xml
Expand Up @@ -254,6 +254,13 @@ the relevant Commercial Agreement.
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-values</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
Expand Down
@@ -0,0 +1,105 @@
/*
* Copyright (c) 2002-2018 "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.index.schema;

import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.io.pagecache.PageCursor;

import static java.lang.String.format;

import static org.neo4j.kernel.impl.index.schema.StringSchemaKey.ENTITY_ID_SIZE;

/**
* {@link Layout} for numbers where numbers doesn't need to be unique.
*/
abstract class StringLayout extends Layout.Adapter<StringSchemaKey,NativeSchemaValue>
{
@Override
public StringSchemaKey newKey()
{
return new StringSchemaKey();
}

@Override
public StringSchemaKey copyKey( StringSchemaKey key, StringSchemaKey into )
{
// TODO when we have reuse of byte[] take that into consideration here too
into.bytes = key.bytes.clone();
into.setEntityId( key.getEntityId() );
into.setEntityIdIsSpecialTieBreaker( key.getEntityIdIsSpecialTieBreaker() );
return into;
}

@Override
public NativeSchemaValue newValue()
{
return NativeSchemaValue.INSTANCE;
}

@Override
public int keySize( StringSchemaKey key )
{
return key.size();
}

@Override
public int valueSize( NativeSchemaValue value )
{
return NativeSchemaValue.SIZE;
}

@Override
public void writeKey( PageCursor cursor, StringSchemaKey key )
{
cursor.putLong( key.getEntityId() );
cursor.putBytes( key.bytes );
}

@Override
public void writeValue( PageCursor cursor, NativeSchemaValue value )
{
}

@Override
public void readKey( PageCursor cursor, StringSchemaKey into, int keySize )
{
// TODO consider reusing byte[] instances somehow
into.setEntityId( cursor.getLong() );
into.bytes = new byte[keySize - ENTITY_ID_SIZE];
cursor.getBytes( into.bytes );
}

@Override
public void readValue( PageCursor cursor, NativeSchemaValue into, int valueSize )
{
}

@Override
public boolean fixedSize()
{
return false;
}

@Override
public String toString()
{
return format( "%s[version:%d.%d, identifier:%d]", getClass().getSimpleName(), majorVersion(), minorVersion(), identifier() );
}
}
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2002-2018 "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.index.schema;

import org.neo4j.index.internal.gbptree.Layout;

public class StringLayoutNonUnique extends StringLayout
{
private static final String IDENTIFIER_NAME = "NUSI";
static final int MAJOR_VERSION = 0;
static final int MINOR_VERSION = 1;
static long IDENTIFIER = Layout.namedIdentifier( IDENTIFIER_NAME, NativeSchemaValue.SIZE );

@Override
public long identifier()
{
return IDENTIFIER;
}

@Override
public int majorVersion()
{
return MAJOR_VERSION;
}

@Override
public int minorVersion()
{
return MINOR_VERSION;
}

@Override
public int compare( StringSchemaKey o1, StringSchemaKey o2 )
{
int comparison = o1.compareValueTo( o2 );
return comparison != 0 ? comparison : Long.compare( o1.getEntityId(), o2.getEntityId() );
}
}
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2002-2018 "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.index.schema;

import org.neo4j.index.internal.gbptree.Layout;

/**
* {@link Layout} for numbers where numbers need to be unique.
*/
class StringLayoutUnique extends StringLayout
{
private static final String IDENTIFIER_NAME = "USI";
static final int MAJOR_VERSION = 0;
static final int MINOR_VERSION = 1;
static long IDENTIFIER = Layout.namedIdentifier( IDENTIFIER_NAME, NativeSchemaValue.SIZE );

@Override
public long identifier()
{
return IDENTIFIER;
}

@Override
public int majorVersion()
{
return MAJOR_VERSION;
}

@Override
public int minorVersion()
{
return MINOR_VERSION;
}

@Override
public int compare( StringSchemaKey o1, StringSchemaKey o2 )
{
int comparison = o1.compareValueTo( o2 );
if ( comparison == 0 )
{
// This is a special case where we need also compare entityId to support inclusive/exclusive
if ( o1.getEntityIdIsSpecialTieBreaker() || o2.getEntityIdIsSpecialTieBreaker() )
{
return Long.compare( o1.getEntityId(), o2.getEntityId() );
}
}
return comparison;
}
}
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2002-2018 "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.index.schema;

import java.io.File;
import java.io.IOException;

import org.neo4j.index.internal.gbptree.Layout;
import org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.api.index.SchemaIndexProvider;
import org.neo4j.kernel.api.schema.index.IndexDescriptor;
import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig;
import org.neo4j.storageengine.api.schema.IndexReader;

public class StringSchemaIndexAccessor<KEY extends StringSchemaKey, VALUE extends NativeSchemaValue>
extends NativeSchemaIndexAccessor<KEY,VALUE>
{
StringSchemaIndexAccessor(
PageCache pageCache,
FileSystemAbstraction fs,
File storeFile,
Layout<KEY,VALUE> layout,
RecoveryCleanupWorkCollector recoveryCleanupWorkCollector,
SchemaIndexProvider.Monitor monitor,
IndexDescriptor descriptor,
long indexId,
IndexSamplingConfig samplingConfig ) throws IOException
{
super( pageCache, fs, storeFile, layout, recoveryCleanupWorkCollector, monitor, descriptor, indexId, samplingConfig );
}

@Override
public IndexReader newReader()
{
assertOpen();
return new StringSchemaIndexReader<>( tree, layout, samplingConfig, descriptor );
}
}

0 comments on commit 4a6e91c

Please sign in to comment.