mirror of https://github.com/apache/cassandra
Fix pre-3.0 counter mutation serialization
patch by pauloricardomg; reviewed by slebresne for CASSANDRA-10470
This commit is contained in:
parent
10ef01d1ca
commit
df7c6581be
|
|
@ -1,4 +1,5 @@
|
|||
3.0
|
||||
* Fix backward compatibility for counters (CASSANDRA-10470)
|
||||
* Remove memory_allocator paramter from cassandra.yaml (CASSANDRA-10581)
|
||||
* Execute the metadata reload task of all registered indexes on CFS::reload (CASSANDRA-10604)
|
||||
* Fix thrift cas operations with defined columns (CASSANDRA-10576)
|
||||
|
|
|
|||
|
|
@ -367,29 +367,29 @@ public abstract class LegacyLayout
|
|||
for (LegacyLayout.LegacyCell cell : legacyPartition.cells)
|
||||
{
|
||||
ByteBufferUtil.writeWithShortLength(cell.name.encode(partition.metadata()), out);
|
||||
if (cell.kind == LegacyLayout.LegacyCell.Kind.EXPIRING)
|
||||
out.writeByte(cell.serializationFlags());
|
||||
if (cell.isExpiring())
|
||||
{
|
||||
out.writeByte(LegacyLayout.EXPIRATION_MASK); // serialization flags
|
||||
out.writeInt(cell.ttl);
|
||||
out.writeInt(cell.localDeletionTime);
|
||||
}
|
||||
else if (cell.kind == LegacyLayout.LegacyCell.Kind.DELETED)
|
||||
else if (cell.isTombstone())
|
||||
{
|
||||
out.writeByte(LegacyLayout.DELETION_MASK); // serialization flags
|
||||
out.writeLong(cell.timestamp);
|
||||
out.writeInt(TypeSizes.sizeof(cell.localDeletionTime));
|
||||
out.writeInt(cell.localDeletionTime);
|
||||
continue;
|
||||
}
|
||||
else if (cell.kind == LegacyLayout.LegacyCell.Kind.COUNTER)
|
||||
else if (cell.isCounterUpdate())
|
||||
{
|
||||
out.writeByte(LegacyLayout.COUNTER_MASK); // serialization flags
|
||||
out.writeLong(Long.MIN_VALUE); // timestampOfLastDelete (not used, and MIN_VALUE is the default)
|
||||
out.writeLong(cell.timestamp);
|
||||
long count = CounterContext.instance().getLocalCount(cell.value);
|
||||
ByteBufferUtil.writeWithLength(ByteBufferUtil.bytes(count), out);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
else if (cell.isCounter())
|
||||
{
|
||||
// normal cell
|
||||
out.writeByte(0); // serialization flags
|
||||
out.writeLong(Long.MIN_VALUE); // timestampOfLastDelete (not used, and MIN_VALUE is the default)
|
||||
}
|
||||
|
||||
out.writeLong(cell.timestamp);
|
||||
|
|
@ -1401,11 +1401,19 @@ public abstract class LegacyLayout
|
|||
return EXPIRATION_MASK;
|
||||
if (isTombstone())
|
||||
return DELETION_MASK;
|
||||
if (isCounterUpdate())
|
||||
return COUNTER_UPDATE_MASK;
|
||||
if (isCounter())
|
||||
return COUNTER_MASK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean isCounterUpdate()
|
||||
{
|
||||
// See UpdateParameters.addCounter() for more details on this
|
||||
return isCounter() && CounterContext.instance().isLocal(value);
|
||||
}
|
||||
|
||||
public ClusteringPrefix clustering()
|
||||
{
|
||||
return name.clustering;
|
||||
|
|
|
|||
|
|
@ -673,6 +673,22 @@ public class CounterContext
|
|||
return getClockAndCountOf(context, CounterId.getLocalId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the count associated with the local counter id, or 0 if no such shard is present.
|
||||
*/
|
||||
public long getLocalCount(ByteBuffer context)
|
||||
{
|
||||
return getLocalClockAndCount(context).count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a context is local
|
||||
*/
|
||||
public boolean isLocal(ByteBuffer context)
|
||||
{
|
||||
return ContextState.wrap(context).isLocal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the clock and the count associated with the given counter id, or (0, 0) if no such shard is present.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue