From 1c758b0bb0df584940c05f74718fc371918d018f Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 24 Dec 2013 10:06:35 +0100 Subject: [PATCH] clear the list of releases once released also double check that once a recycler is released, it can't be released again or used --- .../org/elasticsearch/common/recycler/NoneRecycler.java | 8 +++++++- .../org/elasticsearch/common/recycler/QueueRecycler.java | 7 ++++++- .../common/recycler/ThreadLocalRecycler.java | 7 ++++++- .../search/internal/DefaultSearchContext.java | 1 + 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/recycler/NoneRecycler.java b/src/main/java/org/elasticsearch/common/recycler/NoneRecycler.java index 9f55410295d..46a78b2c844 100644 --- a/src/main/java/org/elasticsearch/common/recycler/NoneRecycler.java +++ b/src/main/java/org/elasticsearch/common/recycler/NoneRecycler.java @@ -19,6 +19,8 @@ package org.elasticsearch.common.recycler; +import org.elasticsearch.ElasticSearchIllegalStateException; + /** */ public class NoneRecycler extends Recycler { @@ -39,7 +41,7 @@ public class NoneRecycler extends Recycler { public static class NV implements Recycler.V { - final T value; + T value; NV(T value) { this.value = value; @@ -57,6 +59,10 @@ public class NoneRecycler extends Recycler { @Override public void release() { + if (value == null) { + throw new ElasticSearchIllegalStateException("recycler entry already released..."); + } + value = null; } } } diff --git a/src/main/java/org/elasticsearch/common/recycler/QueueRecycler.java b/src/main/java/org/elasticsearch/common/recycler/QueueRecycler.java index 41499d29c4d..57d0edcb782 100644 --- a/src/main/java/org/elasticsearch/common/recycler/QueueRecycler.java +++ b/src/main/java/org/elasticsearch/common/recycler/QueueRecycler.java @@ -19,6 +19,7 @@ package org.elasticsearch.common.recycler; +import org.elasticsearch.ElasticSearchIllegalStateException; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import java.util.Queue; @@ -54,7 +55,7 @@ public class QueueRecycler extends Recycler { class QV implements Recycler.V { - final T value; + T value; QV(T value) { this.value = value; @@ -72,8 +73,12 @@ public class QueueRecycler extends Recycler { @Override public void release() { + if (value == null) { + throw new ElasticSearchIllegalStateException("recycler entry already released..."); + } c.clear(value); queue.offer(this); + value = null; } } } diff --git a/src/main/java/org/elasticsearch/common/recycler/ThreadLocalRecycler.java b/src/main/java/org/elasticsearch/common/recycler/ThreadLocalRecycler.java index 9673df279e3..dc6904a2a81 100644 --- a/src/main/java/org/elasticsearch/common/recycler/ThreadLocalRecycler.java +++ b/src/main/java/org/elasticsearch/common/recycler/ThreadLocalRecycler.java @@ -22,6 +22,7 @@ package org.elasticsearch.common.recycler; import org.apache.lucene.util.ArrayUtil; import org.apache.lucene.util.CloseableThreadLocal; import org.apache.lucene.util.RamUsageEstimator; +import org.elasticsearch.ElasticSearchIllegalStateException; /** */ @@ -60,7 +61,7 @@ public class ThreadLocalRecycler extends Recycler { final Stack stack; final C c; - final T value; + T value; TV(Stack stack, C c, T value) { this.stack = stack; @@ -81,8 +82,12 @@ public class ThreadLocalRecycler extends Recycler { @Override public void release() { assert Thread.currentThread() == stack.thread; + if (value == null) { + throw new ElasticSearchIllegalStateException("recycler entry already released..."); + } c.clear(value); stack.push(value); + value = null; } } diff --git a/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java b/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java index 5695446f96c..e18dbf4bb68 100644 --- a/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java +++ b/src/main/java/org/elasticsearch/search/internal/DefaultSearchContext.java @@ -652,6 +652,7 @@ public class DefaultSearchContext extends SearchContext { } } } + clearables.clear(); if (th != null) { throw new RuntimeException(th); }