Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce NativeSchemaNumberIndex and separate updater
NativeSchemaNumberIndex will act as common parent for Populator and Accessor. Updater will be used by both. Also, clean up test hierarchy.
- Loading branch information
Showing
10 changed files
with
289 additions
and
181 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
69 changes: 69 additions & 0 deletions
69
...nity/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeSchemaNumberIndex.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,69 @@ | ||
/* | ||
* 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 java.io.Closeable; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.neo4j.index.internal.gbptree.GBPTree; | ||
import org.neo4j.index.internal.gbptree.Layout; | ||
import org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector; | ||
import org.neo4j.io.pagecache.PageCache; | ||
|
||
import static org.neo4j.index.internal.gbptree.GBPTree.NO_HEADER_READER; | ||
import static org.neo4j.index.internal.gbptree.GBPTree.NO_HEADER_WRITER; | ||
import static org.neo4j.index.internal.gbptree.GBPTree.NO_MONITOR; | ||
|
||
class NativeSchemaNumberIndex<KEY extends NumberKey, VALUE extends NumberValue> | ||
{ | ||
final PageCache pageCache; | ||
final File storeFile; | ||
final Layout<KEY,VALUE> layout; | ||
|
||
GBPTree<KEY,VALUE> tree; | ||
|
||
NativeSchemaNumberIndex( PageCache pageCache, File storeFile, Layout<KEY,VALUE> layout ) | ||
{ | ||
this.pageCache = pageCache; | ||
this.storeFile = storeFile; | ||
this.layout = layout; | ||
} | ||
|
||
void instantiateTree( RecoveryCleanupWorkCollector recoveryCleanupWorkCollector ) throws IOException | ||
{ | ||
tree = new GBPTree<>( pageCache, storeFile, layout, 0, NO_MONITOR, NO_HEADER_READER, NO_HEADER_WRITER, | ||
recoveryCleanupWorkCollector ); | ||
} | ||
|
||
void closeTree() throws IOException | ||
{ | ||
tree = closeIfPresent( tree ); | ||
} | ||
|
||
<T extends Closeable> T closeIfPresent( T closeable ) throws IOException | ||
{ | ||
if ( closeable != null ) | ||
{ | ||
closeable.close(); | ||
} | ||
return null; | ||
} | ||
} |
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
108 changes: 108 additions & 0 deletions
108
...rnel/src/main/java/org/neo4j/kernel/impl/index/schema/NativeSchemaNumberIndexUpdater.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,108 @@ | ||
/* | ||
* 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 java.io.IOException; | ||
|
||
import org.neo4j.collection.primitive.PrimitiveLongSet; | ||
import org.neo4j.index.internal.gbptree.Writer; | ||
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; | ||
import org.neo4j.kernel.api.index.IndexEntryUpdate; | ||
import org.neo4j.kernel.api.index.IndexUpdater; | ||
import org.neo4j.values.ValueTuple; | ||
|
||
class NativeSchemaNumberIndexUpdater<KEY extends NumberKey, VALUE extends NumberValue> | ||
implements IndexUpdater | ||
{ | ||
private final KEY treeKey; | ||
private final VALUE treeValue; | ||
private final ConflictDetectingValueMerger<VALUE> conflictDetectingValueMerger; | ||
private Writer<KEY,VALUE> writer; | ||
|
||
private boolean closed = true; | ||
private boolean manageClosingOfWriter; | ||
|
||
NativeSchemaNumberIndexUpdater( KEY treeKey, VALUE treeValue ) | ||
{ | ||
this.treeKey = treeKey; | ||
this.treeValue = treeValue; | ||
this.conflictDetectingValueMerger = new ConflictDetectingValueMerger<VALUE>(); | ||
} | ||
|
||
NativeSchemaNumberIndexUpdater<KEY,VALUE> initialize( Writer<KEY,VALUE> writer, boolean manageClosingOfWriter ) | ||
{ | ||
if ( !closed ) | ||
{ | ||
throw new IllegalStateException( "Updater still open" ); | ||
} | ||
|
||
this.manageClosingOfWriter = manageClosingOfWriter; | ||
this.writer = writer; | ||
closed = false; | ||
return this; | ||
} | ||
|
||
@Override | ||
public void process( IndexEntryUpdate update ) throws IOException, IndexEntryConflictException | ||
{ | ||
assertOpen(); | ||
processAdd( treeKey, treeValue, update, writer, conflictDetectingValueMerger ); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException, IndexEntryConflictException | ||
{ | ||
if ( manageClosingOfWriter ) | ||
{ | ||
writer.close(); | ||
} | ||
closed = true; | ||
} | ||
|
||
@Override | ||
public void remove( PrimitiveLongSet nodeIds ) throws IOException | ||
{ | ||
assertOpen(); | ||
} | ||
|
||
private void assertOpen() | ||
{ | ||
if ( closed ) | ||
{ | ||
throw new IllegalStateException( "Updater has been closed" ); | ||
} | ||
} | ||
|
||
static <KEY extends NumberKey, VALUE extends NumberValue> void processAdd( KEY treeKey, VALUE treeValue, | ||
IndexEntryUpdate update, Writer<KEY,VALUE> singleWriter, | ||
ConflictDetectingValueMerger<VALUE> conflictDetectingValueMerger ) | ||
throws IOException, IndexEntryConflictException | ||
{ | ||
treeKey.from( update.getEntityId(), update.values() ); | ||
treeValue.from( update.getEntityId(), update.values() ); | ||
singleWriter.merge( treeKey, treeValue, conflictDetectingValueMerger ); | ||
if ( conflictDetectingValueMerger.wasConflict() ) | ||
{ | ||
long existingNodeId = conflictDetectingValueMerger.existingNodeId(); | ||
long addedNodeId = conflictDetectingValueMerger.addedNodeId(); | ||
throw new IndexEntryConflictException( existingNodeId, addedNodeId, ValueTuple.of( update.values() ) ); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.