Package org.apache.cassandra.db.tries
Class InMemoryTrie<T>
java.lang.Object
org.apache.cassandra.db.tries.Trie<T>
org.apache.cassandra.db.tries.InMemoryReadTrie<T>
org.apache.cassandra.db.tries.InMemoryTrie<T>
In-memory trie built for fast modification and reads executing concurrently with writes from a single mutator thread.
This class can currently only provide atomicity (i.e. reads seeing either the content before a write, or the
content after it; any read seeing the write enforcing any subsequent (i.e. started after it completed) reads to
also see it) for singleton writes (i.e. calls to
putRecursive(org.apache.cassandra.utils.bytecomparable.ByteComparable, R, org.apache.cassandra.db.tries.InMemoryTrie.UpsertTransformer<T, R>), putSingleton(org.apache.cassandra.utils.bytecomparable.ByteComparable, R, org.apache.cassandra.db.tries.InMemoryTrie.UpsertTransformer<T, ? super R>) or apply(org.apache.cassandra.db.tries.Trie<U>, org.apache.cassandra.db.tries.InMemoryTrie.UpsertTransformer<T, U>)
with a singleton trie as argument).
Because it uses 32-bit pointers in byte buffers, this trie has a fixed size limit of 2GB.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBecause we use buffers and 32-bit pointers, the trie cannot grow over 2GB of size.static interfaceSomewhat similar toTrie.MergeResolver, this encapsulates logic to be applied whenever new content is being upserted into aInMemoryTrie.Nested classes/interfaces inherited from class org.apache.cassandra.db.tries.Trie
Trie.CollectionMergeResolver<T>, Trie.Cursor<T>, Trie.MergeResolver<T>, Trie.ResettingTransitionsReceiver, Trie.TransitionsReceiver, Trie.ValueConsumer<T>, Trie.Walker<T,R> -
Field Summary
Fields inherited from class org.apache.cassandra.db.tries.Trie
BYTE_COMPARABLE_VERSION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<U> voidapply(Trie<U> mutation, InMemoryTrie.UpsertTransformer<T, U> transformer) Modify this trie to apply the mutation given in the form of a trie.void<R> voidputRecursive(ByteComparable key, R value, InMemoryTrie.UpsertTransformer<T, R> transformer) Map-like put method, using a fast recursive implementation through the key bytes.<R> voidputSingleton(ByteComparable key, R value, InMemoryTrie.UpsertTransformer<T, ? super R> transformer) Map-like put method, using the apply machinery above which cannot run into stack overflow.<R> voidputSingleton(ByteComparable key, R value, InMemoryTrie.UpsertTransformer<T, ? super R> transformer, boolean useRecursive) A version of putSingleton which uses recursive put if the last argument is true.booleanReturns true if the allocation threshold has been reached.longReturns the off heap size of the memtable trie itself, not counting any space taken by referenced content.longReturns the on heap size of the memtable trie itself, not counting any space taken by referenced content.longintReturns the values in any order.Methods inherited from class org.apache.cassandra.db.tries.InMemoryReadTrie
cursor, dump, followContentTransition, get, isEmptyMethods inherited from class org.apache.cassandra.db.tries.Trie
dump, empty, entryIterator, entrySet, forEachEntry, forEachValue, merge, mergeDistinct, mergeWith, process, singleton, subtrie, subtrie, throwingResolver, valueIterator, values
-
Constructor Details
-
InMemoryTrie
-
-
Method Details
-
discardBuffers
public void discardBuffers() -
apply
public <U> void apply(Trie<U> mutation, InMemoryTrie.UpsertTransformer<T, U> transformer) throws InMemoryTrie.SpaceExhaustedExceptionModify this trie to apply the mutation given in the form of a trie. Any content in the mutation will be resolved with the given function before being placed in this trie (even if there's no pre-existing content in this trie).- Parameters:
mutation- the mutation to be applied, given in the form of a trie. Note that its content can be of type different than the element type for this memtable trie.transformer- a function applied to the potentially pre-existing value for the given key, and the new value. Applied even if there's no pre-existing value in the memtable trie.- Throws:
InMemoryTrie.SpaceExhaustedException
-
putSingleton
public <R> void putSingleton(ByteComparable key, R value, InMemoryTrie.UpsertTransformer<T, ? super R> transformer) throws InMemoryTrie.SpaceExhaustedExceptionMap-like put method, using the apply machinery above which cannot run into stack overflow. When the correct position in the trie has been reached, the value will be resolved with the given function before being placed in the trie (even if there's no pre-existing content in this trie).- Parameters:
key- the trie path/key for the given value.value- the value being put in the memtable trie. Note that it can be of type different than the element type for this memtable trie. It's up to thetransformerto return the final value that will stay in the memtable trie.transformer- a function applied to the potentially pre-existing value for the given key, and the new value (of a potentially different type), returning the final value that will stay in the memtable trie. Applied even if there's no pre-existing value in the memtable trie.- Throws:
InMemoryTrie.SpaceExhaustedException
-
putSingleton
public <R> void putSingleton(ByteComparable key, R value, InMemoryTrie.UpsertTransformer<T, ? super R> transformer, boolean useRecursive) throws InMemoryTrie.SpaceExhaustedExceptionA version of putSingleton which uses recursive put if the last argument is true. -
putRecursive
public <R> void putRecursive(ByteComparable key, R value, InMemoryTrie.UpsertTransformer<T, R> transformer) throws InMemoryTrie.SpaceExhaustedExceptionMap-like put method, using a fast recursive implementation through the key bytes. May run into stack overflow if the trie becomes too deep. When the correct position in the trie has been reached, the value will be resolved with the given function before being placed in the trie (even if there's no pre-existing content in this trie).- Parameters:
key- the trie path/key for the given value.value- the value being put in the memtable trie. Note that it can be of type different than the element type for this memtable trie. It's up to thetransformerto return the final value that will stay in the memtable trie.transformer- a function applied to the potentially pre-existing value for the given key, and the new value (of a potentially different type), returning the final value that will stay in the memtable trie. Applied even if there's no pre-existing value in the memtable trie.- Throws:
InMemoryTrie.SpaceExhaustedException
-
reachedAllocatedSizeThreshold
public boolean reachedAllocatedSizeThreshold()Returns true if the allocation threshold has been reached. To be called by the the writing thread (ideally, just after the write completes). When this returns true, the user should switch to a new trie as soon as feasible. The trie expects up to 10% growth above this threshold. Any growth beyond that may be done inefficiently, and the trie will fail altogether when the size grows beyond 2G - 256 bytes. -
sizeOffHeap
public long sizeOffHeap()Returns the off heap size of the memtable trie itself, not counting any space taken by referenced content. -
sizeOnHeap
public long sizeOnHeap()Returns the on heap size of the memtable trie itself, not counting any space taken by referenced content. -
valuesUnordered
Description copied from class:TrieReturns the values in any order. For some tries this is much faster than the ordered iterable.- Overrides:
valuesUnorderedin classTrie<T>
-
valuesCount
public int valuesCount() -
unusedReservedMemory
public long unusedReservedMemory()
-