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

Jean-Noel Rouvignac
24.19.2013 225aaf491fb097f9ab165de1c4d24aaa68670784
OPENDJ-1116 Introduce abstraction for the changelog DB

Changed after review from Matt.

ChangelogDB.java:
Removed setReplicationDBDirectory(), now set in JEChangelogDB constructor.
Renamed getDBDirName() to getDBDirectoryName().
Improved javadocs.

JEChangelogDB.java:
Consequence of the changes to ChangelogDB.
Renamed dbDirName to dbDirectoryName.
Made 2 fields final.
Added makeDir().

ReplicationServer.java:
Consequence of the changes to ChangelogDB.
3 files modified
110 ■■■■ changed files
opends/src/server/org/opends/server/replication/server/ReplicationServer.java 10 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/changelog/api/ChangelogDB.java 25 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java 75 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -101,7 +101,7 @@
  private volatile boolean shutdown = false;
  private int rcvWindow;
  private int queueSize;
  private final ChangelogDB changelogDB = new JEChangelogDB(this);
  private final ChangelogDB changelogDB;
  /**
   * The delay (in sec) after which the changes must be deleted from the
@@ -221,8 +221,8 @@
    purgeDelay = configuration.getReplicationPurgeDelay();
    rcvWindow = configuration.getWindowSize();
    this.changelogDB.setReplicationDBDirectory(configuration
        .getReplicationDBDirectory());
    this.changelogDB =
        new JEChangelogDB(this, configuration.getReplicationDBDirectory());
    groupId = (byte)configuration.getGroupId();
    weight = configuration.getWeight();
@@ -973,7 +973,7 @@
    }
    final String newDir = configuration.getReplicationDBDirectory();
    if (newDir != null && !this.changelogDB.getDBDirName().equals(newDir))
    if (newDir != null && !this.changelogDB.getDBDirectoryName().equals(newDir))
    {
      return new ConfigChangeResult(ResultCode.SUCCESS, true);
    }
@@ -1744,7 +1744,7 @@
   */
  public String getDbDirName()
  {
    return this.changelogDB.getDBDirName();
    return this.changelogDB.getDBDirectoryName();
  }
  /**
opends/src/server/org/opends/server/replication/server/changelog/api/ChangelogDB.java
@@ -29,7 +29,6 @@
import java.util.Map;
import java.util.Set;
import org.opends.server.config.ConfigException;
import org.opends.server.replication.common.CSN;
import org.opends.server.replication.protocol.UpdateMsg;
import org.opends.server.types.DN;
@@ -52,31 +51,27 @@
  // DB control methods
  /**
   * Set the directory to be used by the replication database.
   *
   * @param dbDirName
   *          the directory for use by the replication database
   * @throws ConfigException
   *           if a problem occurs opening the directory
   */
  void setReplicationDBDirectory(String dbDirName) throws ConfigException;
  /**
   * Get the replication server database directory. This is used by tests to do
   * some cleanup.
   *
   * @return the database directory name
   */
  String getDBDirName();
  String getDBDirectoryName();
  /**
   * Initializes the replication database.
   * Initializes the replication database by reading its previous state and
   * building the relevant ReplicaDBs according to the previous state. This
   * method must be called once before using the ChangelogDB.
   */
  void initializeDB();
  /**
   * Sets the purge delay for the replication database. This purge delay is a
   * best effort.
   * Sets the purge delay for the replication database. Can be called while the
   * database is running.
   * <p>
   * Purging happens on a best effort basis, i.e. the purge delay is used by the
   * replication database to know which data can be purged, but there are no
   * guarantees on when the purging will actually happen.
   *
   * @param delayInMillis
   *          the purge delay in milliseconds
opends/src/server/org/opends/server/replication/server/changelog/je/JEChangelogDB.java
@@ -66,8 +66,8 @@
  private final Map<DN, Map<Integer, DbHandler>> sourceDbHandlers =
      new ConcurrentHashMap<DN, Map<Integer, DbHandler>>();
  private ReplicationDbEnv dbEnv;
  private String dbDirName = null;
  private File dbDirectory;
  private final String dbDirectoryName;
  private final File dbDirectory;
  /** The local replication server. */
  private final ReplicationServer replicationServer;
@@ -77,10 +77,40 @@
   *
   * @param replicationServer
   *          the local replication server.
   * @param dbDirName
   *          the directory for use by the replication database
   * @throws ConfigException
   *           if a problem occurs opening the supplied directory
   */
  public JEChangelogDB(ReplicationServer replicationServer)
  public JEChangelogDB(ReplicationServer replicationServer, String dbDirName)
      throws ConfigException
  {
    this.replicationServer = replicationServer;
    this.dbDirectoryName = dbDirName != null ? dbDirName : "changelogDb";
    this.dbDirectory = makeDir(this.dbDirectoryName);
  }
  private File makeDir(String dbDirName) throws ConfigException
  {
    // Check that this path exists or create it.
    File dbDirectory = getFileForPath(dbDirName);
    try
    {
      if (!dbDirectory.exists())
      {
        dbDirectory.mkdir();
      }
      return dbDirectory;
    }
    catch (Exception e)
    {
      MessageBuilder mb = new MessageBuilder();
      mb.append(e.getLocalizedMessage());
      mb.append(" ");
      mb.append(String.valueOf(dbDirectory));
      Message msg = ERR_FILE_CHECK_CREATE_FAILED.get(mb.toString());
      throw new ConfigException(msg, e);
    }
  }
  private Map<Integer, DbHandler> getDomainMap(DN baseDN)
@@ -146,8 +176,8 @@
  {
    try
    {
      dbEnv = new ReplicationDbEnv(getFileForPath(dbDirName).getAbsolutePath(),
          replicationServer);
      dbEnv = new ReplicationDbEnv(
          getFileForPath(dbDirectoryName).getAbsolutePath(), replicationServer);
      initializeChangelogState(dbEnv.readChangelogState());
    }
    catch (ChangelogException e)
@@ -369,40 +399,9 @@
  /** {@inheritDoc} */
  @Override
  public void setReplicationDBDirectory(String dbDirName)
      throws ConfigException
  public String getDBDirectoryName()
  {
    if (dbDirName == null)
    {
      dbDirName = "changelogDb";
    }
    this.dbDirName = dbDirName;
    // Check that this path exists or create it.
    dbDirectory = getFileForPath(this.dbDirName);
    try
    {
      if (!dbDirectory.exists())
      {
        dbDirectory.mkdir();
      }
    }
    catch (Exception e)
    {
      MessageBuilder mb = new MessageBuilder();
      mb.append(e.getLocalizedMessage());
      mb.append(" ");
      mb.append(String.valueOf(dbDirectory));
      Message msg = ERR_FILE_CHECK_CREATE_FAILED.get(mb.toString());
      throw new ConfigException(msg, e);
    }
  }
  /** {@inheritDoc} */
  @Override
  public String getDBDirName()
  {
    return this.dbDirName;
    return this.dbDirectoryName;
  }
  /** {@inheritDoc} */