Changeset 25909
- Timestamp:
- 2012-07-06T18:01:29+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/solr/trunk/src/src/java/org/greenstone/gsdl3/service/SolrSearch.java
r25808 r25909 15 15 import java.util.HashMap; 16 16 import java.util.ArrayList; 17 import java.util.Iterator; 17 18 18 19 … … 29 30 import org.apache.solr.servlet.SolrRequestParsers; 30 31 import org.apache.solr.core.CoreContainer; 32 import org.apache.solr.core.SolrCore; 31 33 32 34 import java.io.File; … … 56 58 57 59 String solr_home_str = GSFile.extHome(gsdl3_home,solr_ext_name); 58 File solr_home = new File(solr_home_str); 59 File solr_xml = new File( solr_home,"solr.xml" ); 60 61 solr_cores = new CoreContainer(solr_home_str,solr_xml); 60 61 solr_cores = new CoreContainer(solr_home_str); 62 62 } 63 63 catch (Exception e) { … … 66 66 } 67 67 } 68 68 69 69 70 // Overriding the cleanUp() method here, so as to parallel the structure of GS2SolrSearch … … 71 72 // However, this class has not yet been tested, so it's not certain that this method is 72 73 // required here. 74 // Adjusted to bring it up to speed with changes in GS2SolrSearch (for activate.pl) - not yet tested 73 75 public void cleanUp() { 74 76 super.cleanUp(); 75 solr_cores.shutdown(); 76 } 77 77 78 // 1. clear the map keeping track of the solrcores' EmbeddedSolrServers in this collection 79 solr_server.clear(); 80 81 // 2. Remove all SolrCores in the CoreContainer (solr_cores) that are specific to this collection 82 String collection_core_name_prefix = getCollectionCoreNamePrefix(); 83 84 Collection<String> coreNames = solr_cores.getCoreNames(); 85 if(!coreNames.isEmpty()) { 86 Iterator<String> coreIterator = coreNames.iterator(); 87 while(coreIterator.hasNext()) { 88 89 String solrCoreName = coreIterator.next(); 90 if(solrCoreName.startsWith(collection_core_name_prefix)) { 91 92 logger.error("**** Removing collection-specific core: " + solrCoreName + " from CoreContainer"); 93 94 // CoreContainer.remove(String name): removes and returns registered core w/o decrementing it's reference count 95 // http://lucene.apache.org/solr/api/index.html?org/apache/solr/core/CoreContainer.html 96 SolrCore solr_core = solr_cores.remove(solrCoreName); 97 while(!solr_core.isClosed()) { 98 logger.error("@@@@@@ " + solrCoreName + " was not closed. Closing...."); 99 solr_core.close(); // http://lucene.apache.org/solr/api/org/apache/solr/core/SolrCore.html 100 } 101 if(solr_core.isClosed()) { 102 logger.error("@@@@@@ " + solrCoreName + " is closed."); 103 } 104 solr_core = null; 105 } 106 } 107 } 108 109 // 3. if there are no more solr cores in Greenstone, then solr_cores will be empty, null the CoreContainer 110 // All going well, this will happen when we're ant stopping the Greenstone server and the last Solr collection 111 // is being deactivated 112 Collection<String> coreNamesRemaining = solr_cores.getCoreNames(); 113 if(coreNamesRemaining.isEmpty()) { 114 logger.error("**** CoreContainer contains 0 solrCores. Shutting down..."); 115 116 solr_cores.shutdown(); // wouldn't do anything anyway for 0 cores I think 117 solr_cores = null; 118 } 119 else { // else part is just for debugging 120 Iterator coreIterator = coreNamesRemaining.iterator(); 121 while(coreIterator.hasNext()) { 122 logger.error("**** Core: " + coreIterator.next() + " still exists in CoreContainer"); 123 } 124 } 125 126 } 127 128 129 // adjusted configure to bring it up to speed with changes in GS2SolrSearch (for activate.pl) - not yet tested 78 130 public boolean configure(Element info, Element extra_info) { 79 if (!super.configure(info, extra_info)){ 80 return false; 81 } 131 boolean success = super.configure(info, extra_info); 132 133 // 1. Make the CoreContainer reload solr.xml 134 // This is particularly needed for when activate.pl is executed during 135 // a running GS3 server. At that point, the solr collection is reactivated and 136 // we need to tell Greenstone that the solr index has changed. This requires 137 // the CoreContainer to reload the solr.xml file, and it all works again. 138 139 solr_server.clear(); // clear the map of solr cores for this collection added to the map upon querying 140 141 // Reload the updated solr.xml into the CoreContainer 142 // (Doing a solr_cores.shutdown() first doesn't seem to be required) 143 try { 144 String solr_home_str = solr_cores.getSolrHome(); 145 File solr_home = new File(solr_home_str); 146 File solr_xml = new File( solr_home,"solr.xml" ); 147 148 solr_cores.load(solr_home_str,solr_xml); 149 } catch (Exception e) { 150 logger.error("Exception in SolrSearch.configure(): " + e.getMessage()); 151 e.printStackTrace(); 152 return false; 153 } 82 154 83 155 // initialize required number of SolrCores based on values 84 156 // in 'index_ids' that are set by LuceneSearch::configure() 85 157 86 String site_name = this.router.getSiteName(); 87 String coll_name = this.cluster_name; 158 String core_name_prefix = getCollectionCoreNamePrefix(); 88 159 89 160 for (int i=0; i<index_ids.size(); i++) { 90 161 91 162 String idx_name = (String)index_ids.get(i); 92 String core_name = site_name + "-" + coll_name+ "-" + idx_name;163 String core_name = core_name_prefix + "-" + idx_name; 93 164 94 165 EmbeddedSolrServer solr_core … … 98 169 } 99 170 100 return true;171 return success; 101 172 } 102 173 … … 139 210 //solrParams.set("rows", nbDocuments); 140 211 141 String site_name = this.router.getSiteName(); 142 String coll_name = this.cluster_name; 143 144 String core_name = site_name + "-" + coll_name + "-" + index; 212 String core_name = getCollectionCoreNamePrefix() + "-" + index; 145 213 146 214 EmbeddedSolrServer solr_core = (EmbeddedSolrServer)solr_server.get(core_name); … … 176 244 } 177 245 246 protected String getCollectionCoreNamePrefix() { 247 String site_name = this.router.getSiteName(); 248 String coll_name = this.cluster_name; 249 String collection_core_name_prefix = site_name + "-" + coll_name; 250 return collection_core_name_prefix; 251 } 178 252 179 253 }
Note:
See TracChangeset
for help on using the changeset viewer.