Class ReplicationServerDomain
- java.lang.Object
-
- org.opends.server.api.MonitorProvider
-
- org.opends.server.replication.server.ReplicationServerDomain
-
- All Implemented Interfaces:
MeterBinder
public 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
-
-
Field Summary
-
Fields inherited from class org.opends.server.api.MonitorProvider
registry
-
-
Constructor Summary
Constructors Constructor Description ReplicationServerDomain(Dn baseDN, ReplicationServer localReplicationServer)
Creates a new ReplicationServerDomain associated to the baseDN.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addMonitorObjectClassNames(Attribute objectClassAttribute)
Adds to the provided attribute the objectclass names that should be included in the monitor entry created from this monitor provider.void
bindTo(MeterRegistry parent)
.long
changeGenerationId(long generationId)
Sets the provided value as the new in memory generationId.protected Dn
computeMonitorInstanceDn()
Returns the monitor instance DN for this monitor provider.MonitorMsg
createGlobalTopologyMonitorMsg(ServerId<?> sender)
Creates a new monitor message including monitoring information for the whole topology.TopologyMsg
createTopologyMsgForDS(ServerId<?> destDsId)
Creates a TopologyMsg filled with information to be sent to a DS.TopologyMsg
createTopologyMsgForRS()
Creates a topology message to send to a remote RS.Dn
getBaseDN()
Get the baseDN.Map<ReplicaId,org.opends.server.replication.server.PeerReplica>
getConnectedDSs()
Get the map of connected DSs.Map<ReplicationServerId,org.opends.server.replication.server.PeerReplicationServer>
getConnectedRSs()
Get the map of connected RSs.long
getGenerationId()
Get the generationId associated to this domain.ServerState
getLatestServerState()
Returns the latest most current ServerState describing the newest CSNs for each server in this domain.ServerState
getOldestState()
Returns the oldest known state for the domain, made of the oldest CSN stored for each replica id.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.boolean
hasLock()
Tests if the current thread has the lock on this domain.void
initGenerationID(long generationId)
Initialize the value of the generationID for this ReplicationServerDomain.boolean
isAlreadyConnectedToDS(org.opends.server.replication.server.PeerReplica peerReplica)
Checks whether it is already connected to a replica with same id.boolean
isAlreadyConnectedToRS(org.opends.server.replication.server.PeerReplicationServer peerRs)
Checks whether a remote RS is already connected to this hosting RS.boolean
isDegradedDueToGenerationId(ReplicaId replicaId)
Returns whether the provided server is in degraded state due to the fact that the peer server has an invalid generationId for this domain.void
lock()
Takes the lock on this domain (blocking until lock can be acquired) or calling thread is interrupted.void
processNewStatus(org.opends.server.replication.server.PeerReplica sender, ChangeStatusMsg csMsg)
Process message of a remote server changing his status.void
put(UpdateMsg updateMsg, org.opends.server.replication.server.PeerServer sourceServer)
Processes an update message received from a peer server, updating the server state and publishing the message to the changelog.void
receiveTopoInfoFromRS(TopologyMsg topoMsg, org.opends.server.replication.server.PeerReplicationServer peerRs, boolean allowResetGenId)
Process topology information received from a peer RS.void
register(org.opends.server.replication.server.PeerReplica peerReplica)
Registers a replica into this domain and notifies the domain about it.void
register(org.opends.server.replication.server.PeerReplicationServer peerRs)
Registers the peer replication server into this domain and notifies the domain.void
release()
Releases the lock on this domain.void
resetGenerationId()
Resets the generation id to its default value.void
resetGenerationId(org.opends.server.replication.server.PeerServer sender, ResetGenerationIdMsg genIdMsg)
Resets the generationID.void
sendTopoInfoToAll()
Update every peers (RS/DS) with topology changes.void
shutdown()
Shutdown this ReplicationServerDomain.void
stopPeerServers()
Stop operations with all peer servers this domain is connected with (RS and DS).void
stopReplicationServers(Collection<com.forgerock.opendj.util.HostPort> serversToDisconnect)
Stop operations with a list of replication servers.void
stopServer(org.opends.server.replication.server.PeerServer peerServer, boolean shutdown)
Stop operations with a given peer server.String
toString()
boolean
tryLock(long timeout)
Tries to acquire the lock on the domain within a given amount of time.-
Methods inherited from class org.opends.server.api.MonitorProvider
configurationDnToMonitorDn, deregisterAll, getMonitorEntry, getMonitorInstanceDn
-
-
-
-
Constructor Detail
-
ReplicationServerDomain
public ReplicationServerDomain(Dn baseDN, ReplicationServer localReplicationServer)
Creates a new ReplicationServerDomain associated to the baseDN.- Parameters:
baseDN
- The baseDN associated to the ReplicationServerDomain.localReplicationServer
- the ReplicationServer that created this instance.
-
-
Method Detail
-
put
public void put(UpdateMsg updateMsg, org.opends.server.replication.server.PeerServer sourceServer)
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
-
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 classMonitorProvider
-
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 long getGenerationId()
Get the generationId associated to this domain.- Returns:
- The generationId
-
initGenerationID
public void initGenerationID(long 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 long changeGenerationId(long 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.
-
isDegradedDueToGenerationId
public boolean isDegradedDueToGenerationId(ReplicaId replicaId)
Returns whether the provided server is in degraded state due to the fact that the peer server has an invalid generationId for this domain.- Parameters:
replicaId
- The replicaId for which we want to know the the state.- Returns:
- Whether it is degraded or not.
-
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 RSpeerRs
- The replication server that received the message.allowResetGenId
- True for allowing to reset the generation id ( when called after initial handshake)
-
getConnectedDSs
public Map<ReplicaId,org.opends.server.replication.server.PeerReplica> getConnectedDSs()
Get the map of connected DSs.- Returns:
- The map of connected DSs
-
getConnectedRSs
public Map<ReplicationServerId,org.opends.server.replication.server.PeerReplicationServer> 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 classMonitorProvider
- 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 newMeterRegistryHolder
, 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 theMeterRegistryHolder.hierarchicalNamePrefix(String)
method. Tags common to all metrics for this monitor provider can also be set using theMeterRegistryHolder.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 interfaceMeterBinder
- Specified by:
bindTo
in classMonitorProvider
-
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 classMonitorProvider
- 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
public void register(org.opends.server.replication.server.PeerReplicationServer peerRs)
Registers the peer replication server into this domain and notifies the domain.- Parameters:
peerRs
- The peer replication server to register
-
-