mirror of https://github.com/apache/cassandra
Avoid megamorphic calls for Cell.timestamp/ttl/path/localDeletionTimeAsUnsignedInt methods
minDeletionTime is also added to Cell to avoid double invocation of localDeletionTime method patch by Dmitry Konstantinov; reviewed by Francisco Guerrero for CASSANDRA-21526
This commit is contained in:
parent
6a5bb352af
commit
725c61c1f7
|
|
@ -1,4 +1,5 @@
|
||||||
6.0-alpha2
|
6.0-alpha2
|
||||||
|
* Avoid megamorphic calls for Cell.timestamp/ttl/path/localDeletionTimeAsUnsignedInt methods (CASSANDRA-21526)
|
||||||
* Allow unreserved keywords as user and identity names in USER and IDENTITY statements (CASSANDRA-21510)
|
* Allow unreserved keywords as user and identity names in USER and IDENTITY statements (CASSANDRA-21510)
|
||||||
* Reduce allocations in DefaultQueryOptions (CASSANDRA-21467)
|
* Reduce allocations in DefaultQueryOptions (CASSANDRA-21467)
|
||||||
* Coordinator load-shedding returns OverloadedException without setting streamId, misrouting query responses (CASSANDRA-21508)
|
* Coordinator load-shedding returns OverloadedException without setting streamId, misrouting query responses (CASSANDRA-21508)
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,18 @@ public abstract class AbstractCell<V> extends Cell<V>
|
||||||
|
|
||||||
public boolean isTombstone()
|
public boolean isTombstone()
|
||||||
{
|
{
|
||||||
return localDeletionTime() != NO_DELETION_TIME && ttl() == NO_TTL;
|
return isTombstone(localDeletionTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public long minDeletionTime()
|
||||||
|
{
|
||||||
|
long localDeletionTime = localDeletionTime();
|
||||||
|
return isTombstone(localDeletionTime) ? Long.MIN_VALUE : localDeletionTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isTombstone(long localDeletionTime)
|
||||||
|
{
|
||||||
|
return localDeletionTime != NO_DELETION_TIME && ttl() == NO_TTL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExpiring()
|
public boolean isExpiring()
|
||||||
|
|
|
||||||
|
|
@ -31,17 +31,12 @@ import org.apache.cassandra.utils.memory.ByteBufferCloner;
|
||||||
|
|
||||||
import static org.apache.cassandra.utils.ByteArrayUtil.EMPTY_BYTE_ARRAY;
|
import static org.apache.cassandra.utils.ByteArrayUtil.EMPTY_BYTE_ARRAY;
|
||||||
|
|
||||||
public class ArrayCell extends AbstractCell<byte[]>
|
public class ArrayCell extends HeapAbstractCell<byte[]>
|
||||||
{
|
{
|
||||||
private static final long EMPTY_SIZE = ObjectSizes.measure(new ArrayCell(ColumnMetadata.regularColumn("", "", "", ByteType.instance, ColumnMetadata.NO_UNIQUE_ID), 0L, 0, 0, EMPTY_BYTE_ARRAY, null));
|
private static final long EMPTY_SIZE = ObjectSizes.measure(new ArrayCell(ColumnMetadata.regularColumn("", "", "", ByteType.instance, ColumnMetadata.NO_UNIQUE_ID), 0L, 0, 0, EMPTY_BYTE_ARRAY, null));
|
||||||
|
|
||||||
// Careful: Adding vars here has an impact on memtable size
|
// Careful: Adding vars here has an impact on memtable size
|
||||||
private final long timestamp;
|
|
||||||
private final int ttl;
|
|
||||||
private final int localDeletionTimeUnsignedInteger;
|
|
||||||
|
|
||||||
private final byte[] value;
|
private final byte[] value;
|
||||||
private final CellPath path;
|
|
||||||
|
|
||||||
// Please keep both int/long overloaded ctros public. Otherwise silent casts will mess timestamps when one is not
|
// Please keep both int/long overloaded ctros public. Otherwise silent casts will mess timestamps when one is not
|
||||||
// available.
|
// available.
|
||||||
|
|
@ -52,12 +47,8 @@ public class ArrayCell extends AbstractCell<byte[]>
|
||||||
|
|
||||||
public ArrayCell(ColumnMetadata column, long timestamp, int ttl, int localDeletionTimeUnsignedInteger, byte[] value, CellPath path)
|
public ArrayCell(ColumnMetadata column, long timestamp, int ttl, int localDeletionTimeUnsignedInteger, byte[] value, CellPath path)
|
||||||
{
|
{
|
||||||
super(column);
|
super(column, timestamp, ttl, localDeletionTimeUnsignedInteger, path);
|
||||||
this.timestamp = timestamp;
|
|
||||||
this.ttl = ttl;
|
|
||||||
this.localDeletionTimeUnsignedInteger = localDeletionTimeUnsignedInteger;
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.path = path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayCell live(ColumnMetadata column, long timestamp, byte[] value, CellPath path)
|
public static ArrayCell live(ColumnMetadata column, long timestamp, byte[] value, CellPath path)
|
||||||
|
|
@ -71,16 +62,6 @@ public class ArrayCell extends AbstractCell<byte[]>
|
||||||
return new ArrayCell(column, timestamp, ttl, ExpirationDateOverflowHandling.computeLocalExpirationTime(nowInSec, ttl), value, path);
|
return new ArrayCell(column, timestamp, ttl, ExpirationDateOverflowHandling.computeLocalExpirationTime(nowInSec, ttl), value, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long timestamp()
|
|
||||||
{
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ttl()
|
|
||||||
{
|
|
||||||
return ttl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] value()
|
public byte[] value()
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
|
|
@ -91,10 +72,6 @@ public class ArrayCell extends AbstractCell<byte[]>
|
||||||
return ByteArrayAccessor.instance;
|
return ByteArrayAccessor.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CellPath path()
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cell<?> withUpdatedColumn(ColumnMetadata newColumn)
|
public Cell<?> withUpdatedColumn(ColumnMetadata newColumn)
|
||||||
{
|
{
|
||||||
|
|
@ -144,9 +121,4 @@ public class ArrayCell extends AbstractCell<byte[]>
|
||||||
return EMPTY_SIZE + ObjectSizes.sizeOfArray(value) - value.length + (path == null ? 0 : path.unsharedHeapSizeExcludingData());
|
return EMPTY_SIZE + ObjectSizes.sizeOfArray(value) - value.length + (path == null ? 0 : path.unsharedHeapSizeExcludingData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int localDeletionTimeAsUnsignedInt()
|
|
||||||
{
|
|
||||||
return localDeletionTimeUnsignedInteger;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,7 @@ public class BTreeRow extends AbstractRow
|
||||||
|
|
||||||
private static long minDeletionTime(Cell<?> cell)
|
private static long minDeletionTime(Cell<?> cell)
|
||||||
{
|
{
|
||||||
return cell.isTombstone() ? Long.MIN_VALUE : cell.localDeletionTime();
|
return cell.minDeletionTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long minDeletionTime(LivenessInfo info)
|
private static long minDeletionTime(LivenessInfo info)
|
||||||
|
|
|
||||||
|
|
@ -30,17 +30,12 @@ import org.apache.cassandra.utils.memory.ByteBufferCloner;
|
||||||
|
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
|
|
||||||
public class BufferCell extends AbstractCell<ByteBuffer>
|
public class BufferCell extends HeapAbstractCell<ByteBuffer>
|
||||||
{
|
{
|
||||||
private static final long EMPTY_SIZE = ObjectSizes.measure(new BufferCell(ColumnMetadata.regularColumn("", "", "", ByteType.instance, ColumnMetadata.NO_UNIQUE_ID), 0L, 0, 0, ByteBufferUtil.EMPTY_BYTE_BUFFER, null));
|
private static final long EMPTY_SIZE = ObjectSizes.measure(new BufferCell(ColumnMetadata.regularColumn("", "", "", ByteType.instance, ColumnMetadata.NO_UNIQUE_ID), 0L, 0, 0, ByteBufferUtil.EMPTY_BYTE_BUFFER, null));
|
||||||
|
|
||||||
// Careful: Adding vars here has an impact on memtable size
|
// Careful: Adding vars here has an impact on memtable size
|
||||||
private final long timestamp;
|
|
||||||
private final int ttl;
|
|
||||||
private final int localDeletionTimeUnsignedInteger;
|
|
||||||
|
|
||||||
private final ByteBuffer value;
|
private final ByteBuffer value;
|
||||||
private final CellPath path;
|
|
||||||
|
|
||||||
// Please keep both int/long overloaded ctros public. Otherwise silent casts will mess timestamps when one is not
|
// Please keep both int/long overloaded ctros public. Otherwise silent casts will mess timestamps when one is not
|
||||||
// available.
|
// available.
|
||||||
|
|
@ -51,14 +46,10 @@ public class BufferCell extends AbstractCell<ByteBuffer>
|
||||||
|
|
||||||
public BufferCell(ColumnMetadata column, long timestamp, int ttl, int localDeletionTimeUnsignedInteger, ByteBuffer value, CellPath path)
|
public BufferCell(ColumnMetadata column, long timestamp, int ttl, int localDeletionTimeUnsignedInteger, ByteBuffer value, CellPath path)
|
||||||
{
|
{
|
||||||
super(column);
|
super(column, timestamp, ttl, localDeletionTimeUnsignedInteger, path);
|
||||||
assert !column.isPrimaryKeyColumn();
|
assert !column.isPrimaryKeyColumn();
|
||||||
assert column.isComplex() == (path != null) : format("Column %s.%s(%s: %s) isComplex: %b with cellpath: %s", column.ksName, column.cfName, column.name, column.type.toString(), column.isComplex(), path);
|
assert column.isComplex() == (path != null) : format("Column %s.%s(%s: %s) isComplex: %b with cellpath: %s", column.ksName, column.cfName, column.name, column.type.toString(), column.isComplex(), path);
|
||||||
this.timestamp = timestamp;
|
|
||||||
this.ttl = ttl;
|
|
||||||
this.localDeletionTimeUnsignedInteger = localDeletionTimeUnsignedInteger;
|
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.path = path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BufferCell live(ColumnMetadata column, long timestamp, ByteBuffer value)
|
public static BufferCell live(ColumnMetadata column, long timestamp, ByteBuffer value)
|
||||||
|
|
@ -92,16 +83,6 @@ public class BufferCell extends AbstractCell<ByteBuffer>
|
||||||
return new BufferCell(column, timestamp, NO_TTL, nowInSec, ByteBufferUtil.EMPTY_BYTE_BUFFER, path);
|
return new BufferCell(column, timestamp, NO_TTL, nowInSec, ByteBufferUtil.EMPTY_BYTE_BUFFER, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long timestamp()
|
|
||||||
{
|
|
||||||
return timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int ttl()
|
|
||||||
{
|
|
||||||
return ttl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ByteBuffer value()
|
public ByteBuffer value()
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
|
|
@ -112,10 +93,6 @@ public class BufferCell extends AbstractCell<ByteBuffer>
|
||||||
return ByteBufferAccessor.instance;
|
return ByteBufferAccessor.instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CellPath path()
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cell<?> withUpdatedColumn(ColumnMetadata newColumn)
|
public Cell<?> withUpdatedColumn(ColumnMetadata newColumn)
|
||||||
{
|
{
|
||||||
|
|
@ -163,10 +140,4 @@ public class BufferCell extends AbstractCell<ByteBuffer>
|
||||||
{
|
{
|
||||||
return EMPTY_SIZE + ObjectSizes.sizeOnHeapExcludingDataOf(value) + (path == null ? 0 : path.unsharedHeapSizeExcludingData());
|
return EMPTY_SIZE + ObjectSizes.sizeOnHeapExcludingDataOf(value) + (path == null ? 0 : path.unsharedHeapSizeExcludingData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int localDeletionTimeAsUnsignedInt()
|
|
||||||
{
|
|
||||||
return localDeletionTimeUnsignedInteger;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,8 @@ public abstract class Cell<V> extends ColumnData
|
||||||
return deletionTimeUnsignedIntegerToLong(localDeletionTimeAsUnsignedInt());
|
return deletionTimeUnsignedIntegerToLong(localDeletionTimeAsUnsignedInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract long minDeletionTime();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the cell is a tombstone or not.
|
* Whether the cell is a tombstone or not.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.cassandra.db.rows;
|
||||||
|
|
||||||
|
import org.apache.cassandra.schema.ColumnMetadata;
|
||||||
|
|
||||||
|
public abstract class HeapAbstractCell<V> extends AbstractCell<V>
|
||||||
|
{
|
||||||
|
// Careful: Adding vars here has an impact on memtable size
|
||||||
|
protected final long timestamp;
|
||||||
|
protected final int ttl;
|
||||||
|
protected final int localDeletionTimeUnsignedInteger;
|
||||||
|
|
||||||
|
protected final CellPath path;
|
||||||
|
|
||||||
|
protected HeapAbstractCell(ColumnMetadata column, long timestamp, int ttl, int localDeletionTimeUnsignedInteger, CellPath path)
|
||||||
|
{
|
||||||
|
super(column);
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.ttl = ttl;
|
||||||
|
this.localDeletionTimeUnsignedInteger = localDeletionTimeUnsignedInteger;
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long timestamp()
|
||||||
|
{
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int ttl()
|
||||||
|
{
|
||||||
|
return ttl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int localDeletionTimeAsUnsignedInt()
|
||||||
|
{
|
||||||
|
return localDeletionTimeUnsignedInteger;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CellPath path()
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -103,6 +103,12 @@ public class CellWithSource<T> extends Cell<T>
|
||||||
return cell.localDeletionTime();
|
return cell.localDeletionTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long minDeletionTime()
|
||||||
|
{
|
||||||
|
return cell.minDeletionTime();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTombstone()
|
public boolean isTombstone()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue