Browse Source

Remove Accountable interface from BytesReference (#34900)

Alan Woodward 7 years ago
parent
commit
c74232037a

+ 6 - 2
server/src/main/java/org/elasticsearch/common/bytes/BytesReference.java

@@ -18,7 +18,6 @@
  */
 package org.elasticsearch.common.bytes;
 
-import org.apache.lucene.util.Accountable;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.BytesRefIterator;
 import org.elasticsearch.common.io.stream.BytesStream;
@@ -38,7 +37,7 @@ import java.util.function.ToIntBiFunction;
 /**
  * A reference to bytes.
  */
-public abstract class BytesReference implements Accountable, Comparable<BytesReference>, ToXContentFragment {
+public abstract class BytesReference implements Comparable<BytesReference>, ToXContentFragment {
 
     private Integer hash = null; // we cache the hash of this reference since it can be quite costly to re-calculated it
 
@@ -71,6 +70,11 @@ public abstract class BytesReference implements Accountable, Comparable<BytesRef
      */
     public abstract BytesReference slice(int from, int length);
 
+    /**
+     * The amount of memory used by this BytesReference
+     */
+    public abstract long ramBytesUsed();
+
     /**
      * A stream input of the bytes.
      */

+ 3 - 2
server/src/main/java/org/elasticsearch/index/cache/request/ShardRequestCache.java

@@ -20,6 +20,7 @@
 package org.elasticsearch.index.cache.request;
 
 import org.apache.lucene.util.Accountable;
+import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.metrics.CounterMetric;
 
 /**
@@ -44,11 +45,11 @@ public final class ShardRequestCache {
         missCount.inc();
     }
 
-    public void onCached(Accountable key, Accountable value) {
+    public void onCached(Accountable key, BytesReference value) {
         totalMetric.inc(key.ramBytesUsed() + value.ramBytesUsed());
     }
 
-    public void onRemoval(Accountable key, Accountable value, boolean evicted) {
+    public void onRemoval(Accountable key, BytesReference value, boolean evicted) {
         if (evicted) {
             evictionsMetric.inc();
         }

+ 0 - 7
server/src/test/java/org/elasticsearch/indices/IndicesRequestCacheTests.java

@@ -31,7 +31,6 @@ import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.Accountable;
 import org.apache.lucene.util.BytesRef;
 import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.io.stream.BytesStreamOutput;
@@ -48,7 +47,6 @@ import org.elasticsearch.test.ESTestCase;
 
 import java.io.IOException;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Supplier;
 
@@ -501,11 +499,6 @@ public class IndicesRequestCacheTests extends ESTestCase {
             return 0;
         }
 
-        @Override
-        public Collection<Accountable> getChildResources() {
-            return null;
-        }
-
         @Override
         public boolean isFragment() {
             return false;