|
35 | 35 | import java.util.Locale; |
36 | 36 | import java.util.Map; |
37 | 37 | import java.util.Set; |
38 | | -import java.util.function.Supplier; |
39 | 38 | import javax.servlet.http.HttpServletRequest; |
40 | 39 | import javax.servlet.http.HttpServletResponse; |
41 | 40 | import net.jcip.annotations.ThreadSafe; |
42 | 41 | import org.apache.solr.client.solrj.SolrRequest; |
43 | 42 | import org.apache.solr.common.SolrException; |
44 | 43 | import org.apache.solr.common.cloud.DocCollection; |
45 | | -import org.apache.solr.common.cloud.ZkStateReader; |
46 | 44 | import org.apache.solr.common.params.CommonParams; |
47 | 45 | import org.apache.solr.common.util.JsonSchemaValidator; |
48 | 46 | import org.apache.solr.common.util.PathTrie; |
@@ -140,8 +138,20 @@ public void call(SolrQueryRequest req, SolrQueryResponse rsp) { |
140 | 138 | if (pathSegments.size() > 1 && ("c".equals(prefix) || "collections".equals(prefix))) { |
141 | 139 | origCorename = pathSegments.get(1); |
142 | 140 |
|
143 | | - DocCollection collection = |
144 | | - resolveDocCollection(queryParams.get(COLLECTION_PROP, origCorename)); |
| 141 | + String collectionStr = queryParams.get(COLLECTION_PROP, origCorename); |
| 142 | + collectionsList = |
| 143 | + resolveCollectionListOrAlias(collectionStr); // &collection= takes precedence |
| 144 | + if (collectionsList.size() > 1) { |
| 145 | + throw new SolrException( |
| 146 | + SolrException.ErrorCode.BAD_REQUEST, |
| 147 | + "Request must be sent to a single collection " |
| 148 | + + "or an alias that points to a single collection," |
| 149 | + + " but '" |
| 150 | + + collectionStr |
| 151 | + + "' resolves to " |
| 152 | + + this.collectionsList); |
| 153 | + } |
| 154 | + DocCollection collection = resolveDocCollection(collectionsList); |
145 | 155 | if (collection == null) { |
146 | 156 | if (!path.endsWith(CommonParams.INTROSPECT)) { |
147 | 157 | throw new SolrException( |
@@ -218,54 +228,6 @@ protected void parseRequest() throws Exception { |
218 | 228 | if (solrReq == null) solrReq = parser.parse(core, path, req); |
219 | 229 | } |
220 | 230 |
|
221 | | - /** |
222 | | - * Lookup the collection from the collection string (maybe comma delimited). Also sets {@link |
223 | | - * #collectionsList} by side-effect. if {@code secondTry} is false then we'll potentially |
224 | | - * recursively try this all one more time while ensuring the alias and collection info is sync'ed |
225 | | - * from ZK. |
226 | | - */ |
227 | | - protected DocCollection resolveDocCollection(String collectionStr) { |
228 | | - if (!cores.isZooKeeperAware()) { |
229 | | - throw new SolrException( |
230 | | - SolrException.ErrorCode.BAD_REQUEST, "Solr not running in cloud mode "); |
231 | | - } |
232 | | - ZkStateReader zkStateReader = cores.getZkController().getZkStateReader(); |
233 | | - |
234 | | - Supplier<DocCollection> logic = |
235 | | - () -> { |
236 | | - this.collectionsList = resolveCollectionListOrAlias(collectionStr); // side-effect |
237 | | - if (collectionsList.size() > 1) { |
238 | | - throw new SolrException( |
239 | | - SolrException.ErrorCode.BAD_REQUEST, |
240 | | - "Request must be sent to a single collection " |
241 | | - + "or an alias that points to a single collection," |
242 | | - + " but '" |
243 | | - + collectionStr |
244 | | - + "' resolves to " |
245 | | - + this.collectionsList); |
246 | | - } |
247 | | - String collectionName = collectionsList.get(0); // first |
248 | | - // TODO an option to choose another collection in the list if can't find a local replica |
249 | | - // of the first? |
250 | | - |
251 | | - return zkStateReader.getClusterState().getCollectionOrNull(collectionName); |
252 | | - }; |
253 | | - |
254 | | - DocCollection docCollection = logic.get(); |
255 | | - if (docCollection != null) { |
256 | | - return docCollection; |
257 | | - } |
258 | | - // ensure our view is up to date before trying again |
259 | | - try { |
260 | | - zkStateReader.aliasesManager.update(); |
261 | | - zkStateReader.forceUpdateCollection(collectionsList.get(0)); |
262 | | - } catch (Exception e) { |
263 | | - log.error("Error trying to update state while resolving collection.", e); |
264 | | - // don't propagate exception on purpose |
265 | | - } |
266 | | - return logic.get(); |
267 | | - } |
268 | | - |
269 | 231 | public static Api getApiInfo( |
270 | 232 | PluginBag<SolrRequestHandler> requestHandlers, |
271 | 233 | String path, |
|
0 commit comments