Class CSNGenerator

java.lang.Object
org.opends.server.replication.common.CSNGenerator

public final class CSNGenerator extends Object
This class defines a structure that is used for storing the last CSNs generated on this server or received from other servers and generating new CSNs that are guaranteed to be larger than all the previously seen or generated CSNs.
  • Method Details

    • newCSNGenerator

      public static CSNGenerator newCSNGenerator(ReplicaId replicaId, long timestamp)
      Create a new CSNGenerator.
      Parameters:
      replicaId - id to use when creating CSNs.
      timestamp - time to start with.
      Returns:
      the new CSNGenerator
    • newCSNGenerator

      public static CSNGenerator newCSNGenerator(ReplicaId replicaId, LongSupplier timeSupplier)
      Create a new CSNGenerator.
      Parameters:
      replicaId - the replicaId to use when creating CSNs
      timeSupplier - the timestamp supplier
      Returns:
      the new CSNGenerator
    • newStreamSequenceNumberGenerator

      public static CSNGenerator.StreamSequenceNumberGenerator newStreamSequenceNumberGenerator()
      Returns:
      a new CSNGenerator.StreamSequenceNumberGenerator
    • generateCsn

      public CSN generateCsn()
      Returns the generated CSN.
      Returns:
      the generated CSN
    • generateCsnV3

      public CSN generateCsnV3(long streamTimeStamp, long curTime, CSNGenerator.StreamSequenceNumberGenerator streamSeqNumGen)
      Generate a new CSN using the V3 format.
      Parameters:
      streamTimeStamp - the streamId to use when creating the CSN
      curTime - the current time
      streamSeqNumGen - the stream sequence number generator
      Returns:
      the generated CSN
    • nextStreamSeqNum

      public static long nextStreamSeqNum(long streamSeqNum)
      Returns the next stream sequence number.
      Parameters:
      streamSeqNum - the current stream sequence number
      Returns:
      the next stream sequence number
    • isSequenceBroken

      public static boolean isSequenceBroken(CSN csn1, CSN csn2)
      Checks whether the sequence is broken between two CSNs.
      Parameters:
      csn1 - the first CSN
      csn2 - the second CSN
      Returns:
      if the two csns are in sequence
    • adjust

      public void adjust(ServerState state)
      Adjust utility method that takes ServerState as a parameter.
      Parameters:
      state - the ServerState to adjust with
    • adjust

      public void adjust(CSN csn)
      Adjust the lastTime of this CSNGenerator with a CSN that we have received from another server.

      This is necessary because we need that the CSN generated after processing an update received from other hosts to be as close as possible to the received CSN in order to have a global ordering that is close to wall-clock time.

      Parameters:
      csn - the CSN to adjust with