Class BatchPolicy

java.lang.Object
me.ahoo.cosid.segment.BatchPolicy

public final class BatchPolicy extends Object
How a SegmentGenerator reserves ranges (04-segment.md §2). A reservation is min(maxBatch, roundUpToStep(rate * lookahead)), at least step. Immutable; built with builder(), the only way to create one, so fields can be added with a default (api-freeze.md §4).
  • Field Details

    • DEFAULT_STEP

      public static final long DEFAULT_STEP
      See Also:
    • DEFAULT_INITIAL_OFFSET

      public static final long DEFAULT_INITIAL_OFFSET
      The default first value of a new key: 1, never 0.
      See Also:
    • DEFAULT_MAX_BATCH_VALUES

      public static final long DEFAULT_MAX_BATCH_VALUES
      The default maxBatch is at least this many values, whatever the step.
      See Also:
    • DEFAULT

      public static final BatchPolicy DEFAULT
      Every default: step 100, initial offset 1, lookahead 1s, the default max batch, reserve timeout 3s, no range ttl.
  • Method Details

    • builder

      public static BatchPolicy.Builder builder()
      A builder starting from the defaults (DEFAULT).
      Returns:
      the builder
    • defaultMaxBatch

      public static long defaultMaxBatch(long step)
      The default maxBatch of a step: max(step * 1000, 2^20) rounded up to the step. The batch follows the rate within the lookahead budget, so the cap only bounds what one reservation may burn; it does not depend on a small step, so a fast generator with a small step is not held to many small serial reservations.
      Parameters:
      step - the step, positive
      Returns:
      the default largest reservation, a multiple of step
    • step

      public long step()
      The smallest reservation.
      Returns:
      the step, positive; default 100L
    • initialOffset

      public long initialOffset()
      Where the first range of a new key starts; 4.x started at 1, and IdFiller and most databases take 0 as unset, so a generator should never issue 0.
      Returns:
      the initial offset; default 1L
    • lookahead

      public Duration lookahead()
      How long the ids at hand should last; Duration.ZERO disables prefetching.
      Returns:
      the lookahead; default 1s
    • maxBatch

      public long maxBatch()
      The largest reservation, a multiple of step.
      Returns:
      the largest reservation; default defaultMaxBatch(long) of the step
    • reserveTimeout

      public Duration reserveTimeout()
      How long a caller waits for a refill.
      Returns:
      the timeout; default 3s
    • rangeTtl

      public Optional<Duration> rangeTtl()
      A range unused for this long is dropped (4.x segment ttl).
      Returns:
      the range ttl; default none
    • withStep

      public BatchPolicy withStep(long step)
      This policy with another step. A maxBatch equal to the default of the current step becomes the default of the new one; any other is kept and must be a multiple of the new step.
      Parameters:
      step - the step, positive
      Returns:
      the policy
    • withLookahead

      public BatchPolicy withLookahead(Duration lookahead)
      This policy with another lookahead.
      Parameters:
      lookahead - the lookahead, not negative
      Returns:
      the policy
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object