Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IndexPopulator for native schema number index
Implemented using GBPTree and for the time being only IndexPopulator is implemented, online IndexAccessor and SchemaIndexProvider will come later. Both unique and non-unique layouts are supported and all types of Numbers. There are small differences between unique and non-unique layouts where entity ID is in the key for non-unique, but in the value for unique. This makes the keys smaller for the unique layout, something which will make the overall index size smaller due to internal tree nodes not containing values. Each layout contains both the comparison value, a coerced value type which all numbers are converted into for comparison, but also their original value. This means that there will not need to be an additional entity property lookup for filtering those results higher up in the stack.
- Loading branch information
Showing
31 changed files
with
2,883 additions
and
56 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
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
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
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
92 changes: 92 additions & 0 deletions
92
community/kernel/src/main/java/org/neo4j/kernel/impl/index/GBPTreeUtil.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,92 @@ | |||
/* | |||
* Copyright (c) 2002-2017 "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; | |||
|
|||
import java.io.File; | |||
import java.io.IOException; | |||
import java.nio.file.NoSuchFileException; | |||
|
|||
import org.neo4j.index.internal.gbptree.GBPTree; | |||
import org.neo4j.io.fs.FileHandle; | |||
import org.neo4j.io.pagecache.PageCache; | |||
|
|||
/** | |||
* Utilities for common operations around a {@link GBPTree}. | |||
*/ | |||
public class GBPTreeUtil | |||
{ | |||
/** | |||
* Deletes store file backing a {@link GBPTree}. | |||
* | |||
* @param pageCache {@link PageCache} which manages the file. | |||
* @param storeFile the {@link File} to delete. | |||
* @throws NoSuchFileException if the {@code storeFile} doesn't exist according to the {@code pageCache}. | |||
* @throws IOException on failure to delete existing {@code storeFile}. | |||
*/ | |||
public static void delete( PageCache pageCache, File storeFile ) throws IOException | |||
{ | |||
FileHandle fileHandle = storeFileHandle( pageCache, storeFile ); | |||
fileHandle.delete(); | |||
} | |||
|
|||
/** | |||
* Deletes store file backing a {@link GBPTree}, if it exists according to the {@code pageCache}. | |||
* | |||
* @param pageCache {@link PageCache} which manages the file. | |||
* @param storeFile the {@link File} to delete. | |||
* @throws IOException on failure to delete existing {@code storeFile}. | |||
*/ | |||
public static void deleteIfPresent( PageCache pageCache, File storeFile ) throws IOException | |||
{ | |||
try | |||
{ | |||
delete( pageCache, storeFile ); | |||
} | |||
catch ( NoSuchFileException e ) | |||
{ | |||
// File does not exist, we don't need to delete | |||
} | |||
} | |||
|
|||
/** | |||
* Checks whether or not {@code storeFile} exists according to {@code pageCache}. | |||
* | |||
* @param pageCache {@link PageCache} which manages the file. | |||
* @param storeFile the {@link File} to check for existence. | |||
* @return {@code true} if {@code storeFile} exists according to {@code pageCache}, otherwise {@code false}. | |||
*/ | |||
public static boolean storeFileExists( PageCache pageCache, File storeFile ) | |||
{ | |||
try | |||
{ | |||
storeFileHandle( pageCache, storeFile ); | |||
return true; | |||
} | |||
catch ( IOException e ) | |||
{ | |||
return false; | |||
} | |||
} | |||
|
|||
private static FileHandle storeFileHandle( PageCache pageCache, File storeFile ) throws IOException | |||
{ | |||
return pageCache.getCachedFileSystem().streamFilesRecursive( storeFile ).findFirst().get(); | |||
} | |||
} |
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
70 changes: 70 additions & 0 deletions
70
...kernel/src/main/java/org/neo4j/kernel/impl/index/schema/ConflictDetectingValueMerger.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,70 @@ | |||
/* | |||
* Copyright (c) 2002-2017 "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.ValueMerger; | |||
import org.neo4j.index.internal.gbptree.Writer; | |||
|
|||
/** | |||
* {@link ValueMerger} which will merely detect conflict, not change any value if conflict, i.e. if the | |||
* key already exists. After this merge has been used in a call to {@link Writer#merge(Object, Object, ValueMerger)} | |||
* the {@link #wasConflict()} accessor can be called to check whether or not that call conflicted with | |||
* an existing key. A call to {@link #wasConflict()} will also clear the conflict flag. | |||
* | |||
* @param <VALUE> type of values being merged. | |||
*/ | |||
class ConflictDetectingValueMerger<VALUE extends SchemaNumberValue> implements ValueMerger<VALUE> | |||
{ | |||
private boolean conflict; | |||
private long existingNodeId; | |||
private long addedNodeId; | |||
|
|||
@Override | |||
public VALUE merge( VALUE existingValue, VALUE newValue ) | |||
{ | |||
conflict = true; | |||
existingNodeId = existingValue.getEntityId(); | |||
addedNodeId = newValue.getEntityId(); | |||
return null; | |||
} | |||
|
|||
/** | |||
* @return whether or not merge conflicted with an existing key. This call also clears the conflict flag. | |||
*/ | |||
boolean wasConflict() | |||
{ | |||
boolean result = conflict; | |||
if ( conflict ) | |||
{ | |||
conflict = false; | |||
} | |||
return result; | |||
} | |||
|
|||
long existingNodeId() | |||
{ | |||
return existingNodeId; | |||
} | |||
|
|||
long addedNodeId() | |||
{ | |||
return addedNodeId; | |||
} | |||
} |
Oops, something went wrong.