Package me.ahoo.cosid.store.redis
Class RedisStore
java.lang.Object
me.ahoo.cosid.store.redis.RedisStore
- All Implemented Interfaces:
AutoCloseable,me.ahoo.cosid.lease.SlotLeaseStore,me.ahoo.cosid.segment.RangeStore,me.ahoo.cosid.store.Store
public final class RedisStore
extends Object
implements me.ahoo.cosid.store.Store, me.ahoo.cosid.segment.RangeStore, me.ahoo.cosid.lease.SlotLeaseStore
The Redis store (06-stores.md ยง2.2): both primitives as Lua scripts run through
RedisScripts, stamped by the
Redis clock (TIME). Redis 7.0 or later (D27).
Keys, each group sharing one hash tag so that a script touches one Redis Cluster slot:
cosid:{key}: the counter of a range key, a decimal string;cosid:{key}:sealed: its seal marker. Keys are never deleted (D23).cosid:{ns}:meta: the limit, tolerance and slot offset a namespace was first used with (a hash oflimit,tolerance,slotOffset; a meta written by 5.0.0-alpha.1 has noslotOffset, which reads as 0);cosid:{ns}:slot: slot to its row;cosid:{ns}:free: the free slots, scored by slot number;cosid:{ns}:live: the live leases, scored byexpiresAt;cosid:{ns}:owner: owner key to the slot it took last;cosid:{ns}:held: owner key to the slots whose row names it.
sweepBatch expired leases; there is no scan of the namespace.
Durability precondition. The uniqueness of the ids rests on "an acknowledged write is never
lost": either a single node with AOF and appendfsync always, or WAIT covering every replica. Under
asynchronous replication a failover can lose range and lease writes and so produce duplicate ids; where uniqueness
is strict, prefer the JDBC or ZooKeeper store. The store only hands out a range or a ceiling once its write is
acknowledged (RedisScripts).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intHow many expired leases one acquire moves to the free set at most. -
Constructor Summary
ConstructorsConstructorDescriptionRedisStore(RedisScripts scripts) A store on the given scripts, with the default sweep batch; closing it closes nothing.RedisStore(RedisScripts scripts, int sweepBatch, AutoCloseable resources) A store on the given scripts. -
Method Summary
Modifier and TypeMethodDescriptionme.ahoo.cosid.lease.AcquireResultacquire(String namespace, me.ahoo.cosid.lease.Owner owner, int limit, Duration ttl, Duration tolerance, int slotOffset, OptionalInt preferredSlot) voidclose()me.ahoo.cosid.segment.RangeStoreranges()booleanrelease(me.ahoo.cosid.lease.SlotLease lease, long lastIssued) Optional<me.ahoo.cosid.lease.SlotLease> me.ahoo.cosid.segment.RangebooleanSeals the key; a key that does not exist yet is sealed too, so it is never created (S6).me.ahoo.cosid.lease.SlotLeaseStoreslots()
-
Field Details
-
DEFAULT_SWEEP_BATCH
public static final int DEFAULT_SWEEP_BATCHHow many expired leases one acquire moves to the free set at most.- See Also:
-
-
Constructor Details
-
RedisStore
A store on the given scripts, with the default sweep batch; closing it closes nothing.- Parameters:
scripts- how the store runs its scripts
-
RedisStore
A store on the given scripts.- Parameters:
scripts- how the store runs its scriptssweepBatch- how many expired leases one acquire moves to the free set at most, positiveresources- closed with the store: what the store created itself, never an injected client
-
-
Method Details
-
ranges
public me.ahoo.cosid.segment.RangeStore ranges()- Specified by:
rangesin interfaceme.ahoo.cosid.store.Store
-
slots
public me.ahoo.cosid.lease.SlotLeaseStore slots()- Specified by:
slotsin interfaceme.ahoo.cosid.store.Store
-
reserve
- Specified by:
reservein interfaceme.ahoo.cosid.segment.RangeStore
-
seal
Seals the key; a key that does not exist yet is sealed too, so it is never created (S6).- Specified by:
sealin interfaceme.ahoo.cosid.segment.RangeStore- Parameters:
key- the range key- Returns:
- true
-
acquire
public me.ahoo.cosid.lease.AcquireResult acquire(String namespace, me.ahoo.cosid.lease.Owner owner, int limit, Duration ttl, Duration tolerance, int slotOffset, OptionalInt preferredSlot) - Specified by:
acquirein interfaceme.ahoo.cosid.lease.SlotLeaseStore
-
renew
public Optional<me.ahoo.cosid.lease.SlotLease> renew(me.ahoo.cosid.lease.SlotLease lease, Duration ttl, Duration tolerance) - Specified by:
renewin interfaceme.ahoo.cosid.lease.SlotLeaseStore
-
release
public boolean release(me.ahoo.cosid.lease.SlotLease lease, long lastIssued) - Specified by:
releasein interfaceme.ahoo.cosid.lease.SlotLeaseStore
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceme.ahoo.cosid.segment.RangeStore- Specified by:
closein interfaceme.ahoo.cosid.lease.SlotLeaseStore- Specified by:
closein interfaceme.ahoo.cosid.store.Store
-