Remove Accountable interface from BytesReference (#34900)

This commit is contained in:
Alan Woodward 2018-10-30 10:27:31 +00:00 committed by GitHub
parent 6da2fb7d5b
commit c74232037a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 11 deletions

View File

@ -18,7 +18,6 @@
*/ */
package org.elasticsearch.common.bytes; package org.elasticsearch.common.bytes;
import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.BytesRefIterator; import org.apache.lucene.util.BytesRefIterator;
import org.elasticsearch.common.io.stream.BytesStream; import org.elasticsearch.common.io.stream.BytesStream;
@ -38,7 +37,7 @@ import java.util.function.ToIntBiFunction;
/** /**
* A reference to bytes. * 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 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); 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. * A stream input of the bytes.
*/ */

View File

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

View File

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