From ba04f8f7aeeea23a2b27dd68294d882e98481882 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Tue, 11 Sep 2007 01:43:50 +0000
Subject: [PATCH] Make a number of relatively simple changes to provide basic performance improvements, including:
---
opends/src/server/org/opends/server/backends/jeb/DN2URI.java | 85 ++++++++++++++++++++++++++++++++++++++++--
1 files changed, 81 insertions(+), 4 deletions(-)
diff --git a/opends/src/server/org/opends/server/backends/jeb/DN2URI.java b/opends/src/server/org/opends/server/backends/jeb/DN2URI.java
index 1c06e12..b2a14c7 100644
--- a/opends/src/server/org/opends/server/backends/jeb/DN2URI.java
+++ b/opends/src/server/org/opends/server/backends/jeb/DN2URI.java
@@ -25,17 +25,20 @@
* Portions Copyright 2006-2007 Sun Microsystems, Inc.
*/
package org.opends.server.backends.jeb;
-import org.opends.messages.Message;
import com.sleepycat.je.*;
+import org.opends.messages.Message;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.SearchOperation;
+import org.opends.server.loggers.debug.DebugTracer;
import org.opends.server.protocols.asn1.ASN1OctetString;
import org.opends.server.types.Attribute;
import org.opends.server.types.AttributeType;
import org.opends.server.types.AttributeValue;
+import org.opends.server.types.ConditionResult;
+import org.opends.server.types.DebugLogLevel;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.DN;
import org.opends.server.types.Entry;
@@ -55,8 +58,6 @@
import static org.opends.server.util.ServerConstants.ATTR_REFERRAL_URL;
import static org.opends.server.loggers.debug.DebugLogger.*;
-import org.opends.server.loggers.debug.DebugTracer;
-import org.opends.server.types.DebugLogLevel;
import static org.opends.messages.JebMessages.
INFO_JEB_REFERRAL_RESULT_MESSAGE;
/**
@@ -84,10 +85,19 @@
* The standard attribute type that is used to specify the set of referral
* URLs in a referral entry.
*/
- public AttributeType referralType =
+ private final AttributeType referralType =
DirectoryServer.getAttributeType(ATTR_REFERRAL_URL);
/**
+ * A flag that indicates whether there are any referrals contained in this
+ * database. It should only be set to {@code false} when it is known that
+ * there are no referrals.
+ */
+ private volatile ConditionResult containsReferrals =
+ ConditionResult.UNDEFINED;
+
+
+ /**
* Create a new object representing a referral database in a given
* entryContainer.
*
@@ -155,6 +165,7 @@
{
return false;
}
+ containsReferrals = ConditionResult.TRUE;
return true;
}
@@ -180,6 +191,7 @@
{
return false;
}
+ containsReferrals = containsReferrals(txn);
return true;
}
@@ -220,10 +232,55 @@
{
return false;
}
+ containsReferrals = containsReferrals(txn);
return true;
}
/**
+ * Indicates whether the underlying database contains any referrals.
+ *
+ * @param txn The transaction to use when making the determination.
+ *
+ * @return {@code true} if it is believed that the underlying database may
+ * contain at least one referral, or {@code false} if it is certain
+ * that it doesn't.
+ */
+ private ConditionResult containsReferrals(Transaction txn)
+ {
+ try
+ {
+ Cursor cursor = openCursor(txn, null);
+ DatabaseEntry key = new DatabaseEntry();
+ DatabaseEntry data = new DatabaseEntry();
+
+ OperationStatus status = cursor.getFirst(key, data, null);
+ cursor.close();
+
+ if (status == OperationStatus.SUCCESS)
+ {
+ return ConditionResult.TRUE;
+ }
+ else if (status == OperationStatus.NOTFOUND)
+ {
+ return ConditionResult.FALSE;
+ }
+ else
+ {
+ return ConditionResult.UNDEFINED;
+ }
+ }
+ catch (Exception e)
+ {
+ if (debugEnabled())
+ {
+ TRACER.debugCaught(DebugLogLevel.ERROR, e);
+ }
+
+ return ConditionResult.UNDEFINED;
+ }
+ }
+
+ /**
* Update the referral database for an entry that has been modified. Does
* not do anything unless the entry before the modification or the entry after
* the modification is a referral entry.
@@ -478,6 +535,16 @@
public void targetEntryReferrals(DN targetDN, SearchScope searchScope)
throws DirectoryException
{
+ if (containsReferrals == ConditionResult.UNDEFINED)
+ {
+ containsReferrals = containsReferrals(null);
+ }
+
+ if (containsReferrals == ConditionResult.FALSE)
+ {
+ return;
+ }
+
Transaction txn = null;
CursorConfig cursorConfig = null;
@@ -549,6 +616,16 @@
public boolean returnSearchReferences(SearchOperation searchOp)
throws DirectoryException
{
+ if (containsReferrals == ConditionResult.UNDEFINED)
+ {
+ containsReferrals = containsReferrals(null);
+ }
+
+ if (containsReferrals == ConditionResult.FALSE)
+ {
+ return true;
+ }
+
Transaction txn = null;
CursorConfig cursorConfig = null;
--
Gitblit v1.10.0