| | |
| | | package org.opends.server.replication.server; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | |
| | | import java.util.List; |
| | |
| | | private static final int SHUTDOWN_JOIN_TIMEOUT = 30000; |
| | | |
| | | /** |
| | | * Close the session and log the provided error message |
| | | * Log nothing if message is null. |
| | | * @param providedSession The provided closing session. |
| | | * @param providedMsg The provided error message. |
| | | * @param handler The handler that manages that session. |
| | | */ |
| | | static protected void closeSession(Session providedSession, |
| | | LocalizableMessage providedMsg, ServerHandler handler) |
| | | { |
| | | if (providedMsg != null) |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | logger.trace("In %s closing session with err=%s", |
| | | ((handler != null) ? handler : "Replication Server"), providedMsg); |
| | | logger.error(providedMsg); |
| | | } |
| | | |
| | | if (providedSession != null) |
| | | { |
| | | // This method is only called when aborting a failing handshake and |
| | | // not StopMsg should be sent in such situation. StopMsg are only |
| | | // expected when full handshake has been performed, or at end of |
| | | // handshake phase 1, when DS was just gathering available RS info |
| | | providedSession.close(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * The serverId of the remote server. |
| | | */ |
| | | protected int serverId; |
| | |
| | | Session localSession = session; |
| | | if (localSession != null) |
| | | { |
| | | closeSession(localSession, reason, this); |
| | | if (reason != null) |
| | | { |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("In " + this + " closing session with err=" + reason); |
| | | } |
| | | logger.error(reason); |
| | | } |
| | | |
| | | // This method is only called when aborting a failing handshake and |
| | | // not StopMsg should be sent in such situation. StopMsg are only |
| | | // expected when full handshake has been performed, or at end of |
| | | // handshake phase 1, when DS was just gathering available RS info |
| | | localSession.close(); |
| | | } |
| | | |
| | | releaseDomainLock(); |
| | |
| | | // We may have changed it as it was -1 and we received a value >0 from peer |
| | | // server and the last topo message sent may have failed being sent: in that |
| | | // case retrieve old value of generation id for replication server domain |
| | | if (oldGenerationId != -100 && replicationServerDomain != null) |
| | | if (oldGenerationId != -100) |
| | | { |
| | | replicationServerDomain.changeGenerationId(oldGenerationId); |
| | | } |
| | |
| | | */ |
| | | protected void releaseDomainLock() |
| | | { |
| | | if (replicationServerDomain != null && replicationServerDomain.hasLock()) |
| | | if (replicationServerDomain.hasLock()) |
| | | { |
| | | replicationServerDomain.release(); |
| | | } |
| | |
| | | { |
| | | final LocalizableMessage message = |
| | | ERR_SESSION_STARTUP_INTERRUPTED.get(session.getName()); |
| | | throw new DirectoryException(ResultCode.OTHER, |
| | | message, e); |
| | | throw new DirectoryException(ResultCode.OTHER, message, e); |
| | | } |
| | | reader.start(); |
| | | writer.start(); |
| | |
| | | public void send(ReplicationMsg msg) throws IOException |
| | | { |
| | | // avoid logging anything for unit tests that include a null domain. |
| | | if (logger.isTraceEnabled() && replicationServerDomain != null) |
| | | if (logger.isTraceEnabled()) |
| | | { |
| | | logger.trace("In " |
| | | + replicationServerDomain.getLocalRSMonitorInstanceName() + " " |
| | |
| | | return heartbeatInterval; |
| | | } |
| | | |
| | | /** |
| | | * Get the count of updates received from the server. |
| | | * @return the count of update received from the server. |
| | | */ |
| | | @Override |
| | | public int getInCount() |
| | | { |
| | | return inCount; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public List<Attribute> getMonitorData() |
| | |
| | | public abstract String getMonitorInstanceName(); |
| | | |
| | | /** |
| | | * Get the count of updates sent to this server. |
| | | * @return The count of update sent to this server. |
| | | */ |
| | | @Override |
| | | public int getOutCount() |
| | | { |
| | | return outCount; |
| | | } |
| | | |
| | | /** |
| | | * Gets the protocol version used with this remote server. |
| | | * @return The protocol version used with this remote server. |
| | | */ |
| | |
| | | assuredSrSentUpdatesTimeout.incrementAndGet(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void initializeMonitorProvider(MonitorProviderCfg configuration) |
| | | throws ConfigException, InitializationException |
| | |
| | | public void lockDomainWithTimeout() throws DirectoryException, |
| | | InterruptedException |
| | | { |
| | | if (replicationServerDomain == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | Random random = new Random(); |
| | | int randomTime = random.nextInt(6); // Random from 0 to 5 |
| | | final Random random = new Random(); |
| | | final int randomTime = random.nextInt(6); // Random from 0 to 5 |
| | | // Wait at least 3 seconds + (0 to 5 seconds) |
| | | long timeout = 3000 + (randomTime * 1000); |
| | | boolean lockAcquired = replicationServerDomain.tryLock(timeout); |
| | | final long timeout = 3000 + (randomTime * 1000); |
| | | final boolean lockAcquired = replicationServerDomain.tryLock(timeout); |
| | | if (!lockAcquired) |
| | | { |
| | | LocalizableMessage message = WARN_TIMEOUT_WHEN_CROSS_CONNECTION.get( |
| | |
| | | */ |
| | | void processAck(AckMsg ack) |
| | | { |
| | | if (replicationServerDomain!=null) |
| | | replicationServerDomain.processAck(ack, this); |
| | | replicationServerDomain.processAck(ack, this); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public long getReferenceGenId() |
| | | { |
| | | if (replicationServerDomain != null) |
| | | return replicationServerDomain.getGenerationId(); |
| | | return -1; |
| | | return replicationServerDomain.getGenerationId(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | void processResetGenId(ResetGenerationIdMsg msg) |
| | | { |
| | | if (replicationServerDomain!=null) |
| | | replicationServerDomain.resetGenerationId(this, msg); |
| | | replicationServerDomain.resetGenerationId(this, msg); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void put(UpdateMsg update) throws IOException |
| | | { |
| | | decAndCheckWindow(); |
| | | if (replicationServerDomain!=null) |
| | | replicationServerDomain.put(update, this); |
| | | replicationServerDomain.put(update, this); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public void doStop() |
| | | { |
| | | if (replicationServerDomain!=null) |
| | | replicationServerDomain.stopServer(this, false); |
| | | replicationServerDomain.stopServer(this, false); |
| | | } |
| | | |
| | | /** |