Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements specific SimpleIndexReader#query method
Instead of relying on the default wrapping found in AbstractIndexReader. This removes unnecessary indirection in SimpleIndexReader.
- Loading branch information
Showing
6 changed files
with
342 additions
and
219 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
community/kernel/src/main/java/org/neo4j/kernel/impl/api/schema/BridgingIndexProgressor.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,106 @@ | |||
/* | |||
* 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.api.schema; | |||
|
|||
import java.util.Queue; | |||
import java.util.concurrent.ConcurrentLinkedQueue; | |||
|
|||
import org.neo4j.internal.kernel.api.IndexQuery; | |||
import org.neo4j.kernel.api.schema.index.IndexDescriptor; | |||
import org.neo4j.storageengine.api.schema.IndexProgressor; | |||
import org.neo4j.values.storable.Value; | |||
|
|||
/** | |||
* Combine multiple progressor to act like one single logical progressor seen from client's perspective. | |||
*/ | |||
public class BridgingIndexProgressor implements IndexProgressor.NodeValueClient, IndexProgressor | |||
{ | |||
private final NodeValueClient client; | |||
private final int[] keys; | |||
// This is a thread-safe queue because it can be used in parallel scenarios. | |||
// The overhead of a concurrent queue in this case is negligable since typically there will be two or a very few number | |||
// of progressors and each progressor has many results each | |||
private final Queue<IndexProgressor> progressors = new ConcurrentLinkedQueue<>(); | |||
private IndexProgressor current; | |||
|
|||
public BridgingIndexProgressor( NodeValueClient client, int[] keys ) | |||
{ | |||
this.client = client; | |||
this.keys = keys; | |||
} | |||
|
|||
@Override | |||
public boolean next() | |||
{ | |||
if ( current == null ) | |||
{ | |||
current = progressors.poll(); | |||
} | |||
while ( current != null ) | |||
{ | |||
if ( current.next() ) | |||
{ | |||
return true; | |||
} | |||
else | |||
{ | |||
current.close(); | |||
current = progressors.poll(); | |||
} | |||
} | |||
return false; | |||
} | |||
|
|||
@Override | |||
public boolean needsValues() | |||
{ | |||
return client.needsValues(); | |||
} | |||
|
|||
@Override | |||
public void close() | |||
{ | |||
progressors.forEach( IndexProgressor::close ); | |||
} | |||
|
|||
@Override | |||
public void initialize( IndexDescriptor descriptor, IndexProgressor progressor, IndexQuery[] queries ) | |||
{ | |||
assertKeysAlign( descriptor.schema().getPropertyIds() ); | |||
progressors.add( progressor ); | |||
} | |||
|
|||
private void assertKeysAlign( int[] keys ) | |||
{ | |||
for ( int i = 0; i < this.keys.length; i++ ) | |||
{ | |||
if ( this.keys[i] != keys[i] ) | |||
{ | |||
throw new UnsupportedOperationException( "Can not chain multiple progressors with different key set." ); | |||
} | |||
} | |||
} | |||
|
|||
@Override | |||
public boolean acceptNode( long reference, Value[] values ) | |||
{ | |||
return client.acceptNode( reference, 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.