From 42fbf08eb02ea8464a6b03fc47b75ad400bed44f Mon Sep 17 00:00:00 2001
From: Yannick Lecaillez <yannick.lecaillez@forgerock.com>
Date: Mon, 16 Mar 2015 09:36:32 +0000
Subject: [PATCH] OPENDJ-1866: Make EntryIDSet more maintainable.
---
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Index.java | 75 ++++++++++++++++++++-----------------
1 files changed, 40 insertions(+), 35 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Index.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Index.java
index 8b5b7d8..a90edd3 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Index.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Index.java
@@ -26,7 +26,12 @@
*/
package org.opends.server.backends.pluggable;
-import static org.opends.messages.JebMessages.*;
+import static org.opends.messages.JebMessages.ERR_JEB_INDEX_CORRUPT_REQUIRES_REBUILD;
+import static org.opends.server.backends.pluggable.EntryIDSet.newDefinedSet;
+import static org.opends.server.backends.pluggable.EntryIDSet.newSetFromBytes;
+import static org.opends.server.backends.pluggable.EntryIDSet.newSetFromUnion;
+import static org.opends.server.backends.pluggable.EntryIDSet.newUndefinedSetWithSize;
+import static org.opends.server.backends.pluggable.EntryIDSet.newUndefinedSet;
import java.util.ArrayList;
import java.util.HashSet;
@@ -246,8 +251,8 @@
ByteString value = txn.read(getName(), key);
if (value != null)
{
- EntryIDSet entryIDList = new EntryIDSet(key, value);
- if (entryIDList.isDefined())
+ EntryIDSet entryIDSet = newSetFromBytes(key, value);
+ if (entryIDSet.isDefined())
{
updateKeyWithRMW(txn, key, deletedIDs, addedIDs);
} // else the record exists but we've hit all IDs.
@@ -285,8 +290,8 @@
final ByteString value = txn.getRMW(getName(), key);
if (value != null)
{
- EntryIDSet entryIDList = computeEntryIDList(key, value, deletedIDs, addedIDs);
- ByteString after = entryIDList.toByteString();
+ EntryIDSet entryIDSet = computeEntryIDList(key, value, deletedIDs, addedIDs);
+ ByteString after = entryIDSet.toByteString();
if (!after.isEmpty())
{
txn.create(getName(), key, after);
@@ -316,25 +321,25 @@
private EntryIDSet computeEntryIDList(ByteString key, ByteString value, EntryIDSet deletedIDs,
EntryIDSet addedIDs)
{
- EntryIDSet entryIDList = new EntryIDSet(key, value);
+ EntryIDSet entryIDSet = newSetFromBytes(key, value);
if(addedIDs != null)
{
- if(entryIDList.isDefined() && indexEntryLimit > 0)
+ if(entryIDSet.isDefined() && indexEntryLimit > 0)
{
long idCountDelta = addedIDs.size();
if(deletedIDs != null)
{
idCountDelta -= deletedIDs.size();
}
- if(idCountDelta + entryIDList.size() >= indexEntryLimit)
+ if(idCountDelta + entryIDSet.size() >= indexEntryLimit)
{
if(maintainCount)
{
- entryIDList = new EntryIDSet(entryIDList.size() + idCountDelta);
+ entryIDSet = newUndefinedSetWithSize(key, entryIDSet.size() + idCountDelta);
}
else
{
- entryIDList = new EntryIDSet();
+ entryIDSet = newUndefinedSet();
}
entryLimitExceededCount++;
@@ -350,27 +355,27 @@
}
else
{
- entryIDList.addAll(addedIDs);
+ entryIDSet.addAll(addedIDs);
if(deletedIDs != null)
{
- entryIDList.deleteAll(deletedIDs);
+ entryIDSet.removeAll(deletedIDs);
}
}
}
else
{
- entryIDList.addAll(addedIDs);
+ entryIDSet.addAll(addedIDs);
if(deletedIDs != null)
{
- entryIDList.deleteAll(deletedIDs);
+ entryIDSet.removeAll(deletedIDs);
}
}
}
else if(deletedIDs != null)
{
- entryIDList.deleteAll(deletedIDs);
+ entryIDSet.removeAll(deletedIDs);
}
- return entryIDList;
+ return entryIDSet;
}
final void removeID(IndexBuffer buffer, ByteString keyBytes, EntryID entryID)
@@ -426,12 +431,12 @@
ByteString value = txn.read(getName(), key);
if (value != null)
{
- EntryIDSet entryIDList = new EntryIDSet(key, value);
- if (!entryIDList.isDefined())
+ EntryIDSet entryIDSet = newSetFromBytes(key, value);
+ if (!entryIDSet.isDefined())
{
return ConditionResult.UNDEFINED;
}
- return ConditionResult.valueOf(entryIDList.contains(entryID));
+ return ConditionResult.valueOf(entryIDSet.contains(entryID));
}
else if (trusted)
{
@@ -447,7 +452,7 @@
{
if(rebuildRunning)
{
- return new EntryIDSet();
+ return newUndefinedSet();
}
try
@@ -457,19 +462,19 @@
{
if(trusted)
{
- return new EntryIDSet(key, null);
+ return newDefinedSet();
}
else
{
- return new EntryIDSet();
+ return newUndefinedSet();
}
}
- return new EntryIDSet(key, value);
+ return newSetFromBytes(key, value);
}
catch (StorageRuntimeException e)
{
logger.traceException(e);
- return new EntryIDSet();
+ return newUndefinedSet();
}
}
@@ -502,7 +507,7 @@
// If this index is not trusted, then just return an undefined id set.
if(rebuildRunning || !trusted)
{
- return new EntryIDSet();
+ return newUndefinedSet();
}
try
@@ -510,7 +515,7 @@
// Total number of IDs found so far.
int totalIDCount = 0;
- ArrayList<EntryIDSet> lists = new ArrayList<EntryIDSet>();
+ ArrayList<EntryIDSet> sets = new ArrayList<EntryIDSet>();
Cursor cursor = txn.openCursor(getName());
try
@@ -537,7 +542,7 @@
if (!success)
{
// There are no values.
- return new EntryIDSet(lowerIncluded ? lower : null, null);
+ return newDefinedSet();
}
// Step through the keys until we hit the upper bound or the last key.
@@ -553,23 +558,23 @@
}
}
- EntryIDSet list = new EntryIDSet(cursor.getKey(), cursor.getValue());
- if (!list.isDefined())
+ EntryIDSet set = newSetFromBytes(cursor.getKey(), cursor.getValue());
+ if (!set.isDefined())
{
// There is no point continuing.
- return list;
+ return set;
}
- totalIDCount += list.size();
+ totalIDCount += set.size();
if (cursorEntryLimit > 0 && totalIDCount > cursorEntryLimit)
{
// There are too many. Give up and return an undefined list.
- return new EntryIDSet();
+ return newUndefinedSet();
}
- lists.add(list);
+ sets.add(set);
success = cursor.next();
}
- return EntryIDSet.unionOfSets(lists, false);
+ return newSetFromUnion(sets);
}
finally
{
@@ -579,7 +584,7 @@
catch (StorageRuntimeException e)
{
logger.traceException(e);
- return new EntryIDSet();
+ return newUndefinedSet();
}
}
--
Gitblit v1.10.0