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

pgamba
02.08.2007 4cee71bfa980931c4c74f29f8cea8e53b3b96480
Fix for #2356 - Unexpected generation ID error when replication enabled over empty suffix
2 files modified
84 ■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ReplicationDomain.java 18 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/GenerationIdTest.java 66 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/replication/plugin/ReplicationDomain.java
@@ -179,7 +179,9 @@
  private int maxSendQueue = 0;
  private int maxReceiveDelay = 0;
  private int maxSendDelay = 0;
  private long generationId = -1;
  private boolean generationIdSavedStatus = false;
  private long rejectedGenerationId = -1;
  private boolean requestedResetSinceLastStart = false;
@@ -1049,6 +1051,11 @@
          waitingAckMsgs.put(curChangeNumber, msg);
        }
      }
      if (generationIdSavedStatus != true)
      {
        this.saveGenerationId(generationId);
      }
    }
    else if (!op.isSynchronizationOperation())
    {
@@ -2344,7 +2351,10 @@
    op.run();
    ResultCode result = op.getResultCode();
    if ((result != ResultCode.SUCCESS) && (result != ResultCode.NO_SUCH_OBJECT))
    if (result != ResultCode.SUCCESS)
    {
      generationIdSavedStatus = false;
      if (result != ResultCode.NO_SUCH_OBJECT)
    {
      // The case where the backend is empty (NO_SUCH_OBJECT)
      // is not an error case.
@@ -2354,6 +2364,11 @@
                          baseDN.toString());
      logError(message);
    }
    }
    else
    {
      generationIdSavedStatus = true;
    }
    return result;
  }
@@ -2463,6 +2478,7 @@
    }
    else
    {
      generationIdSavedStatus = true;
      if (debugEnabled())
        TRACER.debugInfo(
            "Generation ID successfully read from domain base DN=" + baseDN +
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/replication/GenerationIdTest.java
@@ -454,7 +454,7 @@
   * replication Server ID.
   * @param changelogID
   */
  private void connectToReplServer(short changelogID)
  private void connectServer1ToChangelog(short changelogID)
  {
    // Connect DS to the replicationServer
    try
@@ -464,10 +464,10 @@
      String synchroServerLdif =
        "dn: cn=" + baseSnStr + ", cn=domains," + synchroServerStringDN + "\n"
        + "objectClass: top\n"
        + "objectClass: ds-cfg-synchronization-provider-config\n"
        + "objectClass: ds-cfg-replication-domain\n"
        + "cn: " + baseSnStr + "\n"
        + "ds-cfg-base-dn: " + baseDnStr + "\n"
        + "ds-cfg-changelog-server: localhost:"
        + "ds-cfg-replication-server: localhost:"
        + getChangelogPort(changelogID)+"\n"
        + "ds-cfg-server-id: " + server1ID + "\n"
        + "ds-cfg-receive-status: true\n"
@@ -720,7 +720,7 @@
      // Connect DS to RS with no data
      // Read generationId - should be not retrievable since no entry
      debugInfo(testCase + " Connecting DS1 to replServer1(" + changelog1ID + ")");
      connectToReplServer(changelog1ID);
      connectServer1ToChangelog(changelog1ID);
      Thread.sleep(1000);
      debugInfo(testCase + " Expect genId attribute to be not retrievable");
@@ -744,7 +744,7 @@
      // Test that generation has been added to the data.
      debugInfo(testCase + " add test entries to DS");
      this.addTestEntriesToDB(updatedEntries);
      connectToReplServer(changelog1ID);
      connectServer1ToChangelog(changelog1ID);
      // Test that the generationId is written in the DB in the
      // root entry on the replica side
@@ -1060,7 +1060,7 @@
    Thread.sleep(500);
    debugInfo("Connecting DS to replServer1");
    connectToReplServer(changelog1ID);
    connectServer1ToChangelog(changelog1ID);
    Thread.sleep(1500);
    debugInfo("Expect genId are set in all replServers.");
@@ -1082,7 +1082,7 @@
    this.addTestEntriesToDB(updatedEntries);
    debugInfo("Connecting DS to replServer2");
    connectToReplServer(changelog2ID);
    connectServer1ToChangelog(changelog2ID);
    Thread.sleep(1000);
    debugInfo("Expect genIds to be set in all servers based on the added entries.");
@@ -1141,7 +1141,7 @@
        " Expected entries :" + updatedEntries.length);
    debugInfo("Connecting DS to replServer1.");
    connectToReplServer(changelog1ID);
    connectServer1ToChangelog(changelog1ID);
    Thread.sleep(1000);
@@ -1215,4 +1215,54 @@
    }
    catch (Exception e) {}
  }
  /**
   * Test generationID saving when the root entry does not exist
   * at the moement when the replication is enabled.
   * @throws Exception
   */
  @Test(enabled=true)
  public void testServerStop() throws Exception
  {
    String testCase = "testServerStop";
    debugInfo("Starting "+ testCase + " debugEnabled:" + debugEnabled());
    debugInfo(testCase + " Clearing DS1 backend");
    ReplicationDomain.clearJEBackend(false,
        "userRoot",
        baseDn.toNormalizedString());
    try
    {
      long genId;
      replServer1 = createReplicationServer(changelog1ID, false, testCase);
      /*
       * Test  : empty replicated backend
       * Check : nothing is broken - no generationId generated
       */
      // Connect DS to RS with no data
      // Read generationId - should be not retrievable since no entry
      debugInfo(testCase + " Connecting DS1 to replServer1(" + changelog1ID + ")");
      connectServer1ToChangelog(changelog1ID);
      Thread.sleep(1000);
      debugInfo(testCase + " Expect genId attribute to be not retrievable");
      genId = readGenId();
      assertEquals(genId,-1);
      this.addTestEntriesToDB(updatedEntries);
      debugInfo(testCase + " Expect genId attribute to be retrievable");
      genId = readGenId();
      assertEquals(genId, 3211313L);
    }
    finally
    {
      postTest();
      debugInfo("Successfully ending " + testCase);
    }
  }
}