Package me.ahoo.cosid.store.mongo
Class MongoSlotLeaseStore
java.lang.Object
me.ahoo.cosid.store.mongo.MongoSlotLeaseStore
- All Implemented Interfaces:
AutoCloseable,me.ahoo.cosid.lease.SlotLeaseStore
SlotLeaseStore on the cosid_slot collection (06-stores.md §2.3): one document per slot,
{ns, slot, ownerKey, incarnation, lastOwnerKey, fence, expiresAt, floor, ceiling, nextFloor, writtenAt}, unique
on (ns, slot), with every slot of a namespace created on its first use; the namespace parameters live in
cosid_namespace, {_id: ns, limit, toleranceMs, slotOffset}. A namespace document written by 5.0.0-alpha.1 has no
slotOffset: it reads as offset 0 and is never rewritten.
An acquire first reads the slots the owner key holds or held last (one aggregation, with $$NOW): that
answers the idempotent step and the duplicate key check and names the sticky candidates. Each step that takes a slot
(05-machine-lease.md §2.1) is then one findOneAndUpdate on one document, so the condition and the change of
§2.2 are atomic: "free" is a $expr on $$NOW, a sticky candidate also matches the fence it was read
with, renewals and releases match the incarnation and the fence. The pipeline update first stamps writtenAt = $$NOW, the store clock, and
derives the expiry from it, so storeNow and expiresAt come from the same write.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMongoSlotLeaseStore(com.mongodb.client.MongoDatabase database, Duration timeout) A slot lease store on a database whose client the caller owns.MongoSlotLeaseStore(com.mongodb.client.MongoDatabase database, Duration timeout, com.mongodb.WriteConcern writeConcern) A slot lease store on a database whose client the caller owns, writing with the given concern. -
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) booleanrelease(me.ahoo.cosid.lease.SlotLease lease, long lastIssued) Optional<me.ahoo.cosid.lease.SlotLease> Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.ahoo.cosid.lease.SlotLeaseStore
close
-
Field Details
-
COLLECTION
The slot collection.- See Also:
-
NAMESPACE_COLLECTION
The namespace collection.- See Also:
-
-
Constructor Details
-
MongoSlotLeaseStore
A slot lease store on a database whose client the caller owns.- Parameters:
database- the databasetimeout- the operation timeout (timeoutMS); zero means none
-
MongoSlotLeaseStore
public MongoSlotLeaseStore(com.mongodb.client.MongoDatabase database, Duration timeout, com.mongodb.WriteConcern writeConcern) A slot lease store on a database whose client the caller owns, writing with the given concern.- Parameters:
database- the databasetimeout- the operation timeout (timeoutMS); zero means nonewriteConcern- the write concern, acknowledged (majoritykeeps leases across a failover)
-
-
Method Details
-
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
-