fix locking in open/close logic, allow more than one clients if connected to different clusters
This commit is contained in:
parent
66df115579
commit
c4562bb681
14 changed files with 124 additions and 121 deletions
|
@ -33,7 +33,6 @@ import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest
|
||||||
import org.elasticsearch.action.search.SearchAction;
|
import org.elasticsearch.action.search.SearchAction;
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
|
||||||
import org.elasticsearch.cluster.metadata.AliasAction;
|
import org.elasticsearch.cluster.metadata.AliasAction;
|
||||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.AliasOrIndex;
|
import org.elasticsearch.cluster.metadata.AliasOrIndex;
|
||||||
|
@ -53,8 +52,6 @@ import org.elasticsearch.search.sort.SortBuilder;
|
||||||
import org.elasticsearch.search.sort.SortBuilders;
|
import org.elasticsearch.search.sort.SortBuilders;
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
import org.xbib.elx.api.AdminClient;
|
import org.xbib.elx.api.AdminClient;
|
||||||
import org.xbib.elx.api.BulkController;
|
|
||||||
import org.xbib.elx.api.BulkMetric;
|
|
||||||
import org.xbib.elx.api.IndexAliasAdder;
|
import org.xbib.elx.api.IndexAliasAdder;
|
||||||
import org.xbib.elx.api.IndexDefinition;
|
import org.xbib.elx.api.IndexDefinition;
|
||||||
import org.xbib.elx.api.IndexPruneResult;
|
import org.xbib.elx.api.IndexPruneResult;
|
||||||
|
@ -70,11 +67,20 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.SortedMap;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public abstract class AbstractBulkClient extends AbstractNativeClient implements BulkClient {
|
public abstract class AbstractBulkClient extends AbstractNativeClient implements BulkClient {
|
||||||
|
|
||||||
|
@ -37,17 +38,19 @@ public abstract class AbstractBulkClient extends AbstractNativeClient implements
|
||||||
|
|
||||||
private BulkController bulkController;
|
private BulkController bulkController;
|
||||||
|
|
||||||
|
private final AtomicBoolean closed = new AtomicBoolean(true);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Settings settings) throws IOException {
|
public void init(Settings settings) throws IOException {
|
||||||
logger.log(Level.INFO, "initializing with settings = " + settings.toDelimitedString(','));
|
if (closed.compareAndSet(true, false)) {
|
||||||
super.init(settings);
|
super.init(settings);
|
||||||
if (bulkMetric == null) {
|
logger.log(Level.INFO, "initializing with settings = " + settings.toDelimitedString(','));
|
||||||
bulkMetric = new DefaultBulkMetric();
|
bulkMetric = new DefaultBulkMetric();
|
||||||
bulkMetric.init(settings);
|
bulkMetric.init(settings);
|
||||||
}
|
|
||||||
if (bulkController == null) {
|
|
||||||
bulkController = new DefaultBulkController(this, bulkMetric);
|
bulkController = new DefaultBulkController(this, bulkMetric);
|
||||||
bulkController.init(settings);
|
bulkController.init(settings);
|
||||||
|
} else {
|
||||||
|
logger.log(Level.WARN, "not initializing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,8 +73,8 @@ public abstract class AbstractBulkClient extends AbstractNativeClient implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
ensureClientIsPresent();
|
|
||||||
if (closed.compareAndSet(false, true)) {
|
if (closed.compareAndSet(false, true)) {
|
||||||
|
ensureClientIsPresent();
|
||||||
if (bulkMetric != null) {
|
if (bulkMetric != null) {
|
||||||
logger.info("closing bulk metric");
|
logger.info("closing bulk metric");
|
||||||
bulkMetric.close();
|
bulkMetric.close();
|
||||||
|
@ -80,7 +83,7 @@ public abstract class AbstractBulkClient extends AbstractNativeClient implements
|
||||||
logger.info("closing bulk controller");
|
logger.info("closing bulk controller");
|
||||||
bulkController.close();
|
bulkController.close();
|
||||||
}
|
}
|
||||||
closeClient();
|
closeClient(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,14 +40,17 @@ public abstract class AbstractNativeClient implements NativeClient {
|
||||||
|
|
||||||
protected ElasticsearchClient client;
|
protected ElasticsearchClient client;
|
||||||
|
|
||||||
protected final AtomicBoolean closed;
|
protected Settings settings;
|
||||||
|
|
||||||
protected AbstractNativeClient() {
|
private final AtomicBoolean closed;
|
||||||
|
|
||||||
|
public AbstractNativeClient() {
|
||||||
closed = new AtomicBoolean(false);
|
closed = new AtomicBoolean(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setClient(ElasticsearchClient client) {
|
public void setClient(ElasticsearchClient client) {
|
||||||
|
logger.log(Level.INFO, "setting client = " + client);
|
||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,16 +59,14 @@ public abstract class AbstractNativeClient implements NativeClient {
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract ElasticsearchClient createClient(Settings settings) throws IOException;
|
|
||||||
|
|
||||||
protected abstract void closeClient() throws IOException;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(Settings settings) throws IOException {
|
public void init(Settings settings) throws IOException {
|
||||||
|
if (closed.compareAndSet(false, true)) {
|
||||||
logger.log(Level.INFO, "initializing with settings = " + settings.toDelimitedString(','));
|
logger.log(Level.INFO, "initializing with settings = " + settings.toDelimitedString(','));
|
||||||
if (client == null) {
|
this.settings = settings;
|
||||||
client = createClient(settings);
|
setClient(createClient(settings));
|
||||||
|
} else {
|
||||||
|
logger.log(Level.WARN, "not initializing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,10 +167,14 @@ public abstract class AbstractNativeClient implements NativeClient {
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
ensureClientIsPresent();
|
ensureClientIsPresent();
|
||||||
if (closed.compareAndSet(false, true)) {
|
if (closed.compareAndSet(false, true)) {
|
||||||
closeClient();
|
closeClient(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract ElasticsearchClient createClient(Settings settings) throws IOException;
|
||||||
|
|
||||||
|
protected abstract void closeClient(Settings settings) throws IOException;
|
||||||
|
|
||||||
protected void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) throws IOException {
|
protected void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) throws IOException {
|
||||||
ensureClientIsPresent();
|
ensureClientIsPresent();
|
||||||
if (index == null) {
|
if (index == null) {
|
||||||
|
@ -217,5 +222,4 @@ public abstract class AbstractNativeClient implements NativeClient {
|
||||||
throw new IllegalArgumentException("unknown time unit: " + timeUnit);
|
throw new IllegalArgumentException("unknown time unit: " + timeUnit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class MockAdminClient extends AbstractAdminClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void closeClient() {
|
protected void closeClient(Settings settings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class MockBulkClient extends AbstractBulkClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void closeClient() {
|
protected void closeClient(Settings settings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class MockSearchClient extends AbstractSearchClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void closeClient() {
|
protected void closeClient(Settings settings) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -4,8 +4,6 @@ import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.xbib.elx.common.AbstractAdminClient;
|
import org.xbib.elx.common.AbstractAdminClient;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class NodeAdminClient extends AbstractAdminClient {
|
public class NodeAdminClient extends AbstractAdminClient {
|
||||||
|
|
||||||
private final NodeClientHelper helper;
|
private final NodeClientHelper helper;
|
||||||
|
@ -15,12 +13,12 @@ public class NodeAdminClient extends AbstractAdminClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElasticsearchClient createClient(Settings settings) throws IOException {
|
public ElasticsearchClient createClient(Settings settings) {
|
||||||
return helper.createClient(settings, null);
|
return helper.createClient(settings, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeClient() {
|
public void closeClient(Settings settings) {
|
||||||
helper.closeClient();
|
helper.closeClient(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package org.xbib.elx.node;
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.xbib.elx.common.AbstractBulkClient;
|
import org.xbib.elx.common.AbstractBulkClient;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class NodeBulkClient extends AbstractBulkClient {
|
public class NodeBulkClient extends AbstractBulkClient {
|
||||||
|
|
||||||
|
@ -14,12 +13,12 @@ public class NodeBulkClient extends AbstractBulkClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElasticsearchClient createClient(Settings settings) throws IOException {
|
public ElasticsearchClient createClient(Settings settings) {
|
||||||
return helper.createClient(settings, null);
|
return helper.createClient(settings, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeClient() {
|
public void closeClient(Settings settings) {
|
||||||
helper.closeClient();
|
helper.closeClient(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,18 +10,18 @@ import org.elasticsearch.node.Node;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
import org.elasticsearch.plugins.Plugin;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class NodeClientHelper {
|
public class NodeClientHelper {
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(NodeClientHelper.class.getName());
|
private static final Logger logger = LogManager.getLogger(NodeClientHelper.class.getName());
|
||||||
|
|
||||||
private static Node node;
|
|
||||||
|
|
||||||
private static ElasticsearchClient client;
|
|
||||||
|
|
||||||
private static Object configurationObject;
|
private static Object configurationObject;
|
||||||
|
|
||||||
private final Object lock = new Object();
|
private static Node node;
|
||||||
|
|
||||||
|
private static final Map<String, ElasticsearchClient> clientMap = new HashMap<>();
|
||||||
|
|
||||||
public ElasticsearchClient createClient(Settings settings, Object object) {
|
public ElasticsearchClient createClient(Settings settings, Object object) {
|
||||||
if (configurationObject == null) {
|
if (configurationObject == null) {
|
||||||
|
@ -30,8 +30,20 @@ public class NodeClientHelper {
|
||||||
if (configurationObject instanceof ElasticsearchClient) {
|
if (configurationObject instanceof ElasticsearchClient) {
|
||||||
return (ElasticsearchClient) configurationObject;
|
return (ElasticsearchClient) configurationObject;
|
||||||
}
|
}
|
||||||
if (client == null) {
|
return clientMap.computeIfAbsent(settings.get("cluster.name"),
|
||||||
synchronized (lock) {
|
key -> innerCreateClient(settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeClient(Settings settings) {
|
||||||
|
ElasticsearchClient client = clientMap.remove(settings.get("cluster.name"));
|
||||||
|
if (client != null) {
|
||||||
|
logger.debug("closing node...");
|
||||||
|
node.close();
|
||||||
|
node = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ElasticsearchClient innerCreateClient(Settings settings) {
|
||||||
String version = System.getProperty("os.name")
|
String version = System.getProperty("os.name")
|
||||||
+ " " + System.getProperty("java.vm.name")
|
+ " " + System.getProperty("java.vm.name")
|
||||||
+ " " + System.getProperty("java.vm.vendor")
|
+ " " + System.getProperty("java.vm.vendor")
|
||||||
|
@ -47,21 +59,7 @@ public class NodeClientHelper {
|
||||||
Collection<Class<? extends Plugin>> plugins = Collections.emptyList();
|
Collection<Class<? extends Plugin>> plugins = Collections.emptyList();
|
||||||
node = new BulkNode(new Environment(effectiveSettings), plugins);
|
node = new BulkNode(new Environment(effectiveSettings), plugins);
|
||||||
node.start();
|
node.start();
|
||||||
client = node.client();
|
return node.client();
|
||||||
}
|
|
||||||
}
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void closeClient() {
|
|
||||||
synchronized (lock) {
|
|
||||||
if (client != null) {
|
|
||||||
logger.debug("closing node...");
|
|
||||||
node.close();
|
|
||||||
node = null;
|
|
||||||
client = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class BulkNode extends Node {
|
private static class BulkNode extends Node {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package org.xbib.elx.node;
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.xbib.elx.common.AbstractSearchClient;
|
import org.xbib.elx.common.AbstractSearchClient;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class NodeSearchClient extends AbstractSearchClient {
|
public class NodeSearchClient extends AbstractSearchClient {
|
||||||
|
|
||||||
|
@ -14,12 +13,12 @@ public class NodeSearchClient extends AbstractSearchClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElasticsearchClient createClient(Settings settings) throws IOException {
|
public ElasticsearchClient createClient(Settings settings) {
|
||||||
return helper.createClient(settings, null);
|
return helper.createClient(settings, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeClient() {
|
public void closeClient(Settings settings) {
|
||||||
helper.closeClient();
|
helper.closeClient(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class TransportAdminClient extends AbstractAdminClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeClient() {
|
public void closeClient(Settings settings) {
|
||||||
helper.closeClient();
|
helper.closeClient(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class TransportBulkClient extends AbstractBulkClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElasticsearchClient createClient(Settings settings) throws IOException {
|
public ElasticsearchClient createClient(Settings settings) {
|
||||||
return helper.createClient(settings, null);
|
return helper.createClient(settings, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class TransportBulkClient extends AbstractBulkClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeClient() {
|
public void closeClient(Settings settings) {
|
||||||
helper.closeClient();
|
helper.closeClient(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,17 +21,17 @@ import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class TransportClientHelper {
|
public class TransportClientHelper {
|
||||||
|
|
||||||
private static final Logger logger = LogManager.getLogger(TransportClientHelper.class.getName());
|
private static final Logger logger = LogManager.getLogger(TransportClientHelper.class.getName());
|
||||||
|
|
||||||
private static ElasticsearchClient client;
|
|
||||||
|
|
||||||
private static Object configurationObject;
|
private static Object configurationObject;
|
||||||
|
|
||||||
private final Object lock = new Object();
|
private static final Map<String, ElasticsearchClient> clientMap = new HashMap<>();
|
||||||
|
|
||||||
public ElasticsearchClient createClient(Settings settings, Object object) {
|
public ElasticsearchClient createClient(Settings settings, Object object) {
|
||||||
if (configurationObject == null && object != null) {
|
if (configurationObject == null && object != null) {
|
||||||
|
@ -40,47 +40,18 @@ public class TransportClientHelper {
|
||||||
if (configurationObject instanceof ElasticsearchClient) {
|
if (configurationObject instanceof ElasticsearchClient) {
|
||||||
return (ElasticsearchClient) configurationObject;
|
return (ElasticsearchClient) configurationObject;
|
||||||
}
|
}
|
||||||
if (client == null) {
|
return clientMap.computeIfAbsent(settings.get("cluster.name"),
|
||||||
synchronized (lock) {
|
key -> innerCreateClient(settings));
|
||||||
String systemIdentifier = System.getProperty("os.name")
|
|
||||||
+ " " + System.getProperty("java.vm.name")
|
|
||||||
+ " " + System.getProperty("java.vm.vendor")
|
|
||||||
+ " " + System.getProperty("java.vm.version")
|
|
||||||
+ " Elasticsearch " + Version.CURRENT.toString();
|
|
||||||
Settings effectiveSettings = Settings.builder()
|
|
||||||
// for thread pool size
|
|
||||||
.put("processors",
|
|
||||||
settings.getAsInt("processors", Runtime.getRuntime().availableProcessors()))
|
|
||||||
.put("client.transport.sniff", false) // do not sniff
|
|
||||||
.put("client.transport.nodes_sampler_interval", "1m") // do not ping
|
|
||||||
.put("client.transport.ping_timeout", "1m") // wait for unresponsive nodes a very long time before disconnect
|
|
||||||
.put("client.transport.ignore_cluster_name", true) // connect to any cluster
|
|
||||||
// custom settings may override defaults
|
|
||||||
.put(settings)
|
|
||||||
.build();
|
|
||||||
logger.info("creating transport client on {} with custom settings {} and effective settings {}",
|
|
||||||
systemIdentifier, settings.getAsMap(), effectiveSettings.getAsMap());
|
|
||||||
|
|
||||||
// we need to disable dead lock check because we may have mixed node/transport clients
|
|
||||||
DefaultChannelFuture.setUseDeadLockChecker(false);
|
|
||||||
client = TransportClient.builder().settings(effectiveSettings).build();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return client;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeClient() {
|
public void closeClient(Settings settings) {
|
||||||
synchronized (lock) {
|
ElasticsearchClient client = clientMap.remove(settings.get("cluster.name"));
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
if (client instanceof Client) {
|
if (client instanceof Client) {
|
||||||
((Client) client).close();
|
((Client) client).close();
|
||||||
}
|
}
|
||||||
if (client != null) {
|
|
||||||
client.threadPool().shutdownNow();
|
client.threadPool().shutdownNow();
|
||||||
}
|
}
|
||||||
client = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(TransportClient transportClient, Settings settings) throws IOException {
|
public void init(TransportClient transportClient, Settings settings) throws IOException {
|
||||||
|
@ -143,4 +114,29 @@ public class TransportClientHelper {
|
||||||
transportClient.addTransportAddress(discoveryNode.getAddress());
|
transportClient.addTransportAddress(discoveryNode.getAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ElasticsearchClient innerCreateClient(Settings settings) {
|
||||||
|
String systemIdentifier = System.getProperty("os.name")
|
||||||
|
+ " " + System.getProperty("java.vm.name")
|
||||||
|
+ " " + System.getProperty("java.vm.vendor")
|
||||||
|
+ " " + System.getProperty("java.vm.version")
|
||||||
|
+ " Elasticsearch " + Version.CURRENT.toString();
|
||||||
|
Settings effectiveSettings = Settings.builder()
|
||||||
|
// for thread pool size
|
||||||
|
.put("processors",
|
||||||
|
settings.getAsInt("processors", Runtime.getRuntime().availableProcessors()))
|
||||||
|
.put("client.transport.sniff", false) // do not sniff
|
||||||
|
.put("client.transport.nodes_sampler_interval", "1m") // do not ping
|
||||||
|
.put("client.transport.ping_timeout", "1m") // wait for unresponsive nodes a very long time before disconnect
|
||||||
|
.put("client.transport.ignore_cluster_name", true) // connect to any cluster
|
||||||
|
// custom settings may override defaults
|
||||||
|
.put(settings)
|
||||||
|
.build();
|
||||||
|
logger.info("creating transport client on {} with custom settings {} and effective settings {}",
|
||||||
|
systemIdentifier, settings.getAsMap(), effectiveSettings.getAsMap());
|
||||||
|
|
||||||
|
// we need to disable dead lock check because we may have mixed node/transport clients
|
||||||
|
DefaultChannelFuture.setUseDeadLockChecker(false);
|
||||||
|
return TransportClient.builder().settings(effectiveSettings).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class TransportSearchClient extends AbstractSearchClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeClient() {
|
public void closeClient(Settings settings) {
|
||||||
helper.closeClient();
|
helper.closeClient(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue