diff --git a/community/index/src/main/java/org/neo4j/index/gbptree/InternalTreeLogic.java b/community/index/src/main/java/org/neo4j/index/gbptree/InternalTreeLogic.java index 697e39f3bc38f..8ff92f0d1ac78 100644 --- a/community/index/src/main/java/org/neo4j/index/gbptree/InternalTreeLogic.java +++ b/community/index/src/main/java/org/neo4j/index/gbptree/InternalTreeLogic.java @@ -79,9 +79,6 @@ class InternalTreeLogic { private final IdProvider idProvider; private final TreeNode bTreeNode; - private final byte[] tmpForKeys; - private final byte[] tmpForValues; - private final byte[] tmpForChildren; private final Layout layout; private final KEY primKeyPlaceHolder; private final KEY readKey; @@ -93,9 +90,6 @@ class InternalTreeLogic this.bTreeNode = bTreeNode; this.layout = layout; int maxKeyCount = max( bTreeNode.internalMaxKeyCount(), bTreeNode.leafMaxKeyCount() ); - this.tmpForKeys = new byte[(maxKeyCount + 1) * layout.keySize()]; - this.tmpForValues = new byte[(maxKeyCount + 1) * layout.valueSize()]; - this.tmpForChildren = new byte[(maxKeyCount + 2) * bTreeNode.childSize()]; this.primKeyPlaceHolder = layout.newKey(); this.readKey = layout.newKey(); this.readValue = layout.newValue(); diff --git a/community/index/src/main/java/org/neo4j/index/gbptree/TreeNode.java b/community/index/src/main/java/org/neo4j/index/gbptree/TreeNode.java index 2488430fc6e3c..508b17099c223 100644 --- a/community/index/src/main/java/org/neo4j/index/gbptree/TreeNode.java +++ b/community/index/src/main/java/org/neo4j/index/gbptree/TreeNode.java @@ -370,101 +370,12 @@ Comparator keyComparator() return layout; } - int readKeysWithInsertRecordInPosition( PageCursor cursor, Consumer newRecordWriter, - int insertPosition, int totalNumberOfRecords, byte[] into ) - { - return readRecordsWithInsertRecordInPosition( cursor, newRecordWriter, insertPosition, totalNumberOfRecords, - keySize, keyOffset( 0 ), into ); - } - - int readValuesWithInsertRecordInPosition( PageCursor cursor, Consumer newRecordWriter, - int insertPosition, int totalNumberOfRecords, byte[] into ) - { - return readRecordsWithInsertRecordInPosition( cursor, newRecordWriter, insertPosition, totalNumberOfRecords, - valueSize, valueOffset( 0 ), into ); - } - - int readChildrenWithInsertRecordInPosition( PageCursor cursor, Consumer newRecordWriter, - int insertPosition, int totalNumberOfRecords, byte[] into ) - { - return readRecordsWithInsertRecordInPosition( cursor, newRecordWriter, insertPosition, totalNumberOfRecords, - childSize(), childOffset( 0 ), into ); - } - void goTo( PageCursor cursor, String messageOnError, long nodeId ) throws IOException { PageCursorUtil.goTo( cursor, messageOnError, GenSafePointerPair.pointer( nodeId ) ); } - /** - * Leaves cursor on same page as when called. No guarantees on offset. - *

- * Create a byte[] with totalNumberOfRecords of recordSize from cursor reading from baseRecordOffset - * with newRecord inserted in insertPosition, with the following records shifted to the right. - *

- * Simply: Records of size recordSize that can be read from offset baseRecordOffset in page pinned by cursor has - * some ordering. This ordering is preserved with new record inserted in insertPosition in the returned byte[], - * NOT in the page. - * - * @param cursor {@link org.neo4j.io.pagecache.PageCursor} pinned to page to read records from - * @param newRecordWriter new data to be inserted in insertPosition in returned byte[]. - * This is a {@link Consumer} since the type of data can differ (value/child), - * although perhaps this can be done in a better way - * @param insertPosition position of newRecord. 0 being before all other records, - * (totalNumberOfRecords - 1) being after all other records - * @param totalNumberOfRecords the total number of records to be contained in returned byte[], including newRecord - * @param recordSize the size in number of bytes of one record - * @param baseRecordOffset the offset from where cursor should start read records - * @param into byte array to copy bytes into - * @return number of bytes copied into the {@code into} byte[], - * that is insertPosition * recordSize - */ - private int readRecordsWithInsertRecordInPosition( PageCursor cursor, Consumer newRecordWriter, - int insertPosition, int totalNumberOfRecords, int recordSize, int baseRecordOffset, byte[] into ) - { - int length = (totalNumberOfRecords) * recordSize; - - // First read all records - - // Read all records on previous to insertPosition - cursor.setOffset( baseRecordOffset ); - cursor.getBytes( into, 0, insertPosition * recordSize ); - - // Read newRecord - PageCursor buffer = ByteArrayPageCursor.wrap( into, insertPosition * recordSize, recordSize ); - newRecordWriter.accept( buffer ); - - // Read all records following insertPosition - cursor.setOffset( baseRecordOffset + insertPosition * recordSize ); - cursor.getBytes( into, (insertPosition + 1) * recordSize, - ((totalNumberOfRecords - 1) - insertPosition) * recordSize ); - return length; - } - - private void writeAll( PageCursor cursor, byte[] source, int sourcePos, int targetPos, int count, - int baseOffset, int recordSize ) - { - int arrayOffset = sourcePos * recordSize; - cursor.setOffset( baseOffset + recordSize * targetPos ); - cursor.putBytes( source, arrayOffset, count * recordSize ); - } - - void writeKeys( PageCursor cursor, byte[] source, int sourcePos, int targetPos, int count ) - { - writeAll( cursor, source, sourcePos, targetPos, count, keyOffset( 0 ), keySize() ); - } - - void writeValues( PageCursor cursor, byte[] source, int sourcePos, int targetPos, int count ) - { - writeAll( cursor, source, sourcePos, targetPos, count, valueOffset( 0 ), valueSize() ); - } - - void writeChildren( PageCursor cursor, byte[] source, int sourcePos, int targetPos, int count ) - { - writeAll( cursor, source, sourcePos, targetPos, count, childOffset( 0 ), childSize() ); - } - @Override public String toString() { diff --git a/community/index/src/main/java/org/neo4j/index/gbptree/ByteArrayPageCursor.java b/community/index/src/test/java/org/neo4j/index/gbptree/ByteArrayPageCursor.java similarity index 96% rename from community/index/src/main/java/org/neo4j/index/gbptree/ByteArrayPageCursor.java rename to community/index/src/test/java/org/neo4j/index/gbptree/ByteArrayPageCursor.java index 198f351324997..4680e9005fc8f 100644 --- a/community/index/src/main/java/org/neo4j/index/gbptree/ByteArrayPageCursor.java +++ b/community/index/src/test/java/org/neo4j/index/gbptree/ByteArrayPageCursor.java @@ -28,10 +28,6 @@ import org.neo4j.io.pagecache.PageCursor; /** - * TODO: Adding another implementation of PageCursor (this implementation) - * TODO: will mean Neo as a whole have three implementations in total. - * TODO: This results in a slower method dispatch for ALL PageCursors. Is it worth it? - *

* Wraps a byte array and present it as a PageCursor. *

* This class is bridging something which would otherwise make {@link InternalTreeLogic} code slightly more diff --git a/community/index/src/test/java/org/neo4j/index/gbptree/TreeNodeTest.java b/community/index/src/test/java/org/neo4j/index/gbptree/TreeNodeTest.java index d8570f1adae80..45d084cd58c5c 100644 --- a/community/index/src/test/java/org/neo4j/index/gbptree/TreeNodeTest.java +++ b/community/index/src/test/java/org/neo4j/index/gbptree/TreeNodeTest.java @@ -376,8 +376,8 @@ public void shouldReadAndInsertKeys() throws Exception node.insertKeyAt( cursor, key, 1, 1 ); // WHEN - node.readKeysWithInsertRecordInPosition( cursor, c -> c.putLong( 2 ), 1, 3, tmp ); - node.writeKeys( cursor, tmp, 0, 0, 3 ); + key.setValue( 2 ); + node.insertKeyAt( cursor, key, 1, 2 ); // THEN assertEquals( 1, node.keyAt( cursor, key, 0 ).longValue() ); @@ -397,8 +397,8 @@ public void shouldReadAndInsertValues() throws Exception node.insertValueAt( cursor, value, 1, 1 ); // WHEN - node.readValuesWithInsertRecordInPosition( cursor, c -> c.putLong( 2 ), 1, 3, tmp ); - node.writeValues( cursor, tmp, 0, 0, 3 ); + value.setValue( 2 ); + node.insertValueAt( cursor, value, 1, 2 ); // THEN assertEquals( 1, node.valueAt( cursor, value, 0 ).longValue() ); @@ -418,9 +418,7 @@ public void shouldReadAndInsertChildren() throws Exception node.insertChildAt( cursor, thirdChild, 1, 1, STABLE_GENERATION, UNSTABLE_GENERATION ); // WHEN - node.readChildrenWithInsertRecordInPosition( cursor, - c -> node.writeChild( c, secondChild, STABLE_GENERATION, UNSTABLE_GENERATION ), 1, 3, tmp ); - node.writeChildren( cursor, tmp, 0, 0, 3 ); + node.insertChildAt( cursor, secondChild, 1, 2, STABLE_GENERATION, UNSTABLE_GENERATION ); // THEN assertEquals( firstChild, childAt( cursor, 0, STABLE_GENERATION, UNSTABLE_GENERATION ) );