lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From markrmil...@apache.org
Subject svn commit: r1531163 - in /lucene/dev/trunk/solr/core/src/java/org/apache/solr: core/SolrXMLCoresLocator.java handler/admin/CoreAdminHandler.java
Date Fri, 11 Oct 2013 01:37:25 GMT
Author: markrmiller
Date: Fri Oct 11 01:37:24 2013
New Revision: 1531163

URL: http://svn.apache.org/r1531163
Log:
SOLR-5317: Fix race  when persisting cores in solr.xml

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrXMLCoresLocator.java
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrXMLCoresLocator.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrXMLCoresLocator.java?rev=1531163&r1=1531162&r2=1531163&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrXMLCoresLocator.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/core/SolrXMLCoresLocator.java Fri
Oct 11 01:37:24 2013
@@ -20,6 +20,7 @@ package org.apache.solr.core;
 import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableList;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,9 +32,11 @@ import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -142,23 +145,33 @@ public class SolrXMLCoresLocator impleme
   }
 
   @Override
-  public final void persist(CoreContainer cc, CoreDescriptor... coreDescriptors) {
+  public synchronized final void persist(CoreContainer cc, CoreDescriptor... coreDescriptors)
{
     List<CoreDescriptor> cds = new ArrayList<CoreDescriptor>(cc.getCoreDescriptors().size()
+ coreDescriptors.length);
+    
+    System.err.println("Persist existing cores:" + cc.getCoreDescriptors());
+    System.err.println("Persist new cores:" + cc.getCoreDescriptors());
     cds.addAll(cc.getCoreDescriptors());
     cds.addAll(Arrays.asList(coreDescriptors));
+
     doPersist(buildSolrXML(cds));
   }
 
-  protected synchronized void doPersist(String xml) {
+  protected void doPersist(String xml) {
     File file = new File(cfg.config.getResourceLoader().getInstanceDir(), ConfigSolr.SOLR_XML_FILE);
+    Writer writer = null;
+    FileOutputStream fos = null;
     try {
-      Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8);
+      fos = new FileOutputStream(file);
+      writer = new OutputStreamWriter(fos, Charsets.UTF_8);
       writer.write(xml);
       writer.close();
       logger.info("Persisted core descriptions to {}", file.getAbsolutePath());
-    }
-    catch (IOException e) {
-      logger.error("Couldn't persist core descriptions to {} : {}", file.getAbsolutePath(),
e);
+    } catch (IOException e) {
+      logger.error("Couldn't persist core descriptions to {} : {}",
+          file.getAbsolutePath(), e);
+    } finally {
+      IOUtils.closeQuietly(writer);
+      IOUtils.closeQuietly(fos);
     }
   }
 

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java?rev=1531163&r1=1531162&r2=1531163&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
(original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/admin/CoreAdminHandler.java
Fri Oct 11 01:37:24 2013
@@ -19,6 +19,7 @@ package org.apache.solr.handler.admin;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
+
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.lucene.index.DirectoryReader;
@@ -48,6 +49,7 @@ import org.apache.solr.core.CoreDescript
 import org.apache.solr.core.DirectoryFactory;
 import org.apache.solr.core.DirectoryFactory.DirContext;
 import org.apache.solr.core.SolrCore;
+import org.apache.solr.core.SolrXMLCoresLocator;
 import org.apache.solr.handler.RequestHandlerBase;
 import org.apache.solr.request.LocalSolrQueryRequest;
 import org.apache.solr.request.SolrQueryRequest;
@@ -486,9 +488,19 @@ public class CoreAdminHandler extends Re
       if (coreContainer.getZkController() != null) {
         coreContainer.preRegisterInZk(dcore);
       }
+
+      // make sure we can write out the descriptor first
       coreContainer.getCoresLocator().create(coreContainer, dcore);
+      
       SolrCore core = coreContainer.create(dcore);
+      
       coreContainer.register(dcore.getName(), core, false);
+      
+      if (coreContainer.getCoresLocator() instanceof SolrXMLCoresLocator) {
+        // hack - in this case we persist once more because a core create race might
+        // have dropped entries.
+        coreContainer.getCoresLocator().create(coreContainer);
+      }
       rsp.add("core", core.getName());
     }
     catch (Exception ex) {



Mime
View raw message