mirror of https://github.com/apache/cassandra
Avoid memory allocation in NativeCell.valueSize() and NativeClustering.dataSize()
patch by Dmitry Konstantinov; reviewed by Branimir Lambov, Mick Semb Wever for CASSANDRA-20162
This commit is contained in:
parent
ea79f7b13f
commit
4ae1aee39b
|
|
@ -1,4 +1,5 @@
|
|||
5.0.3
|
||||
* Avoid memory allocation in offheap_object's NativeCell.valueSize() and NativeClustering.dataSize() (CASSANDRA-20162)
|
||||
* Add flag to avoid invalidating key cache on sstable deletions (CASSANDRA-20068)
|
||||
* Interpret inet, bigint, varint, and decimal as non-reversed types for query construction and post-filtering (CASSANDRA-20100)
|
||||
* Fix delayed gossip shutdown messages clobbering startup states that leave restarted nodes appearing down (CASSANDRA-20033)
|
||||
|
|
|
|||
|
|
@ -93,6 +93,12 @@ public class NativeClustering implements Clustering<ByteBuffer>
|
|||
return MemoryUtil.getShort(peer);
|
||||
}
|
||||
|
||||
public int dataSize()
|
||||
{
|
||||
int dataSizeOffset = (size() * 2) + 2; // metadataSize - 2
|
||||
return MemoryUtil.getShort(peer + dataSizeOffset);
|
||||
}
|
||||
|
||||
public ByteBuffer get(int i)
|
||||
{
|
||||
// offset at which we store the dataOffset
|
||||
|
|
|
|||
|
|
@ -145,6 +145,11 @@ public class NativeCell extends AbstractCell<ByteBuffer>
|
|||
return ByteBufferAccessor.instance; // FIXME: add native accessor
|
||||
}
|
||||
|
||||
public int valueSize()
|
||||
{
|
||||
return MemoryUtil.getInt(peer + LENGTH);
|
||||
}
|
||||
|
||||
public CellPath path()
|
||||
{
|
||||
if (!hasPath())
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.cassandra.db;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
|
@ -163,9 +164,29 @@ public class NativeCellTest extends CQLTester
|
|||
Assert.assertEquals(row.clustering(), brow.clustering());
|
||||
Assert.assertEquals(nrow.clustering(), brow.clustering());
|
||||
|
||||
Assert.assertEquals(row.clustering().dataSize(), nrow.clustering().dataSize());
|
||||
Assert.assertEquals(row.clustering().dataSize(), brow.clustering().dataSize());
|
||||
|
||||
ClusteringComparator comparator = new ClusteringComparator(UTF8Type.instance);
|
||||
Assert.assertEquals(0, comparator.compare(row.clustering(), nrow.clustering()));
|
||||
Assert.assertEquals(0, comparator.compare(row.clustering(), brow.clustering()));
|
||||
Assert.assertEquals(0, comparator.compare(nrow.clustering(), brow.clustering()));
|
||||
|
||||
assertCellsDataSize(row, nrow);
|
||||
assertCellsDataSize(row, brow);
|
||||
|
||||
}
|
||||
|
||||
private static void assertCellsDataSize(Row row1, Row row2)
|
||||
{
|
||||
Iterator<Cell<?>> row1Iterator = row1.cells().iterator();
|
||||
Iterator<Cell<?>> row2Iterator = row2.cells().iterator();
|
||||
while (row1Iterator.hasNext())
|
||||
{
|
||||
Cell cell1 = row1Iterator.next();
|
||||
Cell cell2 = row2Iterator.next();
|
||||
Assert.assertEquals(cell1.dataSize(), cell2.dataSize());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue