Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public enum ClientDnsLookup {
USE_ALL_DNS_IPS("use_all_dns_ips"),
RESOLVE_CANONICAL_BOOTSTRAP_SERVERS_ONLY("resolve_canonical_bootstrap_servers_only");

private String clientDnsLookup;
private final String clientDnsLookup;

ClientDnsLookup(String clientDnsLookup) {
this.clientDnsLookup = clientDnsLookup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static List<InetSocketAddress> parseAndValidateAddresses(List<String> url
* some third-party applications still rely on this API to parse and validate addresses.
*/
public static List<InetSocketAddress> parseAndValidateAddresses(List<String> urls) {
return parseAndValidateAddresses(urls, ClientDnsLookup.DEFAULT);
return parseAndValidateAddresses(urls, ClientDnsLookup.USE_ALL_DNS_IPS);
}

public static List<InetSocketAddress> parseAndValidateAddresses(List<String> urls, ClientDnsLookup clientDnsLookup) {
Expand Down
4 changes: 2 additions & 2 deletions clients/src/main/java/org/apache/kafka/clients/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ public synchronized void incrementNodesTriedSinceLastSuccessfulRefresh() {
/**
* Whether the client should update the cluster metadata by resolving the bootstrap server again
* @param nowMs
* @return true if client hasn't refreshed cluster metadata for maxClusterMetadataExpireTimeMs and
* @return true if client is not in bootstrap mode and hasn't refreshed cluster metadata for maxClusterMetadataExpireTimeMs and
* has tried connecting to at least one node in current node set; or forceClusterMetadataUpdateFromBootstrap
* has been set by receiving stale metadata from a different cluster
*/
public synchronized boolean shouldUpdateClusterMetadataFromBootstrap(long nowMs) {
return (this.nodesTriedSinceLastSuccessfulRefresh >= 1 &&
this.lastSuccessfulRefreshMs + this.maxClusterMetadataExpireTimeMs <= nowMs) ||
(this.lastRefreshMs != 0 && this.lastSuccessfulRefreshMs + this.maxClusterMetadataExpireTimeMs <= nowMs)) ||
this.forceClusterMetadataUpdateFromBootstrap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ public Node leastLoadedNode(long now) {

int offset = this.randOffset.nextInt(newNodes.size());
Node node = newNodes.get(offset);
log.info("Resolved bootstrap server again, randomly picked node {} as least loaded node from the resolved node set", node);
log.trace("Resolved bootstrap server again, randomly picked node {} as least loaded node from the resolved node set", node);

return node;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public class AdminClientConfig extends AbstractConfig {
METRICS_RECORDING_LEVEL_DOC)
.define(CLIENT_DNS_LOOKUP_CONFIG,
Type.STRING,
ClientDnsLookup.DEFAULT.toString(),
ClientDnsLookup.USE_ALL_DNS_IPS.toString(),
in(ClientDnsLookup.DEFAULT.toString(),
ClientDnsLookup.USE_ALL_DNS_IPS.toString(),
ClientDnsLookup.RESOLVE_CANONICAL_BOOTSTRAP_SERVERS_ONLY.toString()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public class ConsumerConfig extends AbstractConfig {
CommonClientConfigs.BOOTSTRAP_SERVERS_DOC)
.define(CLIENT_DNS_LOOKUP_CONFIG,
Type.STRING,
ClientDnsLookup.DEFAULT.toString(),
ClientDnsLookup.USE_ALL_DNS_IPS.toString(),
in(ClientDnsLookup.DEFAULT.toString(),
ClientDnsLookup.USE_ALL_DNS_IPS.toString(),
ClientDnsLookup.RESOLVE_CANONICAL_BOOTSTRAP_SERVERS_ONLY.toString()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public class ProducerConfig extends AbstractConfig {
CONFIG = new ConfigDef().define(BOOTSTRAP_SERVERS_CONFIG, Type.LIST, Collections.emptyList(), new ConfigDef.NonNullValidator(), Importance.HIGH, CommonClientConfigs.BOOTSTRAP_SERVERS_DOC)
.define(CLIENT_DNS_LOOKUP_CONFIG,
Type.STRING,
ClientDnsLookup.DEFAULT.toString(),
ClientDnsLookup.USE_ALL_DNS_IPS.toString(),
in(ClientDnsLookup.DEFAULT.toString(),
ClientDnsLookup.USE_ALL_DNS_IPS.toString(),
ClientDnsLookup.RESOLVE_CANONICAL_BOOTSTRAP_SERVERS_ONLY.toString()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
*/
package org.apache.kafka.clients;

import org.apache.kafka.common.config.ConfigException;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.apache.kafka.common.config.ConfigException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Ignore;
import org.junit.Test;

public class ClientUtilsTest {

Expand Down Expand Up @@ -107,8 +108,9 @@ public void testResolveDnsLookup() throws UnknownHostException {
}

@Test
@Ignore
public void testResolveDnsLookupAllIps() throws UnknownHostException {
assertEquals(2, ClientUtils.resolve("kafka.apache.org", ClientDnsLookup.USE_ALL_DNS_IPS).size());
assertTrue(ClientUtils.resolve("kafka.apache.org", ClientDnsLookup.USE_ALL_DNS_IPS).size() > 1);
}

private List<InetSocketAddress> checkWithoutLookup(String... url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.kafka.common.utils.LogContext;
import org.apache.kafka.common.utils.MockTime;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class ClusterConnectionStatesTest {
Expand Down Expand Up @@ -254,6 +255,7 @@ public void testSingleIPWithUseAll() throws UnknownHostException {
assertSame(currAddress, connectionStates.currentAddress(nodeId1));
}

@Ignore
@Test
public void testMultipleIPsWithDefault() throws UnknownHostException {
assertEquals(2, ClientUtils.resolve(hostTwoIps, ClientDnsLookup.USE_ALL_DNS_IPS).size());
Expand All @@ -264,6 +266,7 @@ public void testMultipleIPsWithDefault() throws UnknownHostException {
assertSame(currAddress, connectionStates.currentAddress(nodeId1));
}

@Ignore
@Test
public void testMultipleIPsWithUseAll() throws UnknownHostException {
assertEquals(2, ClientUtils.resolve(hostTwoIps, ClientDnsLookup.USE_ALL_DNS_IPS).size());
Expand All @@ -279,6 +282,7 @@ public void testMultipleIPsWithUseAll() throws UnknownHostException {
assertSame(addr1, addr3);
}

@Ignore
@Test
public void testHostResolveChange() throws UnknownHostException, ReflectiveOperationException {
assertEquals(2, ClientUtils.resolve(hostTwoIps, ClientDnsLookup.USE_ALL_DNS_IPS).size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public void testResolveBootstrapAfterClusterMetadataTimeout() {
//bootstrap the metadata cache with some valid nodes
clusterMetadata.bootstrap(addresses, time.milliseconds());

clusterMetadata.requestClusterMetadataUpdateFromBootstrap();

//first time call leastLoadedNode on the created NetworkClient should pass since nodesTriedSinceLastSuccessfulRefresh is 0
clusterClient.leastLoadedNode(time.milliseconds());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private static Cluster mockCluster(int controllerIndex) {

private static Cluster mockBootstrapCluster() {
return Cluster.bootstrap(ClientUtils.parseAndValidateAddresses(
Collections.singletonList("localhost:8121"), ClientDnsLookup.DEFAULT));
singletonList("localhost:8121"), ClientDnsLookup.USE_ALL_DNS_IPS));
}

private static AdminClientUnitTestEnv mockClientEnv(String... configVals) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ public void testQuotaMetrics() {
Cluster cluster = TestUtils.singletonCluster("test", 1);
Node node = cluster.nodes().get(0);
NetworkClient client = new NetworkClient(selector, metadata, "mock", Integer.MAX_VALUE,
1000, 1000, 64 * 1024, 64 * 1024, 1000, ClientDnsLookup.DEFAULT,
1000, 1000, 64 * 1024, 64 * 1024, 1000, ClientDnsLookup.USE_ALL_DNS_IPS,
time, true, new ApiVersions(), throttleTimeSensor, new LogContext());

short apiVersionsResponseVersion = ApiKeys.API_VERSIONS.latestVersion();
Expand Down Expand Up @@ -3203,7 +3203,7 @@ private void testGetOffsetsForTimesWithError(Errors errorForP0,
TopicPartition t2p0 = new TopicPartition(topicName2, 0);
// Expect a metadata refresh.
metadata.bootstrap(ClientUtils.parseAndValidateAddresses(Collections.singletonList("1.1.1.1:1111"),
ClientDnsLookup.DEFAULT), time.milliseconds());
ClientDnsLookup.USE_ALL_DNS_IPS), time.milliseconds());

Map<String, Integer> partitionNumByTopic = new HashMap<>();
partitionNumByTopic.put(topicName, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public void testQuotaMetrics() throws Exception {
Cluster cluster = TestUtils.singletonCluster("test", 1);
Node node = cluster.nodes().get(0);
NetworkClient client = new NetworkClient(selector, metadata, "mock", Integer.MAX_VALUE,
1000, 1000, 64 * 1024, 64 * 1024, 1000, ClientDnsLookup.DEFAULT,
1000, 1000, 64 * 1024, 64 * 1024, 1000, ClientDnsLookup.USE_ALL_DNS_IPS,
time, true, new ApiVersions(), throttleTimeSensor, logContext);

short apiVersionsResponseVersion = ApiKeys.API_VERSIONS.latestVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected static ConfigDef baseConfigDef() {
Importance.HIGH, BOOTSTRAP_SERVERS_DOC)
.define(CLIENT_DNS_LOOKUP_CONFIG,
Type.STRING,
ClientDnsLookup.DEFAULT.toString(),
ClientDnsLookup.USE_ALL_DNS_IPS.toString(),
in(ClientDnsLookup.DEFAULT.toString(),
ClientDnsLookup.USE_ALL_DNS_IPS.toString(),
ClientDnsLookup.RESOLVE_CANONICAL_BOOTSTRAP_SERVERS_ONLY.toString()),
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/kafka/admin/AdminClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ object AdminClient {
CommonClientConfigs.BOOTSTRAP_SERVERS_DOC)
.define(CommonClientConfigs.CLIENT_DNS_LOOKUP_CONFIG,
Type.STRING,
ClientDnsLookup.DEFAULT.toString,
ClientDnsLookup.USE_ALL_DNS_IPS.toString,
in(ClientDnsLookup.DEFAULT.toString,
ClientDnsLookup.USE_ALL_DNS_IPS.toString,
ClientDnsLookup.RESOLVE_CANONICAL_BOOTSTRAP_SERVERS_ONLY.toString),
Expand Down Expand Up @@ -468,7 +468,7 @@ object AdminClient {
DefaultSendBufferBytes,
DefaultReceiveBufferBytes,
requestTimeoutMs,
ClientDnsLookup.DEFAULT,
ClientDnsLookup.USE_ALL_DNS_IPS,
time,
true,
new ApiVersions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ConsumerFetcherManager(private val consumerIdString: String,

private def bootstrapNodes() : java.util.List[Node] = {
val bootstrapServers = seqAsJavaList(ClientUtils.getSslBrokerEndPoints(zkUtils).map(_.connectionString))
val addresses = org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(bootstrapServers, ClientDnsLookup.DEFAULT)
val addresses = org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(bootstrapServers, ClientDnsLookup.USE_ALL_DNS_IPS)
JCluster.bootstrap(addresses).nodes
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/kafka/consumer/SSLNetworkClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SSLNetworkClient(config: ConsumerConfig, metadataUpdater: ManualMetadataUp
Selectable.USE_DEFAULT_BUFFER_SIZE,
config.socketReceiveBufferBytes,
socketTimeoutMs,
ClientDnsLookup.DEFAULT,
ClientDnsLookup.USE_ALL_DNS_IPS,
time,
true,
new ApiVersions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class ControllerChannelManager(controllerContext: ControllerContext,
Selectable.USE_DEFAULT_BUFFER_SIZE,
Selectable.USE_DEFAULT_BUFFER_SIZE,
config.requestTimeoutMs,
ClientDnsLookup.DEFAULT,
ClientDnsLookup.USE_ALL_DNS_IPS,
time,
false,
new ApiVersions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ object TransactionMarkerChannelManager {
Selectable.USE_DEFAULT_BUFFER_SIZE,
config.socketReceiveBufferBytes,
config.requestTimeoutMs,
ClientDnsLookup.DEFAULT,
ClientDnsLookup.USE_ALL_DNS_IPS,
time,
false,
new ApiVersions,
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/kafka/server/KafkaServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ class KafkaServer(val config: KafkaConfig, time: Time = Time.SYSTEM, threadNameP
Selectable.USE_DEFAULT_BUFFER_SIZE,
Selectable.USE_DEFAULT_BUFFER_SIZE,
config.requestTimeoutMs,
ClientDnsLookup.DEFAULT,
ClientDnsLookup.USE_ALL_DNS_IPS,
time,
false,
new ApiVersions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class ReplicaFetcherBlockingSend(sourceBroker: BrokerEndPoint,
Selectable.USE_DEFAULT_BUFFER_SIZE,
brokerConfig.replicaSocketReceiveBufferBytes,
brokerConfig.requestTimeoutMs,
ClientDnsLookup.DEFAULT,
ClientDnsLookup.USE_ALL_DNS_IPS,
time,
false,
new ApiVersions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ private class ReplicaFetcherBlockingSend(sourceNode: Node,
Selectable.USE_DEFAULT_BUFFER_SIZE,
consumerConfig.getInt(ConsumerConfig.RECEIVE_BUFFER_CONFIG),
consumerConfig.getInt(ConsumerConfig.REQUEST_TIMEOUT_MS_CONFIG),
ClientDnsLookup.DEFAULT,
ClientDnsLookup.USE_ALL_DNS_IPS,
time,
false,
new ApiVersions,
Expand Down