|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.cassandra.db.context.CounterContext
public class CounterContext
An implementation of a partitioned counter context. A context is primarily a list of tuples (counter id, clock, count) -- called shard in the following. But with some shard are flagged as delta (with special resolution rules in merge()). The data structure has two parts: a) a header containing the lists of "delta" (a list of references to the second parts) b) a list of shard -- (counter id, logical clock, count) tuples -- (the so-called 'body' below) The exact layout is: | header | body | context : |--|------|----------| ^ ^ | list of indices in the body list (2*#elt bytes) #elt in rest of header (2 bytes) The body layout being: body: |----|----|----|----|----|----|.... ^ ^ ^ ^ ^ ^ | | count_1 | | count_2 | clock_1 | clock_2 counterid_1 counterid_2 The rules when merging two shard with the same counterid are: - delta + delta = sum counts (and logical clock) - delta + other = keep the delta one - other + other = keep the shard with highest logical clock For a detailed description of the meaning of a delta and why the merging rules work this way, see CASSANDRA-1938 - specifically the 1938_discussion attachment.
| Nested Class Summary | |
|---|---|
static class |
CounterContext.ContextState
Helper class to work on contexts (works by iterating over them). |
| Nested classes/interfaces inherited from interface org.apache.cassandra.db.context.IContext |
|---|
IContext.ContextRelationship |
| Constructor Summary | |
|---|---|
CounterContext()
|
|
| Method Summary | |
|---|---|
java.nio.ByteBuffer |
clearAllDelta(java.nio.ByteBuffer context)
Remove all the delta of a context (i.e, set an empty header). |
java.nio.ByteBuffer |
computeOldShardMerger(java.nio.ByteBuffer context,
java.util.List<CounterId.CounterIdRecord> oldIds,
long mergeBefore)
Compute a new context such that if applied to context yields the same total but with old local counter ids nulified and there content merged to the current localCounterId. |
java.nio.ByteBuffer |
create(CounterId id,
long clock,
long value,
boolean isDelta)
|
java.nio.ByteBuffer |
create(long value,
Allocator allocator)
Creates an initial counter context with an initial value for the local node. |
IContext.ContextRelationship |
diff(java.nio.ByteBuffer left,
java.nio.ByteBuffer right)
Determine the count relationship between two contexts. |
boolean |
hasCounterId(java.nio.ByteBuffer context,
CounterId id)
Checks whether the provided context has a count for the provided CounterId. |
static CounterContext |
instance()
|
java.nio.ByteBuffer |
markDeltaToBeCleared(java.nio.ByteBuffer context)
Mark context to delete delta afterward. |
java.nio.ByteBuffer |
merge(java.nio.ByteBuffer left,
java.nio.ByteBuffer right,
Allocator allocator)
Return a context w/ an aggregated count for each counter id. |
java.nio.ByteBuffer |
removeOldShards(java.nio.ByteBuffer context,
int gcBefore)
Remove shards that have been canceled through computeOldShardMerger since a time older than gcBefore. |
java.lang.String |
toString(java.nio.ByteBuffer context)
Human-readable String from context. |
long |
total(java.nio.ByteBuffer context)
Returns the aggregated count across all counter ids. |
void |
updateDigest(java.security.MessageDigest message,
java.nio.ByteBuffer context)
Update a MessageDigest with the content of a context. |
void |
validateContext(java.nio.ByteBuffer context)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CounterContext()
| Method Detail |
|---|
public static CounterContext instance()
public java.nio.ByteBuffer create(long value,
Allocator allocator)
value - the value for this initial updateallocator -
public java.nio.ByteBuffer create(CounterId id,
long clock,
long value,
boolean isDelta)
public IContext.ContextRelationship diff(java.nio.ByteBuffer left,
java.nio.ByteBuffer right)
diff in interface IContextleft - counter context.right - counter context.
public java.nio.ByteBuffer merge(java.nio.ByteBuffer left,
java.nio.ByteBuffer right,
Allocator allocator)
merge in interface IContextleft - counter context.right - counter context.allocator - An allocator for the merged value.public java.lang.String toString(java.nio.ByteBuffer context)
toString in interface IContextcontext - counter context.
public long total(java.nio.ByteBuffer context)
context - a counter context
contextpublic java.nio.ByteBuffer markDeltaToBeCleared(java.nio.ByteBuffer context)
context - a counter context
public java.nio.ByteBuffer clearAllDelta(java.nio.ByteBuffer context)
context - a counter context
context where no count are a delta.
public void validateContext(java.nio.ByteBuffer context)
throws MarshalException
MarshalException
public void updateDigest(java.security.MessageDigest message,
java.nio.ByteBuffer context)
public boolean hasCounterId(java.nio.ByteBuffer context,
CounterId id)
public java.nio.ByteBuffer computeOldShardMerger(java.nio.ByteBuffer context,
java.util.List<CounterId.CounterIdRecord> oldIds,
long mergeBefore)
public java.nio.ByteBuffer removeOldShards(java.nio.ByteBuffer context,
int gcBefore)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||