package sequence
Lerna Util Sequence
Overview
The package provides an ID generator.
- Alphabetic
- By Inheritance
- sequence
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
abstract
class
CassandraSequenceFactory extends SequenceFactory with AppLogging
A sequence factory using Cassandra
A sequence factory using Cassandra
Overview
- Manage sequences using (
seqId,subId) as a key - Reduce overhead by generating and persisting sequence beforehand
- For each key (
seqId,subId), hold the next IDs in memory
seqIDconcept is introduced by this implementation. It can be thought of as a sub-namespace.Details
Define an increment value as max server count (name it
n) beforehand. Assign the different initial values (that is in the range [1 ton]) to each server. We can generate a unique ID using the above condition.For example, suppose we have 3 servers initially and scale it out to 5 servers in the future.
Assign initial values as follows
- Server A: (Assign an initial value = 1)
- Server B: (Assign an initial value = 2)
- Server C: (Assign an initial value = 3)
Each server generates a sequence like the below
- Server A generates a sequence 1, 6, 11, ...,
Ai = 1 + n * i - Server B generates a sequence 2, 7, 12, ...,
Bi = 2 + n * i - Server C generates a sequence 3, 8, 13, ...,
Ci = 3 + n * i
In the future, we can add two servers (named Server D and Server E).
- Server D is assigned 4 as an initial value.
It generates a sequence 4, 9, 14, ...,
Di = 4 + n * i. - Server E is assigned 5 as an initial value.
It generates a sequence 5, 10, 15, ...,
Ei = 5 + n * i.
Therefore, as we see the above, we can generate unique IDs.
- Annotations
- @SuppressWarnings()
- Manage sequences using (
-
trait
SequenceFactory extends AnyRef
A trait that provides generating ID sequence
A trait that provides generating ID sequence
A concrete implementation for this trait must behave like below.
- Generate unique ID only for the given
subIDThis means that IDs generated with differentsubIDcan be the same value. We can thinksubIDas a namespace. - A Generated ID should be in the range [0,
maxSequence] (both inclusive)
Behaviors that are not described above are dependent on a concrete implementation.
- Generate unique ID only for the given
- class SequenceFactoryCassandraConfig extends AnyRef
Value Members
- object FutureConverters