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
2 changes: 1 addition & 1 deletion core/src/main/scala/kafka/server/KafkaConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ object KafkaConfig {
.define(SocketSendBufferBytesProp, INT, Defaults.SocketSendBufferBytes, HIGH, SocketSendBufferBytesDoc)
.define(SocketReceiveBufferBytesProp, INT, Defaults.SocketReceiveBufferBytes, HIGH, SocketReceiveBufferBytesDoc)
.define(SocketRequestMaxBytesProp, INT, Defaults.SocketRequestMaxBytes, atLeast(1), HIGH, SocketRequestMaxBytesDoc)
.define(MaxConnectionsPerIpProp, INT, Defaults.MaxConnectionsPerIp, atLeast(1), MEDIUM, MaxConnectionsPerIpDoc)
.define(MaxConnectionsPerIpProp, INT, Defaults.MaxConnectionsPerIp, atLeast(0), MEDIUM, MaxConnectionsPerIpDoc)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR. Can we also update the doc string of MaxConnectionsPerIpOverridesDoc.
Currently it is not clear about the format of the config string.

some thing like this:
A comma separated list of per-ip or hostname overrides to the default maximum number of connections. Example value is : hostName:100,127.0.0.1:200.

.define(MaxConnectionsPerIpOverridesProp, STRING, Defaults.MaxConnectionsPerIpOverrides, MEDIUM, MaxConnectionsPerIpOverridesDoc)
.define(ConnectionsMaxIdleMsProp, LONG, Defaults.ConnectionsMaxIdleMs, MEDIUM, ConnectionsMaxIdleMsDoc)

Expand Down
43 changes: 40 additions & 3 deletions core/src/test/scala/unit/kafka/network/SocketServerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ package kafka.network
import java.io._
import java.net._
import java.nio.ByteBuffer
import java.util.{HashMap, Properties, Random}
import java.nio.channels.SocketChannel
import java.util.{HashMap, Random}
import javax.net.ssl._

import com.yammer.metrics.core.{Gauge, Meter}
Expand Down Expand Up @@ -134,8 +134,8 @@ class SocketServerTest extends JUnitSuite {
channel.sendResponse(new RequestChannel.Response(request, Some(send), SendAction, Some(request.header.toString)))
}

def connect(s: SocketServer = server, protocol: SecurityProtocol = SecurityProtocol.PLAINTEXT) = {
val socket = new Socket("localhost", s.boundPort(ListenerName.forSecurityProtocol(protocol)))
def connect(s: SocketServer = server, protocol: SecurityProtocol = SecurityProtocol.PLAINTEXT, localAddr: InetAddress = null) = {
val socket = new Socket("localhost", s.boundPort(ListenerName.forSecurityProtocol(protocol)), localAddr, 0)
sockets += socket
socket
}
Expand Down Expand Up @@ -443,6 +443,43 @@ class SocketServerTest extends JUnitSuite {
assertNotNull(request)
}

@Test
def testZeroMaxConnectionsPerIp() {
val newProps = TestUtils.createBrokerConfig(0, TestUtils.MockZkConnect, port = 0)
newProps.setProperty(KafkaConfig.MaxConnectionsPerIpProp, "0")
newProps.setProperty(KafkaConfig.MaxConnectionsPerIpOverridesProp, "%s:%s".format("127.0.0.1", "5"))
val server = new SocketServer(KafkaConfig.fromProps(newProps), new Metrics(), Time.SYSTEM, credentialProvider)
try {
server.startup()
// make the maximum allowable number of connections
val conns = (0 until 5).map(_ => connect(server))
// now try one more (should fail)
val conn = connect(server)
conn.setSoTimeout(3000)
assertEquals(-1, conn.getInputStream.read())
conn.close()

// it should succeed after closing one connection
val address = conns.head.getInetAddress
conns.head.close()
TestUtils.waitUntilTrue(() => server.connectionCount(address) < conns.length,
"Failed to decrement connection count after close")
val conn2 = connect(server)
val serializedBytes = producerRequestBytes()
sendRequest(conn2, serializedBytes)
val request = server.requestChannel.receiveRequest(2000)
assertNotNull(request)

// now try to connect from the external facing interface, which should fail
val conn3 = connect(s = server, localAddr = InetAddress.getLocalHost)
conn3.setSoTimeout(3000)
assertEquals(-1, conn3.getInputStream.read())
conn3.close()
} finally {
shutdownServerAndMetrics(server)
}
}

@Test
def testMaxConnectionsPerIpOverrides() {
val overrideNum = server.config.maxConnectionsPerIp + 1
Expand Down
1 change: 1 addition & 0 deletions docs/upgrade.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ <h4><a id="upgrade_1_2_0" href="#upgrade_1_2_0">Upgrading from 0.8.x, 0.9.x, 0.1
<h5><a id="upgrade_120_notable" href="#upgrade_120_notable">Notable changes in 1.2.0</a></h5>
<ul>
<li><a href="https://cwiki.apache.org/confluence/x/oYtjB">KIP-186</a> increases the default offset retention time from 1 day to 7 days. This makes it less likely to "lose" offsets in an application that commits infrequently. It also increases the active set of offsets and therefore can increase memory usage on the broker. Note that the console consumer currently enables offset commit by default and can be the source of a large number of offsets which this change will now preserve for 7 days instead of 1. You can preserve the existing behavior by setting the broker config <code>offsets.retention.minutes</code> to 1440.</li>
<li><a href="https://issues.apache.org/jira/browse/KAFKA-5674">KAFKA-5674</a> extends the lower interval of <code>max.connections.per.ip minimum</code> to zero and therefore allows IP-based filtering of inbound connections.</li>
</ul>

<h5><a id="upgrade_120_new_protocols" href="#upgrade_120_new_protocols">New Protocol Versions</a></h5>
Expand Down