Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MergingBlockEntryReader can merge join multiple BlockEntryReaders
Name change: BlockReader -> BlockEntryReader BlockStorageReader -> BlockReader
- Loading branch information
Showing
7 changed files
with
441 additions
and
103 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/BlockEntryCursor.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,32 @@ | |||
/* | |||
* Copyright (c) 2002-2019 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.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.IOException; | |||
|
|||
public interface BlockEntryCursor<KEY,VALUE> extends Closeable | |||
{ | |||
boolean next() throws IOException; | |||
|
|||
KEY key(); | |||
|
|||
VALUE value(); | |||
} |
76 changes: 76 additions & 0 deletions
76
community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/BlockEntryReader.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,76 @@ | |||
/* | |||
* Copyright (c) 2002-2019 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.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.index.internal.gbptree.Layout; | |||
import org.neo4j.io.pagecache.PageCursor; | |||
|
|||
public class BlockEntryReader<KEY,VALUE> implements BlockEntryCursor<KEY,VALUE> | |||
{ | |||
private final long entryCount; | |||
private final PageCursor pageCursor; | |||
private final KEY key; | |||
private final VALUE value; | |||
private final Layout<KEY,VALUE> layout; | |||
private long readEntries; | |||
|
|||
BlockEntryReader( PageCursor pageCursor, Layout<KEY,VALUE> layout ) | |||
{ | |||
this.pageCursor = pageCursor; | |||
this.entryCount = pageCursor.getLong(); | |||
this.layout = layout; | |||
this.key = layout.newKey(); | |||
this.value = layout.newValue(); | |||
} | |||
|
|||
public boolean next() throws IOException | |||
{ | |||
if ( readEntries >= entryCount ) | |||
{ | |||
return false; | |||
} | |||
BlockEntry.read( pageCursor, layout, key, value ); | |||
readEntries++; | |||
return true; | |||
} | |||
|
|||
public long entryCount() | |||
{ | |||
return entryCount; | |||
} | |||
|
|||
public KEY key() | |||
{ | |||
return key; | |||
} | |||
|
|||
public VALUE value() | |||
{ | |||
return value; | |||
} | |||
|
|||
@Override | |||
public void close() throws IOException | |||
{ | |||
pageCursor.close(); | |||
} | |||
} |
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: 0 additions & 69 deletions
69
community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/BlockStorageReader.java
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
...nity/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/MergingBlockEntryReader.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,87 @@ | |||
/* | |||
* Copyright (c) 2002-2019 "Neo4j," | |||
* Neo4j Sweden AB [http://neo4j.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 java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.PriorityQueue; | |||
|
|||
import org.neo4j.index.internal.gbptree.Layout; | |||
import org.neo4j.io.IOUtils; | |||
|
|||
public class MergingBlockEntryReader<KEY,VALUE> implements BlockEntryCursor<KEY,VALUE> | |||
{ | |||
// todo more or less expensive compared to iterating over heads? | |||
private final PriorityQueue<BlockEntryCursor<KEY,VALUE>> sortedReaders; | |||
private List<BlockEntryCursor<KEY,VALUE>> readersToClose = new ArrayList<>(); | |||
private BlockEntryCursor<KEY,VALUE> lastReturned; | |||
|
|||
MergingBlockEntryReader( Layout<KEY,VALUE> layout ) | |||
{ | |||
this.sortedReaders = new PriorityQueue<>( ( o1, o2 ) -> layout.compare( o1.key(), o2.key() ) ); | |||
} | |||
|
|||
void addSource( BlockEntryCursor<KEY,VALUE> source ) throws IOException | |||
{ | |||
readersToClose.add( source ); | |||
if ( source.next() ) | |||
{ | |||
sortedReaders.add( source ); | |||
} | |||
} | |||
|
|||
@Override | |||
public boolean next() throws IOException | |||
{ | |||
if ( lastReturned != null ) | |||
{ | |||
if ( lastReturned.next() ) | |||
{ | |||
sortedReaders.add( lastReturned ); | |||
} | |||
} | |||
|
|||
if ( sortedReaders.isEmpty() ) | |||
{ | |||
return false; | |||
} | |||
lastReturned = sortedReaders.poll(); | |||
return true; | |||
} | |||
|
|||
@Override | |||
public KEY key() | |||
{ | |||
return lastReturned.key(); | |||
} | |||
|
|||
@Override | |||
public VALUE value() | |||
{ | |||
return lastReturned.value(); | |||
} | |||
|
|||
@Override | |||
public void close() throws IOException | |||
{ | |||
IOUtils.closeAll( readersToClose ); | |||
} | |||
} |
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.