Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to fixate dynamic NumberArray
when it has done all it's dynamic growing. Fixating a dynamic NumberArray returns a new instance with better performance, but one which cannot dynamically grow anymore. ParallelBatchImporter now fixates the node->relationship cache after relationship import for faster relationship->relationship stage.
- Loading branch information
Showing
19 changed files
with
433 additions
and
87 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
117 changes: 117 additions & 0 deletions
117
...nity/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/ChunkedNumberArray.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,117 @@ | |||
/** | |||
* Copyright (c) 2002-2015 "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; | |||
|
|||
/** | |||
* A {@link NumberArray} base built up out of smaller chunks. | |||
*/ | |||
abstract class ChunkedNumberArray<N extends NumberArray> implements NumberArray | |||
{ | |||
protected final long chunkSize; | |||
protected NumberArray[] chunks; | |||
|
|||
ChunkedNumberArray( long chunkSize ) | |||
{ | |||
this.chunkSize = chunkSize; | |||
} | |||
|
|||
@Override | |||
public long length() | |||
{ | |||
return chunks.length * chunkSize; | |||
} | |||
|
|||
@Override | |||
public long size() | |||
{ | |||
long size = 0; | |||
for ( int i = 0; i < chunks.length; i++ ) | |||
{ | |||
size += chunks[i].size(); | |||
} | |||
return size; | |||
} | |||
|
|||
@Override | |||
public void clear() | |||
{ | |||
for ( NumberArray chunk : chunks ) | |||
{ | |||
chunk.clear(); | |||
} | |||
} | |||
|
|||
@Override | |||
public long highestSetIndex() | |||
{ | |||
for ( int i = chunks.length-1; i >= 0; i-- ) | |||
{ | |||
NumberArray chunk = chunks[i]; | |||
long highestSetInChunk = chunk.highestSetIndex(); | |||
if ( highestSetInChunk > -1 ) | |||
{ | |||
return i*chunkSize + highestSetInChunk; | |||
} | |||
} | |||
return -1; | |||
} | |||
|
|||
@Override | |||
public void acceptMemoryStatsVisitor( MemoryStatsVisitor visitor ) | |||
{ | |||
for ( NumberArray chunk : chunks ) | |||
{ | |||
chunk.acceptMemoryStatsVisitor( visitor ); | |||
} | |||
} | |||
|
|||
@SuppressWarnings( "unchecked" ) | |||
protected N chunkAt( long index ) | |||
{ | |||
int chunkIndex = chunkIndex( index ); | |||
return (N) chunks[chunkIndex]; | |||
} | |||
|
|||
@SuppressWarnings( "unchecked" ) | |||
protected N chunkOrNullAt( long index ) | |||
{ | |||
int chunkIndex = chunkIndex( index ); | |||
return chunkIndex < chunks.length ? (N) chunks[chunkIndex] : null; | |||
} | |||
|
|||
protected int chunkIndex( long index ) | |||
{ | |||
return (int) (index/chunkSize); | |||
} | |||
|
|||
protected long index( long index ) | |||
{ | |||
return index % chunkSize; | |||
} | |||
|
|||
@Override | |||
public void close() | |||
{ | |||
for ( NumberArray chunk : chunks ) | |||
{ | |||
chunk.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
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
62 changes: 62 additions & 0 deletions
62
community/kernel/src/main/java/org/neo4j/unsafe/impl/batchimport/cache/FixedIntArray.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,62 @@ | |||
/** | |||
* Copyright (c) 2002-2015 "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; | |||
|
|||
class FixedIntArray extends FixedNumberArray<IntArray> implements IntArray | |||
{ | |||
private final int defaultValue; | |||
|
|||
FixedIntArray( NumberArray[] chunks, long chunkSize, int defaultValue ) | |||
{ | |||
super( chunks, chunkSize ); | |||
this.defaultValue = defaultValue; | |||
} | |||
|
|||
@Override | |||
public void swap( long fromIndex, long toIndex, int numberOfEntries ) | |||
{ | |||
// Let's just do this the stupid way. There's room for optimization here | |||
for ( int i = 0; i < numberOfEntries; i++ ) | |||
{ | |||
int intermediary = get( fromIndex+i ); | |||
set( fromIndex+i, get( toIndex+i ) ); | |||
set( toIndex+i, intermediary ); | |||
} | |||
} | |||
|
|||
@Override | |||
public int get( long index ) | |||
{ | |||
IntArray chunk = chunkOrNullAt( index ); | |||
return chunk != null ? chunk.get( index( index ) ) : defaultValue; | |||
} | |||
|
|||
@Override | |||
public void set( long index, int value ) | |||
{ | |||
chunkAt( index ).set( index( index ), value ); | |||
} | |||
|
|||
@Override | |||
public IntArray fixate() | |||
{ | |||
return this; | |||
} | |||
} |
Oops, something went wrong.