Changeset 25898
- Timestamp:
- 2012-07-05T14:52:18+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/GS2SolrSearch.java
r25892 r25898 22 22 import java.io.File; 23 23 import java.util.ArrayList; 24 import java.util.Collection; 24 25 import java.util.HashMap; 25 26 import java.util.Iterator; … … 33 34 import org.apache.solr.client.solrj.response.FacetField; 34 35 import org.apache.solr.core.CoreContainer; 36 import org.apache.solr.core.SolrCore; 35 37 import org.greenstone.LuceneWrapper3.SharedSoleneQueryResult; 36 38 import org.greenstone.gsdl3.util.FacetWrapper; … … 97 99 // the CoreContainer to reload the solr.xml file, and it all works again. 98 100 99 solr_core_cache.clear(); // clear the map of existing solr cores101 solr_core_cache.clear(); // clear the map of solr cores for this collection added to the map upon querying 100 102 101 103 // Reload the updated solr.xml into the CoreContainer … … 107 109 108 110 all_solr_cores.load(solr_home_str,solr_xml); 111 109 112 } catch (Exception e) { 110 113 logger.error("Exception in GS2SolrSearch.configure(): " + e.getMessage()); … … 153 156 super.cleanUp(); 154 157 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 } 156 212 } 157 213 … … 273 329 // now we know the index level, we can dig out the required 274 330 // 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; 280 332 281 333 EmbeddedSolrServer solr_core = null; … … 402 454 return newFacetList; 403 455 } 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 } 404 464 }
Note:
See TracChangeset
for help on using the changeset viewer.