Class MongoRangeStore

java.lang.Object
me.ahoo.cosid.store.mongo.MongoRangeStore
All Implemented Interfaces:
AutoCloseable, me.ahoo.cosid.segment.RangeStore

public final class MongoRangeStore extends Object implements me.ahoo.cosid.segment.RangeStore
RangeStore on the cosid_range collection, {_id: key, next, sealed} (06-stores.md ยง2.3).

A reservation is one findOneAndUpdate: an upsert with the pipeline update next = ifNull(next, initialOffset) + size, filtered on sealed != true and on next leaving room for size, returning the updated document; the range is [next - size, next). When the filter matches nothing on an existing key the upsert fails with E11000, as it does when a concurrent first reservation created the key: the store then reads the key, reports a sealed or exhausted one, and otherwise retries.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The collection.
  • Constructor Summary

    Constructors
    Constructor
    Description
    MongoRangeStore(com.mongodb.client.MongoDatabase database, Duration timeout)
    A range store on a database whose client the caller owns.
    MongoRangeStore(com.mongodb.client.MongoDatabase database, Duration timeout, com.mongodb.WriteConcern writeConcern)
    A range store on a database whose client the caller owns, writing with the given concern.
  • Method Summary

    Modifier and Type
    Method
    Description
    me.ahoo.cosid.segment.Range
    reserve(String key, long size, long initialOffset)
     
    boolean
    seal(String key)
    Seals the key with an upsert, so a key that does not exist yet is sealed too and never created (S6).

    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.segment.RangeStore

    close
  • Field Details

  • Constructor Details

    • MongoRangeStore

      public MongoRangeStore(com.mongodb.client.MongoDatabase database, Duration timeout)
      A range store on a database whose client the caller owns.
      Parameters:
      database - the database
      timeout - the operation timeout (timeoutMS); zero means none
    • MongoRangeStore

      public MongoRangeStore(com.mongodb.client.MongoDatabase database, Duration timeout, com.mongodb.WriteConcern writeConcern)
      A range 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 ranges across a failover)
  • Method Details

    • reserve

      public me.ahoo.cosid.segment.Range reserve(String key, long size, long initialOffset)
      Specified by:
      reserve in interface me.ahoo.cosid.segment.RangeStore
    • seal

      public boolean seal(String key)
      Seals the key with an upsert, so a key that does not exist yet is sealed too and never created (S6).
      Specified by:
      seal in interface me.ahoo.cosid.segment.RangeStore
      Parameters:
      key - the range key
      Returns:
      true