Class ReplicationServerDomain

java.lang.Object
org.opends.server.api.MonitorProvider
org.opends.server.replication.server.ReplicationServerDomain
All Implemented Interfaces:
MeterBinder

public final class ReplicationServerDomain extends MonitorProvider
This class define an in-memory cache that will be used to store the messages that have been received from an LDAP server or from another replication server and that should be forwarded to other servers. The size of the cache is set by configuration. If the cache becomes bigger than the configured size, the older messages are removed and should they be needed again must be read from the backing file it runs a thread that is responsible for saving the messages received to the disk and for trimming them Decision to trim can be based on disk space or age of the message
  • Method Details

    • put

      public void put(UpdateMsg updateMsg, org.opends.server.replication.server.PeerServer sourceServer) throws ChangelogException
      Processes an update message received from a peer server, updating the server state and publishing the message to the changelog.
      Parameters:
      updateMsg - The update that has been received.
      sourceServer - The peer server from which the update was received
      Throws:
      ChangelogException - When an unexpected error occurs publishing the update in the changelog.
    • stopReplicationServers

      public void stopReplicationServers(Collection<com.forgerock.opendj.util.HostPort> serversToDisconnect)
      Stop operations with a list of replication servers.
      Parameters:
      serversToDisconnect - the replication servers addresses for which we want to stop operations
    • stopPeerServers

      public void stopPeerServers()
      Stop operations with all peer servers this domain is connected with (RS and DS).
    • isAlreadyConnectedToDS

      public boolean isAlreadyConnectedToDS(org.opends.server.replication.server.PeerReplica peerReplica)
      Checks whether it is already connected to a replica with same id.
      Parameters:
      peerReplica - the replica we want to check
      Returns:
      whether this replica is already connected to the current server
    • stopServer

      public void stopServer(org.opends.server.replication.server.PeerServer peerServer, boolean shutdown)
      Stop operations with a given peer server.
      Parameters:
      peerServer - the server for which we want to stop operations.
      shutdown - A boolean indicating if the stop is due to a shutdown condition.
    • isAlreadyConnectedToRS

      public boolean isAlreadyConnectedToRS(org.opends.server.replication.server.PeerReplicationServer peerRs) throws LdapException
      Checks whether a remote RS is already connected to this hosting RS.
      Parameters:
      peerRs - The remote replication server.
      Returns:
      flag specifying whether the remote RS is already connected.
      Throws:
      LdapException - when a problem occurs.
    • getPublisher

      public Flowable<UpdateRecord> getPublisher(String name, Dn baseDn, ServerState startState, ServerState endState)
      Returns a publisher of changes from the provided domain, using the provided states to determine the starting and ending points of each replica of the domain.

      See ReplicationDomainDB.getPublisherForDomain(String, Dn, ServerState, ServerState) for a detailed explanation on starting and ending conditions.

      The publisher is automatically updated if some replica is either added or removed to/from the domain.

      The publisher returns an error (ChangelogException) immediately after subscription if there is a change with a CSN greater than the start CSN in a replica changelog and no change with the start CSN (which indicates that the corresponding change has been purged). If the most recent change in a replica changelog is older than the start CSN, then it is not an error and the changes will be eventually published just after the start CSN is reached.

      The publisher must be cancelled at the end of use.

      Reading will start only when the returned Flowable has been subscribed to.

      Parameters:
      name - The name of the publisher.
      baseDn - The base DN of the domain to be published.
      startState - Provides the starting point for each replica. If a replica is not present in this state, then the starting point is the oldest record of the replica.
      endState - Provides the ending point for each replica. If a replica is not present in this state, then it has no ending point and its records will be published until the publisher is stopped or cancelled.
      Returns:
      a publisher of changes from the provided domain, using the provided states to determine the starting and ending points of each replica of the domain.
    • getBaseDN

      public Dn getBaseDN()
      Get the baseDN.
      Returns:
      Returns the baseDN.
    • createGlobalTopologyMonitorMsg

      public MonitorMsg createGlobalTopologyMonitorMsg(ServerId<?> sender)
      Creates a new monitor message including monitoring information for the whole topology.
      Parameters:
      sender - The sender of this message.
      Returns:
      The newly created and filled MonitorMsg. Null if a problem occurred during message creation.
    • shutdown

      public void shutdown()
      Shutdown this ReplicationServerDomain.
    • getLatestServerState

      public ServerState getLatestServerState()
      Returns the latest most current ServerState describing the newest CSNs for each server in this domain.
      Returns:
      The ServerState describing the newest CSNs for each server in in this domain.
    • toString

      public String toString()
      Overrides:
      toString in class MonitorProvider
    • createTopologyMsgForRS

      public TopologyMsg createTopologyMsgForRS()
      Creates a topology message to send to a remote RS.

      The topology message includes all DSs connected to this RS and all RSs of the topology.

      Returns:
      a topology message to send to a remote RS
    • createTopologyMsgForDS

      public TopologyMsg createTopologyMsgForDS(ServerId<?> destDsId)
      Creates a TopologyMsg filled with information to be sent to a DS. We send remote DS the info of every known DS and RS in the topology (our directly connected DSs plus the DSs connected to other RSs) except himself. Also put info related to local RS.
      Parameters:
      destDsId - The id of the DS the TopologyMsg PDU is to be sent to and that we must not include in the DS list.
      Returns:
      A suitable TopologyMsg PDU to be sent to a peer DS
    • getGenerationId

      public GenerationId getGenerationId()
      Get the generationId associated to this domain.
      Returns:
      The generationId
    • initGenerationID

      public void initGenerationID(GenerationId generationId)
      Initialize the value of the generationID for this ReplicationServerDomain. This method is intended to be used for initialization at startup and simply stores the new value without any additional processing. For example it does not clear the change-log DBs
      Parameters:
      generationId - The new value of generationId.
    • changeGenerationId

      public GenerationId changeGenerationId(GenerationId generationId)
      Sets the provided value as the new in memory generationId. Also clear the changelog databases.
      Parameters:
      generationId - The new value of generationId.
      Returns:
      The previous value of generation id
    • resetGenerationId

      public void resetGenerationId()
      Resets the generation id to its default value.
    • resetGenerationId

      public void resetGenerationId(org.opends.server.replication.server.PeerServer sender, ResetGenerationIdMsg genIdMsg)
      Resets the generationID.
      Parameters:
      sender - The server that requested to reset the generationId.
      genIdMsg - The reset generation ID msg received.
    • processNewStatus

      public void processNewStatus(org.opends.server.replication.server.PeerReplica sender, ChangeStatusMsg csMsg)
      Process message of a remote server changing his status.
      Parameters:
      sender - The server that changed his status.
      csMsg - The message containing the new status
    • sendTopoInfoToAll

      public void sendTopoInfoToAll()
      Update every peers (RS/DS) with topology changes.
    • hasDifferentGenerationIdThan

      public boolean hasDifferentGenerationIdThan(ReplicaId replicaId)
      Returns whether the provided replica has a different generationId than this replication domain.
      Parameters:
      replicaId - The replicaId for which we want to make the determination.
      Returns:
      Whether the provided replica has a different generationId than this replication domain.
    • receiveTopoInfoFromRS

      public void receiveTopoInfoFromRS(TopologyMsg topoMsg, org.opends.server.replication.server.PeerReplicationServer peerRs, boolean allowResetGenId)
      Process topology information received from a peer RS.
      Parameters:
      topoMsg - The just received topo message from remote RS
      peerRs - The replication server that received the message.
      allowResetGenId - True for allowing to reset the generation id ( when called after initial handshake)
    • getConnectedDSs

      Get the map of connected DSs.
      Returns:
      The map of connected DSs
    • getConnectedRSs

      Get the map of connected RSs.
      Returns:
      The map of connected RSs
    • hasLock

      public boolean hasLock()
      Tests if the current thread has the lock on this domain.
      Returns:
      True if the current thread has the lock.
    • lock

      public void lock() throws InterruptedException
      Takes the lock on this domain (blocking until lock can be acquired) or calling thread is interrupted.
      Throws:
      InterruptedException - If interrupted.
    • release

      public void release()
      Releases the lock on this domain.
    • tryLock

      public boolean tryLock(long timeout) throws InterruptedException
      Tries to acquire the lock on the domain within a given amount of time.
      Parameters:
      timeout - The amount of milliseconds to wait for acquiring the lock.
      Returns:
      True if the lock was acquired, false if timeout occurred.
      Throws:
      InterruptedException - When call was interrupted.
    • computeMonitorInstanceDn

      protected Dn computeMonitorInstanceDn()
      Description copied from class: MonitorProvider
      Returns the monitor instance DN for this monitor provider.
      Specified by:
      computeMonitorInstanceDn in class MonitorProvider
      Returns:
      the monitor instance DN.
    • bindTo

      public void bindTo(MeterRegistry parent)
      Description copied from class: MonitorProvider
      .

      Implementation considerations

      Implementations MUST set the MonitorProvider.registry field by creating a new MeterRegistryHolder, and specifying the appropriate prefix for the dimensional model and also the hierarchical model if they are different. This can be done using a parameter on the constructor, or the MeterRegistryHolder.hierarchicalNamePrefix(String) method. Tags common to all metrics for this monitor provider can also be set using the MeterRegistryHolder.tag(String, String) method.

      Attribute names are then registered by calling factory methods on the MonitorProvider.registry field.

      Sample dummy implementation

      (Please remove the comments when using this code as a template)

       
       public void bindTo(final MeterRegistry parent) {
           // create the MeterRegistryHolder wrapping OpenDJ's MeterRegistry
           registry = new MeterRegistryHolder("dimensional-name-prefix", parent)
                    .tag("label", "dimension")
                    .hierarchicalNamePrefix("hierarchical-name-prefix.dimension");
      
           // register the metrics against the wrapper
           registry.numberGauge("gauge", numberSupplier); // use lambdas or method references here
           timer = registry.timer("requests-submitted");
           // set a different name for the metric in cn=monitor, dimensional model and hierarchical model
           Gauge.doubleGauge(dimensionalName, supplier)
                .hierarchicalName(hierarchicalName)
                .tag(MeterRegistryHolder.TAG_ATTRIBUTE_NAME, "cn-monitor-name") // drop the "ds-mon-" prefix here
                .register(registry);
           // this gauge will only output to cn=monitor based monitoring endpoints
           registry.monitoringGauge("only-visible-in-cn-monitor", supplier);
       }
       
       
      Specified by:
      bindTo in interface MeterBinder
      Specified by:
      bindTo in class MonitorProvider
    • addMonitorObjectClassNames

      protected void addMonitorObjectClassNames(Attribute objectClassAttribute)
      Description copied from class: MonitorProvider
      Adds to the provided attribute the objectclass names that should be included in the monitor entry created from this monitor provider. This method should be implemented by child classes to make it easier to search for monitor entries of a specific type.
      Specified by:
      addMonitorObjectClassNames in class MonitorProvider
      Parameters:
      objectClassAttribute - the objectClass attribute where to add the object class names
    • getOldestState

      public ServerState getOldestState()
      Returns the oldest known state for the domain, made of the oldest CSN stored for each replica id.
      Returns:
      the start state of the domain.
    • register

      public void register(org.opends.server.replication.server.PeerReplica peerReplica)
      Registers a replica into this domain and notifies the domain about it.
      Parameters:
      peerReplica - The replica to register
    • register

      Registers the peer replication server into this domain and notifies the domain.
      Parameters:
      peerRs - The peer replication server to register