From 38a66ffda0dd97801656c4e0c0f8cc34771f64af Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 11 Feb 2015 14:25:44 +0000
Subject: [PATCH] OPENDJ-1707 Persistit: various import problems

---
 opendj3-server-dev/src/server/org/opends/server/backends/pluggable/Index.java |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/Index.java b/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/Index.java
index c6495d9..8c91108 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/Index.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/Index.java
@@ -106,6 +106,8 @@
    */
   private boolean rebuildRunning;
 
+  private final ImportIDSet newImportIDSet;
+
   /**
    * Create a new index object.
    * @param name The name of the index database within the entryContainer.
@@ -132,6 +134,7 @@
     this.indexEntryLimit = indexEntryLimit;
     this.cursorEntryLimit = cursorEntryLimit;
     this.maintainCount = maintainCount;
+    this.newImportIDSet = new ImportIDSet(indexEntryLimit, indexEntryLimit, maintainCount);
 
     this.state = state;
     this.trusted = state.getIndexTrustState(txn, this);
@@ -156,6 +159,60 @@
   }
 
   /**
+   * Delete the specified import ID set from the import ID set associated with the key.
+   *
+   * @param txn The database transaction
+   * @param key The key to delete the set from.
+   * @param importIdSet The import ID set to delete.
+   * @throws StorageRuntimeException If a database error occurs.
+   */
+  void delete(WriteableStorage txn, ByteSequence key, ImportIDSet importIdSet) throws StorageRuntimeException {
+    ByteString value = read(txn, key, false);
+    if (value != null) {
+      newImportIDSet.clear();
+      newImportIDSet.remove(value, importIdSet);
+      if (newImportIDSet.isDefined() && newImportIDSet.size() == 0)
+      {
+        delete(txn, key);
+      }
+      else
+      {
+        value = newImportIDSet.valueToByteString();
+        put(txn, key, value);
+      }
+    } else {
+      // Should never happen -- the keys should always be there.
+      throw new RuntimeException();
+    }
+  }
+
+  /**
+   * Insert the specified import ID set into this index. Creates a DB cursor if needed.
+   *
+   * @param txn The database transaction
+   * @param key The key to add the set to.
+   * @param importIdSet The set of import IDs.
+   * @throws StorageRuntimeException If a database error occurs.
+   */
+  void insert(WriteableStorage txn, ByteSequence key, ImportIDSet importIdSet) throws StorageRuntimeException {
+    ByteString value = read(txn, key, false);
+    if(value != null) {
+      newImportIDSet.clear();
+      if (newImportIDSet.merge(value, importIdSet)) {
+        entryLimitExceededCount++;
+      }
+      value = newImportIDSet.valueToByteString();
+      put(txn, key, value);
+    } else {
+      if(!importIdSet.isDefined()) {
+        entryLimitExceededCount++;
+      }
+      value = importIdSet.valueToByteString();
+      put(txn, key, value);
+    }
+  }
+
+  /**
    * Update the set of entry IDs for a given key.
    *
    * @param txn A database transaction, or null if none is required.

--
Gitblit v1.10.0