Class ServerState

  • All Implemented Interfaces:
    Iterable<CSN>

    public class ServerState
    extends Object
    implements Iterable<CSN>
    This class is used to associate ReplicaIds with CSNs.

    For example, it is exchanged with the replication servers at connection establishment time to communicate "which CSNs was last seen by a replicaId".

    • Constructor Detail

      • ServerState

        public ServerState()
    • Method Detail

      • clear

        public void clear()
        Empty the ServerState. After this call the Server State will be in the same state as if it was just created.
      • update

        public boolean update​(CSN csn)
        Forward update the Server State with a CSN. The provided CSN will be put on the current object only if it is newer than the existing CSN for the same replicaId or if there is no existing CSN.
        Parameters:
        csn - The committed CSN.
        Returns:
        a boolean indicating if the update was meaningful.
      • removeCSN

        public boolean removeCSN​(CSN expectedCSN)
        Removes the mapping to the provided CSN if it is present in this ServerState.
        Parameters:
        expectedCSN - the CSN to be removed
        Returns:
        true if the CSN could be removed, false otherwise.
      • getSnapshot

        public Set<CSN> getSnapshot()
        Returns a snapshot of this object.
        Returns:
        an unmodifiable List representing a snapshot of this object.
      • toString

        public String toString()
        Return the text representation of ServerState.
        Overrides:
        toString in class Object
        Returns:
        the text representation of ServerState
      • getCSN

        public CSN getCSN​(ReplicaId replicaId)
        Returns the CSN contained in this server state which corresponds to the provided replica ID.
        Parameters:
        replicaId - The replica ID.
        Returns:
        The CSN contained in this server state which corresponds to the provided replica ID.
      • getReplicaIdToCSNMap

        public Map<ReplicaId,​CSN> getReplicaIdToCSNMap()
        Returns a copy of this ServerState's content as a Map of replicaId to CSN.
        Returns:
        a copy of this ServerState's content as a Map of replicaId to CSN.
      • cover

        public boolean cover​(ServerState covered)
        Check that all the CSNs in the covered serverState are also in this serverState.
        Parameters:
        covered - The ServerState that needs to be checked.
        Returns:
        A boolean indicating if this ServerState covers the ServerState given in parameter.
      • cover

        public boolean cover​(CSN covered)
        Checks that the CSN given as a parameter is in this ServerState.
        Parameters:
        covered - The CSN that should be checked.
        Returns:
        A boolean indicating if this ServerState contains the CSN given in parameter.
      • isEmpty

        public boolean isEmpty()
        Tests if the state is empty.
        Returns:
        True if the state is empty.
      • duplicate

        public ServerState duplicate()
        Make a duplicate of this state.
        Returns:
        The duplicate of this state.
      • countNbChanges

        public static int countNbChanges​(ServerState ss1,
                                         ServerState ss2)
                                  throws IllegalArgumentException
        Unreliably computes the number of changes a first server state has in advance compared to a second server state.

        Note: this method used to be more reliable for a single replication domain, i.e. until OPENDJ-4977. Before that, each replication domains had its own unique server id, and so the CSN could trivially follow a global ordering across domains. After OPENDJ-4977, a single server would have a single server id shared by all its replication domains, which means the sequence numbers are now incremented per server instead of per replication domains. The end result is that this {#countNbChanges} method can no longer give accurate results per replication domain, which implies a replica could now be "degraded" much faster, impacted by another replication domain that is a "noisy neighbour", independent of the number of changes that are happening in its replication domain.

        Maybe dropping the DEGRADED status (based on this unreliable count) and replacing it by the LATE status (time-based) would be simpler.

        Parameters:
        ss1 - The server state supposed to be newer than the second one
        ss2 - The server state supposed to be older than the first one
        Returns:
        The difference of changes (sum of the differences for each replica id changes). 0 If no gap between 2 states.
        Throws:
        IllegalArgumentException - If one of the passed state is null
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object