From a72ae6523fc66a21ced5b5ab04c23e1629ae4d20 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Thu, 20 Dec 2007 17:45:49 +0000
Subject: [PATCH] Updated indexes to order the keys before inserting them into the database. This assures no deadlocks will occur between multiple adds and mods.  Disabled lock timeouts for add and mod operations since deadlocks can not occur. This prevents txn aborts and op retry expiration due to lock timeouts of add and mod operations when the server is under high write load. 

---
 opends/src/server/org/opends/server/backends/jeb/PresenceIndexer.java |   41 +++++++++++++++++++----------------------
 1 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/jeb/PresenceIndexer.java b/opends/src/server/org/opends/server/backends/jeb/PresenceIndexer.java
index c1fa5a6..c4af8c3 100644
--- a/opends/src/server/org/opends/server/backends/jeb/PresenceIndexer.java
+++ b/opends/src/server/org/opends/server/backends/jeb/PresenceIndexer.java
@@ -26,7 +26,6 @@
  */
 package org.opends.server.backends.jeb;
 
-import org.opends.server.protocols.asn1.ASN1OctetString;
 import org.opends.server.types.Attribute;
 import org.opends.server.types.Entry;
 import org.opends.server.types.Modification;
@@ -100,7 +99,7 @@
    * @throws DatabaseException If an error occurs in the JE database.
    */
   public void indexEntry(Transaction txn, Entry entry,
-                       Set<ASN1OctetString> keys) throws DatabaseException
+                       Set<byte[]> keys) throws DatabaseException
   {
     List<Attribute> attrList =
          entry.getAttribute(attributeType);
@@ -108,7 +107,7 @@
     {
       if (!attrList.isEmpty())
       {
-        keys.add(new ASN1OctetString(AttributeIndex.presenceKey.getData()));
+        keys.add(AttributeIndex.presenceKey.getData());
       }
     }
   }
@@ -128,25 +127,25 @@
    * @throws DatabaseException If an error occurs in the JE database.
    */
   public void replaceEntry(Transaction txn, Entry oldEntry, Entry newEntry,
-                           Set<ASN1OctetString> addKeys,
-                           Set<ASN1OctetString> delKeys)
-       throws DatabaseException
+                           Set<byte[]> addKeys,
+                           Set<byte[]> delKeys)
+      throws DatabaseException
   {
-    List<Attribute> beforeList, afterList;
-
-    beforeList = oldEntry.getAttribute(attributeType);
-    afterList = newEntry.getAttribute(attributeType);
-
-    if (beforeList == null || beforeList.isEmpty())
+    List<Attribute> newAttributes = newEntry.getAttribute(attributeType, true);
+    List<Attribute> oldAttributes = oldEntry.getAttribute(attributeType, true);
+    if(oldAttributes == null)
     {
-      if (afterList != null && !afterList.isEmpty())
+      if(newAttributes != null)
       {
-        addKeys.add(new ASN1OctetString(AttributeIndex.presenceKey.getData()));
+        addKeys.add(AttributeIndex.presenceKey.getData());
       }
     }
-    else if (afterList == null || afterList.isEmpty())
+    else
     {
-      delKeys.add(new ASN1OctetString(AttributeIndex.presenceKey.getData()));
+      if(newAttributes == null)
+      {
+        delKeys.add(AttributeIndex.presenceKey.getData());
+      }
     }
   }
 
@@ -167,8 +166,8 @@
    */
   public void modifyEntry(Transaction txn, Entry oldEntry, Entry newEntry,
                           List<Modification> mods,
-                          Set<ASN1OctetString> addKeys,
-                          Set<ASN1OctetString> delKeys)
+                          Set<byte[]> addKeys,
+                          Set<byte[]> delKeys)
        throws DatabaseException
   {
     List<Attribute> newAttributes = newEntry.getAttribute(attributeType, true);
@@ -177,16 +176,14 @@
     {
       if(newAttributes != null)
       {
-        addKeys.add(
-              new ASN1OctetString(AttributeIndex.presenceKey.getData()));
+        addKeys.add(AttributeIndex.presenceKey.getData());
       }
     }
     else
     {
       if(newAttributes == null)
       {
-        delKeys.add(
-              new ASN1OctetString(AttributeIndex.presenceKey.getData()));
+        delKeys.add(AttributeIndex.presenceKey.getData());
       }
     }
   }

--
Gitblit v1.10.0