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

pgamba
26.41.2009 7eaa7570dcac3c076380d3ad71bcb7f3ebfc0202
Fix #4359 ECL - draft mode: changenumber reset takes a long time
2 files modified
68 ■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/replication/server/DraftCNDbHandler.java 53 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServer.java 15 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/replication/server/DraftCNDbHandler.java
@@ -314,27 +314,62 @@
    if (trimage == 0)
      return;
    clear(null);
  }
  /**
   * Clear the changes from this DB (from both memory cache and DB storage)
   * for the provided serviceID.
   * @param serviceIDToClear The serviceID for which we want to remove the
   *         all records from the DraftCNDb.
   * @throws DatabaseException When an exception occurs while removing the
   * changes from the DB.
   * @throws Exception When an exception occurs while accessing a resource
   * from the DB.
   *
   */
  public void clear(String serviceIDToClear)
  throws DatabaseException, Exception
  {
    if (this.count()==0)
      return;
    int size = 0;
    int tries = 0;
    boolean finished = false;
    boolean done = false;
    DraftCNDBCursor cursor = db.openDeleteCursor();
    try
    {
      // In case of deadlock detection by the Database, this thread can
      // by aborted by a DeadlockException. This is a transient error and
      // the transaction should be attempted again.
      // We will try DEADLOCK_RETRIES times before failing.
      while ((tries++ < DEADLOCK_RETRIES) && (!done))
      {
      DraftCNDBCursor cursor = db.openDeleteCursor();
      try
      {
        while ((size < 5000 ) &&  (!finished))
        {
        // let's traverse the DraftCNDb
        if (!cursor.next())
          break;
        // Fomr the draftCNDb change record, get the domain and changeNumber
        String serviceID = cursor.currentServiceID();
          {
            finished=true;
          }
          else
          {
        ChangeNumber cn = cursor.currentChangeNumber();
            // From the draftCNDb change record, get the domain and changeNumber
            String serviceID = cursor.currentServiceID();
            if ((serviceIDToClear!=null) &&
                (serviceIDToClear.equalsIgnoreCase(serviceID)))
            {
              size++;
              cursor.delete();
              continue;
            }
        ReplicationServerDomain domain =
          replicationServer.getReplicationServerDomain(serviceID, false);
@@ -343,6 +378,7 @@
          // the domain has been removed since the record was written in the
          // draftCNDb, thus it makes no sense to keep the record in the
          // draftCNDb.
              size++;
          cursor.delete();
        }
        else
@@ -358,10 +394,12 @@
          //  of the domain, then it can be removed.
          if (cn.older(fcn)||cn.newer(lcn))
          {
                size++;
            cursor.delete();
          }
        }
      }
        }
      cursor.close();
      done = true;
    }
@@ -385,6 +423,7 @@
      throw (e);
    }
  }
  }
  /**
   * This internal class is used to implement the Monitoring capabilities
opendj-sdk/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -909,6 +909,21 @@
    try
    {
      dbEnv.clearGenerationId(baseDn);
      if (this.draftCNDbHandler != null)
      {
        try
        {
          try
          {
            draftCNDbHandler.clear(baseDn);
          }
          catch(Exception e){}
          lastGeneratedDraftCN = draftCNDbHandler.getLastKey();
        }
        catch(Exception e) {}
      }
    }
    catch(Exception e)
    {