mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Ludovic Poitou
19.02.2013 f26886f60c623cdfc477e0855a9f8ddd43fbbeeb
Simplify via refactoring the processing within LDAPReplicationDomain's synchronize(PostOperationOperation op) method. 
Reviewed by JN, CR-2193.
1 files modified
84 ■■■■■ changed files
opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java 84 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/plugin/LDAPReplicationDomain.java
@@ -533,14 +533,8 @@
     * This has no negative impact because the changes on schema should
     * not produce conflicts.
     */
    if (baseDn.compareTo(DirectoryServer.getSchemaDN()) == 0)
    {
      solveConflictFlag = false;
    }
    else
    {
      solveConflictFlag = configuration.isSolveConflicts();
    }
    solveConflictFlag = configuration.isSolveConflicts()
        && !baseDn.equals(DirectoryServer.getSchemaDN());
    Backend backend = retrievesBackend(baseDn);
    if (backend == null)
@@ -2229,12 +2223,6 @@
  public void synchronize(PostOperationOperation op)
  {
    ResultCode result = op.getResultCode();
    if ((result == ResultCode.SUCCESS) && op.isSynchronizationOperation())
    {
      numReplayedPostOpCalled++;
    }
    LDAPUpdateMsg msg = null;
    // Note that a failed non-replication operation might not have a change
    // number.
    ChangeNumber curChangeNumber = OperationContext.getChangeNumber(op);
@@ -2244,11 +2232,28 @@
          "replicationCN", curChangeNumber));
    }
    if ((result == ResultCode.SUCCESS) && (!op.isSynchronizationOperation()))
    if (result == ResultCode.SUCCESS)
    {
      if (op.isSynchronizationOperation())
      { // Replaying a sync operation
        numReplayedPostOpCalled++;
        try
        {
          remotePendingChanges.commit(curChangeNumber);
        }
        catch  (NoSuchElementException e)
        {
          Message message = ERR_OPERATION_NOT_FOUND_IN_PENDING.get(
              op.toString(), curChangeNumber.toString());
          logError(message);
          return;
        }
      }
      else
    {
      // Generate a replication message for a successful non-replication
      // operation.
      msg = LDAPUpdateMsg.generateMsg(op);
        LDAPUpdateMsg msg = LDAPUpdateMsg.generateMsg(op);
      if (msg == null)
      {
@@ -2262,18 +2267,7 @@
        logError(message);
        return;
      }
    }
    if (result == ResultCode.SUCCESS)
    {
      try
      {
        if (op.isSynchronizationOperation())
        {
          remotePendingChanges.commit(curChangeNumber);
        }
        else
        {
          try
          {
            addEntryAttributesForCL(msg,op);
@@ -2289,13 +2283,11 @@
          try
          {
            msg.encode();
          pendingChanges.commitAndPushCommittedChanges(curChangeNumber, msg);
          } catch (UnsupportedEncodingException e)
          {
            // will be caught at publish time.
          }
          pendingChanges.commitAndPushCommittedChanges(curChangeNumber, msg);
        }
      }
      catch  (NoSuchElementException e)
      {
        Message message = ERR_OPERATION_NOT_FOUND_IN_PENDING.get(
@@ -2303,24 +2295,6 @@
        logError(message);
        return;
      }
      // If the operation is a DELETE on the base entry of the suffix
      // that is replicated, the generation is now lost because the
      // DB is empty. We need to save it again the next time we add an entry.
      if ((op.getOperationType().equals(OperationType.DELETE))
          && (((PostOperationDeleteOperation) op).getEntryDN().equals(baseDn)))
      {
        generationIdSavedStatus = false;
      }
      if (!generationIdSavedStatus)
      {
        this.saveGenerationId(generationId);
      }
      if (!op.isSynchronizationOperation())
      {
        // If assured replication is enabled, this will wait for the matching
        // ack or time out. If assured replication is disabled, this returns
        // immediately
@@ -2336,6 +2310,20 @@
          logError(errorMsg);
        }
      }
      // If the operation is a DELETE on the base entry of the suffix
      // that is replicated, the generation is now lost because the
      // DB is empty. We need to save it again the next time we add an entry.
      if ((op.getOperationType().equals(OperationType.DELETE))
          && (((PostOperationDeleteOperation) op).getEntryDN().equals(baseDn)))
      {
        generationIdSavedStatus = false;
      }
      if (!generationIdSavedStatus)
      {
        saveGenerationId(generationId);
      }
    }
    else if (!op.isSynchronizationOperation())
    {