Class RepoSequence

java.lang.Object
com.google.gerrit.server.notedb.RepoSequence
All Implemented Interfaces:
Sequence

public class RepoSequence extends Object implements Sequence
Class for managing an incrementing sequence backed by a git repository.

The current sequence number is stored as UTF-8 text in a blob pointed to by a ref in the refs/sequences/* namespace. Multiple processes can share the same sequence by incrementing the counter using normal git ref updates. To amortize the cost of these ref updates, processes can increment the counter by a larger number and hand out numbers from that range in memory until they run out. This means concurrent processes will hand out somewhat non-monotonic numbers.

  • Constructor Details

  • Method Details

    • next

      public int next()
      Retrieves the next available sequence number.

      This method is thread-safe.

      Specified by:
      next in interface Sequence
      Returns:
      the next available sequence number
    • next

      public com.google.common.collect.ImmutableList<Integer> next(int count)
      Retrieves the next N available sequence number.

      This method is thread-safe.

      Specified by:
      next in interface Sequence
      Parameters:
      count - the number of sequence numbers which should be returned
      Returns:
      the next N available sequence numbers
    • storeNew

      public void storeNew(int value)
      Description copied from interface: Sequence
      Stores a new value to be returned on the next calls for Sequence.next() or Sequence.current().
      Specified by:
      storeNew in interface Sequence
    • getBatchSize

      public int getBatchSize()
      Description copied from interface: Sequence
      Returns the batch size that was used to initialize the sequence.
      Specified by:
      getBatchSize in interface Sequence
    • current

      public int current()
      Description copied from interface: Sequence
      Returns the next available sequence value.
      Specified by:
      current in interface Sequence
    • last

      public int last()
      Retrieves the last returned sequence number.

      Explicitly calls next() if this instance didn't return sequence number until now.

      Specified by:
      last in interface Sequence