From 17e216ed32e21eddece22d782f8a256711ab3ad8 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 04 Dec 2014 15:08:07 +0000
Subject: [PATCH] OPENDJ-1602 (CR-5566) New pluggable storage based backend
---
opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java | 175 ++++++++++------------------------------------------------
1 files changed, 30 insertions(+), 145 deletions(-)
diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java
index 59bbe33..1997c79 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java
@@ -1512,7 +1512,8 @@
}
// Insert into the indexes, in index configuration order.
- indexInsertEntry(txn, entry, entryID);
+ final IndexBuffer indexBuffer = new IndexBuffer(this);
+ indexInsertEntry(indexBuffer, entry, entryID);
// Insert into id2children and id2subtree.
// The database transaction locks on these records will be hotly
@@ -1520,11 +1521,9 @@
// shortest duration.
if (parentDN != null)
{
- // Insert into id2children for parent ID.
- id2children.insertID(txn, parentID.getDatabaseEntry(), entryID);
-
- // Insert into id2subtree for parent ID.
- id2subtree.insertID(txn, parentID.getDatabaseEntry(), entryID);
+ final ByteString parentIDKeyBytes = toByteString(parentID);
+ id2children.insertID(indexBuffer, parentIDKeyBytes, entryID);
+ id2subtree.insertID(indexBuffer, parentIDKeyBytes, entryID);
// Iterate up through the superior entries, starting above the parent.
for (DN dn = getParentWithinBase(parentDN); dn != null;
@@ -1538,9 +1537,10 @@
}
// Insert into id2subtree for this node.
- id2subtree.insertID(txn, nodeID.getDatabaseEntry(), entryID);
+ id2subtree.insertID(indexBuffer, toByteString(nodeID), entryID);
}
}
+ indexBuffer.flush(txn);
if(addOperation != null)
{
@@ -1588,6 +1588,11 @@
}
}
+ private ByteString toByteString(EntryID entryID)
+ {
+ return ByteString.wrap(entryID.getDatabaseEntry().getData());
+ }
+
/**
* Removes the specified entry from this database. This method must ensure
* that the entry exists and that it does not have any subordinate entries
@@ -1608,7 +1613,7 @@
throws DirectoryException, DatabaseException, CanceledOperationException
{
Transaction txn = beginTransaction();
- IndexBuffer indexBuffer = null;
+ final IndexBuffer indexBuffer = new IndexBuffer(this);
try
{
@@ -1674,13 +1679,6 @@
ERR_JEB_DELETE_NOT_ALLOWED_ON_NONLEAF.get(entryDN));
}
- // This is a subtree delete so create a index buffer
- // if it there isn't one.
- if(indexBuffer == null)
- {
- indexBuffer = new IndexBuffer(EntryContainer.this);
- }
-
/*
* Delete this entry which by now must be a leaf because
* we have been deleting from the bottom of the tree upwards.
@@ -1732,11 +1730,7 @@
isSubtreeDelete || isManageDsaITOperation(deleteOperation),
entryDN, null, null);
-
- if(indexBuffer != null)
- {
- indexBuffer.flush(txn);
- }
+ indexBuffer.flush(txn);
if(deleteOperation != null)
@@ -1844,28 +1838,12 @@
}
// Remove from the indexes, in index config order.
- if(indexBuffer != null)
- {
- indexRemoveEntry(indexBuffer, entry, leafID);
- }
- else
- {
- indexRemoveEntry(txn, entry, leafID);
- }
+ indexRemoveEntry(indexBuffer, entry, leafID);
// Remove the id2c and id2s records for this entry.
- if(indexBuffer != null)
- {
- ByteString leafIDKeyBytes = ByteString.valueOf(leafID.longValue());
- id2children.delete(indexBuffer, leafIDKeyBytes);
- id2subtree.delete(indexBuffer, leafIDKeyBytes);
- }
- else
- {
- DatabaseEntry leafIDKey = leafID.getDatabaseEntry();
- id2children.delete(txn, leafIDKey);
- id2subtree.delete(txn, leafIDKey);
- }
+ final ByteString leafIDKeyBytes = ByteString.valueOf(leafID.longValue());
+ id2children.delete(indexBuffer, leafIDKeyBytes);
+ id2subtree.delete(indexBuffer, leafIDKeyBytes);
// Iterate up through the superior entries from the target entry.
boolean isParent = true;
@@ -1879,28 +1857,14 @@
throw new JebException(ERR_JEB_MISSING_DN2ID_RECORD.get(parentDN));
}
- if(indexBuffer != null)
+ ByteString parentIDBytes = ByteString.valueOf(parentID.longValue());
+ // Remove from id2children.
+ if (isParent)
{
- ByteString parentIDBytes = ByteString.valueOf(parentID.longValue());
- // Remove from id2children.
- if (isParent)
- {
- id2children.removeID(indexBuffer, parentIDBytes, leafID);
- isParent = false;
- }
- id2subtree.removeID(indexBuffer, parentIDBytes, leafID);
+ id2children.removeID(indexBuffer, parentIDBytes, leafID);
+ isParent = false;
}
- else
- {
- DatabaseEntry nodeIDData = parentID.getDatabaseEntry();
- // Remove from id2children.
- if(isParent)
- {
- id2children.removeID(txn, nodeIDData, leafID);
- isParent = false;
- }
- id2subtree.removeID(txn, nodeIDData, leafID);
- }
+ id2subtree.removeID(indexBuffer, parentIDBytes, leafID);
}
// Remove the entry from the entry cache.
@@ -2060,19 +2024,22 @@
id2entry.put(txn, entryID, newEntry);
// Update the indexes.
+ final IndexBuffer indexBuffer = new IndexBuffer(this);
if (modifyOperation != null)
{
// In this case we know from the operation what the modifications were.
List<Modification> mods = modifyOperation.getModifications();
- indexModifications(txn, oldEntry, newEntry, entryID, mods);
+ indexModifications(indexBuffer, oldEntry, newEntry, entryID, mods);
}
else
{
// The most optimal would be to figure out what the modifications were.
- indexRemoveEntry(txn, oldEntry, entryID);
- indexInsertEntry(txn, newEntry, entryID);
+ indexRemoveEntry(indexBuffer, oldEntry, entryID);
+ indexInsertEntry(indexBuffer, newEntry, entryID);
}
+ indexBuffer.flush(txn);
+
if(modifyOperation != null)
{
// One last check before committing
@@ -2655,30 +2622,6 @@
/**
* Insert a new entry into the attribute indexes.
*
- * @param txn The database transaction to be used for the updates.
- * @param entry The entry to be inserted into the indexes.
- * @param entryID The ID of the entry to be inserted into the indexes.
- * @throws DatabaseException If an error occurs in the JE database.
- * @throws DirectoryException If a Directory Server error occurs.
- * @throws JebException If an error occurs in the JE backend.
- */
- private void indexInsertEntry(Transaction txn, Entry entry, EntryID entryID)
- throws DatabaseException, DirectoryException, JebException
- {
- for (AttributeIndex index : attrIndexMap.values())
- {
- index.addEntry(txn, entryID, entry);
- }
-
- for (VLVIndex vlvIndex : vlvIndexMap.values())
- {
- vlvIndex.addEntry(txn, entryID, entry);
- }
- }
-
- /**
- * Insert a new entry into the attribute indexes.
- *
* @param buffer The index buffer used to buffer up the index changes.
* @param entry The entry to be inserted into the indexes.
* @param entryID The ID of the entry to be inserted into the indexes.
@@ -2702,30 +2645,6 @@
/**
* Remove an entry from the attribute indexes.
*
- * @param txn The database transaction to be used for the updates.
- * @param entry The entry to be removed from the indexes.
- * @param entryID The ID of the entry to be removed from the indexes.
- * @throws DatabaseException If an error occurs in the JE database.
- * @throws DirectoryException If a Directory Server error occurs.
- * @throws JebException If an error occurs in the JE backend.
- */
- private void indexRemoveEntry(Transaction txn, Entry entry, EntryID entryID)
- throws DatabaseException, DirectoryException, JebException
- {
- for (AttributeIndex index : attrIndexMap.values())
- {
- index.removeEntry(txn, entryID, entry);
- }
-
- for (VLVIndex vlvIndex : vlvIndexMap.values())
- {
- vlvIndex.removeEntry(txn, entryID, entry);
- }
- }
-
- /**
- * Remove an entry from the attribute indexes.
- *
* @param buffer The index buffer used to buffer up the index changes.
* @param entry The entry to be removed from the indexes.
* @param entryID The ID of the entry to be removed from the indexes.
@@ -2750,40 +2669,6 @@
* Update the attribute indexes to reflect the changes to the
* attributes of an entry resulting from a sequence of modifications.
*
- * @param txn The database transaction to be used for the updates.
- * @param oldEntry The contents of the entry before the change.
- * @param newEntry The contents of the entry after the change.
- * @param entryID The ID of the entry that was changed.
- * @param mods The sequence of modifications made to the entry.
- * @throws DatabaseException If an error occurs in the JE database.
- * @throws DirectoryException If a Directory Server error occurs.
- * @throws JebException If an error occurs in the JE backend.
- */
- private void indexModifications(Transaction txn, Entry oldEntry,
- Entry newEntry,
- EntryID entryID, List<Modification> mods)
- throws DatabaseException, DirectoryException, JebException
- {
- // Process in index configuration order.
- for (AttributeIndex index : attrIndexMap.values())
- {
- // Check whether any modifications apply to this indexed attribute.
- if (isAttributeModified(index, mods))
- {
- index.modifyEntry(txn, entryID, oldEntry, newEntry, mods);
- }
- }
-
- for(VLVIndex vlvIndex : vlvIndexMap.values())
- {
- vlvIndex.modifyEntry(txn, entryID, oldEntry, newEntry, mods);
- }
- }
-
- /**
- * Update the attribute indexes to reflect the changes to the
- * attributes of an entry resulting from a sequence of modifications.
- *
* @param buffer The index buffer used to buffer up the index changes.
* @param oldEntry The contents of the entry before the change.
* @param newEntry The contents of the entry after the change.
--
Gitblit v1.10.0