use of org.apache.solr.common.params.ModifiableSolrParams in project lucene-solr by apache.
the class SolrCmdDistributorTest method testMaxRetries.
private void testMaxRetries() throws IOException {
final MockStreamingSolrClients streamingClients = new MockStreamingSolrClients(updateShardHandler);
SolrCmdDistributor cmdDistrib = new SolrCmdDistributor(streamingClients, 5, 0);
streamingClients.setExp(Exp.CONNECT_EXCEPTION);
ArrayList<Node> nodes = new ArrayList<>();
final HttpSolrClient solrclient1 = (HttpSolrClient) clients.get(0);
final AtomicInteger retries = new AtomicInteger();
ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, solrclient1.getBaseURL(), ZkStateReader.CORE_NAME_PROP, "");
RetryNode retryNode = new RetryNode(new ZkCoreNodeProps(nodeProps), null, "collection1", "shard1") {
@Override
public boolean checkRetry() {
retries.incrementAndGet();
return true;
}
};
nodes.add(retryNode);
AddUpdateCommand cmd = new AddUpdateCommand(null);
cmd.solrDoc = sdoc("id", id.incrementAndGet());
ModifiableSolrParams params = new ModifiableSolrParams();
cmdDistrib.distribAdd(cmd, nodes, params);
cmdDistrib.finish();
assertEquals(6, retries.get());
assertEquals(1, cmdDistrib.getErrors().size());
}
use of org.apache.solr.common.params.ModifiableSolrParams in project lucene-solr by apache.
the class SolrCmdDistributorTest method testOneRetry.
private void testOneRetry() throws Exception {
final HttpSolrClient solrclient = (HttpSolrClient) clients.get(0);
long numFoundBefore = solrclient.query(new SolrQuery("*:*")).getResults().getNumFound();
final MockStreamingSolrClients streamingClients = new MockStreamingSolrClients(updateShardHandler);
SolrCmdDistributor cmdDistrib = new SolrCmdDistributor(streamingClients, 5, 0);
streamingClients.setExp(Exp.CONNECT_EXCEPTION);
ArrayList<Node> nodes = new ArrayList<>();
ZkNodeProps nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, solrclient.getBaseURL(), ZkStateReader.CORE_NAME_PROP, "");
final AtomicInteger retries = new AtomicInteger();
nodeProps = new ZkNodeProps(ZkStateReader.BASE_URL_PROP, solrclient.getBaseURL(), ZkStateReader.CORE_NAME_PROP, "");
RetryNode retryNode = new RetryNode(new ZkCoreNodeProps(nodeProps), null, "collection1", "shard1") {
@Override
public boolean checkRetry() {
streamingClients.setExp(null);
retries.incrementAndGet();
return true;
}
};
nodes.add(retryNode);
AddUpdateCommand cmd = new AddUpdateCommand(null);
cmd.solrDoc = sdoc("id", id.incrementAndGet());
ModifiableSolrParams params = new ModifiableSolrParams();
CommitUpdateCommand ccmd = new CommitUpdateCommand(null, false);
cmdDistrib.distribAdd(cmd, nodes, params);
cmdDistrib.distribCommit(ccmd, nodes, params);
cmdDistrib.finish();
assertEquals(1, retries.get());
long numFoundAfter = solrclient.query(new SolrQuery("*:*")).getResults().getNumFound();
// we will get java.net.ConnectException which we retry on
assertEquals(numFoundBefore + 1, numFoundAfter);
assertEquals(0, cmdDistrib.getErrors().size());
}
use of org.apache.solr.common.params.ModifiableSolrParams in project lucene-solr by apache.
the class HttpClientUtil method createClient.
public static CloseableHttpClient createClient(final SolrParams params, PoolingHttpClientConnectionManager cm, boolean sharedConnectionManager, HttpRequestExecutor httpRequestExecutor) {
final ModifiableSolrParams config = new ModifiableSolrParams(params);
if (logger.isDebugEnabled()) {
logger.debug("Creating new http client, config:" + config);
}
cm.setMaxTotal(params.getInt(HttpClientUtil.PROP_MAX_CONNECTIONS, 10000));
cm.setDefaultMaxPerRoute(params.getInt(HttpClientUtil.PROP_MAX_CONNECTIONS_PER_HOST, 10000));
cm.setValidateAfterInactivity(Integer.getInteger(VALIDATE_AFTER_INACTIVITY, VALIDATE_AFTER_INACTIVITY_DEFAULT));
HttpClientBuilder newHttpClientBuilder = HttpClientBuilder.create();
if (sharedConnectionManager) {
newHttpClientBuilder.setConnectionManagerShared(true);
} else {
newHttpClientBuilder.setConnectionManagerShared(false);
}
ConnectionKeepAliveStrategy keepAliveStrat = new ConnectionKeepAliveStrategy() {
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
// we only close connections based on idle time, not ttl expiration
return -1;
}
};
if (httpClientBuilder.getAuthSchemeRegistryProvider() != null) {
newHttpClientBuilder.setDefaultAuthSchemeRegistry(httpClientBuilder.getAuthSchemeRegistryProvider().getAuthSchemeRegistry());
}
if (httpClientBuilder.getCookieSpecRegistryProvider() != null) {
newHttpClientBuilder.setDefaultCookieSpecRegistry(httpClientBuilder.getCookieSpecRegistryProvider().getCookieSpecRegistry());
}
if (httpClientBuilder.getCredentialsProviderProvider() != null) {
newHttpClientBuilder.setDefaultCredentialsProvider(httpClientBuilder.getCredentialsProviderProvider().getCredentialsProvider());
}
newHttpClientBuilder.addInterceptorLast(new DynamicInterceptor());
newHttpClientBuilder = newHttpClientBuilder.setKeepAliveStrategy(keepAliveStrat).evictIdleConnections((long) Integer.getInteger(EVICT_IDLE_CONNECTIONS, EVICT_IDLE_CONNECTIONS_DEFAULT), TimeUnit.MILLISECONDS);
if (httpRequestExecutor != null) {
newHttpClientBuilder.setRequestExecutor(httpRequestExecutor);
}
HttpClientBuilder builder = setupBuilder(newHttpClientBuilder, params);
HttpClient httpClient = builder.setConnectionManager(cm).build();
assert ObjectReleaseTracker.track(httpClient);
return (CloseableHttpClient) httpClient;
}
use of org.apache.solr.common.params.ModifiableSolrParams in project lucene-solr by apache.
the class HttpClusterStateProvider method fetchClusterState.
@SuppressWarnings({ "rawtypes", "unchecked" })
private ClusterState fetchClusterState(SolrClient client, String collection) throws SolrServerException, IOException {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("collection", collection);
params.set("action", "CLUSTERSTATUS");
QueryRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList cluster = (SimpleOrderedMap) client.request(request).get("cluster");
Map<String, Object> collectionsMap = Collections.singletonMap(collection, ((NamedList) cluster.get("collections")).get(collection));
int znodeVersion = (int) ((Map<String, Object>) (collectionsMap).get(collection)).get("znodeVersion");
Set<String> liveNodes = new HashSet((List<String>) (cluster.get("live_nodes")));
this.liveNodes = liveNodes;
liveNodesTimestamp = System.nanoTime();
ClusterState cs = ClusterState.load(znodeVersion, collectionsMap, liveNodes, ZkStateReader.CLUSTER_STATE);
return cs;
}
use of org.apache.solr.common.params.ModifiableSolrParams in project lucene-solr by apache.
the class ModelCache method getModel.
public Tuple getModel(String zkHost, String collection, String modelID, long checkMillis) throws IOException {
Model model = null;
long currentTime = new Date().getTime();
synchronized (this) {
model = models.get(modelID);
if (model != null && ((currentTime - model.getLastChecked()) <= checkMillis)) {
return model.getTuple();
}
if (model != null) {
//model is expired
models.remove(modelID);
}
}
//Model is not in cache or has expired so fetch the model
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", "name_s:" + modelID);
params.set("fl", "terms_ss, idfs_ds, weights_ds, iteration_i, _version_");
params.set(SORT, "iteration_i desc");
StreamContext streamContext = new StreamContext();
streamContext.setSolrClientCache(solrClientCache);
CloudSolrStream stream = new CloudSolrStream(zkHost, collection, params);
stream.setStreamContext(streamContext);
Tuple tuple = null;
try {
stream.open();
tuple = stream.read();
if (tuple.EOF) {
return null;
}
} finally {
stream.close();
}
synchronized (this) {
//check again to see if another thread has updated the same model
Model m = models.get(modelID);
if (m != null) {
Tuple t = m.getTuple();
long v = t.getLong(VERSION_FIELD);
if (v >= tuple.getLong(VERSION_FIELD)) {
return t;
} else {
models.put(modelID, new Model(tuple, currentTime));
return tuple;
}
} else {
models.put(modelID, new Model(tuple, currentTime));
return tuple;
}
}
}
Aggregations