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

Jean-Noel Rouvignac
01.44.2013 0cea62907aa1c9179e359bacccf0b2692ca01d46
OPENDJ-1116 Introduce abstraction for the changelog DB


Removed ReplicationServer.removeDb() + let the exceptions propagate up in ChangelogDB.shutdownDB() and ChangelogDB.removeDB().


ReplicationServer.java:
Removed removeDb(), instead use JEChangelogDB.removeDB().

ChangelogDB.java:
shutdownDB() and removeDB() can now throw ChangelogException.

JEChangelogDB.java:
shutdownCNIndexDB(), shutdownDB() and removeDB() can now throw ChangelogException + ensured code proceed till the end of the methods before throwing the first caught exception.
In removeDB(), called shutdownDB().

*Test[Case].java:
Allowed exceptions to propagate up, this will allow detecting issues in tests suite.
9 files modified
131 ■■■■■ changed files
opends/src/server/org/opends/server/replication/server/ReplicationServer.java 20 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/changelog/api/ChangelogDB.java 10 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java 71 ●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java 2 ●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java 20 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/FractionalReplicationTest.java 2 ●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ReplicationServerLoadBalancingTest.java 2 ●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/AssuredReplicationServerTest.java 2 ●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ExternalChangeLogTest.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -760,7 +760,17 @@
    shutdownECL();
    this.changelogDB.shutdownDB();
    try
    {
      this.changelogDB.shutdownDB();
    }
    catch (ChangelogException ignored)
    {
      if (debugEnabled())
      {
        TRACER.debugCaught(DebugLogLevel.WARNING, ignored);
      }
    }
    // Remove this instance from the global instance list
    allInstances.remove(this);
@@ -1106,14 +1116,6 @@
  }
  /**
   * Removes the changelog database directory.
   */
  public void removeDb()
  {
    this.changelogDB.removeDB();
  }
  /**
   * {@inheritDoc}
   */
  @Override
opends/src/server/org/opends/server/replication/server/changelog/api/ChangelogDB.java
@@ -80,13 +80,19 @@
  /**
   * Shutdown the replication database.
   *
   * @throws ChangelogException
   *           If a database problem happened
   */
  void shutdownDB();
  void shutdownDB() throws ChangelogException;
  /**
   * Removes the changelog database directory.
   *
   * @throws ChangelogException
   *           If a database problem happened
   */
  void removeDB();
  void removeDB() throws ChangelogException;
  /**
   * Returns the {@link ChangeNumberIndexDB} object.
opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java
@@ -264,45 +264,60 @@
    }
  }
  private void shutdownCNIndexDB()
  private void shutdownCNIndexDB() throws ChangelogException
  {
    synchronized (cnIndexDBLock)
    {
      if (cnIndexDB != null)
      {
        try
        {
          cnIndexDB.shutdown();
        }
        catch (ChangelogException ignored)
        {
          if (debugEnabled())
          {
            TRACER.debugCaught(DebugLogLevel.WARNING, ignored);
          }
        }
        cnIndexDB.shutdown();
      }
    }
  }
  /** {@inheritDoc} */
  @Override
  public void shutdownDB()
  public void shutdownDB() throws ChangelogException
  {
    shutdownCNIndexDB();
    // Remember the first exception because :
    // - we want to try to remove everything we want to remove
    // - then throw the first encountered exception
    ChangelogException firstException = null;
    try
    {
      shutdownCNIndexDB();
    }
    catch (ChangelogException e)
    {
      firstException = e;
    }
    if (dbEnv != null)
    {
      dbEnv.shutdown();
    }
    if (firstException != null)
    {
      throw firstException;
    }
  }
  /**
   * Clears all content from the changelog database, but leaves its directory on
   * the filesystem.
   *
   * @throws ChangelogException
   *           If a database problem happened
   */
  public void clearDB()
  public void clearDB() throws ChangelogException
  {
    // Remember the first exception because :
    // - we want to try to remove everything we want to remove
    // - then throw the first encountered exception
    ChangelogException firstException = null;
    for (DN baseDN : this.sourceDbHandlers.keySet())
    {
      removeDomain(baseDN);
@@ -316,26 +331,40 @@
        {
          cnIndexDB.clear();
        }
        catch (Exception ignored)
        catch (ChangelogException e)
        {
          if (debugEnabled())
          firstException = e;
        }
        try
        {
          shutdownCNIndexDB();
        }
        catch (ChangelogException e)
        {
          if (firstException == null)
          {
            TRACER.debugCaught(DebugLogLevel.WARNING, ignored);
            firstException = e;
          }
        }
        shutdownCNIndexDB();
        cnIndexDB = null;
      }
    }
    if (firstException != null)
    {
      throw firstException;
    }
  }
  /** {@inheritDoc} */
  @Override
  public void removeDB()
  public void removeDB() throws ChangelogException
  {
    StaticUtils.recursiveDelete(dbDirectory);
    // there is no point in keeping the DB open after it has been removed
    shutdownDB();
  }
  /** {@inheritDoc} */
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/InitOnLineTest.java
@@ -1443,7 +1443,7 @@
   * Disconnect broker and remove entries from the local DB
   * @param testCase The name of the test case.
   */
  private void afterTest(String testCase)
  private void afterTest(String testCase) throws Exception
  {
    // Check that the domain has completed the import/export task.
    if (replDomain != null)
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/ReplicationTestCase.java
@@ -464,7 +464,7 @@
    assertEquals(DirectoryServer.getBackend("replicationChanges"), null, "Replication changes backend object has been left");
  }
  protected void clearChangelogDB(ReplicationServer rs)
  protected void clearChangelogDB(ReplicationServer rs) throws Exception
  {
    ((JEChangelogDB) rs.getChangelogDB()).clearDB();
  }
@@ -473,8 +473,10 @@
   * Cleanup databases of the currently instantiated replication servers in the
   * VM
   */
  protected void cleanUpReplicationServersDB() {
    for (ReplicationServer rs : ReplicationServer.getAllInstances()) {
  protected void cleanUpReplicationServersDB() throws Exception
  {
    for (ReplicationServer rs : ReplicationServer.getAllInstances())
    {
      clearChangelogDB(rs);
    }
  }
@@ -483,21 +485,23 @@
   * Remove trailing directories and databases of the currently instantiated
   * replication servers.
   */
  protected void removeReplicationServerDB() {
    for (ReplicationServer rs : ReplicationServer.getAllInstances()) {
  protected void removeReplicationServerDB() throws Exception
  {
    for (ReplicationServer rs : ReplicationServer.getAllInstances())
    {
      clearChangelogDB(rs);
      rs.removeDb();
      rs.getChangelogDB().removeDB();
    }
  }
  protected void remove(ReplicationServer... replicationServers)
  protected void remove(ReplicationServer... replicationServers) throws Exception
  {
    for (ReplicationServer rs : replicationServers)
    {
      if (rs != null)
      {
        rs.remove();
        rs.removeDb();
        rs.getChangelogDB().removeDB();
      }
    }
  }
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/FractionalReplicationTest.java
@@ -401,7 +401,7 @@
    gen = new CSNGenerator(DS2_ID, 0L);
  }
  private void endTest()
  private void endTest() throws Exception
  {
    if (replicationDomain != null)
    {
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/plugin/ReplicationServerLoadBalancingTest.java
@@ -766,7 +766,7 @@
    }
  }
  private void stopRs(int... rsIndexes)
  private void stopRs(int... rsIndexes) throws Exception
  {
    for (int rsIndex : rsIndexes)
    {
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/AssuredReplicationServerTest.java
@@ -201,7 +201,7 @@
    rs1 = rs2 = rs3 = rs4 = null;
  }
  private void endTest()
  private void endTest() throws Exception
  {
    disableService(fakeRDs);
    Arrays.fill(fakeRDs, null);
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/ExternalChangeLogTest.java
@@ -2069,7 +2069,7 @@
  }
  @AfterMethod
  public void clearReplicationDb()
  public void clearReplicationDb() throws Exception
  {
    clearChangelogDB(replicationServer);
  }