java.lang.Object
me.ahoo.cosid.segment.BatchPolicy
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).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilds aBatchPolicy;BatchPolicy.Builder.build()checks the fields. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BatchPolicyEvery default: step 100, initial offset 1, lookahead 1s, the default max batch, reserve timeout 3s, no range ttl.static final longThe default first value of a new key: 1, never 0.static final longThe defaultmaxBatchis at least this many values, whatever the step.static final long -
Method Summary
Modifier and TypeMethodDescriptionstatic BatchPolicy.Builderbuilder()A builder starting from the defaults (DEFAULT).static longdefaultMaxBatch(long step) The defaultmaxBatchof a step:max(step * 1000, 2^20)rounded up to the step.booleaninthashCode()longWhere the first range of a new key starts; 4.x started at 1, andIdFillerand most databases take 0 as unset, so a generator should never issue 0.How long the ids at hand should last;Duration.ZEROdisables prefetching.longmaxBatch()The largest reservation, a multiple ofstep.rangeTtl()A range unused for this long is dropped (4.x segment ttl).How long a caller waits for a refill.longstep()The smallest reservation.toString()withLookahead(Duration lookahead) This policy with another lookahead.withStep(long step) This policy with another step.
-
Field Details
-
DEFAULT_STEP
public static final long DEFAULT_STEP- See Also:
-
DEFAULT_INITIAL_OFFSET
public static final long DEFAULT_INITIAL_OFFSETThe default first value of a new key: 1, never 0.- See Also:
-
DEFAULT_MAX_BATCH_VALUES
public static final long DEFAULT_MAX_BATCH_VALUESThe defaultmaxBatchis at least this many values, whatever the step.- See Also:
-
DEFAULT
Every default: step 100, initial offset 1, lookahead 1s, the default max batch, reserve timeout 3s, no range ttl.
-
-
Method Details
-
builder
A builder starting from the defaults (DEFAULT).- Returns:
- the builder
-
defaultMaxBatch
public static long defaultMaxBatch(long step) The defaultmaxBatchof 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, andIdFillerand most databases take 0 as unset, so a generator should never issue 0.- Returns:
- the initial offset; default 1L
-
lookahead
How long the ids at hand should last;Duration.ZEROdisables prefetching.- Returns:
- the lookahead; default 1s
-
maxBatch
public long maxBatch()The largest reservation, a multiple ofstep.- Returns:
- the largest reservation; default
defaultMaxBatch(long)of the step
-
reserveTimeout
How long a caller waits for a refill.- Returns:
- the timeout; default 3s
-
rangeTtl
A range unused for this long is dropped (4.x segment ttl).- Returns:
- the range ttl; default none
-
withStep
This policy with another step. AmaxBatchequal 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
This policy with another lookahead.- Parameters:
lookahead- the lookahead, not negative- Returns:
- the policy
-
equals
-
hashCode
public int hashCode() -
toString
-