|
18 | 18 | */
|
19 | 19 | package org.elasticsearch.transport;
|
20 | 20 |
|
| 21 | +import org.elasticsearch.cluster.node.DiscoveryNode; |
21 | 22 | import org.elasticsearch.common.Nullable;
|
| 23 | +import org.elasticsearch.common.settings.Settings; |
22 | 24 | import org.elasticsearch.common.unit.TimeValue;
|
23 | 25 |
|
24 | 26 | import java.util.ArrayList;
|
25 | 27 | import java.util.Arrays;
|
26 | 28 | import java.util.Collections;
|
27 | 29 | import java.util.EnumSet;
|
28 | 30 | import java.util.List;
|
| 31 | +import java.util.Objects; |
29 | 32 | import java.util.Set;
|
30 | 33 | import java.util.concurrent.atomic.AtomicInteger;
|
31 | 34 |
|
@@ -70,6 +73,55 @@ private ConnectionProfile(List<ConnectionTypeHandle> handles, int numConnections
|
70 | 73 | }
|
71 | 74 |
|
72 | 75 | /**
|
| 76 | +<<<<<<< HEAD |
| 77 | +======= |
| 78 | + * takes a {@link ConnectionProfile} resolves it to a fully specified (i.e., no nulls) profile |
| 79 | + */ |
| 80 | + public static ConnectionProfile resolveConnectionProfile(@Nullable ConnectionProfile profile, ConnectionProfile fallbackProfile) { |
| 81 | + Objects.requireNonNull(fallbackProfile); |
| 82 | + if (profile == null) { |
| 83 | + return fallbackProfile; |
| 84 | + } else if (profile.getConnectTimeout() != null && profile.getHandshakeTimeout() != null) { |
| 85 | + return profile; |
| 86 | + } else { |
| 87 | + ConnectionProfile.Builder builder = new ConnectionProfile.Builder(profile); |
| 88 | + if (profile.getConnectTimeout() == null) { |
| 89 | + builder.setConnectTimeout(fallbackProfile.getConnectTimeout()); |
| 90 | + } |
| 91 | + if (profile.getHandshakeTimeout() == null) { |
| 92 | + builder.setHandshakeTimeout(fallbackProfile.getHandshakeTimeout()); |
| 93 | + } |
| 94 | + return builder.build(); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + /** |
| 99 | + * Builds a default connection profile based on the provided settings. |
| 100 | + * |
| 101 | + * @param settings to build the connection profile from |
| 102 | + * @return the connection profile |
| 103 | + */ |
| 104 | + public static ConnectionProfile buildDefaultConnectionProfile(Settings settings) { |
| 105 | + int connectionsPerNodeRecovery = TcpTransport.CONNECTIONS_PER_NODE_RECOVERY.get(settings); |
| 106 | + int connectionsPerNodeBulk = TcpTransport.CONNECTIONS_PER_NODE_BULK.get(settings); |
| 107 | + int connectionsPerNodeReg = TcpTransport.CONNECTIONS_PER_NODE_REG.get(settings); |
| 108 | + int connectionsPerNodeState = TcpTransport.CONNECTIONS_PER_NODE_STATE.get(settings); |
| 109 | + int connectionsPerNodePing = TcpTransport.CONNECTIONS_PER_NODE_PING.get(settings); |
| 110 | + Builder builder = new Builder(); |
| 111 | + builder.setConnectTimeout(TcpTransport.TCP_CONNECT_TIMEOUT.get(settings)); |
| 112 | + builder.setHandshakeTimeout(TcpTransport.TCP_CONNECT_TIMEOUT.get(settings)); |
| 113 | + builder.addConnections(connectionsPerNodeBulk, TransportRequestOptions.Type.BULK); |
| 114 | + builder.addConnections(connectionsPerNodePing, TransportRequestOptions.Type.PING); |
| 115 | + // if we are not master eligible we don't need a dedicated channel to publish the state |
| 116 | + builder.addConnections(DiscoveryNode.isMasterNode(settings) ? connectionsPerNodeState : 0, TransportRequestOptions.Type.STATE); |
| 117 | + // if we are not a data-node we don't need any dedicated channels for recovery |
| 118 | + builder.addConnections(DiscoveryNode.isDataNode(settings) ? connectionsPerNodeRecovery : 0, TransportRequestOptions.Type.RECOVERY); |
| 119 | + builder.addConnections(connectionsPerNodeReg, TransportRequestOptions.Type.REG); |
| 120 | + return builder.build(); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | +>>>>>>> 419ad4569dc... Reduce channels in AbstractSimpleTransportTestCase (#34863) (#34880) |
73 | 125 | * A builder to build a new {@link ConnectionProfile}
|
74 | 126 | */
|
75 | 127 | public static class Builder {
|
|
0 commit comments