clear the list of releases once released

also double check that once a recycler is released, it can't be released again or used
This commit is contained in:
Shay Banon 2013-12-24 10:06:35 +01:00
parent 69d88a1edd
commit 1c758b0bb0
4 changed files with 20 additions and 3 deletions

View File

@ -19,6 +19,8 @@
package org.elasticsearch.common.recycler;
import org.elasticsearch.ElasticSearchIllegalStateException;
/**
*/
public class NoneRecycler<T> extends Recycler<T> {
@ -39,7 +41,7 @@ public class NoneRecycler<T> extends Recycler<T> {
public static class NV<T> implements Recycler.V<T> {
final T value;
T value;
NV(T value) {
this.value = value;
@ -57,6 +59,10 @@ public class NoneRecycler<T> extends Recycler<T> {
@Override
public void release() {
if (value == null) {
throw new ElasticSearchIllegalStateException("recycler entry already released...");
}
value = null;
}
}
}

View File

@ -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<T> extends Recycler<T> {
class QV implements Recycler.V<T> {
final T value;
T value;
QV(T value) {
this.value = value;
@ -72,8 +73,12 @@ public class QueueRecycler<T> extends Recycler<T> {
@Override
public void release() {
if (value == null) {
throw new ElasticSearchIllegalStateException("recycler entry already released...");
}
c.clear(value);
queue.offer(this);
value = null;
}
}
}

View File

@ -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<T> extends Recycler<T> {
final Stack<T> stack;
final C<T> c;
final T value;
T value;
TV(Stack<T> stack, C<T> c, T value) {
this.stack = stack;
@ -81,8 +82,12 @@ public class ThreadLocalRecycler<T> extends Recycler<T> {
@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;
}
}

View File

@ -652,6 +652,7 @@ public class DefaultSearchContext extends SearchContext {
}
}
}
clearables.clear();
if (th != null) {
throw new RuntimeException(th);
}