From 08f9243b55eb5f0f8030eebe976a0d85ffbd44c2 Mon Sep 17 00:00:00 2001
From: ludovicp <ludovicp@localhost>
Date: Fri, 30 Jul 2010 15:11:25 +0000
Subject: [PATCH] Implements a configurable limit in the number of persistent searches a server can handle.

---
 opends/src/server/org/opends/server/extensions/ParallelWorkQueue.java |   41 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/opends/src/server/org/opends/server/extensions/ParallelWorkQueue.java b/opends/src/server/org/opends/server/extensions/ParallelWorkQueue.java
index 3fb7f68..2273dcd 100644
--- a/opends/src/server/org/opends/server/extensions/ParallelWorkQueue.java
+++ b/opends/src/server/org/opends/server/extensions/ParallelWorkQueue.java
@@ -104,6 +104,9 @@
   // a configuration change has not been completely applied).
   private int numWorkerThreads;
 
+   // The number of maximum allowed persistent searches.
+  private int maxPSearches;
+
   // The queue that will be used to actually hold the pending operations.
   private ConcurrentLinkedQueue<AbstractOperation> opQueue;
 
@@ -142,6 +145,17 @@
     // Get the necessary configuration from the provided entry.
     numWorkerThreads = getNumWorkerThreads(configuration);
 
+    //Check the value of the maximum persistent searches attribute.
+    //We don't allow a value greater than the number of threads.
+    maxPSearches = configuration.getMaxPsearches()==null?
+      numWorkerThreads:configuration.getMaxPsearches();
+    if(maxPSearches >  numWorkerThreads)
+    {
+      Message message = ERR_CONFIG_CORE_INVALID_MAX_PSEARCH_LIMIT.get(
+              maxPSearches, numWorkerThreads, numWorkerThreads);
+      throw new ConfigException(message);
+    }
+
     // Create the actual work queue.
     opQueue = new ConcurrentLinkedQueue<AbstractOperation>();
 
@@ -498,7 +512,19 @@
                       ParallelWorkQueueCfg configuration,
                       List<Message> unacceptableReasons)
   {
-    // The provided configuration will always be acceptable.
+    //Check if the max persistent search value is under limit.
+    if(configuration.getMaxPsearches() !=null)
+    {
+      int nPSearches = configuration.getMaxPsearches();
+      int nWorkerThreads = getNumWorkerThreads(configuration);
+      if(nPSearches >  nWorkerThreads)
+      {
+        Message message = ERR_CONFIG_CORE_INVALID_MAX_PSEARCH_LIMIT.get(
+                nPSearches, nWorkerThreads, nWorkerThreads);
+        unacceptableReasons.add(message);
+        return false;
+      }
+    }
     return true;
   }
 
@@ -550,6 +576,9 @@
         }
       }
     }
+     //Get the new maximum psearch value.
+     maxPSearches = configuration.getMaxPsearches()==null?
+      numWorkerThreads:configuration.getMaxPsearches();
 
     return new ConfigChangeResult(ResultCode.SUCCESS, false, resultMessages);
   }
@@ -582,6 +611,16 @@
 
 
 
+  /**
+   * {@inheritDoc}
+   */
+  public int getMaxPersistentSearchLimit()
+  {
+    return maxPSearches;
+  }
+
+
+
   // Determine the number of worker threads.
   private int getNumWorkerThreads(ParallelWorkQueueCfg configuration)
   {

--
Gitblit v1.10.0