FAQ
ack - misplaced quote in my commit...
I'll fix.

-Yonik
On Tue, Oct 19, 2010 at 1:42 PM, wrote:
Author: yonik
Date: Tue Oct 19 17:42:27 2010
New Revision: 1024335

URL: http://svn.apache.org/viewvc?rev=1024335&view=rev
Log:
tests: src/test/org/apache/solr/util/SolrPluginUtilsTest.javafix resource leak

Removed:
lucene/dev/trunk/solr/src/test/org/apache/solr/SolrInfoMBeanTest.java
Modified:
lucene/dev/trunk/solr/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java
lucene/dev/trunk/solr/src/java/org/apache/solr/core/QuerySenderListener.java
lucene/dev/trunk/solr/src/java/org/apache/solr/request/SolrQueryRequestBase.java
lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java
lucene/dev/trunk/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java
lucene/dev/trunk/solr/testlogging.properties

Modified: lucene/dev/trunk/solr/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java?rev=1024335&r1=1024334&r2=1024335&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java (original)
+++ lucene/dev/trunk/solr/src/common/org/apache/solr/common/util/ConcurrentLRUCache.java Tue Oct 19 17:42:27 2010
@@ -59,6 +59,8 @@ public class ConcurrentLRUCache<K,V> {
public ConcurrentLRUCache(int upperWaterMark, final int lowerWaterMark, int acceptableWatermark,
int initialSize, boolean runCleanupThread, boolean runNewThreadForCleanup,
EvictionListener<K,V> evictionListener) {
+log.info("new ConcurrentLRUCache: " + this);
+
if (upperWaterMark < 1) throw new IllegalArgumentException("upperWaterMark must be > 0");
if (lowerWaterMark >= upperWaterMark)
throw new IllegalArgumentException("lowerWaterMark must be  < upperWaterMark");
@@ -500,8 +502,9 @@ public class ConcurrentLRUCache<K,V> {
}
}

- private boolean isDestroyed =  false;
+ private volatile boolean isDestroyed =  false;
public void destroy() {
+    log.info("destroying " + this);
try {
if(cleanupThread != null){
cleanupThread.stopThread();
@@ -607,7 +610,7 @@ public class ConcurrentLRUCache<K,V> {
protected void finalize() throws Throwable {
try {
if(!isDestroyed){
-        log.error("ConcurrentLRUCache was not destroyed prior to finalize(), indicates a bug -- POSSIBLE RESOURCE LEAK!!!");
+        log.error("ConcurrentLRUCache was not destroyed prior to finalize(), indicates a bug -- POSSIBLE RESOURCE LEAK!!! - " + this);
destroy();
}
} finally {

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/core/QuerySenderListener.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/core/QuerySenderListener.java?rev=1024335&r1=1024334&r2=1024335&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/core/QuerySenderListener.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/core/QuerySenderListener.java Tue Oct 19 17:42:27 2010
@@ -45,7 +45,7 @@ class QuerySenderListener extends Abstra
NamedList params = addEventParms(currentSearcher, nlst);
LocalSolrQueryRequest req = new LocalSolrQueryRequest(core,params) {
@Override public SolrIndexSearcher getSearcher() { return searcher; }
-          @Override public void close() { }
+          // @Override public void close() { }
};

SolrQueryResponse rsp = new SolrQueryResponse();

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/request/SolrQueryRequestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/request/SolrQueryRequestBase.java?rev=1024335&r1=1024334&r2=1024335&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/request/SolrQueryRequestBase.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/request/SolrQueryRequestBase.java Tue Oct 19 17:42:27 2010
@@ -232,8 +232,22 @@ public abstract class SolrQueryRequestBa
searcherHolder.decref();
searcherHolder = null;
}
+    allocator = null;
}

+  public volatile Exception allocator;
+  {
+    allocator = new RuntimeException("WhoAmI");
+    allocator.fillInStackTrace();
+  }
+  @Override
+  protected void finalize() throws Throwable {
+    if (allocator != null) {
+      SolrException.log(SolrCore.log, "MISSING CLOSE for req allocated at ", allocator);
+    }
+  }
+
+
/** A Collection of ContentStreams passed to the request
*/
public Iterable<ContentStream> getContentStreams() {
@@ -252,4 +266,6 @@ public abstract class SolrQueryRequestBa
return this.getClass().getSimpleName() + '{' + params + '}';
}

+
+
}

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java?rev=1024335&r1=1024334&r2=1024335&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java Tue Oct 19 17:42:27 2010
@@ -37,6 +37,7 @@ import org.apache.lucene.util.OpenBitSet
import java.io.IOException;
import java.net.URL;
import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.solr.search.function.ValueSource;
@@ -57,6 +58,8 @@ public class SolrIndexSearcher extends I
public static final AtomicLong numOpens = new AtomicLong();
public static final AtomicLong numCloses = new AtomicLong();

+  public static Map<SolrIndexSearcher, Throwable> openSearchers = new ConcurrentHashMap<SolrIndexSearcher, Throwable>();
+

private static Logger log = LoggerFactory.getLogger(SolrIndexSearcher.class);
private final SolrCore core;
@@ -138,6 +141,7 @@ public class SolrIndexSearcher extends I

public SolrIndexSearcher(SolrCore core, IndexSchema schema, String name, IndexReader r, boolean closeReader, boolean enableCache) {
super(wrap(r));
+openSearchers.put(this, new RuntimeException("SearcherAlloc").fillInStackTrace());
this.reader = (SolrIndexReader)super.getIndexReader();
this.core = core;
this.schema = schema;
@@ -228,6 +232,7 @@ public class SolrIndexSearcher extends I
* In particular, the underlying reader and any cache's in use are closed.
*/
public void close() throws IOException {
+    openSearchers.remove(this);
if (cachingEnabled) {
StringBuilder sb = new StringBuilder();
sb.append("Closing ").append(name);

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java?rev=1024335&r1=1024334&r2=1024335&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java Tue Oct 19 17:42:27 2010
@@ -30,6 +30,7 @@ import org.apache.solr.core.SolrConfig;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.SolrIndexSearcher;
+import org.apache.solr.util.RefCounted;
import org.apache.solr.util.TestHarness;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -44,6 +45,7 @@ import java.io.StringWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -64,6 +66,10 @@ public abstract class SolrTestCaseJ4 ext
public static void afterClassSolrTestCase() throws Exception {
deleteCore();
resetExceptionIgnores();
+    for (Map.Entry<SolrIndexSearcher,Throwable> entry : SolrIndexSearcher.openSearchers.entrySet()) {
+      log.error("ERROR SEARCHER="+entry.getKey());
+      SolrException.log(log, "SEARCHER ALLOCED AT ", entry.getValue());
+    }
}

@Override
@@ -238,6 +244,10 @@ public abstract class SolrTestCaseJ4 ext
("standard",0,20,"version","2.2");
}
log.info("####initCore end");
+
+    RefCounted<SolrIndexSearcher> holder = h.getCore().getSearcher();
+    log.info("START SEARCHER REFCOUNT=" + (holder.getRefcount()-1) + " instance="+holder.get());
+    holder.decref();
}

/** Subclasses that override setUp can optionally call this method
@@ -264,7 +274,13 @@ public abstract class SolrTestCaseJ4 ext
*/
public static void deleteCore() throws Exception {
log.info("###deleteCore" );
-    if (h != null) { h.close(); }
+    RefCounted<SolrIndexSearcher> holder = null;
+
+    if (h != null) {
+      holder = h.getCore().getSearcher();
+      log.info("END SEARCHER REFCOUNT=" + (holder.getRefcount()-1) + " instance="+holder.get());
+      h.close();
+    }
if (dataDir != null) {
String skip = System.getProperty("solr.test.leavedatadir");
if (null != skip && 0 != skip.trim().length()) {
@@ -286,6 +302,12 @@ public abstract class SolrTestCaseJ4 ext
lrf = null;
configString = schemaString = null;

+
+    if (holder != null) {
+      log.info("FINAL SEARCHER REFCOUNT=" + (holder.getRefcount()-1) + " instance="+holder.get());
+      holder.decref();
+    }
+
endTrackingSearchers();
}


Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java?rev=1024335&r1=1024334&r2=1024335&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/util/SolrPluginUtilsTest.java Tue Oct 19 17:42:27 2010
@@ -66,7 +66,8 @@ public class SolrPluginUtilsTest extends
assertU("", adoc("id", "3235", "val_t", "quick green fox"));
assertU("", adoc("id", "3236", "val_t", "quick brown fox"));
commit();
-    SolrIndexSearcher srchr = h.getCore().getSearcher().get();
+    RefCounted<SolrIndexSearcher> holder = h.getCore().getSearcher();
+    SolrIndexSearcher srchr = holder.get();
SolrIndexSearcher.QueryResult qr = new SolrIndexSearcher.QueryResult();
SolrIndexSearcher.QueryCommand cmd = new SolrIndexSearcher.QueryCommand();
cmd.setQuery(new MatchAllDocsQuery());
@@ -82,7 +83,7 @@ public class SolrPluginUtilsTest extends
for (SolrDocument document : list) {
assertNotNull(document.get("val_t"));
}
-    srchr.close();
+    holder.close();
}

@Test

Modified: lucene/dev/trunk/solr/testlogging.properties
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/testlogging.properties?rev=1024335&r1=1024334&r2=1024335&view=diff
==============================================================================
--- lucene/dev/trunk/solr/testlogging.properties (original)
+++ lucene/dev/trunk/solr/testlogging.properties Tue Oct 19 17:42:27 2010
@@ -1,4 +1,4 @@
handlers=java.util.logging.ConsoleHandler
-.level=SEVERE
+.level=INFO
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 1 | next ›
Discussion Overview
groupdev @
categorieslucene
postedOct 19, '10 at 5:49p
activeOct 19, '10 at 5:49p
posts1
users1
websitelucene.apache.org

1 user in discussion

Yonik Seeley: 1 post

People

Translate

site design / logo © 2021 Grokbase