From 65c4b9f6eef396deec7aa3f0c335f9ef1b9099ce Mon Sep 17 00:00:00 2001
From: Fabio Pistolesi <fabio.pistolesi@forgerock.com>
Date: Thu, 09 Jul 2015 16:37:07 +0000
Subject: [PATCH] OPENDJ-2171 CR-7414 import-ldif in append mode should not reset index state

---
 opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Suffix.java |   53 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Suffix.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Suffix.java
index 42b2539..d762ad2 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Suffix.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Suffix.java
@@ -37,7 +37,6 @@
 import org.opends.server.backends.pluggable.OnDiskMergeBufferImporter.DNCache;
 import org.opends.server.backends.pluggable.spi.StorageRuntimeException;
 import org.opends.server.backends.pluggable.spi.WriteableTransaction;
-import org.opends.server.types.AttributeType;
 import org.opends.server.types.DN;
 
 /**
@@ -71,6 +70,8 @@
   private static final int PARENT_ID_SET_SIZE = 16 * 1024;
   private final ConcurrentHashMap<DN, CountDownLatch> pendingMap = new ConcurrentHashMap<>();
   private final Set<DN> parentSet = new HashSet<>(PARENT_ID_SET_SIZE);
+  private final List<AttributeIndex> attributeIndexes = new ArrayList<>();
+  private final List<VLVIndex> vlvIndexes = new ArrayList<>();
 
   Suffix(EntryContainer entryContainer)
   {
@@ -155,9 +156,14 @@
    *
    * @return A suffixes Attribute Type - Index map.
    */
-  Map<AttributeType, AttributeIndex> getAttrIndexMap()
+  List<AttributeIndex> getAttributeIndexes()
   {
-    return entryContainer.getAttributeIndexMap();
+    return attributeIndexes;
+  }
+
+  List<VLVIndex> getVLVIndexes()
+  {
+    return vlvIndexes;
   }
 
   /**
@@ -246,21 +252,44 @@
   }
 
   /**
-   * Sets the trusted status of all of the indexes and vlvIndexes.
+   * Builds the lists of Attribute and VLV indexes to process, setting their status as not trusted.
    *
-   * @param txn a non null transaction
-   * @param trusted True if the indexes should be trusted or false otherwise.
-   * @throws StorageRuntimeException If an error occurred setting the indexes to trusted.
+   * @param txn
+   *          a non null transaction
+   * @param OnlyCurrentlyTrusted
+   *          true if currently untrusted indexes should be processed as well.
+   * @throws StorageRuntimeException
+   *          If an error occurred setting the indexes to trusted.
    */
-  void setIndexesTrusted(WriteableTransaction txn, boolean trusted) throws StorageRuntimeException
+  void setIndexesNotTrusted(WriteableTransaction txn, boolean onlyCurrentlyTrusted) throws StorageRuntimeException
   {
-    for (AttributeIndex attributeIndex : entryContainer.getAttributeIndexes())
+    for (AttributeIndex attrIndex : entryContainer.getAttributeIndexes())
     {
-      setTrusted(txn, attributeIndex.getNameToIndexes().values(), trusted);
+      if (!onlyCurrentlyTrusted || attrIndex.isTrusted())
+      {
+        setTrusted(txn, attrIndex.getNameToIndexes().values(), false);
+        attributeIndexes.add(attrIndex);
+      }
     }
-    for (VLVIndex vlvIdx : entryContainer.getVLVIndexes())
+    for (VLVIndex vlvIndex : entryContainer.getVLVIndexes())
     {
-      vlvIdx.setTrusted(txn, trusted);
+      if (!onlyCurrentlyTrusted || vlvIndex.isTrusted())
+      {
+        vlvIndex.setTrusted(txn, false);
+        vlvIndexes.add(vlvIndex);
+      }
+    }
+  }
+
+  void setIndexesTrusted(WriteableTransaction txn) throws StorageRuntimeException
+  {
+    for (AttributeIndex attrIndex : attributeIndexes)
+    {
+      setTrusted(txn, attrIndex.getNameToIndexes().values(), true);
+    }
+    for (VLVIndex vlvIdx : vlvIndexes)
+    {
+      vlvIdx.setTrusted(txn, true);
     }
   }
 

--
Gitblit v1.10.0