Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic implementation of native schema string indexing layer
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
Showing
22 changed files
with
1,249 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/StringLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() ); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/StringLayoutNonUnique.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() ); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/StringLayoutUnique.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ty/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/StringSchemaIndexAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ); | ||
} | ||
} |
Oops, something went wrong.