Package me.ahoo.cosid.sharding
Class CachedSharding<T extends Comparable<? super T>>
java.lang.Object
me.ahoo.cosid.sharding.CachedSharding<T>
- Type Parameters:
T- the type of comparable sharding value
- All Implemented Interfaces:
PreciseSharding<T>,RangeSharding<T>,Sharding<T>
Caching wrapper for sharding algorithms.
Caches range sharding results to reduce computation overhead
for frequently accessed ranges. The cache is bounded: once it holds maximumSize ranges it is emptied
before the next one is added, which keeps lookups lock-free (4.x used a Guava LRU cache).
A collection the range sharding returns is the cached one, shared by every later call for the same range: treat it as unmodifiable (R1-sharding-02). Changing it changes what the next calls return; a later version may return an unmodifiable view.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longThe most ranges kept by default: query ranges come from user input, so the cache must not grow without bound. -
Constructor Summary
ConstructorsConstructorDescriptionCachedSharding(Sharding<T> actual) Creates a cached wrapper around the specified sharding algorithm.CachedSharding(Sharding<T> actual, long maximumSize) Creates a cached wrapper around the specified sharding algorithm, keeping at mostmaximumSizeranges. -
Method Summary
Modifier and TypeMethodDescriptionGets all effective node names.sharding(ShardingRange<T> shardingValue) The nodes of a range, cached.Gets the node for a single sharding value.
-
Field Details
-
DEFAULT_MAXIMUM_SIZE
public static final long DEFAULT_MAXIMUM_SIZEThe most ranges kept by default: query ranges come from user input, so the cache must not grow without bound.- See Also:
-
-
Constructor Details
-
CachedSharding
Creates a cached wrapper around the specified sharding algorithm.- Parameters:
actual- the underlying sharding algorithm
-
CachedSharding
Creates a cached wrapper around the specified sharding algorithm, keeping at mostmaximumSizeranges.- Parameters:
actual- the underlying sharding algorithmmaximumSize- the most ranges kept in the cache
-
-
Method Details
-
sharding
Description copied from interface:PreciseShardingGets the node for a single sharding value.- Specified by:
shardingin interfacePreciseSharding<T extends Comparable<? super T>>- Parameters:
shardingValue- the sharding value- Returns:
- the node name
-
sharding
The nodes of a range, cached.- Specified by:
shardingin interfaceRangeSharding<T extends Comparable<? super T>>- Parameters:
shardingValue- the range- Returns:
- the nodes; shared with every call for the same range, so never to be modified
-
getEffectiveNodes
Description copied from interface:ShardingGets all effective node names.- Specified by:
getEffectiveNodesin interfaceSharding<T extends Comparable<? super T>>- Returns:
- collection of effective node names
-