Class IntervalTimeline

java.lang.Object
me.ahoo.cosid.sharding.IntervalTimeline
All Implemented Interfaces:
PreciseSharding<LocalDateTime>, RangeSharding<LocalDateTime>, Sharding<LocalDateTime>

@ThreadSafe public class IntervalTimeline extends Object implements 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).

CosIdIntervalShardingAlgorithm

  • 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 names
      effectiveInterval - the effective time range
      step - the interval step configuration
      suffixFormatter - formatter for interval suffixes
  • Method Details

    • size

      public int size()
      Gets the number of intervals.
      Returns:
      the number of intervals
    • contains

      public boolean contains(LocalDateTime time)
      Checks if the given time is within the effective interval.
      Parameters:
      time - the time to check
      Returns:
      true if within effective interval
    • getStartInterval

      public IntervalTimeline.Interval getStartInterval()
      Gets the start interval.
      Returns:
      the start interval
    • getEffectiveNodes

      public @NonNull Collection<String> getEffectiveNodes()
      Description copied from interface: Sharding
      Gets all effective node names.
      Specified by:
      getEffectiveNodes in interface Sharding<LocalDateTime>
      Returns:
      collection of effective node names
    • sharding

      public @NonNull String sharding(LocalDateTime shardingValue)
      Description copied from interface: PreciseSharding
      Gets the node for a single sharding value.
      Specified by:
      sharding in interface PreciseSharding<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: RangeSharding
      Gets the nodes that should handle the given range of IDs.
      Specified by:
      sharding in interface RangeSharding<LocalDateTime>
      Parameters:
      shardingValue - the range of sharding values
      Returns:
      collection of node names that should handle the range