From 901f18d5248e311b50b6e8011ad45182fd645b3e Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 20 Dec 2013 11:29:03 +0000
Subject: [PATCH] More code cleanups
---
opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java | 41 +++++-----
opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java | 84 ++++++++-------------
opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java | 72 ++++++-----------
3 files changed, 79 insertions(+), 118 deletions(-)
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
index 117309c..b3c75db 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -753,11 +753,10 @@
if (search.getResultCode() != ResultCode.SUCCESS
&& search.getResultCode() != ResultCode.NO_SUCH_OBJECT)
{
- Message message = ERR_SEARCHING_GENERATION_ID.get(
+ logError(ERR_SEARCHING_GENERATION_ID.get(
search.getResultCode().getResultCodeName() + " " +
search.getErrorMessage(),
- getBaseDNString());
- logError(message);
+ getBaseDNString()));
return false;
}
@@ -807,10 +806,9 @@
}
if (attr.size() > 1)
{
- Message message = ERR_LOADING_GENERATION_ID.get(getBaseDNString(),
+ logError(ERR_LOADING_GENERATION_ID.get(getBaseDNString(),
"#Values=" + attr.size() + " Must be exactly 1 in entry "
- + resultEntry.toLDIFString());
- logError(message);
+ + resultEntry.toLDIFString()));
}
}
}
@@ -2109,9 +2107,8 @@
}
catch (NoSuchElementException e)
{
- Message message = ERR_OPERATION_NOT_FOUND_IN_PENDING.get(
- op.toString(), curCSN.toString());
- logError(message);
+ logError(ERR_OPERATION_NOT_FOUND_IN_PENDING.get(
+ op.toString(), curCSN.toString()));
return;
}
}
@@ -2128,9 +2125,7 @@
* It should never happen.
*/
pendingChanges.remove(curCSN);
- Message message =
- ERR_UNKNOWN_TYPE.get(op.getOperationType().toString());
- logError(message);
+ logError(ERR_UNKNOWN_TYPE.get(op.getOperationType().toString()));
return;
}
@@ -2154,11 +2149,10 @@
{
// will be caught at publish time.
}
- catch (NoSuchElementException e)
+ catch (NoSuchElementException e)
{
- Message message = ERR_OPERATION_NOT_FOUND_IN_PENDING.get(
- op.toString(), curCSN.toString());
- logError(message);
+ logError(ERR_OPERATION_NOT_FOUND_IN_PENDING.get(
+ op.toString(), curCSN.toString()));
return;
}
// If assured replication is enabled, this will wait for the matching
@@ -2169,11 +2163,9 @@
waitForAckIfAssuredEnabled(msg);
} catch (TimeoutException ex)
{
- // This exception may only be raised if assured replication is
- // enabled
- Message errorMsg = NOTE_DS_ACK_TIMEOUT.get(getBaseDNString(),
- Long.toString(getAssuredTimeout()), msg.toString());
- logError(errorMsg);
+ // This exception may only be raised if assured replication is enabled
+ logError(NOTE_DS_ACK_TIMEOUT.get(getBaseDNString(),
+ Long.toString(getAssuredTimeout()), msg.toString()));
}
}
@@ -2274,9 +2266,8 @@
ResultCode res = newOp.getResultCode();
if (res != ResultCode.SUCCESS)
{
- Message message =
- ERR_COULD_NOT_SOLVE_CONFLICT.get(entryDN.toString(), res.toString());
- logError(message);
+ logError(ERR_COULD_NOT_SOLVE_CONFLICT.get(
+ entryDN.toString(), res.toString()));
}
}
}
@@ -2804,10 +2795,9 @@
{
// The other type of errors can not be caused by naming conflicts.
// Log a message for the repair tool.
- Message message = ERR_ERROR_REPLAYING_OPERATION.get(
+ logError(ERR_ERROR_REPLAYING_OPERATION.get(
op.toString(), ctx.getCSN().toString(),
- result.toString(), op.getErrorMessage().toString());
- logError(message);
+ result.toString(), op.getErrorMessage().toString()));
return true;
}
}
@@ -2874,10 +2864,9 @@
{
// The other type of errors can not be caused by naming conflicts.
// Log a message for the repair tool.
- Message message = ERR_ERROR_REPLAYING_OPERATION.get(
+ logError(ERR_ERROR_REPLAYING_OPERATION.get(
op.toString(), ctx.getCSN().toString(),
- result.toString(), op.getErrorMessage().toString());
- logError(message);
+ result.toString(), op.getErrorMessage().toString()));
return true;
}
}
@@ -2995,10 +2984,9 @@
{
// The other type of errors can not be caused by naming conflicts.
// Log a message for the repair tool.
- Message message = ERR_ERROR_REPLAYING_OPERATION.get(
+ logError(ERR_ERROR_REPLAYING_OPERATION.get(
op.toString(), ctx.getCSN().toString(),
- result.toString(), op.getErrorMessage().toString());
- logError(message);
+ result.toString(), op.getErrorMessage().toString()));
return true;
}
}
@@ -3094,10 +3082,9 @@
{
// The other type of errors can not be caused by naming conflicts.
// log a message for the repair tool.
- Message message = ERR_ERROR_REPLAYING_OPERATION.get(
+ logError(ERR_ERROR_REPLAYING_OPERATION.get(
op.toString(), ctx.getCSN().toString(),
- result.toString(), op.getErrorMessage().toString());
- logError(message);
+ result.toString(), op.getErrorMessage().toString()));
return true;
}
}
@@ -3544,12 +3531,11 @@
if (search.getResultCode() != ResultCode.SUCCESS)
{
if (search.getResultCode() != ResultCode.NO_SUCH_OBJECT)
- { // This is an error.
- Message message = ERR_SEARCHING_GENERATION_ID.get(
+ {
+ logError(ERR_SEARCHING_GENERATION_ID.get(
search.getResultCode().getResultCodeName() + " " +
search.getErrorMessage(),
- getBaseDNString());
- logError(message);
+ getBaseDNString()));
}
}
else
@@ -3567,14 +3553,13 @@
Attribute attr = attrs.get(0);
if (attr.size()>1)
{
- Message message = ERR_LOADING_GENERATION_ID.get(
+ logError(ERR_LOADING_GENERATION_ID.get(
getBaseDNString(), "#Values=" + attr.size() +
- " Must be exactly 1 in entry " + resultEntry.toLDIFString());
- logError(message);
+ " Must be exactly 1 in entry " + resultEntry.toLDIFString()));
}
else if (attr.size() == 1)
{
- found=true;
+ found = true;
try
{
aGenerationId = Long.decode(attr.iterator().next().toString());
@@ -4260,18 +4245,13 @@
/** {@inheritDoc} */
@Override
- public void sessionInitiated(
- ServerStatus initStatus,
- ServerState replicationServerState,
- long generationID,
- Session session)
+ public void sessionInitiated(ServerStatus initStatus, ServerState rsState)
{
// Check domain fractional configuration consistency with local
// configuration variables
forceBadDataSet = !isBackendFractionalConfigConsistent();
- super.sessionInitiated(
- initStatus, replicationServerState,generationID, session);
+ super.sessionInitiated(initStatus, rsState);
// Now that we are connected , we can enable ECL if :
// 1/ RS must in the same JVM and created an ECL_WORKFLOW_ELEMENT
@@ -4314,7 +4294,7 @@
* Check that the ReplicationServer has seen all our previous
* changes.
*/
- CSN replServerMaxCSN = replicationServerState.getCSN(getServerId());
+ CSN replServerMaxCSN = rsState.getCSN(getServerId());
// we don't want to update from here (a DS) an empty RS because
// normally the RS should have been updated by other RSes except for
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java b/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
index 3e464a0..c1e4c4f 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationBroker.java
@@ -162,7 +162,7 @@
/**
* String reported under CSN=monitor when there is no connected RS.
*/
- public final static String NO_CONNECTED_SERVER = "Not connected";
+ public static final String NO_CONNECTED_SERVER = "Not connected";
private final ServerState state;
private Semaphore sendWindow;
private int maxSendWindow;
@@ -1020,8 +1020,7 @@
if (domain != null)
{
- domain.sessionInitiated(initStatus, rsInfo.getServerState(),
- rsInfo.getGenerationId(), rs.session);
+ domain.sessionInitiated(initStatus, rsInfo.getServerState());
}
final byte groupId = getGroupId();
@@ -1500,13 +1499,11 @@
@Override
public String toString()
{
- return new StringBuilder()
- .append("Current best replication server Ids: ").append(
- this.bestRSs.keySet()).append(
- ", Evaluation of connected replication servers").append(
- " (ServerId => Evaluation): ").append(this.rsEvals.keySet())
- .append(", Any replication server not appearing here").append(
- " could not be contacted.").toString();
+ return "Current best replication server Ids: " + bestRSs.keySet()
+ + ", Evaluation of connected replication servers"
+ + " (ServerId => Evaluation): " + rsEvals.keySet()
+ + ", Any replication server not appearing here"
+ + " could not be contacted.";
}
}
@@ -2166,16 +2163,8 @@
arrived on the new RS. But we should disconnect if we reach the
perfect balance (both values are 0).
*/
- MathContext roundMc = new MathContext(6, RoundingMode.DOWN);
- BigDecimal potentialCurrentRsNewLoadDistanceBdRounded =
- potentialCurrentRsNewLoadDistanceBd.round(roundMc);
- BigDecimal potentialNewSumOfLoadDistancesOfOtherRSsBdRounded =
- potentialNewSumOfLoadDistancesOfOtherRSsBd.round(roundMc);
-
- if ((potentialCurrentRsNewLoadDistanceBdRounded.compareTo(
- BigDecimal.ZERO) != 0)
- && (potentialCurrentRsNewLoadDistanceBdRounded.equals(
- potentialNewSumOfLoadDistancesOfOtherRSsBdRounded.negate())))
+ if (mustAvoidYoyoEffect(potentialCurrentRsNewLoadDistanceBd,
+ potentialNewSumOfLoadDistancesOfOtherRSsBd))
{
// Avoid the yoyo effect, and keep the local DS connected to its
// current RS
@@ -2219,6 +2208,18 @@
}
}
+ private static boolean mustAvoidYoyoEffect(BigDecimal rsNewLoadDistance,
+ BigDecimal otherRSsNewSumOfLoadDistances)
+ {
+ final MathContext roundCtx = new MathContext(6, RoundingMode.DOWN);
+ final BigDecimal rsLoadDistance = rsNewLoadDistance.round(roundCtx);
+ final BigDecimal otherRSsSumOfLoadDistances =
+ otherRSsNewSumOfLoadDistances.round(roundCtx);
+
+ return rsLoadDistance.compareTo(BigDecimal.ZERO) != 0
+ && rsLoadDistance.compareTo(otherRSsSumOfLoadDistances.negate()) == 0;
+ }
+
/**
* Returns whether the local DS is overloading the RS.
* <p>
diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java b/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
index 4afa94d..ae0a284 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/service/ReplicationDomain.java
@@ -379,31 +379,23 @@
* that don't need to perform additional computing.
*
* @param initStatus The status to enter the state machine with.
- * @param replicationServerState The ServerState of the ReplicationServer
+ * @param rsState The ServerState of the ReplicationServer
* with which the session was established.
- * @param generationID The current generationID of the
- * ReplicationServer with which the session
- * was established.
- * @param session The Session that is currently used.
*/
- public void sessionInitiated(
- ServerStatus initStatus,
- ServerState replicationServerState,
- long generationID,
- Session session)
+ public void sessionInitiated(ServerStatus initStatus, ServerState rsState)
{
// Sanity check: is it a valid initial status?
if (!isValidInitialStatus(initStatus))
{
- Message msg = ERR_DS_INVALID_INIT_STATUS.get(initStatus.toString(),
- getBaseDNString(), Integer.toString(serverID));
- logError(msg);
- } else
+ logError(ERR_DS_INVALID_INIT_STATUS.get(initStatus.toString(),
+ getBaseDNString(), Integer.toString(serverID)));
+ }
+ else
{
status = initStatus;
}
generator.adjust(state);
- generator.adjust(replicationServerState);
+ generator.adjust(rsState);
}
/**
@@ -424,9 +416,8 @@
StatusMachineEvent event = StatusMachineEvent.statusToEvent(reqStatus);
if (event == StatusMachineEvent.INVALID_EVENT)
{
- Message msg = ERR_DS_INVALID_REQUESTED_STATUS.get(reqStatus.toString(),
- getBaseDNString(), Integer.toString(serverID));
- logError(msg);
+ logError(ERR_DS_INVALID_REQUESTED_STATUS.get(reqStatus.toString(),
+ getBaseDNString(), Integer.toString(serverID)));
return;
}
@@ -958,10 +949,9 @@
Some problems detected: message did not correctly reach every
requested servers. Log problem
*/
- Message errorMsg = NOTE_DS_RECEIVED_ACK_ERROR.get(
+ logError(NOTE_DS_RECEIVED_ACK_ERROR.get(
getBaseDNString(), Integer.toString(serverID),
- update.toString(), ack.errorsToString());
- logError(errorMsg);
+ update.toString(), ack.errorsToString()));
List<Integer> failedServers = ack.getFailedServers();
@@ -1428,9 +1418,8 @@
if (serverToInitialize == RoutableMsg.ALL_SERVERS)
{
- Message msg = NOTE_FULL_UPDATE_ENGAGED_FOR_REMOTE_START_ALL.get(
- countEntries(), getBaseDNString(), serverID);
- logError(msg);
+ logError(NOTE_FULL_UPDATE_ENGAGED_FOR_REMOTE_START_ALL.get(
+ countEntries(), getBaseDNString(), serverID));
for (DSInfo dsi : getReplicasList())
{
@@ -1448,9 +1437,8 @@
}
else
{
- Message msg = NOTE_FULL_UPDATE_ENGAGED_FOR_REMOTE_START.get(
- countEntries(), getBaseDNString(), serverID, serverToInitialize);
- logError(msg);
+ logError(NOTE_FULL_UPDATE_ENGAGED_FOR_REMOTE_START.get(
+ countEntries(), getBaseDNString(), serverID, serverToInitialize));
ieContext.startList.add(serverToInitialize);
@@ -2294,9 +2282,8 @@
try
{
// Log starting
- Message msg = NOTE_FULL_UPDATE_ENGAGED_FROM_REMOTE_START.get(
- getBaseDNString(), initTargetMsgReceived.getSenderID(), serverID);
- logError(msg);
+ logError(NOTE_FULL_UPDATE_ENGAGED_FROM_REMOTE_START.get(
+ getBaseDNString(), initTargetMsgReceived.getSenderID(), serverID));
// Go into full update status
setNewStatus(StatusMachineEvent.TO_FULL_UPDATE_STATUS_EVENT);
@@ -2468,14 +2455,11 @@
*/
protected void setNewStatus(StatusMachineEvent event)
{
- ServerStatus newStatus =
- StatusMachine.computeNewStatus(status, event);
-
+ ServerStatus newStatus = StatusMachine.computeNewStatus(status, event);
if (newStatus == ServerStatus.INVALID_STATUS)
{
- Message msg = ERR_DS_CANNOT_CHANGE_STATUS.get(getBaseDNString(),
- Integer.toString(serverID), status.toString(), event.toString());
- logError(msg);
+ logError(ERR_DS_CANNOT_CHANGE_STATUS.get(getBaseDNString(),
+ Integer.toString(serverID), status.toString(), event.toString()));
return;
}
@@ -3251,10 +3235,8 @@
}
else if (assuredMode != AssuredMode.SAFE_DATA_MODE)
{
- Message errorMsg =
- ERR_DS_UNKNOWN_ASSURED_MODE.get(Integer.toString(serverID),
- msgAssuredMode.toString(), getBaseDNString(), msg.toString());
- logError(errorMsg);
+ logError(ERR_DS_UNKNOWN_ASSURED_MODE.get(Integer.toString(serverID),
+ msgAssuredMode.toString(), getBaseDNString(), msg.toString()));
}
// Nothing to do in Assured safe data mode, only RS ack updates.
}
@@ -3455,17 +3437,15 @@
try
{
/*
- If assured replication is enabled, this will wait for the matching
- ack or time out. If assured replication is disabled, this returns
- immediately
+ If assured replication is enabled, this will wait for the matching ack or
+ time out. If assured replication is disabled, this returns immediately
*/
waitForAckIfAssuredEnabled(update);
} catch (TimeoutException ex)
{
// This exception may only be raised if assured replication is enabled
- Message errorMsg = NOTE_DS_ACK_TIMEOUT.get(getBaseDNString(),
- Long.toString(assuredTimeout), update.toString());
- logError(errorMsg);
+ logError(NOTE_DS_ACK_TIMEOUT.get(getBaseDNString(),
+ Long.toString(assuredTimeout), update.toString()));
}
}
--
Gitblit v1.10.0