lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r1402847 - /lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
Date Sat, 27 Oct 2012 18:49:09 GMT
Author: markrmiller
Date: Sat Oct 27 18:49:09 2012
New Revision: 1402847

URL: http://svn.apache.org/viewvc?rev=1402847&view=rev
Log:
SOLR-4001: In CachingDirectoryFactory#close, if there are still refs for a Directory outstanding,
we need to wait for them to be released before closing.

Modified:
    lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java

Modified: lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java?rev=1402847&r1=1402846&r2=1402847&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
(original)
+++ lucene/dev/branches/branch_4x/solr/core/src/java/org/apache/solr/core/CachingDirectoryFactory.java
Sat Oct 27 18:49:09 2012
@@ -109,6 +109,18 @@ public abstract class CachingDirectoryFa
     synchronized (this) {
       for (CacheValue val : byDirectoryCache.values()) {
         try {
+          // if there are still refs out, we have to wait for them
+          int cnt = 0;
+          while(val.refCnt != 0) {
+            wait(100);
+            
+            if (cnt++ >= 300) {
+              log.error("Timeout waiting for all directory ref counts to be released");
+              break;
+            }
+          }
+          
+          assert val.refCnt == 0 : val.refCnt;
           val.directory.close();
         } catch (Throwable t) {
           SolrException.log(log, "Error closing directory", t);
@@ -184,9 +196,22 @@ public abstract class CachingDirectoryFa
         directory = cacheValue.directory;
         if (forceNew) {
           cacheValue.doneWithDir = true;
+          
+          // we make a quick close attempt,
+          // otherwise this should be closed
+          // when whatever is using it, releases it
+          
           if (cacheValue.refCnt == 0) {
-            close(cacheValue.directory);
+            try {
+              // the following will decref, so
+              // first incref
+              cacheValue.refCnt++;
+              close(cacheValue.directory);
+            } catch (IOException e) {
+              SolrException.log(log, "Error closing directory", e);
+            }
           }
+          
         }
       }
       



Mime
View raw message