| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package org.opends.server.replication.service; |
| | | |
| | |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.messages.MessageBuilder; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.opends.server.admin.std.server.ReplicationDomainCfg; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.loggers.debug.DebugTracer; |
| | |
| | | /** |
| | | * Create a new instance of ReplicationServerInfo wrapping the passed |
| | | * message. |
| | | * @param msg Message to wrap. |
| | | * @param msg LocalizableMessage to wrap. |
| | | * @param newServerURL Override serverURL. |
| | | * @return The new instance wrapping the passed message. |
| | | * @throws IllegalArgumentException If the passed message has an unexpected |
| | |
| | | /** |
| | | * Create a new instance of ReplicationServerInfo wrapping the passed |
| | | * message. |
| | | * @param msg Message to wrap. |
| | | * @param msg LocalizableMessage to wrap. |
| | | * @return The new instance wrapping the passed message. |
| | | * @throws IllegalArgumentException If the passed message has an unexpected |
| | | * type. |
| | |
| | | Session newSession = null; |
| | | Socket socket = null; |
| | | boolean hasConnected = false; |
| | | Message errorMessage = null; |
| | | LocalizableMessage errorMessage = null; |
| | | |
| | | try |
| | | { |
| | |
| | | |
| | | private final int localServerId; |
| | | private Map<Integer, ReplicationServerInfo> bestRSs; |
| | | private final Map<Integer, Message> rsEvals = |
| | | new HashMap<Integer, Message>(); |
| | | private final Map<Integer, LocalizableMessage> rsEvals = |
| | | new HashMap<Integer, LocalizableMessage>(); |
| | | |
| | | /** |
| | | * Ctor. |
| | |
| | | * @param rejectedRSsEval |
| | | * the evaluation for all the rejected replication servers |
| | | */ |
| | | private void setBestRS(int bestRsId, Message rejectedRSsEval) |
| | | private void setBestRS(int bestRsId, LocalizableMessage rejectedRSsEval) |
| | | { |
| | | for (Iterator<Entry<Integer, ReplicationServerInfo>> it = |
| | | this.bestRSs.entrySet().iterator(); it.hasNext();) |
| | |
| | | } |
| | | } |
| | | |
| | | private void discardAll(Message eval) |
| | | private void discardAll(LocalizableMessage eval) |
| | | { |
| | | for (Integer rsId : bestRSs.keySet()) |
| | | { |
| | |
| | | /** |
| | | * Returns the evaluations for all the candidate replication servers. |
| | | * |
| | | * @return a Map of serverId => Message containing the evaluation for each |
| | | * @return a Map of serverId => LocalizableMessage containing the evaluation for each |
| | | * candidate replication servers. |
| | | */ |
| | | Map<Integer, Message> getEvaluations() |
| | | Map<Integer, LocalizableMessage> getEvaluations() |
| | | { |
| | | if (foundBestRS()) |
| | | { |
| | | final Integer bestRSServerId = getBestRS().getServerId(); |
| | | if (rsEvals.get(bestRSServerId) == null) |
| | | { |
| | | final Message eval = NOTE_BEST_RS.get(bestRSServerId, localServerId); |
| | | final LocalizableMessage eval = NOTE_BEST_RS.get(bestRSServerId, localServerId); |
| | | rsEvals.put(bestRSServerId, eval); |
| | | } |
| | | } |
| | |
| | | * |
| | | * @param rsServerId |
| | | * the supplied replication server Id |
| | | * @return the evaluation {@link Message} for the supplied replication |
| | | * @return the evaluation {@link LocalizableMessage} for the supplied replication |
| | | * server Id |
| | | */ |
| | | private Message getEvaluation(int rsServerId) |
| | | private LocalizableMessage getEvaluation(int rsServerId) |
| | | { |
| | | final Message evaluation = getEvaluations().get(rsServerId); |
| | | final LocalizableMessage evaluation = getEvaluations().get(rsServerId); |
| | | if (evaluation != null) |
| | | { |
| | | return evaluation; |
| | |
| | | { |
| | | private final Map<Integer, ReplicationServerInfo> accepted = |
| | | new HashMap<Integer, ReplicationServerInfo>(); |
| | | private final Map<ReplicationServerInfo, Message> rsEvals = |
| | | new HashMap<ReplicationServerInfo, Message>(); |
| | | private final Map<ReplicationServerInfo, LocalizableMessage> rsEvals = |
| | | new HashMap<ReplicationServerInfo, LocalizableMessage>(); |
| | | |
| | | private void accept(Integer rsId, ReplicationServerInfo rsInfo) |
| | | { |
| | |
| | | this.accepted.put(rsId, rsInfo); |
| | | } |
| | | |
| | | private void reject(ReplicationServerInfo rsInfo, Message reason) |
| | | private void reject(ReplicationServerInfo rsInfo, LocalizableMessage reason) |
| | | { |
| | | this.accepted.remove(rsInfo.getServerId()); // undo accept |
| | | this.rsEvals.put(rsInfo, reason); |
| | |
| | | new ReplicationServerInfo[accepted.size()]); |
| | | } |
| | | |
| | | public Map<Integer, Message> getRejected() |
| | | public Map<Integer, LocalizableMessage> getRejected() |
| | | { |
| | | final Map<Integer, Message> result = new HashMap<Integer, Message>(); |
| | | for (Entry<ReplicationServerInfo, Message> entry : rsEvals.entrySet()) |
| | | final Map<Integer, LocalizableMessage> result = new HashMap<Integer, LocalizableMessage>(); |
| | | for (Entry<ReplicationServerInfo, LocalizableMessage> entry : rsEvals.entrySet()) |
| | | { |
| | | result.put(entry.getKey().getServerId(), entry.getValue()); |
| | | } |
| | |
| | | { |
| | | final String rsCSN = |
| | | getCSN(rsInfo.getServerState(), localServerId).toStringUI(); |
| | | final Message reason = |
| | | final LocalizableMessage reason = |
| | | NOTE_RS_LATER_THAN_ANOTHER_RS_MORE_UP_TO_DATE_THAN_LOCAL_DS.get( |
| | | rsInfo.getServerId(), rsCSN, localServerId, localCSN.toStringUI()); |
| | | eval.reject(rsInfo, reason); |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | MessageBuilder mb = new MessageBuilder(); |
| | | LocalizableMessageBuilder mb = new LocalizableMessageBuilder(); |
| | | mb.append(NOTE_EXCEPTION_RESTARTING_SESSION.get( |
| | | getBaseDN().toNormalizedString(), e.getLocalizedMessage())); |
| | | mb.append(stackTraceToSingleLineString(e)); |
| | |
| | | /** |
| | | * Publish a message to the other servers. |
| | | * @param msg the message to publish |
| | | * @param recoveryMsg the message is a recovery Message |
| | | * @param recoveryMsg the message is a recovery LocalizableMessage |
| | | * @param retryOnFailure whether retry should be done on failure |
| | | * @return whether the message was successfully sent. |
| | | */ |
| | |
| | | else if (msg instanceof StopMsg) |
| | | { |
| | | // RS performs a proper disconnection |
| | | Message message = WARN_REPLICATION_SERVER_PROPERLY_DISCONNECTED.get( |
| | | LocalizableMessage message = WARN_REPLICATION_SERVER_PROPERLY_DISCONNECTED.get( |
| | | previousRsServerID, rs.replicationServer, |
| | | serverId, baseDN.toNormalizedString()); |
| | | logError(message); |
| | |
| | | { |
| | | // The best replication server is no more the one we are |
| | | // currently using. Disconnect properly then reconnect. |
| | | Message message; |
| | | LocalizableMessage message; |
| | | if (bestServerInfo == null) |
| | | { |
| | | message = NOTE_LOAD_BALANCE_REPLICATION_SERVER.get( |
| | |
| | | { |
| | | monitorResponse.set(false); |
| | | |
| | | // publish Monitor Request Message to the Replication Server |
| | | // publish Monitor Request LocalizableMessage to the Replication Server |
| | | publish(new MonitorRequestMsg(getServerId(), getRsServerId())); |
| | | |
| | | // wait for Response up to 10 seconds. |
| | |
| | | new ChangeStatusMsg(ServerStatus.INVALID_STATUS, newStatus)); |
| | | } catch (IOException ex) |
| | | { |
| | | Message message = ERR_EXCEPTION_SENDING_CS.get( |
| | | LocalizableMessage message = ERR_EXCEPTION_SENDING_CS.get( |
| | | getBaseDN().toNormalizedString(), |
| | | Integer.toString(getServerId()), |
| | | ex.getLocalizedMessage() + " " + stackTraceToSingleLineString(ex)); |