lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [lucene-solr] 30/36: Broken, interim check-in.
Date Wed, 18 Dec 2019 16:39:08 GMT
This is an automated email from the ASF dual-hosted git repository.

ab pushed a commit to branch jira/solr-13579
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 9bd5ebb67a52b3bb84735719e2b54ccfcdf1f6c6
Author: Andrzej Bialecki <ab@apache.org>
AuthorDate: Tue Nov 19 12:09:10 2019 +0100

    Broken, interim check-in.
---
 .../solr/managed/DefaultResourceManagerPool.java   | 11 ++--------
 .../org/apache/solr/managed/ManagedComponent.java  | 14 +++++++-----
 .../apache/solr/managed/ManagedComponentId.java    | 24 +++++++++++++++------
 .../org/apache/solr/managed/ManagedContext.java    | 25 +++++++++++++++++++---
 .../org/apache/solr/managed/ResourceManager.java   |  4 ++--
 .../apache/solr/managed/ResourceManagerPlugin.java |  2 +-
 .../apache/solr/managed/ResourceManagerPool.java   |  6 ------
 .../java/org/apache/solr/search/CaffeineCache.java | 14 +++++++-----
 .../solr/managed/types/TestCacheManagerPlugin.java |  9 ++++++++
 9 files changed, 71 insertions(+), 38 deletions(-)

diff --git a/solr/core/src/java/org/apache/solr/managed/DefaultResourceManagerPool.java b/solr/core/src/java/org/apache/solr/managed/DefaultResourceManagerPool.java
index 07eb5bf..98771b8 100644
--- a/solr/core/src/java/org/apache/solr/managed/DefaultResourceManagerPool.java
+++ b/solr/core/src/java/org/apache/solr/managed/DefaultResourceManagerPool.java
@@ -44,7 +44,6 @@ public class DefaultResourceManagerPool implements ResourceManagerPool {
   private final ResourceManagerPlugin resourceManagerPlugin;
   private final Map<String, Object> args;
   private final ManagedContext poolContext = new ManagedContext();
-  private Map<String, Map<String, Object>> currentValues = null;
   private final ReentrantLock updateLock = new ReentrantLock();
   int scheduleDelaySeconds;
   ScheduledFuture<?> scheduledFuture;
@@ -119,15 +118,14 @@ public class DefaultResourceManagerPool implements ResourceManagerPool
{
     updateLock.lockInterruptibly();
     try {
       // collect the current values
-      Map<String, Map<String, Object>> newCurrentValues = new HashMap<>();
+      Map<String, Map<String, Object>> currentValues = new HashMap<>();
       for (ManagedComponent managedComponent : components.values()) {
         try {
-          newCurrentValues.put(managedComponent.getManagedComponentId().toString(), resourceManagerPlugin.getMonitoredValues(managedComponent));
+          currentValues.put(managedComponent.getManagedComponentId().toString(), resourceManagerPlugin.getMonitoredValues(managedComponent));
         } catch (Exception e) {
           log.warn("Error getting managed values from " + managedComponent.getManagedComponentId(),
e);
         }
       }
-      this.currentValues = newCurrentValues;
       return Collections.unmodifiableMap(currentValues);
     } finally {
       updateLock.unlock();
@@ -135,11 +133,6 @@ public class DefaultResourceManagerPool implements ResourceManagerPool
{
   }
 
   @Override
-  public Map<String, Object> getTotalValues() throws InterruptedException {
-    return Collections.unmodifiableMap(resourceManagerPlugin.aggregateTotalValues(currentValues));
-  }
-
-  @Override
   public Map<String, Object> getPoolLimits() {
     return poolLimits;
   }
diff --git a/solr/core/src/java/org/apache/solr/managed/ManagedComponent.java b/solr/core/src/java/org/apache/solr/managed/ManagedComponent.java
index cf75af3..d8e6692 100644
--- a/solr/core/src/java/org/apache/solr/managed/ManagedComponent.java
+++ b/solr/core/src/java/org/apache/solr/managed/ManagedComponent.java
@@ -16,19 +16,23 @@
  */
 package org.apache.solr.managed;
 
+import org.apache.solr.core.SolrInfoBean;
+
 /**
  * A managed component.
  */
-public interface ManagedComponent {
+public interface ManagedComponent extends SolrInfoBean {
   /**
-   * Unique name of this component. By convention id-s form a dot-separated hierarchy that
-   * follows the naming of metric registries and metric names.
+   * Unique name of this component. By convention id-s form a colon-separated hierarchy.
    */
   ManagedComponentId getManagedComponentId();
 
   /**
-   * Component context used for managing additional component state.
-   * @return component's context
+   * Component context used for managing additional component state for the purpose of resource
management.
    */
   ManagedContext getManagedContext();
+
+  default void close() throws Exception {
+    SolrInfoBean.super.close();
+  }
 }
diff --git a/solr/core/src/java/org/apache/solr/managed/ManagedComponentId.java b/solr/core/src/java/org/apache/solr/managed/ManagedComponentId.java
index bd09080..7b5d908 100644
--- a/solr/core/src/java/org/apache/solr/managed/ManagedComponentId.java
+++ b/solr/core/src/java/org/apache/solr/managed/ManagedComponentId.java
@@ -23,11 +23,13 @@ import java.util.Arrays;
  * Hierarchical component id.
  */
 public class ManagedComponentId {
+  private final String type;
   private final String name;
   private final String[] path;
   private final String id;
 
-  public ManagedComponentId(String name, String... path) {
+  public ManagedComponentId(String type, String name, String... path) {
+    this.type = type;
     this.name = name;
     this.path = path;
     StringBuilder sb = new StringBuilder();
@@ -46,6 +48,10 @@ public class ManagedComponentId {
     id = sb.toString();
   }
 
+  public String getType() {
+    return type;
+  }
+
   public String getName() {
     return name;
   }
@@ -63,12 +69,16 @@ public class ManagedComponentId {
       return null;
     }
     String[] parts = fullName.split(":");
-    if (parts.length > 1) {
-      String name = parts[parts.length - 1];
-      String[] path = Arrays.copyOfRange(parts, 0, parts.length - 1);
-      return new ManagedComponentId(name, path);
+    if (parts.length < 2) {
+      throw new RuntimeException("at least 2 parts (type and name) must be present: " + fullName);
+    }
+    if (parts.length > 2) {
+      String type = parts[parts.length - 1];
+      String name = parts[parts.length - 2];
+      String[] path = Arrays.copyOfRange(parts, 0, parts.length - 2);
+      return new ManagedComponentId(type, name, path);
     } else {
-      return new ManagedComponentId(parts[0]);
+      return new ManagedComponentId(parts[0], parts[1]);
     }
   }
-}
+}
\ No newline at end of file
diff --git a/solr/core/src/java/org/apache/solr/managed/ManagedContext.java b/solr/core/src/java/org/apache/solr/managed/ManagedContext.java
index 74919ee..3cf6839 100644
--- a/solr/core/src/java/org/apache/solr/managed/ManagedContext.java
+++ b/solr/core/src/java/org/apache/solr/managed/ManagedContext.java
@@ -16,11 +16,30 @@
  */
 package org.apache.solr.managed;
 
-import java.util.concurrent.ConcurrentHashMap;
-
 /**
  *
  */
-public class ManagedContext extends ConcurrentHashMap<String, Object> {
+public class ManagedContext {
+  private final ResourceManager resourceManager;
+  private final String poolName;
+  private final ManagedComponent component;
+
+  public ManagedContext(ResourceManager resourceManager, String poolName, ManagedComponent
component) {
+    this.resourceManager = resourceManager;
+    this.poolName = poolName;
+    this.component = component;
+    this.resourceManager.registerComponent(poolName, component);
+  }
+
+  public ResourceManager getResourceManager() {
+    return resourceManager;
+  }
+
+  public String getPoolName() {
+    return poolName;
+  }
 
+  public void unregister() {
+    resourceManager.unregisterComponent(poolName, component.getManagedComponentId());
+  }
 }
diff --git a/solr/core/src/java/org/apache/solr/managed/ResourceManager.java b/solr/core/src/java/org/apache/solr/managed/ResourceManager.java
index 24a6e44..364a99d 100644
--- a/solr/core/src/java/org/apache/solr/managed/ResourceManager.java
+++ b/solr/core/src/java/org/apache/solr/managed/ResourceManager.java
@@ -198,7 +198,7 @@ public abstract class ResourceManager implements SolrCloseable, PluginInfoInitia
    * @param pool existing pool name.
    * @param managedComponents components to add
    */
-  public void registerComponents(String pool, Collection<ManagedComponent> managedComponents)
throws Exception {
+  public void registerComponents(String pool, Collection<ManagedComponent> managedComponents)
{
     ensureActive();
     for (ManagedComponent managedComponent : managedComponents) {
       registerComponent(pool, managedComponent);
@@ -212,7 +212,7 @@ public abstract class ResourceManager implements SolrCloseable, PluginInfoInitia
    *                        used in the selected pool. The component must not be already
managed by
    *                        another pool of the same type.
    */
-  public abstract void registerComponent(String pool, ManagedComponent managedComponent)
throws Exception;
+  public abstract void registerComponent(String pool, ManagedComponent managedComponent);
 
   /**
    * Remove a managed component from a pool.
diff --git a/solr/core/src/java/org/apache/solr/managed/ResourceManagerPlugin.java b/solr/core/src/java/org/apache/solr/managed/ResourceManagerPlugin.java
index 1fbeaf0..dc6a5b6 100644
--- a/solr/core/src/java/org/apache/solr/managed/ResourceManagerPlugin.java
+++ b/solr/core/src/java/org/apache/solr/managed/ResourceManagerPlugin.java
@@ -69,7 +69,7 @@ public interface ResourceManagerPlugin<T extends ManagedComponent>
{
   void manage(ResourceManagerPool pool) throws Exception;
 
   /**
-   * Aggregated current monitored values.
+   * Return aggregated current monitored values.
    * <p>Default implementation of this method simply sums up all non-negative numeric
values across
    * components and ignores any non-numeric values.</p>
    */
diff --git a/solr/core/src/java/org/apache/solr/managed/ResourceManagerPool.java b/solr/core/src/java/org/apache/solr/managed/ResourceManagerPool.java
index 2bf4db7..9f2b4ff 100644
--- a/solr/core/src/java/org/apache/solr/managed/ResourceManagerPool.java
+++ b/solr/core/src/java/org/apache/solr/managed/ResourceManagerPool.java
@@ -38,12 +38,6 @@ public interface ResourceManagerPool extends Runnable, Closeable {
    */
   Map<String, Map<String, Object>> getCurrentValues() throws InterruptedException;
 
-  /**
-   * This returns cumulative monitored values of all components.
-   * <p>NOTE: you MUST call {@link #getCurrentValues()} first!</p>
-   */
-  Map<String, Object> getTotalValues() throws InterruptedException;
-
   /** Get current pool limits. */
   Map<String, Object> getPoolLimits();
 
diff --git a/solr/core/src/java/org/apache/solr/search/CaffeineCache.java b/solr/core/src/java/org/apache/solr/search/CaffeineCache.java
index 32837f6..ea1db54 100644
--- a/solr/core/src/java/org/apache/solr/search/CaffeineCache.java
+++ b/solr/core/src/java/org/apache/solr/search/CaffeineCache.java
@@ -23,8 +23,6 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Executor;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.ForkJoinPool;
@@ -39,6 +37,8 @@ import org.apache.lucene.util.RamUsageEstimator;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.managed.ManagedComponentId;
 import org.apache.solr.managed.ManagedContext;
+import org.apache.solr.managed.ResourceManagerPluginFactory;
+import org.apache.solr.managed.types.CacheManagerPlugin;
 import org.apache.solr.metrics.MetricsMap;
 import org.apache.solr.metrics.SolrMetricsContext;
 import org.slf4j.Logger;
@@ -88,10 +88,12 @@ public class CaffeineCache<K, V> extends SolrCacheBase implements
SolrCache<K, V
   private int maxIdleTimeSec;
   private boolean cleanupThread;
 
-  private Set<String> metricNames = ConcurrentHashMap.newKeySet();
   private MetricsMap cacheMap;
   private SolrMetricsContext solrMetricsContext;
 
+  private ManagedContext managedContext;
+  private ManagedComponentId managedComponentId;
+
   private long initialRamBytes = 0;
   private final LongAdder ramBytes = new LongAdder();
 
@@ -387,15 +389,17 @@ public class CaffeineCache<K, V> extends SolrCacheBase implements
SolrCache<K, V
       }
     });
     solrMetricsContext.gauge(cacheMap, true, scope, getCategory().toString());
+    managedComponentId = new ManagedComponentId(CacheManagerPlugin.TYPE, solrMetricsContext.getTag(),
solrMetricsContext.getRegistryName(), getCategory().toString(), scope);
+    managedContext = new ManagedContext()
   }
 
   @Override
   public ManagedComponentId getManagedComponentId() {
-    return null;
+    return managedComponentId;
   }
 
   @Override
   public ManagedContext getManagedContext() {
-    return null;
+    return managedContext;
   }
 }
diff --git a/solr/core/src/test/org/apache/solr/managed/types/TestCacheManagerPlugin.java
b/solr/core/src/test/org/apache/solr/managed/types/TestCacheManagerPlugin.java
new file mode 100644
index 0000000..dab094f
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/managed/types/TestCacheManagerPlugin.java
@@ -0,0 +1,9 @@
+package org.apache.solr.managed.types;
+
+import org.apache.solr.cloud.SolrCloudTestCase;
+
+/**
+ *
+ */
+public class TestCacheManagerPlugin extends SolrCloudTestCase {
+}


Mime
View raw message