Class MongoSlotLeaseStore

java.lang.Object
me.ahoo.cosid.store.mongo.MongoSlotLeaseStore
All Implemented Interfaces:
AutoCloseable, me.ahoo.cosid.lease.SlotLeaseStore

public final class MongoSlotLeaseStore extends Object implements 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
    Modifier and Type
    Field
    Description
    static final String
    The slot collection.
    static final String
    The namespace collection.
  • Constructor Summary

    Constructors
    Constructor
    Description
    MongoSlotLeaseStore(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 Type
    Method
    Description
    me.ahoo.cosid.lease.AcquireResult
    acquire(String namespace, me.ahoo.cosid.lease.Owner owner, int limit, Duration ttl, Duration tolerance, int slotOffset, OptionalInt preferredSlot)
     
    boolean
    release(me.ahoo.cosid.lease.SlotLease lease, long lastIssued)
     
    Optional<me.ahoo.cosid.lease.SlotLease>
    renew(me.ahoo.cosid.lease.SlotLease lease, Duration ttl, Duration tolerance)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface me.ahoo.cosid.lease.SlotLeaseStore

    close
  • Field Details

  • Constructor Details

    • MongoSlotLeaseStore

      public MongoSlotLeaseStore(com.mongodb.client.MongoDatabase database, Duration timeout)
      A slot lease store on a database whose client the caller owns.
      Parameters:
      database - the database
      timeout - 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 database
      timeout - the operation timeout (timeoutMS); zero means none
      writeConcern - the write concern, acknowledged (majority keeps 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:
      acquire in interface me.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:
      renew in interface me.ahoo.cosid.lease.SlotLeaseStore
    • release

      public boolean release(me.ahoo.cosid.lease.SlotLease lease, long lastIssued)
      Specified by:
      release in interface me.ahoo.cosid.lease.SlotLeaseStore