Skip to content

Commit ca8596b

Browse files
committed
Add a commandline parameter to disable cluster sniffing for cases where only some nodes are accessible, e.g. due to network/vpn-setup
1 parent 080346e commit ca8596b

File tree

7 files changed

+52
-7
lines changed

7 files changed

+52
-7
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ Options:
7878
Target f.e. http://localhost:9300/target_index/type
7979
-tc, target-cluster
8080
Target cluster name
81+
-disable-cluster-sniffing
82+
Don't try to determine additional cluster nodes (e.g. when your network
83+
only allows access to one of the nodes)
84+
Default: false
8185
-segmentationField
8286
Segmentation field
8387
-segmentationPrefixes
@@ -88,6 +92,10 @@ Options:
8892
`segmentationField`, `segmentationThreshold` and `segmentationPrefixes` are optional parameters, allowing to spread
8993
querying for field with double values or prefix for string field
9094

95+
`disable-cluster-sniffing` allows to work in cases where the network-setup makes it impossible to connect to all nodes
96+
of the source or target cluster. Note that it may lead to slightly reduced reindexing rates as data can only be sent
97+
via one node then.
98+
9199
During reindex process progress message is prompted after each scroll query.
92100

93101
Example of progress message with the time how long it lasts, number of items queried and indexed, occupancy of queue, number of concurrent reader threads and number of failed document indexing:

src/main/java/pl/allegro/tech/search/elasticsearch/tools/reindex/ReindexCommandParser.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
import com.beust.jcommander.JCommander;
44
import com.beust.jcommander.ParameterException;
5+
56
import pl.allegro.tech.search.elasticsearch.tools.reindex.command.ReindexCommand;
67
import pl.allegro.tech.search.elasticsearch.tools.reindex.connection.ElasticDataPointer;
7-
import pl.allegro.tech.search.elasticsearch.tools.reindex.connection.ParsingElasticsearchAddressException;
8-
import pl.allegro.tech.search.elasticsearch.tools.reindex.query.QuerySegmentationFactory;
98
import pl.allegro.tech.search.elasticsearch.tools.reindex.connection.ElasticDataPointerBuilder;
9+
import pl.allegro.tech.search.elasticsearch.tools.reindex.connection.ParsingElasticsearchAddressException;
1010
import pl.allegro.tech.search.elasticsearch.tools.reindex.query.QuerySegmentation;
11+
import pl.allegro.tech.search.elasticsearch.tools.reindex.query.QuerySegmentationFactory;
1112

1213
public class ReindexCommandParser {
1314

@@ -39,10 +40,12 @@ private void buildReindexParameters(ReindexCommand command) {
3940
sourcePointer = ElasticDataPointerBuilder.builder()
4041
.setClusterName(command.getSourceClusterName())
4142
.setAddress(command.getSource())
43+
.setSniff(!command.isDisableSniff())
4244
.build();
4345
targetPointer = ElasticDataPointerBuilder.builder()
4446
.setClusterName(command.getTargetClusterName())
4547
.setAddress(command.getTarget())
48+
.setSniff(!command.isDisableSniff())
4649
.build();
4750
segmentation = getFieldSegmentation(command);
4851
}

src/main/java/pl/allegro/tech/search/elasticsearch/tools/reindex/command/ReindexCommand.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package pl.allegro.tech.search.elasticsearch.tools.reindex.command;
22

3-
import com.beust.jcommander.Parameter;
4-
53
import java.util.List;
64

5+
import com.beust.jcommander.Parameter;
6+
77
public class ReindexCommand {
88

99
@Parameter(names = { "-s", "source" }, description = "Source f.e. http://localhost:9300/source_index/type",
@@ -28,6 +28,9 @@ public class ReindexCommand {
2828
@Parameter(names = { "-segmentationPrefixes" }, description = "Segmentation prefixes (comma-separated)")
2929
private List<String> segmentationPrefixes;
3030

31+
@Parameter(names = { "-disable-cluster-sniffing" }, description = "Don't try to determine additional cluster nodes (e.g. when your network only allows access to one of the nodes)")
32+
private boolean disableSniff;
33+
3134
public String getSourceClusterName() {
3235
return sourceClusterName;
3336
}
@@ -53,4 +56,8 @@ public String getSource() {
5356
public String getTarget() {
5457
return target;
5558
}
59+
60+
public boolean isDisableSniff() {
61+
return disableSniff;
62+
}
5663
}

src/main/java/pl/allegro/tech/search/elasticsearch/tools/reindex/connection/ElasticDataPointer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ public class ElasticDataPointer {
77
private final String indexName;
88
private final String typeName;
99
private final int port;
10+
private final boolean sniff;
1011

11-
ElasticDataPointer(String host, String clusterName, String indexName, String typeName, int port) {
12+
ElasticDataPointer(String host, String clusterName, String indexName, String typeName, int port, boolean sniff) {
1213
this.host = host;
1314
this.clusterName = clusterName;
1415
this.indexName = indexName;
1516
this.typeName = typeName;
1617
this.port = port;
18+
this.sniff = sniff;
1719
}
1820

1921
public String getHost() {
@@ -35,4 +37,8 @@ public String getTypeName() {
3537
public int getPort() {
3638
return port;
3739
}
40+
41+
public boolean isSniff() {
42+
return sniff;
43+
}
3844
}

src/main/java/pl/allegro/tech/search/elasticsearch/tools/reindex/connection/ElasticDataPointerBuilder.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class ElasticDataPointerBuilder {
66

77
private String clusterName = "elasticsearch";
88
private ElasticAddress address;
9+
private boolean sniff = true;
910

1011
private ElasticDataPointerBuilder() {
1112
}
@@ -20,9 +21,14 @@ public ElasticDataPointerBuilder setClusterName(String clusterName) {
2021
return this;
2122
}
2223

24+
public ElasticDataPointerBuilder setSniff(boolean sniff) {
25+
this.sniff = sniff;
26+
return this;
27+
}
28+
2329
public ElasticDataPointer build() {
2430
return new ElasticDataPointer(address.getHost(), clusterName, address.getIndexName(), address.getTypeName(),
25-
address.getPort());
31+
address.getPort(), sniff);
2632
}
2733

2834
public static ElasticDataPointerBuilder builder() {

src/main/java/pl/allegro/tech/search/elasticsearch/tools/reindex/connection/ElasticSearchClientFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private ElasticSearchClientFactory() {
1515

1616
public static Client createClient(ElasticDataPointer elasticDataPointer) {
1717
Settings settings = Settings.settingsBuilder()
18-
.put("client.transport.sniff", true)
18+
.put("client.transport.sniff", elasticDataPointer.isSniff())
1919
.put(ClusterName.SETTING, elasticDataPointer.getClusterName())
2020
.build();
2121
TransportClient client = TransportClient.builder().settings(settings).build();

src/test/java/pl/allegro/tech/search/elasticsearch/tools/reindex/connection/ElasticSearchClientProducerTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,19 @@ public void validateCreatedLocalElasticClientWithProperClusterName() throws Exce
4545
client.close();
4646
}
4747

48+
49+
@Test
50+
public void validateCreatedLocalElasticClientWithoutSniff() throws Exception {
51+
//given
52+
ElasticDataPointer dataPointer = ElasticDataPointerBuilder.builder()
53+
.setAddress("http://localhost:9300/"+INDEX_NAME+"/type")
54+
.setClusterName(CLUSTER_NAME)
55+
.setSniff(false)
56+
.build();
57+
//when
58+
Client client = ElasticSearchClientFactory.createClient(dataPointer);
59+
//then
60+
Assertions.assertThat(client.settings().get("cluster.name")).isEqualTo(CLUSTER_NAME);
61+
client.close();
62+
}
4863
}

0 commit comments

Comments
 (0)