Changeset 25898

Show
Ignore:
Timestamp:
05.07.2012 14:52:18 (7 years ago)
Author:
ak19
Message:

GS2SolrSearch.cleanUp() called upon deactivating a solr collection no longer calls shutdown on the CoreContainer? all_solr_cores, which would thereby shut down cores of other solr collections in GS3, but removes solrcores from the CoreContainer? belonging to the collection being deactivated. Need to still test this on Windows, to make sure it doesn't hang upon ant stopping the GS3 server after searching a solr collection.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java

    r25892 r25898  
    2222import java.io.File; 
    2323import java.util.ArrayList; 
     24import java.util.Collection; 
    2425import java.util.HashMap; 
    2526import java.util.Iterator; 
     
    3334import org.apache.solr.client.solrj.response.FacetField; 
    3435import org.apache.solr.core.CoreContainer; 
     36import org.apache.solr.core.SolrCore; 
    3537import org.greenstone.LuceneWrapper3.SharedSoleneQueryResult; 
    3638import org.greenstone.gsdl3.util.FacetWrapper; 
     
    9799        // the CoreContainer to reload the solr.xml file, and it all works again. 
    98100 
    99         solr_core_cache.clear(); // clear the map of existing solr cores 
     101        solr_core_cache.clear(); // clear the map of solr cores for this collection added to the map upon querying 
    100102         
    101103        // Reload the updated solr.xml into the CoreContainer 
     
    107109             
    108110            all_solr_cores.load(solr_home_str,solr_xml); 
     111 
    109112        } catch (Exception e) { 
    110113            logger.error("Exception in GS2SolrSearch.configure(): " + e.getMessage()); 
     
    153156        super.cleanUp(); 
    154157        this.solr_src.cleanUp(); 
    155         all_solr_cores.shutdown(); 
     158 
     159        // When cleaning up, not only do we need to empty the solr_core_cache map, but we also need to remove all 
     160        // references to this collection's sorlcores in the CoreContainer object, which can be more SolrCores than 
     161        // the EmbeddedSolrServers instantiated and added to the solr_core_cache, since the cache does lazy loading  
     162        // while the CoreContainer contains all the cores defined in solr.xml, which includes all *possible* cores 
     163        // for this collection even if EmbeddedSolrServers for these were not added to the solr_core_cache_map. 
     164 
     165        // 1. clear the map keeping track of the solrcores' EmbeddedSolrServers in this collection 
     166        solr_core_cache.clear(); 
     167 
     168        // 2. Remove all SolrCores in the CoreContainer (all_solr_cores) that are specific to this collection 
     169        String collection_core_name_prefix = getCollectionCoreNamePrefix(); 
     170 
     171        Collection<String> coreNames = all_solr_cores.getCoreNames(); 
     172        if(!coreNames.isEmpty()) { 
     173            Iterator<String> coreIterator = coreNames.iterator(); 
     174            while(coreIterator.hasNext()) { 
     175 
     176            String solrCoreName = coreIterator.next();       
     177            if(solrCoreName.startsWith(collection_core_name_prefix)) { 
     178 
     179                logger.error("**** Removing collection-specific core: " + solrCoreName + " from CoreContainer"); 
     180 
     181                // CoreContainer.remove(String name): removes and returns registered core w/o decrementing it's reference count 
     182                // http://lucene.apache.org/solr/api/index.html?org/apache/solr/core/CoreContainer.html 
     183                SolrCore solr_core = all_solr_cores.remove(solrCoreName); 
     184                while(!solr_core.isClosed()) { 
     185                logger.error("@@@@@@ " + solrCoreName + " was not closed. Closing...."); 
     186                solr_core.close(); // http://lucene.apache.org/solr/api/org/apache/solr/core/SolrCore.html 
     187                }  
     188                if(solr_core.isClosed()) { 
     189                logger.error("@@@@@@ " + solrCoreName + " is closed."); 
     190                } 
     191                solr_core = null; 
     192            } 
     193            } 
     194        } 
     195 
     196        // 3. if there are no more solr cores in Greenstone, then all_solr_cores will be empty, null the CoreContainer 
     197        // All going well, this will happen when we're ant stopping the Greenstone server and the last Solr collection 
     198        // is being deactivated 
     199        Collection<String> coreNamesRemaining = all_solr_cores.getCoreNames(); 
     200        if(coreNamesRemaining.isEmpty()) { 
     201            logger.error("**** CoreContainer contains 0 solrCores. Shutting down..."); 
     202 
     203            all_solr_cores.shutdown(); // wouldn't do anything anyway for 0 cores I think 
     204            all_solr_cores = null; 
     205        }  
     206        else { // else part is just for debugging 
     207            Iterator coreIterator = coreNamesRemaining.iterator(); 
     208            while(coreIterator.hasNext()) { 
     209            logger.error("**** Core: " + coreIterator.next() + " still exists in CoreContainer"); 
     210            } 
     211        } 
    156212    } 
    157213 
     
    273329        // now we know the index level, we can dig out the required 
    274330        // solr-core, (caching the result in 'solr_core_cache') 
    275  
    276         String site_name = this.router.getSiteName(); 
    277         String coll_name = this.cluster_name; 
    278  
    279         String core_name = site_name + "-" + coll_name + "-" + index; 
     331        String core_name = getCollectionCoreNamePrefix() + "-" + index; 
    280332 
    281333        EmbeddedSolrServer solr_core = null; 
     
    402454        return newFacetList; 
    403455    } 
     456 
     457 
     458    protected String getCollectionCoreNamePrefix() { 
     459    String site_name = this.router.getSiteName(); 
     460    String coll_name = this.cluster_name; 
     461    String collection_core_name_prefix = site_name + "-" + coll_name; 
     462    return collection_core_name_prefix; 
     463    } 
    404464}