Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More testing and multiple blocks working
- Loading branch information
Showing
4 changed files
with
217 additions
and
109 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/BlockReader.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,85 @@ | |||
/* | |||
* 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; | |||
|
|||
import org.neo4j.index.internal.gbptree.Layout; | |||
import org.neo4j.io.pagecache.PageCursor; | |||
|
|||
import static org.neo4j.index.internal.gbptree.DynamicSizeUtil.extractKeySize; | |||
import static org.neo4j.index.internal.gbptree.DynamicSizeUtil.extractValueSize; | |||
import static org.neo4j.index.internal.gbptree.DynamicSizeUtil.readKeyValueSize; | |||
|
|||
public class BlockReader<KEY,VALUE> implements Closeable | |||
{ | |||
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; | |||
|
|||
BlockReader( 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; | |||
} | |||
|
|||
long entrySize = readKeyValueSize( pageCursor ); | |||
layout.readKey( pageCursor, key, extractKeySize( entrySize ) ); | |||
layout.readValue( pageCursor, value, extractValueSize( entrySize ) ); | |||
|
|||
readEntries++; | |||
return true; | |||
} | |||
|
|||
public long entryCount() | |||
{ | |||
return entryCount; | |||
} | |||
|
|||
KEY key() | |||
{ | |||
return key; | |||
} | |||
|
|||
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: 69 additions & 0 deletions
69
community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/BlockStorageReader.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,69 @@ | |||
/* | |||
* 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.File; | |||
import java.io.IOException; | |||
|
|||
import org.neo4j.index.internal.gbptree.Layout; | |||
import org.neo4j.io.fs.FileSystemAbstraction; | |||
import org.neo4j.io.fs.OpenMode; | |||
import org.neo4j.io.fs.StoreChannel; | |||
import org.neo4j.io.pagecache.PageCursor; | |||
import org.neo4j.kernel.impl.transaction.log.ReadAheadChannel; | |||
|
|||
public class BlockStorageReader<KEY,VALUE> implements Closeable | |||
{ | |||
private final StoreChannel channel; | |||
private final long blockSize; | |||
private final FileSystemAbstraction fs; | |||
private final File file; | |||
private final Layout<KEY,VALUE> layout; | |||
|
|||
BlockStorageReader( FileSystemAbstraction fs, File file, long blockSize, Layout<KEY,VALUE> layout ) throws IOException | |||
{ | |||
this.fs = fs; | |||
this.file = file; | |||
this.layout = layout; | |||
this.channel = fs.open( file, OpenMode.READ ); | |||
this.blockSize = blockSize; | |||
} | |||
|
|||
public BlockReader<KEY,VALUE> nextBlock() throws IOException | |||
{ | |||
long position = channel.position(); | |||
if ( position >= channel.size() ) | |||
{ | |||
return null; | |||
} | |||
StoreChannel blockChannel = fs.open( file, OpenMode.READ ); | |||
blockChannel.position( position ); | |||
channel.position( position + blockSize ); | |||
PageCursor pageCursor = new ReadableChannelPageCursor( new ReadAheadChannel<>( blockChannel ) ); | |||
return new BlockReader<>( pageCursor, layout ); | |||
} | |||
|
|||
@Override | |||
public void close() throws IOException | |||
{ | |||
channel.close(); | |||
} | |||
} |
Oops, something went wrong.