From ea9e25490664445215eff3c88189d32d748ee2b6 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Fri, 18 Aug 2006 17:26:43 +0000
Subject: [PATCH] Removed the unnessary first byte in index keys. Updated all methods to remove the use of these prefix keys to iterate over a range of index keys. Index.readRange is modified to allow for unspecified lower and upper bounds so the search starts and ends at the smallest and/or biggest key respectively.
---
opends/src/server/org/opends/server/backends/jeb/Index.java | 51 +++++++++++++++++++++++++++++++++++++--------------
1 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/opends/src/server/org/opends/server/backends/jeb/Index.java b/opends/src/server/org/opends/server/backends/jeb/Index.java
index 3d77600..38be22d 100644
--- a/opends/src/server/org/opends/server/backends/jeb/Index.java
+++ b/opends/src/server/org/opends/server/backends/jeb/Index.java
@@ -368,14 +368,22 @@
* Reads a range of keys and collects all their entry IDs into a
* single set.
*
- * @param lower The lower bound of the range.
- * @param upper The upper bound of the range.
+ * @param lower The lower bound of the range. A 0 length byte array indicates
+ * no lower bound and the range will start from the
+ * smallest key.
+ * @param upper The upper bound of the range. A 0 length byte array indicates
+ * no upper bound and the range will end at the largest
+ * key.
* @param lowerIncluded true if a key exactly matching the lower bound
* is included in the range, false if only keys
* strictly greater than the lower bound are included.
+ * This value is ignored if the lower bound is not
+ * specified.
* @param upperIncluded true if a key exactly matching the upper bound
* is included in the range, false if only keys
* strictly less than the upper bound are included.
+ * This value is ignored if the upper bound is not
+ * specified.
* @return The set of entry IDs.
*/
public EntryIDSet readRange(byte[] lower, byte[] upper,
@@ -389,7 +397,7 @@
int totalIDCount = 0;
DatabaseEntry data = new DatabaseEntry();
- DatabaseEntry key = new DatabaseEntry(lower);
+ DatabaseEntry key;
ArrayList<EntryIDSet> lists = new ArrayList<EntryIDSet>();
@@ -400,14 +408,25 @@
try
{
- // Initialize the cursor to the lower bound.
- status = cursor.getSearchKeyRange(key, data, lockMode);
-
- // Advance past the lower bound if necessary.
- if (status == OperationStatus.SUCCESS && !lowerIncluded &&
- comparator.compare(key.getData(), lower) == 0)
+ // Set the lower bound if necessary.
+ if(lower.length > 0)
{
- // Do not include the lower value.
+ key = new DatabaseEntry(lower);
+
+ // Initialize the cursor to the lower bound.
+ status = cursor.getSearchKeyRange(key, data, lockMode);
+
+ // Advance past the lower bound if necessary.
+ if (status == OperationStatus.SUCCESS && !lowerIncluded &&
+ comparator.compare(key.getData(), lower) == 0)
+ {
+ // Do not include the lower value.
+ status = cursor.getNext(key, data, lockMode);
+ }
+ }
+ else
+ {
+ key = new DatabaseEntry();
status = cursor.getNext(key, data, lockMode);
}
@@ -417,13 +436,17 @@
return new EntryIDSet(key.getData(), null);
}
- // Step through the keys until we hit the upper bound.
+ // Step through the keys until we hit the upper bound or the last key.
while (status == OperationStatus.SUCCESS)
{
- int cmp = comparator.compare(key.getData(), upper);
- if ((cmp > 0) || (cmp == 0 && !upperIncluded))
+ // Check against the upper bound if necessary
+ if(upper.length > 0)
{
- break;
+ int cmp = comparator.compare(key.getData(), upper);
+ if ((cmp > 0) || (cmp == 0 && !upperIncluded))
+ {
+ break;
+ }
}
EntryIDSet list = new EntryIDSet(key.getData(), data.getData());
if (!list.isDefined())
--
Gitblit v1.10.0