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/ImportJob.java | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 52 insertions(+), 1 deletions(-)
diff --git a/opends/src/server/org/opends/server/backends/jeb/ImportJob.java b/opends/src/server/org/opends/server/backends/jeb/ImportJob.java
index 8b0ef2f..9dbebda 100644
--- a/opends/src/server/org/opends/server/backends/jeb/ImportJob.java
+++ b/opends/src/server/org/opends/server/backends/jeb/ImportJob.java
@@ -98,6 +98,17 @@
new HashMap<DN, ImportContext>();
/**
+ * The maximum number of parent ID values that we will remember.
+ */
+ private static final int PARENT_ID_MAP_SIZE = 50;
+
+ /**
+ * Map of likely parent entry DNs to their entry IDs.
+ */
+ private HashMap<DN,EntryID> parentIDMap =
+ new HashMap<DN,EntryID>(PARENT_ID_MAP_SIZE);
+
+ /**
* The number of entries imported.
*/
private int importedCount;
@@ -867,7 +878,7 @@
getParentWithinBase(entryDN);
if (parentDN != null)
{
- parentID = dn2id.get(txn, parentDN);
+ parentID = getParentID(parentDN, dn2id, txn);
if (parentID == null)
{
// Reject the entry.
@@ -952,6 +963,46 @@
}
/**
+ * Retrieves the entry ID for the entry with the given DN. This will use an
+ * in-memory hash if possible, or will go to the database if it's not in
+ * cache. This should only be used for cacheable operations (like getting the
+ * entry ID for the parent entry) where the same parent ID is likely to be
+ * used multiple times.
+ *
+ * @param parentDN The DN of the parent entry for which to retrieve the
+ * corresponding entry ID.
+ * @param dn2id The handle to the dn2id database to use if the parent DN
+ * isn't found in the local cache.
+ * @param txn The transaction to use when interacting with the dn2id
+ * database.
+ *
+ * @return The entry ID for the entry with the given DN, or {@code null} if
+ * no such entry exists.
+ */
+ private EntryID getParentID(DN parentDN, DN2ID dn2id, Transaction txn)
+ throws DatabaseException
+ {
+ EntryID parentID = parentIDMap.get(parentDN);
+ if (parentID != null)
+ {
+ return parentID;
+ }
+
+ parentID = dn2id.get(txn, parentDN);
+ if (parentID != null)
+ {
+ if (parentIDMap.size() >= PARENT_ID_MAP_SIZE)
+ {
+ parentIDMap.keySet().iterator().remove();
+ }
+
+ parentIDMap.put(parentDN, parentID);
+ }
+
+ return parentID;
+ }
+
+ /**
* Get a statistic of the number of keys that reached the entry limit.
* @return The number of keys that reached the entry limit.
*/
--
Gitblit v1.10.0