From 77131174b396433451592ca82362a3534ce74c80 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Tue, 16 Dec 2014 14:49:33 +0000
Subject: [PATCH] OPENDJ-1602 (CR-5566) New pluggable storage based backend

---
 opendj3-server-dev/src/server/org/opends/server/backends/pluggable/VLVIndex.java |   30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/VLVIndex.java b/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/VLVIndex.java
index 37001ee..8325d22 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/VLVIndex.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/pluggable/VLVIndex.java
@@ -51,6 +51,7 @@
 import org.opends.server.backends.pluggable.BackendImpl.ReadableStorage;
 import org.opends.server.backends.pluggable.BackendImpl.Storage;
 import org.opends.server.backends.pluggable.BackendImpl.StorageRuntimeException;
+import org.opends.server.backends.pluggable.BackendImpl.WriteOperation;
 import org.opends.server.backends.pluggable.BackendImpl.WriteableStorage;
 import org.opends.server.controls.ServerSideSortRequestControl;
 import org.opends.server.controls.VLVRequestControl;
@@ -131,7 +132,7 @@
    * configuration
    */
   public VLVIndex(LocalDBVLVIndexCfg config, State state, Storage env,
-                  EntryContainer entryContainer)
+                  EntryContainer entryContainer, ReadableStorage txn)
       throws StorageRuntimeException, ConfigException
   {
     super(entryContainer.getDatabasePrefix().child("vlv."+config.getName()),
@@ -197,7 +198,7 @@
 
     this.state = state;
     this.trusted = state.getIndexTrustState(null, this);
-    if (!trusted && entryContainer.getHighestEntryID().longValue() == 0)
+    if (!trusted && entryContainer.getHighestEntryID(txn).longValue() == 0)
     {
       // If there are no entries in the entry container then there
       // is no reason why this vlvIndex can't be upgraded to trusted.
@@ -223,11 +224,11 @@
 
   /** {@inheritDoc} */
   @Override
-  public void open() throws StorageRuntimeException
+  public void open(WriteableStorage txn) throws StorageRuntimeException
   {
-    super.open();
+    super.open(txn);
 
-    Cursor cursor = storage.openCursor(treeName);
+    final Cursor cursor = txn.openCursor(treeName);
     try
     {
       while (cursor.next())
@@ -1304,8 +1305,8 @@
     {
       this.sortedSetCapacity = cfg.getMaxBlockSize();
 
-      // Require admin action only if the new capacity is larger. Otherwise,
-      // we will lazyly update the sorted sets.
+      // Require admin action only if the new capacity is larger.
+      // Otherwise, we will lazily update the sorted sets.
       if (config.getMaxBlockSize() < cfg.getMaxBlockSize())
       {
         adminActionRequired = true;
@@ -1391,12 +1392,19 @@
       entryContainer.exclusiveLock.lock();
       try
       {
-        close();
-        open();
+        storage.write(new WriteOperation()
+        {
+          @Override
+          public void run(WriteableStorage txn) throws Exception
+          {
+            close();
+            open(txn);
+          }
+        });
       }
-      catch(StorageRuntimeException de)
+      catch (Exception e)
       {
-        messages.add(LocalizableMessage.raw(StaticUtils.stackTraceToSingleLineString(de)));
+        messages.add(LocalizableMessage.raw(StaticUtils.stackTraceToSingleLineString(e)));
         if(resultCode == ResultCode.SUCCESS)
         {
           resultCode = DirectoryServer.getServerErrorResultCode();

--
Gitblit v1.10.0