From e58930180693ca4505030d76bc417a45d3e7e273 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Fri, 4 Apr 2014 11:50:39 +0200 Subject: [PATCH] Make Releasable extend AutoCloseable. Java7's AutoCloseable allows to manage resources more nicely using try-with-resources statements. Since the semantics of our Releasable interface are very close to a Closeable, let's switch to it. Close #5689 --- .../status/TransportIndicesStatusAction.java | 2 +- .../query/TransportValidateQueryAction.java | 2 +- .../action/count/TransportCountAction.java | 2 +- .../explain/TransportExplainAction.java | 2 +- .../suggest/TransportSuggestAction.java | 2 +- .../bytes/ReleasablePagedBytesReference.java | 5 +- .../common/lease/Releasable.java | 6 +- .../common/lease/Releasables.java | 66 ++++++++++++++----- .../common/lucene/index/FreqTermsEnum.java | 5 +- .../netty/ReleaseChannelFutureListener.java | 2 +- .../common/recycler/DequeRecycler.java | 3 +- .../common/recycler/NoneRecycler.java | 3 +- .../common/recycler/Recyclers.java | 6 +- .../common/util/AbstractArray.java | 3 +- .../common/util/AbstractBigArray.java | 9 ++- .../common/util/AbstractHash.java | 5 +- .../elasticsearch/common/util/BigArrays.java | 15 ++--- .../common/util/BytesRefHash.java | 14 ++-- .../common/util/DoubleObjectPagedHashMap.java | 5 +- .../elasticsearch/common/util/LongHash.java | 13 ++-- .../common/util/LongObjectPagedHashMap.java | 5 +- .../http/netty/NettyHttpChannel.java | 2 +- .../SnapshotDeletionPolicy.java | 14 ++-- .../deletionpolicy/SnapshotIndexCommit.java | 6 +- .../deletionpolicy/SnapshotIndexCommits.java | 9 +-- .../elasticsearch/index/engine/Engine.java | 7 +- .../index/engine/internal/InternalEngine.java | 37 +++++------ .../percolator/PercolatorQueriesRegistry.java | 2 +- .../child/ChildrenConstantScoreQuery.java | 7 +- .../index/search/child/ChildrenQuery.java | 13 ++-- .../child/CustomQueryWrappingFilter.java | 3 +- .../child/ParentConstantScoreQuery.java | 7 +- .../index/search/child/ParentQuery.java | 7 +- .../index/search/child/TopChildrenQuery.java | 9 ++- .../shard/service/InternalIndexShard.java | 4 +- .../IndexShardSnapshotAndRestoreService.java | 2 +- .../termvectors/ShardTermVectorService.java | 2 +- .../index/translog/fs/FsChannelSnapshot.java | 3 +- .../index/translog/fs/FsTranslog.java | 4 +- .../cache/filter/IndicesFilterCache.java | 2 +- .../indices/ttl/IndicesTTLService.java | 2 +- .../MultiDocumentPercolatorIndex.java | 3 +- .../percolator/PercolateContext.java | 12 ++-- .../percolator/PercolatorService.java | 10 +-- .../SingleDocumentPercolatorIndex.java | 3 +- .../elasticsearch/search/SearchService.java | 6 +- .../search/aggregations/AggregationPhase.java | 7 +- .../search/aggregations/Aggregator.java | 13 ++-- .../aggregations/AggregatorFactories.java | 4 +- .../bucket/BucketsAggregator.java | 13 ++-- .../bucket/geogrid/GeoHashGridAggregator.java | 4 +- .../bucket/geogrid/InternalGeoHashGrid.java | 2 +- .../bucket/histogram/HistogramAggregator.java | 4 +- .../bucket/histogram/InternalHistogram.java | 2 +- .../SignificantLongTermsAggregator.java | 4 +- .../SignificantStringTermsAggregator.java | 10 +-- .../SignificantTermsAggregatorFactory.java | 5 +- .../bucket/terms/DoubleTerms.java | 2 +- .../bucket/terms/DoubleTermsAggregator.java | 4 +- .../GlobalOrdinalsStringTermsAggregator.java | 4 +- .../aggregations/bucket/terms/LongTerms.java | 2 +- .../bucket/terms/LongTermsAggregator.java | 4 +- .../bucket/terms/StringTermsAggregator.java | 10 +-- .../metrics/avg/AvgAggregator.java | 4 +- .../cardinality/CardinalityAggregator.java | 22 +++---- .../cardinality/HyperLogLogPlusPlus.java | 16 ++--- .../metrics/max/MaxAggregator.java | 4 +- .../metrics/min/MinAggregator.java | 4 +- .../percentiles/PercentilesAggregator.java | 4 +- .../metrics/percentiles/tdigest/TDigest.java | 5 +- .../metrics/stats/StatsAggegator.java | 4 +- .../extended/ExtendedStatsAggregator.java | 4 +- .../metrics/sum/SumAggregator.java | 4 +- .../valuecount/ValueCountAggregator.java | 4 +- .../CountDateHistogramFacetExecutor.java | 2 +- .../InternalCountDateHistogramFacet.java | 2 +- .../InternalFullDateHistogramFacet.java | 2 +- .../ValueDateHistogramFacetExecutor.java | 2 +- ...ValueScriptDateHistogramFacetExecutor.java | 2 +- .../CountHistogramFacetExecutor.java | 2 +- .../histogram/FullHistogramFacetExecutor.java | 2 +- .../InternalCountHistogramFacet.java | 2 +- .../histogram/InternalFullHistogramFacet.java | 2 +- .../ScriptHistogramFacetExecutor.java | 2 +- .../ValueHistogramFacetExecutor.java | 2 +- .../ValueScriptHistogramFacetExecutor.java | 2 +- .../doubles/InternalDoubleTermsFacet.java | 2 +- .../doubles/TermsDoubleFacetExecutor.java | 6 +- .../terms/longs/InternalLongTermsFacet.java | 2 +- .../terms/longs/TermsLongFacetExecutor.java | 6 +- .../strings/InternalStringTermsFacet.java | 2 +- .../ScriptTermsStringFieldFacetExecutor.java | 6 +- .../TermsStringOrdinalsFacetExecutor.java | 13 ++-- .../InternalTermsStatsDoubleFacet.java | 4 +- .../TermsStatsDoubleFacetExecutor.java | 6 +- .../longs/InternalTermsStatsLongFacet.java | 4 +- .../longs/TermsStatsLongFacetExecutor.java | 6 +- .../InternalTermsStatsStringFacet.java | 4 +- .../TermsStatsStringFacetExecutor.java | 4 +- .../search/internal/DefaultSearchContext.java | 11 ++-- .../search/internal/SearchContext.java | 2 +- .../transport/netty/NettyTransport.java | 3 +- .../netty/NettyTransportChannel.java | 4 +- .../common/recycler/RecyclerBenchmark.java | 2 +- .../recycler/AbstractRecyclerTests.java | 18 ++--- .../common/util/BigArraysTests.java | 44 ++++++------- .../common/util/BytesRefHashTests.java | 12 ++-- .../common/util/DoubleObjectHashMapTests.java | 2 +- .../common/util/LongHashTests.java | 12 ++-- .../common/util/LongObjectHashMapTests.java | 2 +- .../SnapshotDeletionPolicyTests.java | 14 ++-- .../engine/internal/InternalEngineTests.java | 30 ++++----- .../index/search/child/TestSearchContext.java | 8 +-- .../translog/AbstractSimpleTranslogTests.java | 52 +++++++-------- .../test/cache/recycler/MockBigArrays.java | 4 +- .../cache/recycler/MockPageCacheRecycler.java | 4 +- .../test/engine/MockInternalEngine.java | 4 +- 117 files changed, 401 insertions(+), 436 deletions(-) diff --git a/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java b/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java index e30e03bfc60..cba944e5704 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/status/TransportIndicesStatusAction.java @@ -164,7 +164,7 @@ public class TransportIndicesStatusAction extends TransportBroadcastOperationAct shardStatus.docs.maxDoc = searcher.reader().maxDoc(); shardStatus.docs.deletedDocs = searcher.reader().numDeletedDocs(); } finally { - searcher.release(); + searcher.close(); } shardStatus.mergeStats = indexShard.mergeScheduler().stats(); diff --git a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java index 4607e01266f..547a61268e7 100644 --- a/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java +++ b/src/main/java/org/elasticsearch/action/admin/indices/validate/query/TransportValidateQueryAction.java @@ -202,7 +202,7 @@ public class TransportValidateQueryAction extends TransportBroadcastOperationAct valid = false; error = e.getMessage(); } finally { - SearchContext.current().release(); + SearchContext.current().close(); SearchContext.removeCurrent(); } } diff --git a/src/main/java/org/elasticsearch/action/count/TransportCountAction.java b/src/main/java/org/elasticsearch/action/count/TransportCountAction.java index bddd6fd7e0d..19ab6632218 100644 --- a/src/main/java/org/elasticsearch/action/count/TransportCountAction.java +++ b/src/main/java/org/elasticsearch/action/count/TransportCountAction.java @@ -199,7 +199,7 @@ public class TransportCountAction extends TransportBroadcastOperationAction releasables, boolean ignoreException) { + private static void close(Iterable releasables, boolean ignoreException) { Throwable th = null; for (Releasable releasable : releasables) { if (releasable != null) { try { - releasable.release(); + releasable.close(); } catch (Throwable t) { if (th == null) { th = t; @@ -54,36 +56,70 @@ public enum Releasables { } /** Release the provided {@link Releasable}s. */ - public static void release(Iterable releasables) { - release(releasables, false); + public static void close(Iterable releasables) { + close(releasables, false); } /** Release the provided {@link Releasable}s. */ - public static void release(Releasable... releasables) { - release(Arrays.asList(releasables)); + public static void close(Releasable... releasables) { + close(Arrays.asList(releasables)); } /** Release the provided {@link Releasable}s, ignoring exceptions. */ - public static void releaseWhileHandlingException(Iterable releasables) { - release(releasables, true); + public static void closeWhileHandlingException(Iterable releasables) { + close(releasables, true); } /** Release the provided {@link Releasable}s, ignoring exceptions. */ - public static void releaseWhileHandlingException(Releasable... releasables) { - releaseWhileHandlingException(Arrays.asList(releasables)); + public static void closeWhileHandlingException(Releasable... releasables) { + closeWhileHandlingException(Arrays.asList(releasables)); } /** Release the provided {@link Releasable}s, ignoring exceptions if success is false. */ - public static void release(boolean success, Iterable releasables) { + public static void close(boolean success, Iterable releasables) { if (success) { - release(releasables); + close(releasables); } else { - releaseWhileHandlingException(releasables); + closeWhileHandlingException(releasables); } } /** Release the provided {@link Releasable}s, ignoring exceptions if success is false. */ - public static void release(boolean success, Releasable... releasables) { - release(success, Arrays.asList(releasables)); + public static void close(boolean success, Releasable... releasables) { + close(success, Arrays.asList(releasables)); + } + + /** Wrap several releasables into a single one. This is typically useful for use with try-with-resources: for example let's assume + * that you store in a list several resources that you would like to see released after execution of the try block: + * + *
+     *  List<Releasable> resources = ...;
+     *  try (Releasable releasable = Releasables.wrap(resources)) {
+     *      // do something
+     *  }
+     *  // the resources will be released when reaching here
+     *  
+ */ + public static Releasable wrap(final Iterable releasables) { + return new Releasable() { + + @Override + public void close() throws ElasticsearchException { + Releasables.close(releasables); + } + + }; + } + + /** @see #wrap(Iterable) */ + public static Releasable wrap(final Releasable... releasables) { + return new Releasable() { + + @Override + public void close() throws ElasticsearchException { + Releasables.close(releasables); + } + + }; } } diff --git a/src/main/java/org/elasticsearch/common/lucene/index/FreqTermsEnum.java b/src/main/java/org/elasticsearch/common/lucene/index/FreqTermsEnum.java index 8c9810f7e3e..308d84a468e 100644 --- a/src/main/java/org/elasticsearch/common/lucene/index/FreqTermsEnum.java +++ b/src/main/java/org/elasticsearch/common/lucene/index/FreqTermsEnum.java @@ -107,15 +107,14 @@ public class FreqTermsEnum extends FilterableTermsEnum implements Releasable { @Override - public boolean release() throws ElasticsearchException { + public void close() throws ElasticsearchException { try { - Releasables.release(cachedTermOrds, termDocFreqs, termsTotalFreqs); + Releasables.close(cachedTermOrds, termDocFreqs, termsTotalFreqs); } finally { cachedTermOrds = null; termDocFreqs = null; termsTotalFreqs = null; } - return true; } } diff --git a/src/main/java/org/elasticsearch/common/netty/ReleaseChannelFutureListener.java b/src/main/java/org/elasticsearch/common/netty/ReleaseChannelFutureListener.java index a31d0f6b96b..6f2979d13ca 100644 --- a/src/main/java/org/elasticsearch/common/netty/ReleaseChannelFutureListener.java +++ b/src/main/java/org/elasticsearch/common/netty/ReleaseChannelFutureListener.java @@ -37,6 +37,6 @@ public class ReleaseChannelFutureListener implements ChannelFutureListener { @Override public void operationComplete(ChannelFuture future) throws Exception { - releasable.release(); + releasable.close(); } } diff --git a/src/main/java/org/elasticsearch/common/recycler/DequeRecycler.java b/src/main/java/org/elasticsearch/common/recycler/DequeRecycler.java index 1a9787295f2..07298b8e3e2 100644 --- a/src/main/java/org/elasticsearch/common/recycler/DequeRecycler.java +++ b/src/main/java/org/elasticsearch/common/recycler/DequeRecycler.java @@ -87,7 +87,7 @@ public class DequeRecycler extends AbstractRecycler { } @Override - public boolean release() { + public void close() { if (value == null) { throw new ElasticsearchIllegalStateException("recycler entry already released..."); } @@ -101,7 +101,6 @@ public class DequeRecycler extends AbstractRecycler { } value = null; afterRelease(recycle); - return true; } } } diff --git a/src/main/java/org/elasticsearch/common/recycler/NoneRecycler.java b/src/main/java/org/elasticsearch/common/recycler/NoneRecycler.java index 556007296db..f347a739607 100644 --- a/src/main/java/org/elasticsearch/common/recycler/NoneRecycler.java +++ b/src/main/java/org/elasticsearch/common/recycler/NoneRecycler.java @@ -58,12 +58,11 @@ public class NoneRecycler extends AbstractRecycler { } @Override - public boolean release() { + public void close() { if (value == null) { throw new ElasticsearchIllegalStateException("recycler entry already released..."); } value = null; - return true; } } } diff --git a/src/main/java/org/elasticsearch/common/recycler/Recyclers.java b/src/main/java/org/elasticsearch/common/recycler/Recyclers.java index 2f0019db889..ef934f6e656 100644 --- a/src/main/java/org/elasticsearch/common/recycler/Recyclers.java +++ b/src/main/java/org/elasticsearch/common/recycler/Recyclers.java @@ -131,7 +131,7 @@ public enum Recyclers { } /** - * Wrap the provided recycler so that calls to {@link Recycler#obtain()} and {@link Recycler.V#release()} are protected by + * Wrap the provided recycler so that calls to {@link Recycler#obtain()} and {@link Recycler.V#close()} are protected by * a lock. */ public static Recycler locked(final Recycler recycler) { @@ -167,9 +167,9 @@ public enum Recyclers { return new Recycler.V() { @Override - public boolean release() throws ElasticsearchException { + public void close() throws ElasticsearchException { synchronized (lock) { - return delegate.release(); + delegate.close(); } } diff --git a/src/main/java/org/elasticsearch/common/util/AbstractArray.java b/src/main/java/org/elasticsearch/common/util/AbstractArray.java index 6c48fa7402f..c63467c453e 100644 --- a/src/main/java/org/elasticsearch/common/util/AbstractArray.java +++ b/src/main/java/org/elasticsearch/common/util/AbstractArray.java @@ -31,10 +31,9 @@ abstract class AbstractArray implements Releasable { } @Override - public boolean release() { + public void close() { assert !released : "double release"; released = true; - return true; // nothing to release by default } } diff --git a/src/main/java/org/elasticsearch/common/util/AbstractBigArray.java b/src/main/java/org/elasticsearch/common/util/AbstractBigArray.java index 5c9b7e78df1..6f8321247ab 100644 --- a/src/main/java/org/elasticsearch/common/util/AbstractBigArray.java +++ b/src/main/java/org/elasticsearch/common/util/AbstractBigArray.java @@ -155,19 +155,18 @@ abstract class AbstractBigArray extends AbstractArray { protected final void releasePage(int page) { if (recycler != null) { - cache[page].release(); + cache[page].close(); cache[page] = null; } } @Override - public final boolean release() { - super.release(); + public final void close() { + super.close(); if (recycler != null) { - Releasables.release(cache); + Releasables.close(cache); cache = null; } - return true; } } diff --git a/src/main/java/org/elasticsearch/common/util/AbstractHash.java b/src/main/java/org/elasticsearch/common/util/AbstractHash.java index 5f261c7a9bb..ed28abe49ab 100644 --- a/src/main/java/org/elasticsearch/common/util/AbstractHash.java +++ b/src/main/java/org/elasticsearch/common/util/AbstractHash.java @@ -56,8 +56,7 @@ abstract class AbstractHash extends AbstractPagedHashMap { } @Override - public boolean release() { - Releasables.release(ids); - return true; + public void close() { + Releasables.close(ids); } } diff --git a/src/main/java/org/elasticsearch/common/util/BigArrays.java b/src/main/java/org/elasticsearch/common/util/BigArrays.java index 57d728b4b6b..dcd2bf011bf 100644 --- a/src/main/java/org/elasticsearch/common/util/BigArrays.java +++ b/src/main/java/org/elasticsearch/common/util/BigArrays.java @@ -96,9 +96,8 @@ public class BigArrays extends AbstractComponent { } @Override - public final boolean release() { - Releasables.release(releasable); - return true; + public final void close() { + Releasables.close(releasable); } } @@ -369,7 +368,7 @@ public class BigArrays extends AbstractComponent { final ByteArray newArray = newByteArray(size, arr.clearOnResize); final byte[] rawArray = ((ByteArrayWrapper) array).array; newArray.set(0, rawArray, 0, (int) Math.min(rawArray.length, newArray.size())); - array.release(); + array.close(); return newArray; } } @@ -451,7 +450,7 @@ public class BigArrays extends AbstractComponent { for (long i = 0, end = Math.min(size, array.size()); i < end; ++i) { newArray.set(i, array.get(i)); } - array.release(); + array.close(); return newArray; } } @@ -500,7 +499,7 @@ public class BigArrays extends AbstractComponent { for (long i = 0, end = Math.min(size, array.size()); i < end; ++i) { newArray.set(i, array.get(i)); } - array.release(); + array.close(); return newArray; } } @@ -546,7 +545,7 @@ public class BigArrays extends AbstractComponent { for (long i = 0, end = Math.min(size, array.size()); i < end; ++i) { newArray.set(i, array.get(i)); } - array.release(); + array.close(); return newArray; } } @@ -630,7 +629,7 @@ public class BigArrays extends AbstractComponent { for (long i = 0, end = Math.min(size, array.size()); i < end; ++i) { newArray.set(i, array.get(i)); } - array.release(); + array.close(); return newArray; } } diff --git a/src/main/java/org/elasticsearch/common/util/BytesRefHash.java b/src/main/java/org/elasticsearch/common/util/BytesRefHash.java index 956dc3e3489..90ee3c75f71 100644 --- a/src/main/java/org/elasticsearch/common/util/BytesRefHash.java +++ b/src/main/java/org/elasticsearch/common/util/BytesRefHash.java @@ -21,6 +21,7 @@ package org.elasticsearch.common.util; import com.carrotsearch.hppc.hash.MurmurHash3; import org.apache.lucene.util.BytesRef; +import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.lease.Releasables; /** @@ -60,7 +61,7 @@ public final class BytesRefHash extends AbstractHash { /** * Return the key at 0 <e; index <e; capacity(). The result is undefined if the slot is unused. - *

Beware that the content of the {@link BytesRef} may become invalid as soon as {@link #release()} is called

+ *

Beware that the content of the {@link BytesRef} may become invalid as soon as {@link #close()} is called

*/ public BytesRef get(long id, BytesRef dest) { final long startOffset = startOffsets.get(id); @@ -159,15 +160,10 @@ public final class BytesRefHash extends AbstractHash { } @Override - public boolean release() { - boolean success = false; - try { - super.release(); - success = true; - } finally { - Releasables.release(success, bytes, hashes, startOffsets); + public void close() { + try (Releasable releasable = Releasables.wrap(bytes, hashes, startOffsets)) { + super.close(); } - return true; } } diff --git a/src/main/java/org/elasticsearch/common/util/DoubleObjectPagedHashMap.java b/src/main/java/org/elasticsearch/common/util/DoubleObjectPagedHashMap.java index fcbc18f8ff7..47950cb6bcc 100644 --- a/src/main/java/org/elasticsearch/common/util/DoubleObjectPagedHashMap.java +++ b/src/main/java/org/elasticsearch/common/util/DoubleObjectPagedHashMap.java @@ -166,9 +166,8 @@ public class DoubleObjectPagedHashMap extends AbstractPagedHashMap implements } @Override - public boolean release() throws ElasticsearchException { - Releasables.release(keys, values); - return true; + public void close() throws ElasticsearchException { + Releasables.close(keys, values); } @Override diff --git a/src/main/java/org/elasticsearch/common/util/LongHash.java b/src/main/java/org/elasticsearch/common/util/LongHash.java index 3e1c317949d..6fb7bd90a0c 100644 --- a/src/main/java/org/elasticsearch/common/util/LongHash.java +++ b/src/main/java/org/elasticsearch/common/util/LongHash.java @@ -19,7 +19,7 @@ package org.elasticsearch.common.util; -import org.elasticsearch.common.lease.Releasables; +import org.elasticsearch.common.lease.Releasable; /** * Specialized hash table implementation similar to BytesRefHash that maps @@ -119,15 +119,10 @@ public final class LongHash extends AbstractHash { } @Override - public boolean release() { - boolean success = false; - try { - super.release(); - success = true; - } finally { - Releasables.release(success, keys); + public void close() { + try (Releasable releasable = keys) { + super.close(); } - return true; } } diff --git a/src/main/java/org/elasticsearch/common/util/LongObjectPagedHashMap.java b/src/main/java/org/elasticsearch/common/util/LongObjectPagedHashMap.java index b23aa17dd89..eff145ae80b 100644 --- a/src/main/java/org/elasticsearch/common/util/LongObjectPagedHashMap.java +++ b/src/main/java/org/elasticsearch/common/util/LongObjectPagedHashMap.java @@ -166,9 +166,8 @@ public class LongObjectPagedHashMap extends AbstractPagedHashMap implements I } @Override - public boolean release() throws ElasticsearchException { - Releasables.release(keys, values); - return true; + public void close() throws ElasticsearchException { + Releasables.close(keys, values); } @Override diff --git a/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java b/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java index bcfabb4507b..862b3be937f 100644 --- a/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java +++ b/src/main/java/org/elasticsearch/http/netty/NettyHttpChannel.java @@ -170,7 +170,7 @@ public class NettyHttpChannel extends HttpChannel { } } finally { if (!addedReleaseListener && content instanceof Releasable) { - ((Releasable) content).release(); + ((Releasable) content).close(); } } } diff --git a/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicy.java b/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicy.java index 23cb4a6bae0..abb485815e9 100644 --- a/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicy.java +++ b/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicy.java @@ -24,14 +24,12 @@ import org.apache.lucene.index.IndexDeletionPolicy; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.name.Named; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; -import org.elasticsearch.index.shard.AbstractIndexShardComponent; import org.elasticsearch.index.shard.IndexShardComponent; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; /** @@ -105,7 +103,7 @@ public class SnapshotDeletionPolicy extends AbstractESDeletionPolicy { /** * Snapshots all the current commits in the index. Make sure to call - * {@link SnapshotIndexCommits#release()} to release it. + * {@link SnapshotIndexCommits#close()} to release it. */ public SnapshotIndexCommits snapshots() throws IOException { synchronized (mutex) { @@ -122,7 +120,7 @@ public class SnapshotDeletionPolicy extends AbstractESDeletionPolicy { /** * Returns a snapshot of the index (for the last commit point). Make - * sure to call {@link SnapshotIndexCommit#release()} in order to release it. + * sure to call {@link SnapshotIndexCommit#close()} in order to release it. */ public SnapshotIndexCommit snapshot() throws IOException { synchronized (mutex) { @@ -164,7 +162,7 @@ public class SnapshotDeletionPolicy extends AbstractESDeletionPolicy { /** * Releases the version provided. Returns true if the release was successful. */ - boolean release(long version) { + boolean close(long version) { synchronized (mutex) { SnapshotDeletionPolicy.SnapshotHolder holder = snapshots.get(version); if (holder == null) { @@ -193,12 +191,12 @@ public class SnapshotDeletionPolicy extends AbstractESDeletionPolicy { } @Override - public boolean release() { + public void close() { if (released) { - return false; + return; } released = true; - return ((SnapshotIndexCommit) delegate).release(); + ((SnapshotIndexCommit) delegate).close(); } } diff --git a/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotIndexCommit.java b/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotIndexCommit.java index 7def5ab3fee..5c975789408 100644 --- a/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotIndexCommit.java +++ b/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotIndexCommit.java @@ -27,7 +27,7 @@ import java.io.IOException; import java.util.ArrayList; /** - * A snapshot index commit point. While this is held and {@link #release()} + * A snapshot index commit point. While this is held and {@link #close()} * was not called, no files will be deleted that relates to this commit point * ({@link #getFileNames()}). * @@ -57,8 +57,8 @@ public class SnapshotIndexCommit extends IndexCommitDelegate implements Releasab * Releases the current snapshot, returning true if it was * actually released. */ - public boolean release() { - return deletionPolicy.release(getGeneration()); + public void close() { + deletionPolicy.close(getGeneration()); } /** diff --git a/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotIndexCommits.java b/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotIndexCommits.java index 69b81153ce4..f8891d1b8ea 100644 --- a/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotIndexCommits.java +++ b/src/main/java/org/elasticsearch/index/deletionpolicy/SnapshotIndexCommits.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.deletionpolicy; import org.elasticsearch.common.lease.Releasable; +import org.elasticsearch.common.lease.Releasables; import java.util.Iterator; import java.util.List; @@ -47,11 +48,7 @@ public class SnapshotIndexCommits implements Iterable, Rele return commits.iterator(); } - public boolean release() { - boolean result = false; - for (SnapshotIndexCommit snapshot : commits) { - result |= snapshot.release(); - } - return result; + public void close() { + Releasables.close(commits); } } diff --git a/src/main/java/org/elasticsearch/index/engine/Engine.java b/src/main/java/org/elasticsearch/index/engine/Engine.java index 81934bbab7d..3b4c0422271 100644 --- a/src/main/java/org/elasticsearch/index/engine/Engine.java +++ b/src/main/java/org/elasticsearch/index/engine/Engine.java @@ -86,7 +86,7 @@ public interface Engine extends IndexShardComponent, CloseableComponent { * API is responsible for releasing the returned seacher in a * safe manner, preferably in a try/finally block. * - * @see Searcher#release() + * @see Searcher#close() */ Searcher acquireSearcher(String source) throws EngineException; @@ -197,9 +197,8 @@ public interface Engine extends IndexShardComponent, CloseableComponent { } @Override - public boolean release() throws ElasticsearchException { + public void close() throws ElasticsearchException { // nothing to release here... - return true; } } @@ -932,7 +931,7 @@ public interface Engine extends IndexShardComponent, CloseableComponent { public void release() { if (searcher != null) { - searcher.release(); + searcher.close(); } } } diff --git a/src/main/java/org/elasticsearch/index/engine/internal/InternalEngine.java b/src/main/java/org/elasticsearch/index/engine/internal/InternalEngine.java index d9cacd94f30..56bd137ddf3 100644 --- a/src/main/java/org/elasticsearch/index/engine/internal/InternalEngine.java +++ b/src/main/java/org/elasticsearch/index/engine/internal/InternalEngine.java @@ -349,14 +349,14 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin try { docIdAndVersion = Versions.loadDocIdAndVersion(searcher.reader(), get.uid()); } catch (Throwable e) { - Releasables.releaseWhileHandlingException(searcher); + Releasables.closeWhileHandlingException(searcher); //TODO: A better exception goes here throw new EngineException(shardId(), "Couldn't resolve version", e); } if (get.version() != Versions.MATCH_ANY && docIdAndVersion != null) { if (get.versionType().isVersionConflict(docIdAndVersion.version, get.version())) { - Releasables.release(searcher); + Releasables.close(searcher); Uid uid = Uid.createUid(get.uid().text()); throw new VersionConflictEngineException(shardId, uid.type(), uid.id(), docIdAndVersion.version, get.version()); } @@ -366,7 +366,7 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin // don't release the searcher on this path, it is the responsability of the caller to call GetResult.release return new GetResult(searcher, docIdAndVersion); } else { - Releasables.release(searcher); + Releasables.close(searcher); return GetResult.NOT_EXISTS; } @@ -1053,14 +1053,14 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin try { phase1Snapshot = deletionPolicy.snapshot(); } catch (Throwable e) { - Releasables.releaseWhileHandlingException(onGoingRecoveries); + Releasables.closeWhileHandlingException(onGoingRecoveries); throw new RecoveryEngineException(shardId, 1, "Snapshot failed", e); } try { recoveryHandler.phase1(phase1Snapshot); } catch (Throwable e) { - Releasables.releaseWhileHandlingException(onGoingRecoveries, phase1Snapshot); + Releasables.closeWhileHandlingException(onGoingRecoveries, phase1Snapshot); if (closed) { e = new EngineClosedException(shardId, e); } @@ -1071,7 +1071,7 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin try { phase2Snapshot = translog.snapshot(); } catch (Throwable e) { - Releasables.releaseWhileHandlingException(onGoingRecoveries, phase1Snapshot); + Releasables.closeWhileHandlingException(onGoingRecoveries, phase1Snapshot); if (closed) { e = new EngineClosedException(shardId, e); } @@ -1081,7 +1081,7 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin try { recoveryHandler.phase2(phase2Snapshot); } catch (Throwable e) { - Releasables.releaseWhileHandlingException(onGoingRecoveries, phase1Snapshot, phase2Snapshot); + Releasables.closeWhileHandlingException(onGoingRecoveries, phase1Snapshot, phase2Snapshot); if (closed) { e = new EngineClosedException(shardId, e); } @@ -1098,9 +1098,9 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin } catch (Throwable e) { throw new RecoveryEngineException(shardId, 3, "Execution failed", e); } finally { - Releasables.release(success, onGoingRecoveries); + Releasables.close(success, onGoingRecoveries); rwl.writeLock().unlock(); - Releasables.release(success, phase1Snapshot, phase2Snapshot, phase3Snapshot); + Releasables.close(success, phase1Snapshot, phase2Snapshot, phase3Snapshot); } } @@ -1122,7 +1122,7 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin } return stats; } finally { - searcher.release(); + searcher.close(); } } finally { rwl.readLock().unlock(); @@ -1158,7 +1158,7 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin segments.put(info.info.name, segment); } } finally { - searcher.release(); + searcher.close(); } // now, correlate or add the committed ones... @@ -1292,7 +1292,7 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin try { return Versions.loadVersion(searcher.reader(), uid); } finally { - searcher.release(); + searcher.close(); } } @@ -1465,25 +1465,23 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin } @Override - public boolean release() throws ElasticsearchException { + public void close() throws ElasticsearchException { if (!released.compareAndSet(false, true)) { /* In general, searchers should never be released twice or this would break reference counting. There is one rare case * when it might happen though: when the request and the Reaper thread would both try to release it in a very short amount * of time, this is why we only log a warning instead of throwing an exception. */ logger.warn("Searcher was released twice", new ElasticsearchIllegalStateException("Double release")); - return false; + return; } try { manager.release(searcher); - return true; } catch (IOException e) { - return false; + throw new ElasticsearchIllegalStateException("Cannot close", e); } catch (AlreadyClosedException e) { /* this one can happen if we already closed the * underlying store / directory and we call into the * IndexWriter to free up pending files. */ - return false; } finally { store.decRef(); } @@ -1575,7 +1573,7 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin } } finally { // no need to release the fullSearcher, nothing really is done... - Releasables.release(currentSearcher); + Releasables.close(currentSearcher); if (newSearcher != null && closeNewSearcher) { IOUtils.closeWhileHandlingException(newSearcher.getIndexReader()); // ignore } @@ -1604,9 +1602,8 @@ public class InternalEngine extends AbstractIndexShardComponent implements Engin } @Override - public boolean release() throws ElasticsearchException { + public void close() throws ElasticsearchException { endRecovery(); - return true; } } diff --git a/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java b/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java index a7b88051a9a..d6b6a2a1203 100644 --- a/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java +++ b/src/main/java/org/elasticsearch/index/percolator/PercolatorQueriesRegistry.java @@ -271,7 +271,7 @@ public class PercolatorQueriesRegistry extends AbstractIndexShardComponent { shardPercolateService.addedQuery(entry.getKey(), previousQuery, entry.getValue()); } } finally { - searcher.release(); + searcher.close(); } } catch (Exception e) { throw new PercolatorException(shardId.index(), "failed to load queries from percolator index", e); diff --git a/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java b/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java index 2475531573e..abd40b0ba4a 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java @@ -128,7 +128,7 @@ public class ChildrenConstantScoreQuery extends Query { return parentWeight; } finally { if (releaseParentIds) { - Releasables.release(parentIds); + Releasables.close(parentIds); } } @@ -209,9 +209,8 @@ public class ChildrenConstantScoreQuery extends Query { } @Override - public boolean release() throws ElasticsearchException { - Releasables.release(parentIds); - return true; + public void close() throws ElasticsearchException { + Releasables.close(parentIds); } private final class ParentDocIdIterator extends FilteredDocIdSetIterator { diff --git a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java index ee01eea69c6..f29a2a70eb8 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java @@ -166,7 +166,7 @@ public class ChildrenQuery extends Query { scores = maxCollector.scores; occurrences = null; } finally { - Releasables.release(maxCollector.parentIdsIndex); + Releasables.close(maxCollector.parentIdsIndex); } break; case SUM: @@ -177,7 +177,7 @@ public class ChildrenQuery extends Query { scores = sumCollector.scores; occurrences = null; } finally { - Releasables.release(sumCollector.parentIdsIndex); + Releasables.close(sumCollector.parentIdsIndex); } break; case AVG: @@ -188,7 +188,7 @@ public class ChildrenQuery extends Query { scores = avgCollector.scores; occurrences = avgCollector.occurrences; } finally { - Releasables.release(avgCollector.parentIdsIndex); + Releasables.close(avgCollector.parentIdsIndex); } break; default: @@ -197,7 +197,7 @@ public class ChildrenQuery extends Query { int size = (int) parentIds.size(); if (size == 0) { - Releasables.release(parentIds, scores, occurrences); + Releasables.close(parentIds, scores, occurrences); return Queries.newMatchNoDocsQuery().createWeight(searcher); } @@ -287,9 +287,8 @@ public class ChildrenQuery extends Query { } @Override - public boolean release() throws ElasticsearchException { - Releasables.release(parentIds, scores, occurrences); - return true; + public void close() throws ElasticsearchException { + Releasables.close(parentIds, scores, occurrences); } private class ParentScorer extends Scorer { diff --git a/src/main/java/org/elasticsearch/index/search/child/CustomQueryWrappingFilter.java b/src/main/java/org/elasticsearch/index/search/child/CustomQueryWrappingFilter.java index 2f7c940c947..56b9478d989 100644 --- a/src/main/java/org/elasticsearch/index/search/child/CustomQueryWrappingFilter.java +++ b/src/main/java/org/elasticsearch/index/search/child/CustomQueryWrappingFilter.java @@ -91,12 +91,11 @@ public class CustomQueryWrappingFilter extends NoCacheFilter implements Releasab } @Override - public boolean release() throws ElasticsearchException { + public void close() throws ElasticsearchException { // We need to clear the docIdSets, otherwise this is leaved unused // DocIdSets around and can potentially become a memory leak. docIdSets = null; searcher = null; - return true; } @Override diff --git a/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java b/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java index 2c689309494..43a4ce05eb1 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java @@ -109,7 +109,7 @@ public class ParentConstantScoreQuery extends Query { return childrenWeight; } finally { if (releaseParentIds) { - Releasables.release(parentIds); + Releasables.close(parentIds); } } } @@ -182,9 +182,8 @@ public class ParentConstantScoreQuery extends Query { } @Override - public boolean release() throws ElasticsearchException { - Releasables.release(parentIds); - return true; + public void close() throws ElasticsearchException { + Releasables.close(parentIds); } private final class ChildrenDocIdIterator extends FilteredDocIdSetIterator { diff --git a/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java b/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java index 9aa0455e889..c7df052e595 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java @@ -153,7 +153,7 @@ public class ParentQuery extends Query { } finally { if (releaseCollectorResource) { // either if we run into an exception or if we return early - Releasables.release(collector.parentIds, collector.scores); + Releasables.close(collector.parentIds, collector.scores); } } searchContext.addReleasable(childWeight); @@ -272,9 +272,8 @@ public class ParentQuery extends Query { } @Override - public boolean release() throws ElasticsearchException { - Releasables.release(parentIds, scores, parentIdsIndexCache); - return true; + public void close() throws ElasticsearchException { + Releasables.close(parentIds, scores, parentIdsIndexCache); } } diff --git a/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java b/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java index 0fad99e6685..aa1644d77e5 100644 --- a/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java @@ -246,10 +246,10 @@ public class TopChildrenQuery extends Query { ParentDoc[] _parentDocs = value.v().values().toArray(ParentDoc.class); Arrays.sort(_parentDocs, PARENT_DOC_COMP); parentDocs.v().put(keys[i], _parentDocs); - Releasables.release(value); + Releasables.close(value); } } - Releasables.release(parentDocsPerReader); + Releasables.close(parentDocsPerReader); return parentHitsResolved; } @@ -321,9 +321,8 @@ public class TopChildrenQuery extends Query { } @Override - public boolean release() throws ElasticsearchException { - Releasables.release(parentDocs); - return true; + public void close() throws ElasticsearchException { + Releasables.close(parentDocs); } @Override diff --git a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java index 64c83adf0e1..2aa1684588f 100644 --- a/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java +++ b/src/main/java/org/elasticsearch/index/shard/service/InternalIndexShard.java @@ -495,7 +495,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I try { return new DocsStats(searcher.reader().numDocs(), searcher.reader().numDeletedDocs()); } finally { - searcher.release(); + searcher.close(); } } @@ -585,7 +585,7 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I completionStats.add(completionPostingsFormat.completionStats(currentSearcher.reader(), fields)); } } finally { - currentSearcher.release(); + currentSearcher.close(); } return completionStats; } diff --git a/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotAndRestoreService.java b/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotAndRestoreService.java index a018c159572..61bc0126237 100644 --- a/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotAndRestoreService.java +++ b/src/main/java/org/elasticsearch/index/snapshots/IndexShardSnapshotAndRestoreService.java @@ -90,7 +90,7 @@ public class IndexShardSnapshotAndRestoreService extends AbstractIndexShardCompo logger.debug(sb.toString()); } } finally { - snapshotIndexCommit.release(); + snapshotIndexCommit.close(); } } catch (SnapshotFailedEngineException e) { throw e; diff --git a/src/main/java/org/elasticsearch/index/termvectors/ShardTermVectorService.java b/src/main/java/org/elasticsearch/index/termvectors/ShardTermVectorService.java index 893b4787277..f31b3583896 100644 --- a/src/main/java/org/elasticsearch/index/termvectors/ShardTermVectorService.java +++ b/src/main/java/org/elasticsearch/index/termvectors/ShardTermVectorService.java @@ -77,7 +77,7 @@ public class ShardTermVectorService extends AbstractIndexShardComponent { } catch (Throwable ex) { throw new ElasticsearchException("failed to execute term vector request", ex); } finally { - searcher.release(); + searcher.close(); } return termVectorResponse; } diff --git a/src/main/java/org/elasticsearch/index/translog/fs/FsChannelSnapshot.java b/src/main/java/org/elasticsearch/index/translog/fs/FsChannelSnapshot.java index 334bab180bc..d2db8771268 100644 --- a/src/main/java/org/elasticsearch/index/translog/fs/FsChannelSnapshot.java +++ b/src/main/java/org/elasticsearch/index/translog/fs/FsChannelSnapshot.java @@ -138,8 +138,7 @@ public class FsChannelSnapshot implements Translog.Snapshot { } @Override - public boolean release() throws ElasticsearchException { + public void close() throws ElasticsearchException { raf.decreaseRefCount(true); - return true; } } diff --git a/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java b/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java index 528c5d66d5c..962d1dcfbcc 100644 --- a/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java +++ b/src/main/java/org/elasticsearch/index/translog/fs/FsTranslog.java @@ -368,7 +368,7 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog // ignore } } - Releasables.release(bytes); + Releasables.close(bytes); released = true; return location; } catch (Throwable e) { @@ -376,7 +376,7 @@ public class FsTranslog extends AbstractIndexShardComponent implements Translog } finally { rwl.readLock().unlock(); if (!released) { - Releasables.release(out.bytes()); + Releasables.close(out.bytes()); } } } diff --git a/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java b/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java index 978d567da66..ac5dce51268 100644 --- a/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java +++ b/src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java @@ -189,7 +189,7 @@ public class IndicesFilterCache extends AbstractComponent implements RemovalList } schedule(); } finally { - keys.release(); + keys.close(); } } }); diff --git a/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java b/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java index 38d144c0eb7..9ba07a5078c 100644 --- a/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java +++ b/src/main/java/org/elasticsearch/indices/ttl/IndicesTTLService.java @@ -194,7 +194,7 @@ public class IndicesTTLService extends AbstractLifecycleComponent { } context.keepAlive(keepAlive); } catch (Throwable e) { - context.release(); + context.close(); throw ExceptionsHelper.convertToRuntime(e); } @@ -546,7 +546,7 @@ public class SearchService extends AbstractLifecycleComponent { return; } context.indexShard().searchService().onFreeContext(context); - context.release(); + context.close(); } private void freeContext(SearchContext context) { @@ -554,7 +554,7 @@ public class SearchService extends AbstractLifecycleComponent { if (removed != null) { removed.indexShard().searchService().onFreeContext(removed); } - context.release(); + context.close(); } public void freeAllScrollContexts() { diff --git a/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java b/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java index 73b899bc0ed..ef7748ec5f1 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java +++ b/src/main/java/org/elasticsearch/search/aggregations/AggregationPhase.java @@ -25,6 +25,7 @@ import org.apache.lucene.search.Query; import org.apache.lucene.search.Scorer; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.lease.Releasables; import org.elasticsearch.common.lucene.search.Queries; import org.elasticsearch.common.lucene.search.XCollector; @@ -106,8 +107,7 @@ public class AggregationPhase implements SearchPhase { } Aggregator[] aggregators = context.aggregations().aggregators(); - boolean success = false; - try { + try (Releasable releasable = Releasables.wrap(aggregators)) { List globals = new ArrayList<>(); for (int i = 0; i < aggregators.length; i++) { if (aggregators[i] instanceof GlobalAggregator) { @@ -136,9 +136,6 @@ public class AggregationPhase implements SearchPhase { aggregations.add(aggregator.buildAggregation(0)); } context.queryResult().aggregations(new InternalAggregations(aggregations)); - success = true; - } finally { - Releasables.release(success, aggregators); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/Aggregator.java b/src/main/java/org/elasticsearch/search/aggregations/Aggregator.java index 4aea993279f..ebabfc2ff9f 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/Aggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/Aggregator.java @@ -174,19 +174,14 @@ public abstract class Aggregator implements Releasable, ReaderContextAware { /** Called upon release of the aggregator. */ @Override - public boolean release() { - boolean success = false; - try { - doRelease(); - success = true; - } finally { - Releasables.release(success, subAggregators); + public void close() { + try (Releasable releasable = Releasables.wrap(subAggregators)) { + doClose(); } - return true; } /** Release instance-specific data. */ - protected void doRelease() {} + protected void doClose() {} /** * Can be overriden by aggregator implementation to be called back when the collection phase ends. diff --git a/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java b/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java index 40d8f53fd5e..c6b7803f975 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java +++ b/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java @@ -134,7 +134,7 @@ public class AggregatorFactories { } @Override - public void doRelease() { + public void doClose() { final Iterable aggregatorsIter = new Iterable() { @Override @@ -157,7 +157,7 @@ public class AggregatorFactories { } }; - Releasables.release(Iterables.concat(aggregatorsIter, Collections.singleton(aggregators))); + Releasables.close(Iterables.concat(aggregatorsIter, Collections.singleton(aggregators))); } }; } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/BucketsAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/BucketsAggregator.java index aa33eb05b9f..e808da1d442 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/BucketsAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/BucketsAggregator.java @@ -18,7 +18,7 @@ */ package org.elasticsearch.search.aggregations.bucket; -import org.elasticsearch.common.lease.Releasables; +import org.elasticsearch.common.lease.Releasable; import org.elasticsearch.common.util.LongArray; import org.elasticsearch.search.aggregations.Aggregator; import org.elasticsearch.search.aggregations.AggregatorFactories; @@ -129,15 +129,10 @@ public abstract class BucketsAggregator extends Aggregator { } @Override - public final boolean release() { - boolean success = false; - try { - super.release(); - success = true; - } finally { - Releasables.release(success, docCounts); + public final void close() { + try (Releasable releasable = docCounts) { + super.close(); } - return true; } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregator.java index 1961ab69bc6..d55794b8992 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoHashGridAggregator.java @@ -127,8 +127,8 @@ public class GeoHashGridAggregator extends BucketsAggregator { @Override - public void doRelease() { - Releasables.release(bucketOrds); + public void doClose() { + Releasables.close(bucketOrds); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGrid.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGrid.java index 036d469b54c..caba75a5881 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGrid.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/InternalGeoHashGrid.java @@ -219,7 +219,7 @@ public class InternalGeoHashGrid extends InternalAggregation implements GeoHashG List sameCellBuckets = cursor.value; ordered.insertWithOverflow(sameCellBuckets.get(0).reduce(sameCellBuckets, reduceContext.bigArrays())); } - buckets.release(); + buckets.close(); Bucket[] list = new Bucket[ordered.size()]; for (int i = ordered.size() - 1; i >= 0; i--) { list[i] = ordered.pop(); diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregator.java index 0fc081aeba8..6b73c0dda17 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/HistogramAggregator.java @@ -129,8 +129,8 @@ public class HistogramAggregator extends BucketsAggregator { } @Override - public void doRelease() { - Releasables.release(bucketOrds); + public void doClose() { + Releasables.close(bucketOrds); } public static class Factory extends ValuesSourceAggregatorFactory { diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java index c64554d14a2..49035f2840e 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/InternalHistogram.java @@ -370,7 +370,7 @@ public class InternalHistogram extends Inter reducedBuckets.add(bucket); } } - bucketsByKey.release(); + bucketsByKey.close(); // adding empty buckets in needed if (minDocCount == 0) { diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantLongTermsAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantLongTermsAggregator.java index feca0bb857f..52dffedf924 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantLongTermsAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantLongTermsAggregator.java @@ -103,8 +103,8 @@ public class SignificantLongTermsAggregator extends LongTermsAggregator { } @Override - public void doRelease() { - Releasables.release(bucketOrds, termsAggFactory); + public void doClose() { + Releasables.close(bucketOrds, termsAggFactory); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantStringTermsAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantStringTermsAggregator.java index 1f3e51c17e9..ff7aadec6c8 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantStringTermsAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantStringTermsAggregator.java @@ -115,8 +115,8 @@ public class SignificantStringTermsAggregator extends StringTermsAggregator { } @Override - public void doRelease() { - Releasables.release(bucketOrds, termsAggFactory); + public void doClose() { + Releasables.close(bucketOrds, termsAggFactory); } /** @@ -143,7 +143,7 @@ public class SignificantStringTermsAggregator extends StringTermsAggregator { final long maxOrd = ordinals.getMaxOrd(); if (ordinalToBucket == null || ordinalToBucket.size() < maxOrd) { if (ordinalToBucket != null) { - ordinalToBucket.release(); + ordinalToBucket.close(); } ordinalToBucket = context().bigArrays().newLongArray(BigArrays.overSize(maxOrd), false); } @@ -175,8 +175,8 @@ public class SignificantStringTermsAggregator extends StringTermsAggregator { } @Override - public void doRelease() { - Releasables.release(bucketOrds, termsAggFactory, ordinalToBucket); + public void doClose() { + Releasables.close(bucketOrds, termsAggFactory, ordinalToBucket); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorFactory.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorFactory.java index 387cfc0c4d2..6d926851e9f 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorFactory.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorFactory.java @@ -207,14 +207,13 @@ public class SignificantTermsAggregatorFactory extends ValuesSourceAggregatorFac } @Override - public boolean release() throws ElasticsearchException { + public void close() throws ElasticsearchException { try { if (termsEnum instanceof Releasable) { - ((Releasable) termsEnum).release(); + ((Releasable) termsEnum).close(); } } finally { termsEnum = null; } - return true; } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTerms.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTerms.java index d81e8bba91e..d41e912a6cd 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTerms.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTerms.java @@ -150,7 +150,7 @@ public class DoubleTerms extends InternalTerms { ordered.insertWithOverflow(b); } } - buckets.release(); + buckets.close(); InternalTerms.Bucket[] list = new InternalTerms.Bucket[ordered.size()]; for (int i = ordered.size() - 1; i >= 0; i--) { list[i] = (Bucket) ordered.pop(); diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTermsAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTermsAggregator.java index 8e2909837dd..ad34e0f0fd6 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTermsAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/DoubleTermsAggregator.java @@ -135,8 +135,8 @@ public class DoubleTermsAggregator extends BucketsAggregator { } @Override - public void doRelease() { - Releasables.release(bucketOrds); + public void doClose() { + Releasables.close(bucketOrds); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/GlobalOrdinalsStringTermsAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/GlobalOrdinalsStringTermsAggregator.java index 293e1e25a60..d1616b7068a 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/GlobalOrdinalsStringTermsAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/GlobalOrdinalsStringTermsAggregator.java @@ -159,8 +159,8 @@ public class GlobalOrdinalsStringTermsAggregator extends AbstractStringTermsAggr } @Override - protected void doRelease() { - Releasables.release(bucketOrds); + protected void doClose() { + Releasables.close(bucketOrds); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTerms.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTerms.java index 65e626dbea3..eb642d05f4f 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTerms.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTerms.java @@ -150,7 +150,7 @@ public class LongTerms extends InternalTerms { ordered.insertWithOverflow(b); } } - buckets.release(); + buckets.close(); InternalTerms.Bucket[] list = new InternalTerms.Bucket[ordered.size()]; for (int i = ordered.size() - 1; i >= 0; i--) { list[i] = (Bucket) ordered.pop(); diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTermsAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTermsAggregator.java index c710f363ead..b43dc250312 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTermsAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/LongTermsAggregator.java @@ -135,8 +135,8 @@ public class LongTermsAggregator extends BucketsAggregator { } @Override - public void doRelease() { - Releasables.release(bucketOrds); + public void doClose() { + Releasables.close(bucketOrds); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/StringTermsAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/StringTermsAggregator.java index 465a72a81d3..8368353d2f8 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/StringTermsAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/StringTermsAggregator.java @@ -240,8 +240,8 @@ public class StringTermsAggregator extends AbstractStringTermsAggregator { } @Override - public void doRelease() { - Releasables.release(bucketOrds); + public void doClose() { + Releasables.close(bucketOrds); } /** @@ -267,7 +267,7 @@ public class StringTermsAggregator extends AbstractStringTermsAggregator { final long maxOrd = ordinals.getMaxOrd(); if (ordinalToBucket == null || ordinalToBucket.size() < maxOrd) { if (ordinalToBucket != null) { - ordinalToBucket.release(); + ordinalToBucket.close(); } ordinalToBucket = context().bigArrays().newLongArray(BigArrays.overSize(maxOrd), false); } @@ -298,8 +298,8 @@ public class StringTermsAggregator extends AbstractStringTermsAggregator { } @Override - public void doRelease() { - Releasables.release(bucketOrds, ordinalToBucket); + public void doClose() { + Releasables.close(bucketOrds, ordinalToBucket); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java index ec592cdaa9f..afa8798115e 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregator.java @@ -114,8 +114,8 @@ public class AvgAggregator extends MetricsAggregator.SingleValue { } @Override - public void doRelease() { - Releasables.release(counts, sums); + public void doClose() { + Releasables.close(counts, sums); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregator.java index 9a88da91fae..27c741a22fb 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregator.java @@ -119,7 +119,7 @@ public class CardinalityAggregator extends MetricsAggregator.SingleValue { if (collector != null) { try { collector.postCollect(); - collector.release(); + collector.close(); } finally { collector = null; } @@ -154,8 +154,8 @@ public class CardinalityAggregator extends MetricsAggregator.SingleValue { } @Override - protected void doRelease() { - Releasables.release(counts, collector); + protected void doClose() { + Releasables.close(counts, collector); } private static interface Collector extends Releasable { @@ -190,8 +190,8 @@ public class CardinalityAggregator extends MetricsAggregator.SingleValue { } @Override - public boolean release() throws ElasticsearchException { - return true; + public void close() throws ElasticsearchException { + // no-op } } @@ -249,9 +249,7 @@ public class CardinalityAggregator extends MetricsAggregator.SingleValue { } final org.elasticsearch.common.hash.MurmurHash3.Hash128 hash = new org.elasticsearch.common.hash.MurmurHash3.Hash128(); - final LongArray hashes = bigArrays.newLongArray(maxOrd, false); - boolean success = false; - try { + try (LongArray hashes = bigArrays.newLongArray(maxOrd, false)) { for (int ord = allVisitedOrds.nextSetBit(0); ord != -1; ord = ord + 1 < maxOrd ? allVisitedOrds.nextSetBit(ord + 1) : -1) { final BytesRef value = values.getValueByOrd(ord); org.elasticsearch.common.hash.MurmurHash3.hash128(value.bytes, value.offset, value.length, 0, hash); @@ -266,16 +264,12 @@ public class CardinalityAggregator extends MetricsAggregator.SingleValue { } } } - success = true; - } finally { - Releasables.release(success, hashes); } } @Override - public boolean release() throws ElasticsearchException { - Releasables.release(visitedOrds); - return true; + public void close() throws ElasticsearchException { + Releasables.close(visitedOrds); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/HyperLogLogPlusPlus.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/HyperLogLogPlusPlus.java index 6e0f95d65f1..6f4a873ec67 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/HyperLogLogPlusPlus.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/HyperLogLogPlusPlus.java @@ -207,7 +207,7 @@ public final class HyperLogLogPlusPlus implements Releasable { } } } finally { - Releasables.release(values); + Releasables.close(values); } } else { if (algorithm.get(thisBucket) != HYPERLOGLOG) { @@ -309,7 +309,7 @@ public final class HyperLogLogPlusPlus implements Releasable { } algorithm.set(bucket); } finally { - Releasables.release(values); + Releasables.close(values); } } @@ -402,9 +402,8 @@ public final class HyperLogLogPlusPlus implements Releasable { } @Override - public boolean release() throws ElasticsearchException { - Releasables.release(runLens, hashSet.sizes); - return true; + public void close() throws ElasticsearchException { + Releasables.close(runLens, hashSet.sizes); } /** @@ -506,16 +505,11 @@ public final class HyperLogLogPlusPlus implements Releasable { out.writeVInt(p); if (algorithm.get(bucket) == LINEAR_COUNTING) { out.writeBoolean(LINEAR_COUNTING); - final IntArray hashes = hashSet.values(bucket); - boolean success = false; - try { + try (IntArray hashes = hashSet.values(bucket)) { out.writeVLong(hashes.size()); for (long i = 0; i < hashes.size(); ++i) { out.writeInt(hashes.get(i)); } - success = true; - } finally { - Releasables.release(success, hashes); } } else { out.writeBoolean(HYPERLOGLOG); diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java index 84f126df230..d6f4a0926b8 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregator.java @@ -115,7 +115,7 @@ public class MaxAggregator extends MetricsAggregator.SingleValue { } @Override - public void doRelease() { - Releasables.release(maxes); + public void doClose() { + Releasables.close(maxes); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java index 45ec0cab65e..8dc36d87a20 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregator.java @@ -114,7 +114,7 @@ public class MinAggregator extends MetricsAggregator.SingleValue { } @Override - public void doRelease() { - Releasables.release(mins); + public void doClose() { + Releasables.close(mins); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/PercentilesAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/PercentilesAggregator.java index 96d15cd4b38..87f59415b1b 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/PercentilesAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/PercentilesAggregator.java @@ -92,8 +92,8 @@ public class PercentilesAggregator extends MetricsAggregator.MultiValue { } @Override - protected void doRelease() { - estimator.release(); + protected void doClose() { + estimator.close(); } public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly { diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/TDigest.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/TDigest.java index 699b6048f9d..b948fab7289 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/TDigest.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/tdigest/TDigest.java @@ -47,9 +47,8 @@ public class TDigest extends PercentilesEstimator { } @Override - public boolean release() throws ElasticsearchException { - states.release(); - return true; + public void close() throws ElasticsearchException { + states.close(); } public void offer(double value, long bucketOrd) { diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggegator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggegator.java index 7b24d02edc2..5abad896fbd 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggegator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggegator.java @@ -156,7 +156,7 @@ public class StatsAggegator extends MetricsAggregator.MultiValue { } @Override - public void doRelease() { - Releasables.release(counts, maxes, mins, sums); + public void doClose() { + Releasables.close(counts, maxes, mins, sums); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java index de8398cefd3..eebc552e783 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregator.java @@ -155,8 +155,8 @@ public class ExtendedStatsAggregator extends MetricsAggregator.MultiValue { } @Override - public void doRelease() { - Releasables.release(counts, maxes, mins, sumOfSqrs, sums); + public void doClose() { + Releasables.close(counts, maxes, mins, sumOfSqrs, sums); } public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly { diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java index 2fd7c5d218d..c31e1bab8bc 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregator.java @@ -109,7 +109,7 @@ public class SumAggregator extends MetricsAggregator.SingleValue { } @Override - public void doRelease() { - Releasables.release(sums); + public void doClose() { + Releasables.close(sums); } } diff --git a/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java b/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java index a9d37fd293d..e2b0f5ccc28 100644 --- a/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java +++ b/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregator.java @@ -92,8 +92,8 @@ public class ValueCountAggregator extends MetricsAggregator.SingleValue { } @Override - public void doRelease() { - Releasables.release(counts); + public void doClose() { + Releasables.close(counts); } public static class Factory extends ValuesSourceAggregatorFactory.LeafOnly { diff --git a/src/main/java/org/elasticsearch/search/facet/datehistogram/CountDateHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/datehistogram/CountDateHistogramFacetExecutor.java index 47a76af4a5a..6c88cf04701 100644 --- a/src/main/java/org/elasticsearch/search/facet/datehistogram/CountDateHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/datehistogram/CountDateHistogramFacetExecutor.java @@ -70,7 +70,7 @@ public class CountDateHistogramFacetExecutor extends FacetExecutor { countEntries[entryIndex++] = new InternalCountDateHistogramFacet.CountEntry(keys[i], values[i]); } } - counts.release(); + counts.close(); return new InternalCountDateHistogramFacet(facetName, comparatorType, countEntries); } diff --git a/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalCountDateHistogramFacet.java b/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalCountDateHistogramFacet.java index 9f50ef6a73d..461179a3b28 100644 --- a/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalCountDateHistogramFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalCountDateHistogramFacet.java @@ -156,7 +156,7 @@ public class InternalCountDateHistogramFacet extends InternalDateHistogramFacet countEntries[entriesIndex++] = new CountEntry(keys[i], values[i]); } } - counts.release(); + counts.close(); Arrays.sort(countEntries, comparatorType.comparator()); diff --git a/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalFullDateHistogramFacet.java b/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalFullDateHistogramFacet.java index 1b25836a80e..49276444ea0 100644 --- a/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalFullDateHistogramFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/datehistogram/InternalFullDateHistogramFacet.java @@ -189,7 +189,7 @@ public class InternalFullDateHistogramFacet extends InternalDateHistogramFacet { ordered.add(value); } - map.release(); + map.close(); // just initialize it as already ordered facet InternalFullDateHistogramFacet ret = new InternalFullDateHistogramFacet(getName()); diff --git a/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueDateHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueDateHistogramFacetExecutor.java index b3b0eb78c6c..913fe942d40 100644 --- a/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueDateHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueDateHistogramFacetExecutor.java @@ -73,7 +73,7 @@ public class ValueDateHistogramFacetExecutor extends FacetExecutor { } } - entries.release(); + entries.close(); return new InternalFullDateHistogramFacet(facetName, comparatorType, entries1); } diff --git a/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueScriptDateHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueScriptDateHistogramFacetExecutor.java index 74afe9f5cbd..5d0a675de75 100644 --- a/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueScriptDateHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/datehistogram/ValueScriptDateHistogramFacetExecutor.java @@ -74,7 +74,7 @@ public class ValueScriptDateHistogramFacetExecutor extends FacetExecutor { } } - entries.release(); + entries.close(); return new InternalFullDateHistogramFacet(facetName, comparatorType, entries1); } diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetExecutor.java index 99793f06c7a..5ddaf6d3b51 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/CountHistogramFacetExecutor.java @@ -67,7 +67,7 @@ public class CountHistogramFacetExecutor extends FacetExecutor { entries[entryIndex++] = new InternalCountHistogramFacet.CountEntry(keys[i], values[i]); } } - counts.release(); + counts.close(); return new InternalCountHistogramFacet(facetName, comparatorType, entries); } diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/FullHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/histogram/FullHistogramFacetExecutor.java index 0c88882ef56..2572c9145d1 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/FullHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/FullHistogramFacetExecutor.java @@ -68,7 +68,7 @@ public class FullHistogramFacetExecutor extends FacetExecutor { fullEntries.add((InternalFullHistogramFacet.FullEntry) values[i]); } } - entries.release(); + entries.close(); return new InternalFullHistogramFacet(facetName, comparatorType, fullEntries); } diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/InternalCountHistogramFacet.java b/src/main/java/org/elasticsearch/search/facet/histogram/InternalCountHistogramFacet.java index 2f934c93baf..62be51d7e1e 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/InternalCountHistogramFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/InternalCountHistogramFacet.java @@ -155,7 +155,7 @@ public class InternalCountHistogramFacet extends InternalHistogramFacet { entries[entryIndex++] = new CountEntry(keys[i], values[i]); } } - counts.release(); + counts.close(); Arrays.sort(entries, comparatorType.comparator()); diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/InternalFullHistogramFacet.java b/src/main/java/org/elasticsearch/search/facet/histogram/InternalFullHistogramFacet.java index 652d7f57304..fe5e2371880 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/InternalFullHistogramFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/InternalFullHistogramFacet.java @@ -186,7 +186,7 @@ public class InternalFullHistogramFacet extends InternalHistogramFacet { ordered.add(value); } - map.release(); + map.close(); // just initialize it as already ordered facet InternalFullHistogramFacet ret = new InternalFullHistogramFacet(getName()); diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/ScriptHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/histogram/ScriptHistogramFacetExecutor.java index 2875e1a8e29..f5f98997691 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/ScriptHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/ScriptHistogramFacetExecutor.java @@ -71,7 +71,7 @@ public class ScriptHistogramFacetExecutor extends FacetExecutor { } } - entries.release(); + entries.close(); return new InternalFullHistogramFacet(facetName, comparatorType, entries1); } diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/ValueHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/histogram/ValueHistogramFacetExecutor.java index fb98ada033e..34090439bfe 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/ValueHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/ValueHistogramFacetExecutor.java @@ -70,7 +70,7 @@ public class ValueHistogramFacetExecutor extends FacetExecutor { entries1.add(value); } } - entries.release(); + entries.close(); return new InternalFullHistogramFacet(facetName, comparatorType, entries1); } diff --git a/src/main/java/org/elasticsearch/search/facet/histogram/ValueScriptHistogramFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/histogram/ValueScriptHistogramFacetExecutor.java index 4f92efb399a..bbefb19038c 100644 --- a/src/main/java/org/elasticsearch/search/facet/histogram/ValueScriptHistogramFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/histogram/ValueScriptHistogramFacetExecutor.java @@ -75,7 +75,7 @@ public class ValueScriptHistogramFacetExecutor extends FacetExecutor { } } - entries.release(); + entries.close(); return new InternalFullHistogramFacet(facetName, comparatorType, entries1); } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/doubles/InternalDoubleTermsFacet.java b/src/main/java/org/elasticsearch/search/facet/terms/doubles/InternalDoubleTermsFacet.java index fd233ff9bc3..27445ab8b92 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/doubles/InternalDoubleTermsFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/doubles/InternalDoubleTermsFacet.java @@ -201,7 +201,7 @@ public class InternalDoubleTermsFacet extends InternalTermsFacet { first.missing = missing; first.total = total; - aggregated.release(); + aggregated.close(); return first; } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/doubles/TermsDoubleFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/terms/doubles/TermsDoubleFacetExecutor.java index 1a28d621220..d40a65d6e83 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/doubles/TermsDoubleFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/doubles/TermsDoubleFacetExecutor.java @@ -101,7 +101,7 @@ public class TermsDoubleFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { if (facets.v().isEmpty()) { - facets.release(); + facets.close(); return new InternalDoubleTermsFacet(facetName, comparatorType, size, ImmutableList.of(), missing, total); } else { final boolean[] states = facets.v().allocated; @@ -118,7 +118,7 @@ public class TermsDoubleFacetExecutor extends FacetExecutor { for (int i = ordered.size() - 1; i >= 0; i--) { list[i] = (InternalDoubleTermsFacet.DoubleEntry) ordered.pop(); } - facets.release(); + facets.close(); return new InternalDoubleTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total); } else { BoundedTreeSet ordered = new BoundedTreeSet<>(comparatorType.comparator(), shardSize); @@ -127,7 +127,7 @@ public class TermsDoubleFacetExecutor extends FacetExecutor { ordered.add(new InternalDoubleTermsFacet.DoubleEntry(keys[i], values[i])); } } - facets.release(); + facets.close(); return new InternalDoubleTermsFacet(facetName, comparatorType, size, ordered, missing, total); } } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/longs/InternalLongTermsFacet.java b/src/main/java/org/elasticsearch/search/facet/terms/longs/InternalLongTermsFacet.java index 5ed3430e01a..54373eb179b 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/longs/InternalLongTermsFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/longs/InternalLongTermsFacet.java @@ -202,7 +202,7 @@ public class InternalLongTermsFacet extends InternalTermsFacet { first.missing = missing; first.total = total; - aggregated.release(); + aggregated.close(); return first; } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetExecutor.java index 3493303e25f..a59303f4c6b 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/longs/TermsLongFacetExecutor.java @@ -100,7 +100,7 @@ public class TermsLongFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { if (facets.v().isEmpty()) { - facets.release(); + facets.close(); return new InternalLongTermsFacet(facetName, comparatorType, size, ImmutableList.of(), missing, total); } else { LongIntOpenHashMap facetEntries = facets.v(); @@ -118,7 +118,7 @@ public class TermsLongFacetExecutor extends FacetExecutor { for (int i = ordered.size() - 1; i >= 0; i--) { list[i] = (InternalLongTermsFacet.LongEntry) ordered.pop(); } - facets.release(); + facets.close(); return new InternalLongTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total); } else { BoundedTreeSet ordered = new BoundedTreeSet<>(comparatorType.comparator(), shardSize); @@ -127,7 +127,7 @@ public class TermsLongFacetExecutor extends FacetExecutor { ordered.add(new InternalLongTermsFacet.LongEntry(keys[i], values[i])); } } - facets.release(); + facets.close(); return new InternalLongTermsFacet(facetName, comparatorType, size, ordered, missing, total); } } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/strings/InternalStringTermsFacet.java b/src/main/java/org/elasticsearch/search/facet/terms/strings/InternalStringTermsFacet.java index dd630053539..26107033eaf 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/strings/InternalStringTermsFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/strings/InternalStringTermsFacet.java @@ -218,7 +218,7 @@ public class InternalStringTermsFacet extends InternalTermsFacet { first.missing = missing; first.total = total; - aggregated.release(); + aggregated.close(); return first; } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/strings/ScriptTermsStringFieldFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/terms/strings/ScriptTermsStringFieldFacetExecutor.java index b93868b51e2..b0b69a444cf 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/strings/ScriptTermsStringFieldFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/strings/ScriptTermsStringFieldFacetExecutor.java @@ -80,7 +80,7 @@ public class ScriptTermsStringFieldFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { if (facets.v().isEmpty()) { - facets.release(); + facets.close(); return new InternalStringTermsFacet(facetName, comparatorType, size, ImmutableList.of(), missing, total); } else { final boolean[] states = facets.v().allocated; @@ -98,7 +98,7 @@ public class ScriptTermsStringFieldFacetExecutor extends FacetExecutor { for (int i = ordered.size() - 1; i >= 0; i--) { list[i] = ((InternalStringTermsFacet.TermEntry) ordered.pop()); } - facets.release(); + facets.close(); return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total); } else { BoundedTreeSet ordered = new BoundedTreeSet<>(comparatorType.comparator(), shardSize); @@ -108,7 +108,7 @@ public class ScriptTermsStringFieldFacetExecutor extends FacetExecutor { ordered.add(new InternalStringTermsFacet.TermEntry(key, values[i])); } } - facets.release(); + facets.close(); return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, missing, total); } } diff --git a/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringOrdinalsFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringOrdinalsFacetExecutor.java index b5cddff33f3..197b50d6200 100644 --- a/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringOrdinalsFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/terms/strings/TermsStringOrdinalsFacetExecutor.java @@ -151,7 +151,7 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { list[i] = (InternalStringTermsFacet.TermEntry) ordered.pop(); } - Releasables.release(aggregators); + Releasables.close(aggregators); return new InternalStringTermsFacet(facetName, comparatorType, size, Arrays.asList(list), missing, total); } @@ -189,7 +189,7 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { } } - Releasables.release(aggregators); + Releasables.close(aggregators); return new InternalStringTermsFacet(facetName, comparatorType, size, ordered, missing, total); } @@ -210,7 +210,7 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { if (current.values.ordinals().getNumOrds() > 0) { aggregators.add(current); } else { - Releasables.release(current); + Releasables.close(current); } } values = indexFieldData.load(context).getBytesValues(false); @@ -238,7 +238,7 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { if (current.values.ordinals().getNumOrds() > 0) { aggregators.add(current); } else { - Releasables.release(current); + Releasables.close(current); } current = null; } @@ -287,9 +287,8 @@ public class TermsStringOrdinalsFacetExecutor extends FacetExecutor { } @Override - public boolean release() { - Releasables.release(counts); - return true; + public void close() { + Releasables.close(counts); } } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/InternalTermsStatsDoubleFacet.java b/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/InternalTermsStatsDoubleFacet.java index 3f4017a23fe..cd52a7158d7 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/InternalTermsStatsDoubleFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/InternalTermsStatsDoubleFacet.java @@ -211,7 +211,7 @@ public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet { if (requiredSize == 0) { // all terms DoubleEntry[] entries1 = map.v().values().toArray(DoubleEntry.class); Arrays.sort(entries1, comparatorType.comparator()); - map.release(); + map.close(); return new InternalTermsStatsDoubleFacet(getName(), comparatorType, requiredSize, Arrays.asList(entries1), missing); } else { Object[] values = map.v().values; @@ -224,7 +224,7 @@ public class InternalTermsStatsDoubleFacet extends InternalTermsStatsFacet { } ordered.add(value); } - map.release(); + map.close(); return new InternalTermsStatsDoubleFacet(getName(), comparatorType, requiredSize, ordered, missing); } } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/TermsStatsDoubleFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/TermsStatsDoubleFacetExecutor.java index 421ffc76f0b..dddfe582bf4 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/TermsStatsDoubleFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/doubles/TermsStatsDoubleFacetExecutor.java @@ -74,7 +74,7 @@ public class TermsStatsDoubleFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { if (entries.v().isEmpty()) { - entries.release(); + entries.close(); return new InternalTermsStatsDoubleFacet(facetName, comparatorType, size, ImmutableList.of(), missing); } if (size == 0) { // all terms @@ -87,7 +87,7 @@ public class TermsStatsDoubleFacetExecutor extends FacetExecutor { doubleEntries.add((InternalTermsStatsDoubleFacet.DoubleEntry) values[i]); } } - entries.release(); + entries.close(); return new InternalTermsStatsDoubleFacet(facetName, comparatorType, 0 /* indicates all terms*/, doubleEntries, missing); } Object[] values = entries.v().values; @@ -103,7 +103,7 @@ public class TermsStatsDoubleFacetExecutor extends FacetExecutor { ordered.add(value); } - entries.release(); + entries.close(); return new InternalTermsStatsDoubleFacet(facetName, comparatorType, size, ordered, missing); } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/longs/InternalTermsStatsLongFacet.java b/src/main/java/org/elasticsearch/search/facet/termsstats/longs/InternalTermsStatsLongFacet.java index 827105d4422..bf6229778a8 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/longs/InternalTermsStatsLongFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/longs/InternalTermsStatsLongFacet.java @@ -211,7 +211,7 @@ public class InternalTermsStatsLongFacet extends InternalTermsStatsFacet { if (requiredSize == 0) { // all terms LongEntry[] entries1 = map.v().values().toArray(LongEntry.class); Arrays.sort(entries1, comparatorType.comparator()); - map.release(); + map.close(); return new InternalTermsStatsLongFacet(getName(), comparatorType, requiredSize, Arrays.asList(entries1), missing); } else { Object[] values = map.v().values; @@ -224,7 +224,7 @@ public class InternalTermsStatsLongFacet extends InternalTermsStatsFacet { } ordered.add(value); } - map.release(); + map.close(); return new InternalTermsStatsLongFacet(getName(), comparatorType, requiredSize, ordered, missing); } } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/longs/TermsStatsLongFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/termsstats/longs/TermsStatsLongFacetExecutor.java index 733318c3ffb..95e3a0d9dea 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/longs/TermsStatsLongFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/longs/TermsStatsLongFacetExecutor.java @@ -75,7 +75,7 @@ public class TermsStatsLongFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { if (entries.v().isEmpty()) { - entries.release(); + entries.close(); return new InternalTermsStatsLongFacet(facetName, comparatorType, size, ImmutableList.of(), missing); } if (size == 0) { // all terms @@ -89,7 +89,7 @@ public class TermsStatsLongFacetExecutor extends FacetExecutor { } } - entries.release(); + entries.close(); return new InternalTermsStatsLongFacet(facetName, comparatorType, 0 /* indicates all terms*/, longEntries, missing); } @@ -106,7 +106,7 @@ public class TermsStatsLongFacetExecutor extends FacetExecutor { } ordered.add(value); } - entries.release(); + entries.close(); return new InternalTermsStatsLongFacet(facetName, comparatorType, size, ordered, missing); } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/strings/InternalTermsStatsStringFacet.java b/src/main/java/org/elasticsearch/search/facet/termsstats/strings/InternalTermsStatsStringFacet.java index 704c0f24091..1de0dadd7cb 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/strings/InternalTermsStatsStringFacet.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/strings/InternalTermsStatsStringFacet.java @@ -216,7 +216,7 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet { if (requiredSize == 0) { // all terms StringEntry[] entries1 = map.v().values().toArray(StringEntry.class); Arrays.sort(entries1, comparatorType.comparator()); - map.release(); + map.close(); return new InternalTermsStatsStringFacet(getName(), comparatorType, requiredSize, Arrays.asList(entries1), missing); } else { Object[] values = map.v().values; @@ -229,7 +229,7 @@ public class InternalTermsStatsStringFacet extends InternalTermsStatsFacet { } ordered.add(value); } - map.release(); + map.close(); return new InternalTermsStatsStringFacet(getName(), comparatorType, requiredSize, ordered, missing); } } diff --git a/src/main/java/org/elasticsearch/search/facet/termsstats/strings/TermsStatsStringFacetExecutor.java b/src/main/java/org/elasticsearch/search/facet/termsstats/strings/TermsStatsStringFacetExecutor.java index 70b2ffdbf36..4037e678f4c 100644 --- a/src/main/java/org/elasticsearch/search/facet/termsstats/strings/TermsStatsStringFacetExecutor.java +++ b/src/main/java/org/elasticsearch/search/facet/termsstats/strings/TermsStatsStringFacetExecutor.java @@ -77,7 +77,7 @@ public class TermsStatsStringFacetExecutor extends FacetExecutor { @Override public InternalFacet buildFacet(String facetName) { if (entries.v().isEmpty()) { - entries.release(); + entries.close(); return new InternalTermsStatsStringFacet(facetName, comparatorType, size, ImmutableList.of(), missing); } if (size == 0) { // all terms @@ -105,7 +105,7 @@ public class TermsStatsStringFacetExecutor extends FacetExecutor { ordered.add(value); } - entries.release(); + entries.close(); return new InternalTermsStatsStringFacet(facetName, comparatorType, size, ordered, missing); } diff --git a/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java b/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java index 424a8146ecb..d5f7f348c48 100644 --- a/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java +++ b/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java @@ -207,19 +207,18 @@ public class DefaultSearchContext extends SearchContext { } @Override - public boolean release() throws ElasticsearchException { + public void close() throws ElasticsearchException { if (scanContext != null) { scanContext.clear(); } // clear and scope phase we have searcher.release(); - engineSearcher.release(); - return true; + engineSearcher.close(); } - public boolean clearAndRelease() { + public void clearAndRelease() { clearReleasables(); - return release(); + close(); } /** @@ -690,7 +689,7 @@ public class DefaultSearchContext extends SearchContext { public void clearReleasables() { if (clearables != null) { try { - Releasables.release(clearables); + Releasables.close(clearables); } finally { clearables.clear(); } diff --git a/src/main/java/org/elasticsearch/search/internal/SearchContext.java b/src/main/java/org/elasticsearch/search/internal/SearchContext.java index db94fdcd140..4bfe0a862dc 100644 --- a/src/main/java/org/elasticsearch/search/internal/SearchContext.java +++ b/src/main/java/org/elasticsearch/search/internal/SearchContext.java @@ -81,7 +81,7 @@ public abstract class SearchContext implements Releasable { return current.get(); } - public abstract boolean clearAndRelease(); + public abstract void clearAndRelease(); /** * Should be called before executing the main query and after all other parameters have been set. diff --git a/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java b/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java index deaf4dd098b..d503aad91a2 100644 --- a/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java +++ b/src/main/java/org/elasticsearch/transport/netty/NettyTransport.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.bytes.ReleasableBytesReference; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.compress.CompressorFactory; import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.HandlesStreamOutput; import org.elasticsearch.common.io.stream.ReleasableBytesStreamOutput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -604,7 +603,7 @@ public class NettyTransport extends AbstractLifecycleComponent implem addedReleaseListener = true; } finally { if (!addedReleaseListener) { - Releasables.release(bStream.bytes()); + Releasables.close(bStream.bytes()); } } } diff --git a/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java b/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java index c915ccea7c6..1ae0e517cbd 100644 --- a/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java +++ b/src/main/java/org/elasticsearch/transport/netty/NettyTransportChannel.java @@ -98,7 +98,7 @@ public class NettyTransportChannel implements TransportChannel { addedReleaseListener = true; } finally { if (!addedReleaseListener) { - Releasables.release(bStream.bytes()); + Releasables.close(bStream.bytes()); } } } @@ -136,7 +136,7 @@ public class NettyTransportChannel implements TransportChannel { addedReleaseListener = true; } finally { if (!addedReleaseListener) { - Releasables.release(stream.bytes()); + Releasables.close(stream.bytes()); } } } diff --git a/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java b/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java index 0d096d97524..37a662dec90 100644 --- a/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java +++ b/src/test/java/org/elasticsearch/benchmark/common/recycler/RecyclerBenchmark.java @@ -58,7 +58,7 @@ public class RecyclerBenchmark { } while (recycles.getAndDecrement() > 0) { final Recycler.V v = recycler.obtain(); - v.release(); + v.close(); } } }; diff --git a/src/test/java/org/elasticsearch/common/recycler/AbstractRecyclerTests.java b/src/test/java/org/elasticsearch/common/recycler/AbstractRecyclerTests.java index 9696bc7bafd..524ae7367a6 100644 --- a/src/test/java/org/elasticsearch/common/recycler/AbstractRecyclerTests.java +++ b/src/test/java/org/elasticsearch/common/recycler/AbstractRecyclerTests.java @@ -88,7 +88,7 @@ public abstract class AbstractRecyclerTests extends ElasticsearchTestCase { assertFalse(o.isRecycled()); final byte[] b1 = o.v(); assertFresh(b1); - o.release(); + o.close(); assertRecycled(b1); o = r.obtain(); final byte[] b2 = o.v(); @@ -99,7 +99,7 @@ public abstract class AbstractRecyclerTests extends ElasticsearchTestCase { assertFresh(b2); assertNotSame(b1, b2); } - o.release(); + o.close(); r.close(); } @@ -108,19 +108,19 @@ public abstract class AbstractRecyclerTests extends ElasticsearchTestCase { Recycler.V o = r.obtain(); assertFresh(o.v()); getRandom().nextBytes(o.v()); - o.release(); + o.close(); o = r.obtain(); assertRecycled(o.v()); - o.release(); + o.close(); r.close(); } public void testDoubleRelease() { final Recycler r = newRecycler(limit); final Recycler.V v1 = r.obtain(); - v1.release(); + v1.close(); try { - v1.release(); + v1.close(); } catch (ElasticsearchIllegalStateException e) { // impl has protection against double release: ok return; @@ -147,11 +147,11 @@ public abstract class AbstractRecyclerTests extends ElasticsearchTestCase { } // Recycler size increases on release, not on obtain! for (V v: vals) { - v.release(); + v.close(); } // release first ref, verify for destruction - o.release(); + o.close(); assertDead(data); // close the rest @@ -168,7 +168,7 @@ public abstract class AbstractRecyclerTests extends ElasticsearchTestCase { // randomize & return to pool getRandom().nextBytes(data); - o.release(); + o.close(); // verify that recycle() ran assertRecycled(data); diff --git a/src/test/java/org/elasticsearch/common/util/BigArraysTests.java b/src/test/java/org/elasticsearch/common/util/BigArraysTests.java index 781ab143d9d..6d17cd4f7cf 100644 --- a/src/test/java/org/elasticsearch/common/util/BigArraysTests.java +++ b/src/test/java/org/elasticsearch/common/util/BigArraysTests.java @@ -57,7 +57,7 @@ public class BigArraysTests extends ElasticsearchTestCase { for (int i = 0; i < totalLen; ++i) { assertEquals(ref[i], array.get(i)); } - array.release(); + array.close(); } public void testIntArrayGrowth() { @@ -73,7 +73,7 @@ public class BigArraysTests extends ElasticsearchTestCase { for (int i = 0; i < totalLen; ++i) { assertEquals(ref[i], array.get(i)); } - array.release(); + array.close(); } public void testLongArrayGrowth() { @@ -89,7 +89,7 @@ public class BigArraysTests extends ElasticsearchTestCase { for (int i = 0; i < totalLen; ++i) { assertEquals(ref[i], array.get(i)); } - array.release(); + array.close(); } public void testFloatArrayGrowth() { @@ -105,7 +105,7 @@ public class BigArraysTests extends ElasticsearchTestCase { for (int i = 0; i < totalLen; ++i) { assertEquals(ref[i], array.get(i), 0.001d); } - array.release(); + array.close(); } public void testDoubleArrayGrowth() { @@ -121,7 +121,7 @@ public class BigArraysTests extends ElasticsearchTestCase { for (int i = 0; i < totalLen; ++i) { assertEquals(ref[i], array.get(i), 0.001d); } - array.release(); + array.close(); } public void testObjectArrayGrowth() { @@ -141,7 +141,7 @@ public class BigArraysTests extends ElasticsearchTestCase { for (int i = 0; i < totalLen; ++i) { assertSame(ref[i], array.get(i)); } - array.release(); + array.close(); } public void testByteArrayFill() { @@ -162,7 +162,7 @@ public class BigArraysTests extends ElasticsearchTestCase { for (int i = 0; i < len; ++i) { assertEquals(array1[i], array2.get(i), 0.001d); } - array2.release(); + array2.close(); } public void testFloatArrayFill() { @@ -183,7 +183,7 @@ public class BigArraysTests extends ElasticsearchTestCase { for (int i = 0; i < len; ++i) { assertEquals(array1[i], array2.get(i), 0.001d); } - array2.release(); + array2.close(); } public void testDoubleArrayFill() { @@ -204,7 +204,7 @@ public class BigArraysTests extends ElasticsearchTestCase { for (int i = 0; i < len; ++i) { assertEquals(array1[i], array2.get(i), 0.001d); } - array2.release(); + array2.close(); } public void testLongArrayFill() { @@ -225,7 +225,7 @@ public class BigArraysTests extends ElasticsearchTestCase { for (int i = 0; i < len; ++i) { assertEquals(array1[i], array2.get(i)); } - array2.release(); + array2.close(); } public void testByteArrayBulkGet() { @@ -242,7 +242,7 @@ public class BigArraysTests extends ElasticsearchTestCase { array2.get(offset, len, ref); assertEquals(new BytesRef(array1, offset, len), ref); } - array2.release(); + array2.close(); } public void testByteArrayBulkSet() { @@ -257,7 +257,7 @@ public class BigArraysTests extends ElasticsearchTestCase { for (int i = 0; i < array1.length; ++i) { assertEquals(array1[i], array2.get(i)); } - array2.release(); + array2.close(); } public void testByteArrayEquals() { @@ -268,29 +268,29 @@ public class BigArraysTests extends ElasticsearchTestCase { assertTrue(bigArrays.equals(empty1, empty1)); // equality: both empty assertTrue(bigArrays.equals(empty1, empty2)); - empty1.release(); - empty2.release(); + empty1.close(); + empty2.close(); // not equal: contents differ final ByteArray a1 = byteArrayWithBytes(new byte[]{0}); final ByteArray a2 = byteArrayWithBytes(new byte[]{1}); assertFalse(bigArrays.equals(a1, a2)); - a1.release(); - a2.release(); + a1.close(); + a2.close(); // not equal: contents differ final ByteArray a3 = byteArrayWithBytes(new byte[]{1,2,3}); final ByteArray a4 = byteArrayWithBytes(new byte[]{1,1,3}); assertFalse(bigArrays.equals(a3, a4)); - a3.release(); - a4.release(); + a3.close(); + a4.close(); // not equal: contents differ final ByteArray a5 = byteArrayWithBytes(new byte[]{1,2,3}); final ByteArray a6 = byteArrayWithBytes(new byte[]{1,2,4}); assertFalse(bigArrays.equals(a5, a6)); - a5.release(); - a6.release(); + a5.close(); + a6.close(); } public void testByteArrayHashCode() { @@ -302,7 +302,7 @@ public class BigArraysTests extends ElasticsearchTestCase { final ByteArray emptyByteArray = byteArrayWithBytes(BytesRef.EMPTY_BYTES); final int emptyByteArrayHash = bigArrays.hashCode(emptyByteArray); assertEquals(emptyHash, emptyByteArrayHash); - emptyByteArray.release(); + emptyByteArray.close(); // FUN FACT: Arrays.hashCode() and BytesReference.bytesHashCode() are inconsistent for empty byte[] // final int emptyHash3 = new BytesArray(BytesRef.EMPTY_BYTES).hashCode(); @@ -315,7 +315,7 @@ public class BigArraysTests extends ElasticsearchTestCase { final ByteArray array2 = byteArrayWithBytes(array1); final int array2Hash = bigArrays.hashCode(array2); assertEquals(array1Hash, array2Hash); - array2.release(); + array2.close(); } private ByteArray byteArrayWithBytes(byte[] bytes) { diff --git a/src/test/java/org/elasticsearch/common/util/BytesRefHashTests.java b/src/test/java/org/elasticsearch/common/util/BytesRefHashTests.java index 982d53bc000..4bc35fd48d7 100644 --- a/src/test/java/org/elasticsearch/common/util/BytesRefHashTests.java +++ b/src/test/java/org/elasticsearch/common/util/BytesRefHashTests.java @@ -36,7 +36,7 @@ public class BytesRefHashTests extends ElasticsearchTestCase { private void newHash() { if (hash != null) { - hash.release(); + hash.close(); } // Test high load factors to make sure that collision resolution works fine final float maxLoadFactor = 0.6f + randomFloat() * 0.39f; @@ -83,7 +83,7 @@ public class BytesRefHashTests extends ElasticsearchTestCase { assertEquals(idToValue[(int) id], spare); } } - hash.release(); + hash.close(); } // START - tests borrowed from LUCENE @@ -114,7 +114,7 @@ public class BytesRefHashTests extends ElasticsearchTestCase { } } } - hash.release(); + hash.close(); } /** @@ -154,7 +154,7 @@ public class BytesRefHashTests extends ElasticsearchTestCase { } newHash(); } - hash.release(); + hash.close(); } /** @@ -195,7 +195,7 @@ public class BytesRefHashTests extends ElasticsearchTestCase { assertAllIn(strings, hash); newHash(); } - hash.release(); + hash.close(); } @Test @@ -231,7 +231,7 @@ public class BytesRefHashTests extends ElasticsearchTestCase { assertAllIn(strings, hash); newHash(); } - hash.release(); + hash.close(); } private void assertAllIn(Set strings, BytesRefHash hash) { diff --git a/src/test/java/org/elasticsearch/common/util/DoubleObjectHashMapTests.java b/src/test/java/org/elasticsearch/common/util/DoubleObjectHashMapTests.java index 0a6585138fa..90a58ab9449 100644 --- a/src/test/java/org/elasticsearch/common/util/DoubleObjectHashMapTests.java +++ b/src/test/java/org/elasticsearch/common/util/DoubleObjectHashMapTests.java @@ -52,7 +52,7 @@ public class DoubleObjectHashMapTests extends ElasticsearchTestCase { for (DoubleObjectPagedHashMap.Cursor cursor : map2) { copy.put(cursor.key, cursor.value); } - map2.release(); + map2.close(); assertEquals(map1, copy); } diff --git a/src/test/java/org/elasticsearch/common/util/LongHashTests.java b/src/test/java/org/elasticsearch/common/util/LongHashTests.java index e4acf0a7e9e..5b908de9a06 100644 --- a/src/test/java/org/elasticsearch/common/util/LongHashTests.java +++ b/src/test/java/org/elasticsearch/common/util/LongHashTests.java @@ -33,7 +33,7 @@ public class LongHashTests extends ElasticsearchTestCase { private void newHash() { if (hash != null) { - hash.release(); + hash.close(); } // Test high load factors to make sure that collision resolution works fine @@ -83,7 +83,7 @@ public class LongHashTests extends ElasticsearchTestCase { assertEquals(idToValue[(int) i], hash.get(i)); } - hash.release(); + hash.close(); } @Test @@ -103,7 +103,7 @@ public class LongHashTests extends ElasticsearchTestCase { } } } - hash.release(); + hash.close(); } @Test @@ -135,7 +135,7 @@ public class LongHashTests extends ElasticsearchTestCase { newHash(); } - hash.release(); + hash.close(); } @Test @@ -164,7 +164,7 @@ public class LongHashTests extends ElasticsearchTestCase { assertAllIn(longs, hash); newHash(); } - hash.release(); + hash.close(); } @Test @@ -194,7 +194,7 @@ public class LongHashTests extends ElasticsearchTestCase { assertAllIn(longs, hash); newHash(); } - hash.release(); + hash.close(); } private static void assertAllIn(Set longs, LongHash hash) { diff --git a/src/test/java/org/elasticsearch/common/util/LongObjectHashMapTests.java b/src/test/java/org/elasticsearch/common/util/LongObjectHashMapTests.java index cb95d0146f3..3452059c39c 100644 --- a/src/test/java/org/elasticsearch/common/util/LongObjectHashMapTests.java +++ b/src/test/java/org/elasticsearch/common/util/LongObjectHashMapTests.java @@ -52,7 +52,7 @@ public class LongObjectHashMapTests extends ElasticsearchTestCase { for (LongObjectPagedHashMap.Cursor cursor : map2) { copy.put(cursor.key, cursor.value); } - map2.release(); + map2.close(); assertEquals(map1, copy); } diff --git a/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java b/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java index eed806c0658..297d6aedec7 100644 --- a/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java +++ b/src/test/java/org/elasticsearch/index/deletionpolicy/SnapshotDeletionPolicyTests.java @@ -91,7 +91,7 @@ public class SnapshotDeletionPolicyTests extends ElasticsearchTestCase { assertThat(listCommits(dir).size(), equalTo(2)); // release the commit, add a document and commit, now we should be back to one commit point - assertThat(snapshot.release(), equalTo(true)); + snapshot.close(); indexWriter.addDocument(testDocument()); indexWriter.commit(); assertThat(listCommits(dir).size(), equalTo(1)); @@ -114,13 +114,13 @@ public class SnapshotDeletionPolicyTests extends ElasticsearchTestCase { assertThat(listCommits(dir).size(), equalTo(2)); // release one snapshot, we should still have two commit points - assertThat(snapshot1.release(), equalTo(true)); + snapshot1.close(); indexWriter.addDocument(testDocument()); indexWriter.commit(); assertThat(listCommits(dir).size(), equalTo(2)); // release the second snapshot, we should be back to one commit - assertThat(snapshot2.release(), equalTo(true)); + snapshot2.close(); indexWriter.addDocument(testDocument()); indexWriter.commit(); assertThat(listCommits(dir).size(), equalTo(1)); @@ -135,8 +135,8 @@ public class SnapshotDeletionPolicyTests extends ElasticsearchTestCase { // snapshot the last commit, and release it twice, the seconds should throw an exception SnapshotIndexCommit snapshot = deletionPolicy.snapshot(); - assertThat(snapshot.release(), equalTo(true)); - assertThat(snapshot.release(), equalTo(false)); + snapshot.close(); + snapshot.close(); } @Test @@ -164,13 +164,13 @@ public class SnapshotDeletionPolicyTests extends ElasticsearchTestCase { // release the snapshot, add a document and commit // we should have 3 commits points since we are holding onto the first two with snapshots // and we are using the keep only last - assertThat(snapshot.release(), equalTo(true)); + snapshot.close(); indexWriter.addDocument(testDocument()); indexWriter.commit(); assertThat(listCommits(dir).size(), equalTo(3)); // now release the snapshots, we should be back to a single commit point - assertThat(snapshots.release(), equalTo(true)); + snapshots.close(); indexWriter.addDocument(testDocument()); indexWriter.commit(); assertThat(listCommits(dir).size(), equalTo(1)); diff --git a/src/test/java/org/elasticsearch/index/engine/internal/InternalEngineTests.java b/src/test/java/org/elasticsearch/index/engine/internal/InternalEngineTests.java index 02e33fa3ecc..563f9532ebf 100644 --- a/src/test/java/org/elasticsearch/index/engine/internal/InternalEngineTests.java +++ b/src/test/java/org/elasticsearch/index/engine/internal/InternalEngineTests.java @@ -402,7 +402,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { public void testSimpleOperations() throws Exception { Engine.Searcher searchResult = engine.acquireSearcher("test"); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(0)); - searchResult.release(); + searchResult.close(); // create a document Document document = testDocumentWithTextField(); @@ -414,7 +414,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { searchResult = engine.acquireSearcher("test"); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(0)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0)); - searchResult.release(); + searchResult.close(); // but, we can still get it (in realtime) Engine.GetResult getResult = engine.get(new Engine.Get(true, newUid("1"))); @@ -434,7 +434,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { searchResult = engine.acquireSearcher("test"); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 1)); - searchResult.release(); + searchResult.close(); // also in non realtime getResult = engine.get(new Engine.Get(false, newUid("1"))); @@ -454,7 +454,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 0)); - searchResult.release(); + searchResult.close(); // but, we can still get it (in realtime) getResult = engine.get(new Engine.Get(true, newUid("1"))); @@ -470,7 +470,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 1)); - searchResult.release(); + searchResult.close(); // now delete engine.delete(new Engine.Delete("test", "1", newUid("1"))); @@ -480,7 +480,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 1)); - searchResult.release(); + searchResult.close(); // but, get should not see it (in realtime) getResult = engine.get(new Engine.Get(true, newUid("1"))); @@ -494,7 +494,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(0)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 0)); - searchResult.release(); + searchResult.close(); // add it back document = testDocumentWithTextField(); @@ -507,7 +507,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(0)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 0)); - searchResult.release(); + searchResult.close(); // refresh and it should be there engine.refresh(new Engine.Refresh("test").force(false)); @@ -517,7 +517,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 0)); - searchResult.release(); + searchResult.close(); // now flush engine.flush(new Engine.Flush()); @@ -541,7 +541,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 0)); - searchResult.release(); + searchResult.close(); // refresh and it should be updated engine.refresh(new Engine.Refresh("test").force(false)); @@ -550,7 +550,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test1")), 1)); - searchResult.release(); + searchResult.close(); engine.close(); } @@ -559,7 +559,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { public void testSearchResultRelease() throws Exception { Engine.Searcher searchResult = engine.acquireSearcher("test"); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(0)); - searchResult.release(); + searchResult.close(); // create a document ParsedDocument doc = testParsedDocument("1", "1", "test", null, -1, -1, testDocumentWithTextField(), Lucene.STANDARD_ANALYZER, B_1, false); @@ -569,7 +569,7 @@ public class InternalEngineTests extends ElasticsearchTestCase { searchResult = engine.acquireSearcher("test"); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(0)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 0)); - searchResult.release(); + searchResult.close(); // refresh and it should be there engine.refresh(new Engine.Refresh("test").force(false)); @@ -585,12 +585,12 @@ public class InternalEngineTests extends ElasticsearchTestCase { engine.refresh(new Engine.Refresh("test").force(false)); Engine.Searcher updateSearchResult = engine.acquireSearcher("test"); MatcherAssert.assertThat(updateSearchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(0)); - updateSearchResult.release(); + updateSearchResult.close(); // the non release search result should not see the deleted yet... MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(1)); MatcherAssert.assertThat(searchResult, EngineSearcherTotalHitsMatcher.engineSearcherTotalHits(new TermQuery(new Term("value", "test")), 1)); - searchResult.release(); + searchResult.close(); } diff --git a/src/test/java/org/elasticsearch/index/search/child/TestSearchContext.java b/src/test/java/org/elasticsearch/index/search/child/TestSearchContext.java index 42bc3d2db16..d278d989c79 100644 --- a/src/test/java/org/elasticsearch/index/search/child/TestSearchContext.java +++ b/src/test/java/org/elasticsearch/index/search/child/TestSearchContext.java @@ -95,8 +95,8 @@ public class TestSearchContext extends SearchContext { } @Override - public boolean clearAndRelease() { - return false; + public void clearAndRelease() { + // no-op } @Override @@ -590,8 +590,8 @@ public class TestSearchContext extends SearchContext { } @Override - public boolean release() throws ElasticsearchException { - return false; + public void close() throws ElasticsearchException { + // no-op } @Override diff --git a/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java b/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java index b6c9190575b..91b893cff90 100644 --- a/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java +++ b/src/test/java/org/elasticsearch/index/translog/AbstractSimpleTranslogTests.java @@ -75,64 +75,64 @@ public abstract class AbstractSimpleTranslogTests { public void testTransientTranslog() { Translog.Snapshot snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(0)); - snapshot.release(); + snapshot.close(); translog.add(new Translog.Create("test", "1", new byte[]{1})); snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(1)); assertThat(snapshot.estimatedTotalOperations(), equalTo(1)); - snapshot.release(); + snapshot.close(); translog.newTransientTranslog(2); snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(1)); assertThat(snapshot.estimatedTotalOperations(), equalTo(1)); - snapshot.release(); + snapshot.close(); translog.add(new Translog.Index("test", "2", new byte[]{2})); snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(2)); assertThat(snapshot.estimatedTotalOperations(), equalTo(2)); - snapshot.release(); + snapshot.close(); translog.makeTransientCurrent(); snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(1)); // now its one, since it only includes "2" assertThat(snapshot.estimatedTotalOperations(), equalTo(1)); - snapshot.release(); + snapshot.close(); } @Test public void testSimpleOperations() { Translog.Snapshot snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(0)); - snapshot.release(); + snapshot.close(); translog.add(new Translog.Create("test", "1", new byte[]{1})); snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(1)); assertThat(snapshot.estimatedTotalOperations(), equalTo(1)); - snapshot.release(); + snapshot.close(); translog.add(new Translog.Index("test", "2", new byte[]{2})); snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(2)); assertThat(snapshot.estimatedTotalOperations(), equalTo(2)); - snapshot.release(); + snapshot.close(); translog.add(new Translog.Delete(newUid("3"))); snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(3)); assertThat(snapshot.estimatedTotalOperations(), equalTo(3)); - snapshot.release(); + snapshot.close(); translog.add(new Translog.DeleteByQuery(new BytesArray(new byte[]{4}), null)); snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(4)); assertThat(snapshot.estimatedTotalOperations(), equalTo(4)); - snapshot.release(); + snapshot.close(); snapshot = translog.snapshot(); @@ -154,7 +154,7 @@ public abstract class AbstractSimpleTranslogTests { assertThat(snapshot.hasNext(), equalTo(false)); - snapshot.release(); + snapshot.close(); long firstId = translog.currentId(); translog.newTranslog(2); @@ -163,26 +163,26 @@ public abstract class AbstractSimpleTranslogTests { snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(0)); assertThat(snapshot.estimatedTotalOperations(), equalTo(0)); - snapshot.release(); + snapshot.close(); } @Test public void testSnapshot() { Translog.Snapshot snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(0)); - snapshot.release(); + snapshot.close(); translog.add(new Translog.Create("test", "1", new byte[]{1})); snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(1)); assertThat(snapshot.estimatedTotalOperations(), equalTo(1)); - snapshot.release(); + snapshot.close(); snapshot = translog.snapshot(); assertThat(snapshot.hasNext(), equalTo(true)); Translog.Create create = (Translog.Create) snapshot.next(); assertThat(create.source().toBytes(), equalTo(new byte[]{1})); - snapshot.release(); + snapshot.close(); Translog.Snapshot snapshot1 = translog.snapshot(); // we use the translogSize to also navigate to the last position on this snapshot @@ -194,7 +194,7 @@ public abstract class AbstractSimpleTranslogTests { snapshot = translog.snapshot(snapshot1); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(1)); assertThat(snapshot.estimatedTotalOperations(), equalTo(2)); - snapshot.release(); + snapshot.close(); snapshot = translog.snapshot(snapshot1); assertThat(snapshot.hasNext(), equalTo(true)); @@ -202,15 +202,15 @@ public abstract class AbstractSimpleTranslogTests { assertThat(index.source().toBytes(), equalTo(new byte[]{2})); assertThat(snapshot.hasNext(), equalTo(false)); assertThat(snapshot.estimatedTotalOperations(), equalTo(2)); - snapshot.release(); - snapshot1.release(); + snapshot.close(); + snapshot1.close(); } @Test public void testSnapshotWithNewTranslog() { Translog.Snapshot snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(0)); - snapshot.release(); + snapshot.close(); translog.add(new Translog.Create("test", "1", new byte[]{1})); Translog.Snapshot actualSnapshot = translog.snapshot(); @@ -223,7 +223,7 @@ public abstract class AbstractSimpleTranslogTests { snapshot = translog.snapshot(actualSnapshot); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(1)); - snapshot.release(); + snapshot.close(); snapshot = translog.snapshot(actualSnapshot); assertThat(snapshot.hasNext(), equalTo(true)); @@ -231,34 +231,34 @@ public abstract class AbstractSimpleTranslogTests { assertThat(index.source().toBytes(), equalTo(new byte[]{3})); assertThat(snapshot.hasNext(), equalTo(false)); - actualSnapshot.release(); - snapshot.release(); + actualSnapshot.close(); + snapshot.close(); } @Test public void testSnapshotWithSeekForward() { Translog.Snapshot snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(0)); - snapshot.release(); + snapshot.close(); translog.add(new Translog.Create("test", "1", new byte[]{1})); snapshot = translog.snapshot(); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(1)); long lastPosition = snapshot.position(); - snapshot.release(); + snapshot.close(); translog.add(new Translog.Create("test", "2", new byte[]{1})); snapshot = translog.snapshot(); snapshot.seekForward(lastPosition); MatcherAssert.assertThat(snapshot, TranslogSizeMatcher.translogSize(1)); - snapshot.release(); + snapshot.close(); snapshot = translog.snapshot(); snapshot.seekForward(lastPosition); assertThat(snapshot.hasNext(), equalTo(true)); Translog.Create create = (Translog.Create) snapshot.next(); assertThat(create.id(), equalTo("2")); - snapshot.release(); + snapshot.close(); } private Term newUid(String id) { diff --git a/src/test/java/org/elasticsearch/test/cache/recycler/MockBigArrays.java b/src/test/java/org/elasticsearch/test/cache/recycler/MockBigArrays.java index 435d1127eb4..90c4f8bc4eb 100644 --- a/src/test/java/org/elasticsearch/test/cache/recycler/MockBigArrays.java +++ b/src/test/java/org/elasticsearch/test/cache/recycler/MockBigArrays.java @@ -267,13 +267,13 @@ public class MockBigArrays extends BigArrays { return getDelegate().size(); } - public boolean release() { + public void close() { if (!released.compareAndSet(false, true)) { throw new IllegalStateException("Double release"); } ACQUIRED_ARRAYS.remove(this); randomizeContent(0, size()); - return getDelegate().release(); + getDelegate().close(); } } diff --git a/src/test/java/org/elasticsearch/test/cache/recycler/MockPageCacheRecycler.java b/src/test/java/org/elasticsearch/test/cache/recycler/MockPageCacheRecycler.java index e01774aaf1b..798e28e2877 100644 --- a/src/test/java/org/elasticsearch/test/cache/recycler/MockPageCacheRecycler.java +++ b/src/test/java/org/elasticsearch/test/cache/recycler/MockPageCacheRecycler.java @@ -80,7 +80,7 @@ public class MockPageCacheRecycler extends PageCacheRecycler { return new V() { @Override - public boolean release() throws ElasticsearchException { + public void close() throws ElasticsearchException { final Throwable t = ACQUIRED_PAGES.remove(v); if (t == null) { throw new IllegalStateException("Releasing a page that has not been acquired"); @@ -103,7 +103,7 @@ public class MockPageCacheRecycler extends PageCacheRecycler { Array.set(ref, i, (byte) random.nextInt(256)); } } - return v.release(); + v.close(); } @Override diff --git a/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java b/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java index 80340ea2ff1..053ad84603c 100644 --- a/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java +++ b/src/test/java/org/elasticsearch/test/engine/MockInternalEngine.java @@ -163,7 +163,7 @@ public final class MockInternalEngine extends InternalEngine implements Engine { } @Override - public boolean release() throws ElasticsearchException { + public void close() throws ElasticsearchException { RuntimeException remove = INFLIGHT_ENGINE_SEARCHERS.remove(this); synchronized (lock) { // make sure we only get this once and store the stack of the first caller! @@ -182,7 +182,7 @@ public final class MockInternalEngine extends InternalEngine implements Engine { // problems. assert refCount > 0 : "IndexReader#getRefCount() was [" + refCount + "] expected a value > [0] - reader is already closed. Initial refCount was: [" + initialRefCount + "]"; try { - return wrappedSearcher.release(); + wrappedSearcher.close(); } catch (RuntimeException ex) { logger.debug("Failed to release searcher", ex); throw ex;