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

Matthew Swift
23.51.2012 60eebeca51e75c9d3fdb0a82f0a5b5be6f64dd17
Fix OPENDJ-410: Frequent corruption in ds-sync-hist ordering index
3 files modified
80 ■■■■■ changed files
opends/src/messages/messages/replication.properties 4 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java 50 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/plugin/MultimasterReplication.java 26 ●●●●● patch | view | raw | blame | history
opends/src/messages/messages/replication.properties
@@ -21,7 +21,7 @@
# CDDL HEADER END
#
#      Copyright 2006-2010 Sun Microsystems, Inc.
#      Portions copyright 2011 ForgeRock AS
#      Portions copyright 2011-2012 ForgeRock AS
#
#
# This file contains the primary Directory Server configuration.  It must not
@@ -541,3 +541,5 @@
NOTICE_LOAD_BALANCE_REPLICATION_SERVER_213=Directory Server DS(%d) is disconnecting \
 from replication server RS(%d) at %s for domain "%s" in order to find another \
 replication server in the topology and distribute load more equally
SEVERE_WARN_INVALID_SYNC_HIST_VALUE_214=The attribute value '%s' is not a valid \
 synchronization history value
opends/src/server/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRule.java
@@ -23,15 +23,19 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.server.replication.plugin;
import static org.opends.messages.ReplicationMessages.*;
import static org.opends.server.util.StaticUtils.hexStringToByteArray;
import java.util.Collection;
import java.util.Collections;
import org.opends.server.api.AbstractMatchingRule;
import org.opends.server.api.OrderingMatchingRule;
import org.opends.server.types.ByteString;
import org.opends.server.types.ByteSequence;
import org.opends.server.types.*;
/**
 * Used to establish an order between historical information and index them.
@@ -122,30 +126,34 @@
  }
  /**
   * Normalize historical information representation.
   * @param value the value that must be normalized
   * @return The String form that must be used for historical information
   * comparison
   * {@inheritDoc}
   */
  @Override
  public ByteString normalizeValue(ByteSequence value)
      throws DirectoryException
  {
    String[] token = value.toString().split(":", 3);
    /* Change the format of the value to index and start
     * with the serverId. In that manner, the search response
     * time is optimised for a particulare serverId.
     * The format of the key is now :
     * serverId + timestamp + seqNum
    /*
     * Change the format of the value to index and start with the serverId. In
     * that manner, the search response time is optimised for a particular
     * serverId. The format of the key is now : serverId + timestamp + seqNum
     */
    String timestamp = token[1].substring(0,16);
    String serverId = token[1].substring(16,20);
    String seqNumber = token[1].substring(20, 28);
    if (MultimasterReplication.isLocalServerId(Integer.parseInt(serverId, 16)))
      return ByteString.valueOf(serverId + timestamp + seqNumber);
    else
      return (ByteString.valueOf("0"));
    try
    {
      int csnIndex = value.toString().indexOf(':') + 1;
      String csn = value.subSequence(csnIndex, csnIndex + 28).toString();
      ByteStringBuilder builder = new ByteStringBuilder(14);
      builder.append(hexStringToByteArray(csn.substring(16, 20)));
      builder.append(hexStringToByteArray(csn.substring(00, 16)));
      builder.append(hexStringToByteArray(csn.substring(20, 28)));
      return builder.toByteString();
    }
    catch (Exception e)
    {
      // This should never occur in practice since these attributes are managed
      // internally.
      throw new DirectoryException(ResultCode.INVALID_ATTRIBUTE_SYNTAX,
          WARN_INVALID_SYNC_HIST_VALUE.get(String.valueOf(value)), e);
    }
  }
  /**
opends/src/server/org/opends/server/replication/plugin/MultimasterReplication.java
@@ -23,7 +23,7 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 *      Portions Copyright 2011-2012 ForgeRock AS
 */
package org.opends.server.replication.plugin;
@@ -120,8 +120,6 @@
  private boolean isRegistered = false;
  private static boolean initializationCompleted = true;
  /**
   * The configurable connection/handshake timeout.
   */
@@ -276,7 +274,6 @@
      ReplicationSynchronizationProviderCfg configuration)
  throws ConfigException
  {
    initializationCompleted = false;
    domains.clear();
    replicationServerListener = new ReplicationServerListener(configuration);
@@ -318,8 +315,6 @@
    DirectoryServer.registerSupportedControl(
        ReplicationRepairRequestControl.OID_REPLICATION_REPAIR_CONTROL);
    initializationCompleted = true;
  }
  /**
@@ -874,25 +869,6 @@
  }
  /**
   * Checks if a given serverID is used by a local Replication Domain.
   *
   * @param serverId   The serverID that should be checked.
   * @return           true if the serverID is local, false otherwise.
   */
  public static boolean isLocalServerId(Integer serverId)
  {
    if (!initializationCompleted)
      return true;
    for (LDAPReplicationDomain domain : domains.values())
    {
      if (domain.getServerId() == serverId)
        return true;
    }
    return false;
  }
  /**
   * Returns the connection timeout in milli-seconds.
   *
   * @return The connection timeout in milli-seconds.