public SolrIndex(final Configuration config) throws BackendException { Preconditions.checkArgument(config!=null); configuration = config; mode = Mode.parse(config.get(SOLR_MODE)); dynFields = config.get(DYNAMIC_FIELDS); keyFieldIds = parseKeyFieldsForCollections(config); maxResults = config.get(INDEX_MAX_RESULT_SET_SIZE); ttlField = config.get(TTL_FIELD); waitSearcher = config.get(WAIT_SEARCHER); if (mode==Mode.CLOUD) { String zookeeperUrl = config.get(SolrIndex.ZOOKEEPER_URL); CloudSolrClient cloudServer = new CloudSolrClient(zookeeperUrl, true); cloudServer.connect(); solrClient = cloudServer; } else if (mode==Mode.HTTP) { HttpClient clientParams = HttpClientUtil.createClient(new ModifiableSolrParams() {{ add(HttpClientUtil.PROP_ALLOW_COMPRESSION, config.get(HTTP_ALLOW_COMPRESSION).toString()); add(HttpClientUtil.PROP_CONNECTION_TIMEOUT, config.get(HTTP_CONNECTION_TIMEOUT).toString()); add(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, config.get(HTTP_MAX_CONNECTIONS_PER_HOST).toString()); add(HttpClientUtil.PROP_MAX_CONNECTIONS, config.get(HTTP_GLOBAL_MAX_CONNECTIONS).toString()); }}); solrClient = new LBHttpSolrClient(clientParams, config.get(HTTP_URLS)); } else { throw new IllegalArgumentException("Unsupported Solr operation mode: " + mode); } }
/** * Note: This setter method is <b>not thread-safe</b>. * * @param processor * Default Response Parser chosen to parse the response if the parser * were not specified as part of the request. * @see org.apache.solr.client.solrj.SolrRequest#getResponseParser() */ public void setParser(ResponseParser processor) { lbClient.setParser(processor); }
/** * @param zkHost * A zookeeper client endpoint. * @param updatesToLeaders * If true, sends updates only to shard leaders. * @param httpClient * the {@link HttpClient} instance to be used for all requests. The provided httpClient should use a * multi-threaded connection manager. * @see #CloudSolrClient(String) for full description and details on zkHost */ public CloudSolrClient(String zkHost, boolean updatesToLeaders, HttpClient httpClient) { this.zkHost = zkHost; this.clientIsInternal = httpClient == null; this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient; this.lbClient = new LBHttpSolrClient(myClient); this.lbClient.setRequestWriter(new BinaryRequestWriter()); this.lbClient.setParser(new BinaryResponseParser()); this.updatesToLeaders = updatesToLeaders; shutdownLBHttpSolrServer = true; lbClient.addQueryParams(STATE_VERSION); }
this.clientIsInternal = httpClient == null; this.myClient = httpClient == null ? HttpClientUtil.createClient(null) : httpClient; this.lbClient = new LBHttpSolrClient(myClient); this.lbClient.setRequestWriter(new BinaryRequestWriter()); this.lbClient.setParser(new BinaryResponseParser()); this.updatesToLeaders = true; shutdownLBHttpSolrServer = true;
private SolrClient getStandaloneQuerySolrClient() { LBHttpSolrClient lbHttpSolrClient = null; try { if (StringUtils.isEmpty(solrSlaves) && StringUtils.isNotEmpty(solrMaster)) { LOG.debug("Creating LBHttpSolrClient using solrMaster {}", solrMaster); lbHttpSolrClient = new LBHttpSolrClient(solrMaster); } else if (StringUtils.isNotEmpty(solrSlaves)) { LOG.debug("Creating LBHttpSolrClient using solrSlaves {}", solrSlaves); lbHttpSolrClient = new LBHttpSolrClient(solrSlaves); if (solrAllowMasterQueriesEnabled && StringUtils.isNotEmpty(solrMaster)) { LOG.debug("Adding solrMaster {} to the LBHttpSolrClient", solrSlaves); lbHttpSolrClient.addSolrServer(solrMaster); } } else if (StringUtils.isEmpty(solrSlaves) && StringUtils.isEmpty(solrMaster)) { // unexpected throw new AEMSolrSearchException("Initialization failed. " + "Either 'solr.master' or 'solr.slaves' properties are missing for Standalone mode."); } else { // Do nothing } } catch (MalformedURLException e) { LOG.error("Error for malformed URL.", e); } catch (AEMSolrSearchException e) { LOG.error("Solr client initialization failed.", e); } lbHttpSolrClient.setParser(new XMLResponseParser()); return lbHttpSolrClient; }
List<ServerWrapper> skipped = null; long timeAllowedNano = getTimeAllowedInNanos(req.getRequest()); long timeOutTime = System.nanoTime() + timeAllowedNano; for (String serverStr : req.getServers()) { if(isTimeExceeded(timeAllowedNano, timeOutTime)) { break; serverStr = normalize(serverStr); try { MDC.put("LBHttpSolrClient.url", serverStr); HttpSolrClient client = makeSolrClient(serverStr); ex = doRequest(client, req, rsp, isUpdate, false, null); if (ex == null) { return rsp; // SUCCESS if(isTimeExceeded(timeAllowedNano, timeOutTime)) { break; ex = doRequest(wrapper.client, req, rsp, isUpdate, true, wrapper.getKey()); if (ex == null) { return rsp; // SUCCESS
if (serverUserAuth) { HttpClientUtil.setBasicAuth( (DefaultHttpClient) ((CloudSolrClient) adminServer).getLbClient().getHttpClient(), serverUsername, serverPassword); HttpClientUtil.setBasicAuth( (DefaultHttpClient) ((CloudSolrClient) server).getLbClient().getHttpClient(), serverUsername, serverPassword); String[] solrUrlElements = StringUtils.split(SolrClientUrl); try { this.adminServer = new LBHttpSolrClient(solrUrlElements); } catch (MalformedURLException e) { throw new GoraException(e); this.server = new LBHttpSolrClient( solrUrlElements + "/" + mapping.getCoreName() ); } catch (MalformedURLException e) { throw new GoraException(e); (DefaultHttpClient) ((LBHttpSolrClient) adminServer).getHttpClient(), serverUsername, serverPassword); HttpClientUtil.setBasicAuth( (DefaultHttpClient) ((LBHttpSolrClient) server).getHttpClient(), serverUsername, serverPassword);
long timeAllowedNano = getTimeAllowedInNanos(request); long timeOutTime = System.nanoTime() + timeAllowedNano; for (int attempts=0; attempts<maxTries; attempts++) { if (timeAllowedExceeded = isTimeExceeded(timeAllowedNano, timeOutTime)) { break; if (e.getRootCause() instanceof IOException) { ex = e; moveAliveToDead(wrapper); if (justFailed == null) justFailed = new HashMap<>(); justFailed.put(wrapper.getKey(), wrapper); if (timeAllowedExceeded = isTimeExceeded(timeAllowedNano, timeOutTime)) { break; addToAlive(wrapper); return rsp; } catch (SolrException e) {
private static LBHttpSolrClient createLBHttpSolrClient(Builder cloudSolrClientBuilder, HttpClient httpClient) { final LBHttpSolrClient.Builder lbBuilder = new LBHttpSolrClient.Builder(); lbBuilder.withHttpClient(httpClient); if (cloudSolrClientBuilder.connectionTimeoutMillis != null) { lbBuilder.withConnectionTimeout(cloudSolrClientBuilder.connectionTimeoutMillis); } if (cloudSolrClientBuilder.socketTimeoutMillis != null) { lbBuilder.withSocketTimeout(cloudSolrClientBuilder.socketTimeoutMillis); } final LBHttpSolrClient lbClient = lbBuilder.build(); lbClient.setRequestWriter(new BinaryRequestWriter()); lbClient.setParser(new BinaryResponseParser()); return lbClient; }
public void addSolrServer(String server) throws MalformedURLException { HttpSolrClient client = makeSolrClient(server); addToAlive(new ServerWrapper(client)); }
private void startAliveCheckExecutor() { // double-checked locking, but it's OK because we don't *do* anything with aliveCheckExecutor // if it's not null. if (aliveCheckExecutor == null) { synchronized (this) { if (aliveCheckExecutor == null) { aliveCheckExecutor = Executors.newSingleThreadScheduledExecutor( new SolrjNamedThreadFactory("aliveCheckExecutor")); aliveCheckExecutor.scheduleAtFixedRate( getAliveCheckRunner(new WeakReference<>(this)), this.interval, this.interval, TimeUnit.MILLISECONDS); } } } }
wrapper.failedPings = 0; if (wrapper.standard) { addToAlive(wrapper);
ex = (!isZombie) ? addZombie(client, e) : e; } else { ex = (!isZombie) ? addZombie(client, e) : e; } else { throw e; ex = (!isZombie) ? addZombie(client, e) : e; } else { throw e; Throwable rootCause = e.getRootCause(); if (!isUpdate && rootCause instanceof IOException) { ex = (!isZombie) ? addZombie(client, e) : e; } else if (isUpdate && rootCause instanceof ConnectException) { ex = (!isZombie) ? addZombie(client, e) : e; } else { throw e;
builder.loadBalancedSolrClient = builder.lbClientBuilder.build(); if(builder.loadBalancedSolrClient != null) builder.httpClient = builder.loadBalancedSolrClient.getHttpClient(); this.myClient = (builder.httpClient == null) ? HttpClientUtil.createClient(null) : builder.httpClient; if (builder.loadBalancedSolrClient == null) builder.loadBalancedSolrClient = createLBHttpSolrClient(builder, myClient);
this.clientIsInternal = true; this.myClient = HttpClientUtil.createClient(null); this.lbClient = new LBHttpSolrClient(myClient); this.lbClient.setRequestWriter(new BinaryRequestWriter()); this.lbClient.setParser(new BinaryResponseParser()); this.updatesToLeaders = true; shutdownLBHttpSolrServer = true; lbClient.addQueryParams(STATE_VERSION);
long timeAllowedNano = getTimeAllowedInNanos(req.getRequest()); long timeOutTime = System.nanoTime() + timeAllowedNano; for (String serverStr : req.getServers()) { if (timeAllowedExceeded = isTimeExceeded(timeAllowedNano, timeOutTime)) { break; serverStr = normalize(serverStr); HttpSolrClient client = makeSolrClient(serverStr); ex = doRequest(client, req, rsp, isNonRetryable, false, null); if (ex == null) { return rsp; // SUCCESS if (timeAllowedExceeded = isTimeExceeded(timeAllowedNano, timeOutTime)) { break; MDC.put("LBHttpSolrClient.url", wrapper.client.getBaseURL()); ++numServersTried; ex = doRequest(wrapper.client, req, rsp, isNonRetryable, true, wrapper.getKey()); if (ex == null) { return rsp; // SUCCESS
Map<String,ServerWrapper> justFailed = null; long timeAllowedNano = getTimeAllowedInNanos(request); long timeOutTime = System.nanoTime() + timeAllowedNano; for (int attempts=0; attempts<maxTries; attempts++) { if(isTimeExceeded(timeAllowedNano, timeOutTime)) { break; if (e.getRootCause() instanceof IOException) { ex = e; moveAliveToDead(wrapper); if (justFailed == null) justFailed = new HashMap<>(); justFailed.put(wrapper.getKey(), wrapper); if(isTimeExceeded(timeAllowedNano, timeOutTime)) { break; addToAlive(wrapper); return rsp; } catch (SolrException e) {
public void addSolrServer(String server) throws MalformedURLException { HttpSolrClient client = makeSolrClient(server); addToAlive(new ServerWrapper(client)); }
private void startAliveCheckExecutor() { // double-checked locking, but it's OK because we don't *do* anything with aliveCheckExecutor // if it's not null. if (aliveCheckExecutor == null) { synchronized (this) { if (aliveCheckExecutor == null) { aliveCheckExecutor = Executors.newSingleThreadScheduledExecutor( new SolrjNamedThreadFactory("aliveCheckExecutor")); aliveCheckExecutor.scheduleAtFixedRate( getAliveCheckRunner(new WeakReference<>(this)), this.interval, this.interval, TimeUnit.MILLISECONDS); } } } }
wrapper.failedPings = 0; if (wrapper.standard) { addToAlive(wrapper);