|
||||||||||
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 (node 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 -- (node 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 nodeid_1 nodeid_2 The rules when merging two shard with the same nodeid are: - delta + delta = sum counts (and logical clock) - delta + other = keep the delta one - other + other = keep the shard with highest logical clock
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<NodeId.NodeIdRecord> oldIds)
Compute a new context such that if applied to context yields the same total but with the older local node id merged into the second to older one (excluding current local node id) if need be. |
java.nio.ByteBuffer |
create(long value,
Allocator allocator)
Creates an initial counter context with an initial value for the local node. |
java.nio.ByteBuffer |
create(NodeId id,
long clock,
long value,
boolean isDelta)
|
IContext.ContextRelationship |
diff(java.nio.ByteBuffer left,
java.nio.ByteBuffer right)
Determine the count relationship between two contexts. |
boolean |
hasNodeId(java.nio.ByteBuffer context,
NodeId id)
Checks whether the provided context has a count for the provided NodeId. |
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 node 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 node 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(NodeId id, long clock, long value, boolean isDelta)
public IContext.ContextRelationship diff(java.nio.ByteBuffer left, java.nio.ByteBuffer right)
diff
in interface IContext
left
- counter context.right
- counter context.
public java.nio.ByteBuffer merge(java.nio.ByteBuffer left, java.nio.ByteBuffer right, Allocator allocator)
merge
in interface IContext
left
- counter context.right
- counter context.allocator
- An allocator for the merged value.public java.lang.String toString(java.nio.ByteBuffer context)
toString
in interface IContext
context
- counter context.
public long total(java.nio.ByteBuffer context)
context
- a counter context
context
public 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 hasNodeId(java.nio.ByteBuffer context, NodeId id)
public java.nio.ByteBuffer computeOldShardMerger(java.nio.ByteBuffer context, java.util.List<NodeId.NodeIdRecord> oldIds)
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 |