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/JebFormat.java | 74 ++++++++++++++++++++++++++----------
1 files changed, 53 insertions(+), 21 deletions(-)
diff --git a/opends/src/server/org/opends/server/backends/jeb/JebFormat.java b/opends/src/server/org/opends/server/backends/jeb/JebFormat.java
index 2e133ae..934a70f 100644
--- a/opends/src/server/org/opends/server/backends/jeb/JebFormat.java
+++ b/opends/src/server/org/opends/server/backends/jeb/JebFormat.java
@@ -301,26 +301,47 @@
}
/**
+ * Decode an entry ID count from its database representation.
+ *
+ * @param bytes The database value of the entry ID count.
+ * @return The entry ID count.
+ */
+ public static long entryIDUndefinedSizeFromDatabase(byte[] bytes)
+ {
+ if(bytes == null)
+ {
+ return 0;
+ }
+
+ if(bytes.length == 8)
+ {
+ long v = 0;
+ v |= (bytes[0] & 0x7F);
+ for (int i = 1; i < 8; i++)
+ {
+ v <<= 8;
+ v |= (bytes[i] & 0xFF);
+ }
+ return v;
+ }
+ else
+ {
+ return Long.MAX_VALUE;
+ }
+ }
+
+ /**
* Decode an array of entry ID values from its database representation.
*
* @param bytes The raw database value, null if there is no value and
- * hence no entry IDs. Zero length means the index entry
- * limit has been exceeded.
+ * hence no entry IDs. Note that this method will throw an
+ * ArrayIndexOutOfBoundsException if the bytes array length is
+ * not a multiple of 8.
*
* @return An array of entry ID values.
*/
public static long[] entryIDListFromDatabase(byte[] bytes)
{
- if (bytes == null)
- {
- return new long[0];
- }
-
- if (bytes.length == 0)
- {
- return null;
- }
-
byte[] decodedBytes = bytes;
int count = decodedBytes.length / 8;
@@ -360,21 +381,32 @@
}
/**
+ * Encode an entry ID set count to its database representation.
+ * @param count The entry ID set count to be encoded.
+ * @return The encoded database value of the entry ID.
+ */
+ public static byte[] entryIDUndefinedSizeToDatabase(long count)
+ {
+ byte[] bytes = new byte[8];
+ long v = count;
+ for (int i = 7; i >= 1; i--)
+ {
+ bytes[i] = (byte) (v & 0xFF);
+ v >>>= 8;
+ }
+ bytes[0] = (byte) ((v | 0x80) & 0xFF);
+ return bytes;
+ }
+
+ /**
* Encode an array of entry ID values to its database representation.
*
- * @param entryIDArray An array of entry ID values. A null value indicates
- * that the entry limit is exceeded, and a zero length array indicates no
- * values.
+ * @param entryIDArray An array of entry ID values.
+ *
* @return The encoded database value.
*/
public static byte[] entryIDListToDatabase(long[] entryIDArray)
{
- if (entryIDArray == null)
- {
- // index entry limit exceeded
- return new byte[0];
- }
-
if (entryIDArray.length == 0)
{
// Zero values
--
Gitblit v1.10.0