From ffb9044301d1c169f934e0adf4f473e99da39a47 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Mon, 27 Aug 2007 18:58:10 +0000
Subject: [PATCH] This adds the numSubordinates and hasSubordinates operational attribute support in OpenDS.    - Implemented as virtual attributes    - They are enabled by default    - numSubordinates and hasSubordinates methods added to the backend API and implemented for all existing backends    - JE implementation uses the id2children index to keep count of the number of subordinates for each entry.    - The behavior of exceeding the index-entry-limit (ALL-IDs) has changed to store a 8 byte entry ID set count with the most significant bit  set to 1 instead of a 0 byte array to signify the index-entry-limit has been exceeded. The previous format is still compatible but all requests  for numSubordinates will return undefined (-1).    - The DBTest tool is also included in this fix. This can be used to list root containers, entry containers, database containers, index  status, as well as dumping a database with or without decoding the data. 

---
 opends/src/server/org/opends/server/backends/jeb/IndexMergeThread.java |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/jeb/IndexMergeThread.java b/opends/src/server/org/opends/server/backends/jeb/IndexMergeThread.java
index 2090df5..f4afb02 100644
--- a/opends/src/server/org/opends/server/backends/jeb/IndexMergeThread.java
+++ b/opends/src/server/org/opends/server/backends/jeb/IndexMergeThread.java
@@ -257,9 +257,32 @@
               if (index.read(txn, dbKey, dbData, LockMode.RMW) ==
                    OperationStatus.SUCCESS)
               {
-                if (dbData.getSize() == 0)
+                if (dbData.getSize() == 8 &&
+                    (dbData.getData()[0] & 0x80) == 0x80)
                 {
-                  // Entry limit already exceeded.
+                  // Entry limit already exceeded. Just update the
+                  // undefined size assuming no overlap will occur between
+                  // the add values and the longs in the DB.
+                  long undefinedSize =
+                   JebFormat.entryIDUndefinedSizeFromDatabase(dbData.getData());
+
+                  for(Longs l : addValues)
+                  {
+                    undefinedSize += l.size();
+                  }
+
+                  if(replaceExisting)
+                  {
+                    for(Longs l : delValues)
+                    {
+                      undefinedSize -= l.size();
+                    }
+                  }
+
+                  byte[] undefinedSizeBytes =
+                      JebFormat.entryIDUndefinedSizeToDatabase(undefinedSize);
+                  dbData.setData(undefinedSizeBytes);
+                  index.put(txn, dbKey, dbData);
                   break writeMergedValue;
                 }
                 merged.decode(dbData.getData());
@@ -281,7 +304,10 @@
 
             if (merged.size() > entryLimit)
             {
-              index.writeKey(txn, dbKey, new EntryIDSet());
+              byte[] undefinedSizeBytes =
+                  JebFormat.entryIDUndefinedSizeToDatabase(merged.size());
+              dbData.setData(undefinedSizeBytes);
+              index.put(txn, dbKey, dbData);
             }
             else
             {

--
Gitblit v1.10.0