Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
404 additions
and
24 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
84 changes: 84 additions & 0 deletions
84
...unity/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/PageCacheIntArray.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,84 @@ | |||
/* | |||
* 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.unsafe.impl.batchimport.cache; | |||
|
|||
import java.io.IOException; | |||
|
|||
import org.neo4j.io.pagecache.PagedFile; | |||
|
|||
import static java.lang.Math.toIntExact; | |||
|
|||
public class PageCacheIntArray extends PageCacheNumberArray<IntArray> implements IntArray | |||
{ | |||
private static final int ENTRY_SIZE = Integer.BYTES; | |||
private static final int ENTRIES_PER_PAGE = PAGE_SIZE / ENTRY_SIZE; | |||
|
|||
public PageCacheIntArray( PagedFile pagedFile ) throws IOException | |||
{ | |||
super( pagedFile, ENTRIES_PER_PAGE, ENTRY_SIZE ); | |||
} | |||
|
|||
@Override | |||
public int get( long index ) | |||
{ | |||
long pageId = index / ENTRIES_PER_PAGE; | |||
int offset = toIntExact( index % ENTRIES_PER_PAGE ) * ENTRY_SIZE; | |||
if ( writeCursor.getCurrentPageId() == pageId ) | |||
{ | |||
// We have to read from the write cursor, since the write cursor is on it | |||
return writeCursor.getInt( offset ); | |||
} | |||
|
|||
// Go ahead and read from the read cursor | |||
try | |||
{ | |||
goTo( readCursor, pageId ); | |||
int result; | |||
do | |||
{ | |||
result = readCursor.getInt( offset ); | |||
} | |||
while ( readCursor.shouldRetry() ); | |||
checkBounds( readCursor ); | |||
return result; | |||
} | |||
catch ( IOException e ) | |||
{ | |||
throw new RuntimeException( e ); | |||
} | |||
} | |||
|
|||
@Override | |||
public void set( long index, int value ) | |||
{ | |||
long pageId = index / ENTRIES_PER_PAGE; | |||
int offset = toIntExact( index % ENTRIES_PER_PAGE ) * ENTRY_SIZE; | |||
try | |||
{ | |||
goTo( writeCursor, pageId ); | |||
writeCursor.putInt( offset, value ); | |||
checkBounds( writeCursor ); | |||
} | |||
catch ( IOException e ) | |||
{ | |||
throw new RuntimeException( e ); | |||
} | |||
} | |||
} |
84 changes: 84 additions & 0 deletions
84
...nity/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/PageCacheLongArray.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,84 @@ | |||
/* | |||
* 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.unsafe.impl.batchimport.cache; | |||
|
|||
import java.io.IOException; | |||
|
|||
import org.neo4j.io.pagecache.PagedFile; | |||
|
|||
import static java.lang.Math.toIntExact; | |||
|
|||
public class PageCacheLongArray extends PageCacheNumberArray<LongArray> implements LongArray | |||
{ | |||
private static final int ENTRY_SIZE = Long.BYTES; | |||
private static final int ENTRIES_PER_PAGE = PAGE_SIZE / ENTRY_SIZE; | |||
|
|||
public PageCacheLongArray( PagedFile pagedFile ) throws IOException | |||
{ | |||
super( pagedFile, ENTRIES_PER_PAGE, ENTRY_SIZE ); | |||
} | |||
|
|||
@Override | |||
public long get( long index ) | |||
{ | |||
long pageId = index / ENTRIES_PER_PAGE; | |||
int offset = toIntExact( index % ENTRIES_PER_PAGE ) * ENTRY_SIZE; | |||
if ( writeCursor.getCurrentPageId() == pageId ) | |||
{ | |||
// We have to read from the write cursor, since the write cursor is on it | |||
return writeCursor.getLong( offset ); | |||
} | |||
|
|||
// Go ahead and read from the read cursor | |||
try | |||
{ | |||
goTo( readCursor, pageId ); | |||
long result; | |||
do | |||
{ | |||
result = readCursor.getLong( offset ); | |||
} | |||
while ( readCursor.shouldRetry() ); | |||
checkBounds( readCursor ); | |||
return result; | |||
} | |||
catch ( IOException e ) | |||
{ | |||
throw new RuntimeException( e ); | |||
} | |||
} | |||
|
|||
@Override | |||
public void set( long index, long value ) | |||
{ | |||
long pageId = index / ENTRIES_PER_PAGE; | |||
int offset = toIntExact( index % ENTRIES_PER_PAGE ) * ENTRY_SIZE; | |||
try | |||
{ | |||
goTo( writeCursor, pageId ); | |||
writeCursor.putLong( offset, value ); | |||
checkBounds( writeCursor ); | |||
} | |||
catch ( IOException e ) | |||
{ | |||
throw new RuntimeException( e ); | |||
} | |||
} | |||
} |
109 changes: 109 additions & 0 deletions
109
...ty/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/PageCacheNumberArray.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,109 @@ | |||
/* | |||
* 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.unsafe.impl.batchimport.cache; | |||
|
|||
import java.io.IOException; | |||
|
|||
import org.neo4j.io.pagecache.PageCursor; | |||
import org.neo4j.io.pagecache.PagedFile; | |||
|
|||
import static org.neo4j.io.ByteUnit.kibiBytes; | |||
|
|||
public abstract class PageCacheNumberArray<N extends NumberArray<N>> implements NumberArray<N> | |||
{ | |||
static final int PAGE_SIZE = (int) kibiBytes( 8 ); | |||
|
|||
protected final PagedFile pagedFile; | |||
protected final PageCursor readCursor; | |||
protected final PageCursor writeCursor; | |||
private final int entriesPerPage; | |||
private final int entrySize; | |||
|
|||
public PageCacheNumberArray( PagedFile pagedFile, int entriesPerPage, int entrySize ) throws IOException | |||
{ | |||
this.pagedFile = pagedFile; | |||
this.entriesPerPage = entriesPerPage; | |||
this.entrySize = entrySize; | |||
this.readCursor = pagedFile.io( 0, PagedFile.PF_SHARED_READ_LOCK ); | |||
this.writeCursor = pagedFile.io( 0, PagedFile.PF_SHARED_WRITE_LOCK ); | |||
goTo( writeCursor, 0 ); | |||
} | |||
|
|||
@Override | |||
public long length() | |||
{ | |||
try | |||
{ | |||
return pagedFile.getLastPageId() * entriesPerPage; | |||
} | |||
catch ( IOException e ) | |||
{ | |||
throw new RuntimeException( e ); | |||
} | |||
} | |||
|
|||
@Override | |||
public void clear() | |||
{ | |||
} | |||
|
|||
@Override | |||
public void close() | |||
{ | |||
readCursor.close(); | |||
writeCursor.close(); | |||
try | |||
{ | |||
pagedFile.close(); | |||
} | |||
catch ( IOException e ) | |||
{ | |||
throw new RuntimeException( e ); | |||
} | |||
} | |||
|
|||
@Override | |||
public N at( long index ) | |||
{ | |||
return (N) this; | |||
} | |||
|
|||
@Override | |||
public void acceptMemoryStatsVisitor( MemoryStatsVisitor visitor ) | |||
{ | |||
visitor.offHeapUsage( length() * entrySize ); | |||
} | |||
|
|||
protected void checkBounds( PageCursor cursor ) | |||
{ | |||
if ( cursor.checkAndClearBoundsFlag() ) | |||
{ | |||
throw new IllegalStateException(); | |||
} | |||
} | |||
|
|||
protected void goTo( PageCursor cursor, long pageId ) throws IOException | |||
{ | |||
if ( !cursor.next( pageId ) ) | |||
{ | |||
throw new IllegalStateException(); | |||
} | |||
} | |||
} |
Oops, something went wrong.