Package me.ahoo.cosid.sharding
Class IntervalTimeline
java.lang.Object
me.ahoo.cosid.sharding.IntervalTimeline
- All Implemented Interfaces:
PreciseSharding<LocalDateTime>,RangeSharding<LocalDateTime>,Sharding<LocalDateTime>
Timeline-based interval sharding algorithm.
Distributes IDs across time-based intervals, where each interval maps to a specific node. The intervals are calculated based on a configured step size (e.g., daily, monthly).

-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a time interval with an associated node name. -
Constructor Summary
ConstructorsConstructorDescriptionIntervalTimeline(String logicNamePrefix, com.google.common.collect.Range<LocalDateTime> effectiveInterval, IntervalStep step, DateTimeFormatter suffixFormatter) Creates an IntervalTimeline sharding algorithm. -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(LocalDateTime time) Checks if the given time is within the effective interval.@NonNull Collection<String>Gets all effective node names.Gets the start interval.@NonNull Collection<String>sharding(com.google.common.collect.Range<LocalDateTime> shardingValue) Gets the nodes that should handle the given range of IDs.@NonNull Stringsharding(LocalDateTime shardingValue) Gets the node for a single sharding value.intsize()Gets the number of intervals.
-
Constructor Details
-
IntervalTimeline
public IntervalTimeline(String logicNamePrefix, com.google.common.collect.Range<LocalDateTime> effectiveInterval, IntervalStep step, DateTimeFormatter suffixFormatter) Creates an IntervalTimeline sharding algorithm.- Parameters:
logicNamePrefix- the prefix for node nameseffectiveInterval- the effective time rangestep- the interval step configurationsuffixFormatter- formatter for interval suffixes
-
-
Method Details
-
size
public int size()Gets the number of intervals.- Returns:
- the number of intervals
-
contains
Checks if the given time is within the effective interval.- Parameters:
time- the time to check- Returns:
- true if within effective interval
-
getStartInterval
Gets the start interval.- Returns:
- the start interval
-
getEffectiveNodes
Description copied from interface:ShardingGets all effective node names.- Specified by:
getEffectiveNodesin interfaceSharding<LocalDateTime>- Returns:
- collection of effective node names
-
sharding
Description copied from interface:PreciseShardingGets the node for a single sharding value.- Specified by:
shardingin interfacePreciseSharding<LocalDateTime>- Parameters:
shardingValue- the sharding value- Returns:
- the node name
-
sharding
public @NonNull Collection<String> sharding(com.google.common.collect.Range<LocalDateTime> shardingValue) Description copied from interface:RangeShardingGets the nodes that should handle the given range of IDs.- Specified by:
shardingin interfaceRangeSharding<LocalDateTime>- Parameters:
shardingValue- the range of sharding values- Returns:
- collection of node names that should handle the range
-