Skip to content

Commit

Permalink
Merge remote-tracking branch 'apache/master' into ZOOKEEPER-3188
Browse files Browse the repository at this point in the history
  • Loading branch information
symat authored and Mate Szalay-Beko committed Nov 16, 2019
2 parents f875f5c + d2bec6b commit 40bc44c
Show file tree
Hide file tree
Showing 22 changed files with 316 additions and 5,056 deletions.
23 changes: 0 additions & 23 deletions README_packaging.md
Expand Up @@ -65,26 +65,3 @@ The compiled C client can be found here:
- `zookeeper-client/zookeeper-client-c/target/c/include/zookeeper` - Native library headers

The same folders gets archived to the `zookeeper-assembly/target/apache-zookeeper-<version>-lib.tar.gz` file, assuming you activated the `full-build` maven profile.

## Package build command (using ant)

**Command to build tarball package:** `ant tar`

`zookeeper-<version>.tar.gz` tarball file structure layout:

- `/bin` - User executable
- `/sbin` - System executable
- `/libexec` - Configuration boot trap script
- `/lib` - Library dependencies
- `/docs` - Documents
- `/share/zookeeper` - Project files


**Command to build tarball package with native components:** `ant package-native tar`

`zookeeper-<version>-lib.tar.gz` tarball file structure layout:

- `/bin` - User executable
- `/lib` - Native libraries
- `/include/zookeeper` - Native library headers

2,003 changes: 0 additions & 2,003 deletions build.xml

This file was deleted.

164 changes: 0 additions & 164 deletions ivy.xml

This file was deleted.

41 changes: 0 additions & 41 deletions ivysettings.xml

This file was deleted.

3 changes: 0 additions & 3 deletions zookeeper-assembly/src/main/assembly/source-package.xml
Expand Up @@ -107,9 +107,6 @@
<outputDirectory>.</outputDirectory>
<includes>
<include>pom.xml</include>
<include>build.xml</include>
<include>ivy.xml</include>
<include>ivysettings.xml</include>
<include>excludeFindBugsFilter.xml</include>
<include>owaspSuppressions.xml</include>
<include>checktyle.xml</include>
Expand Down
9 changes: 9 additions & 0 deletions zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md
Expand Up @@ -667,6 +667,15 @@ property, when available, is noted below.
recommended to set the value to N * **preAllocSize**
where N >= 2.

* *maxCnxns* :
(Java system property: **zookeeper.maxCnxns**)
Limits the total number of concurrent connections that can be made to a
zookeeper server (per client Port of each server ). This is used to prevent certain
classes of DoS attacks. The default is 0 and setting it to 0 entirely removes
the limit on total number of concurrent connections. Accounting for the
number of connections for serverCnxnFactory and a secureServerCnxnFactory is done
separately, so a peer is allowed to host up to 2*maxCnxns provided they are of appropriate types.

* *maxClientCnxns* :
(No Java system property)
Limits the number of concurrent connections (at the socket
Expand Down
Expand Up @@ -48,10 +48,7 @@ public enum ExitCode {
QUORUM_PACKET_ERROR(13),

/** Unable to bind to the quorum (election) port after multiple retry */
UNABLE_TO_BIND_QUORUM_PORT(14),

/** Failed to shutdown the request processor pipeline gracefully **/
SHUTDOWN_UNGRACEFULLY(16);
UNABLE_TO_BIND_QUORUM_PORT(14);

private final int value;

Expand Down
Expand Up @@ -273,6 +273,9 @@ private boolean doAccept() {
try {
sc = acceptSocket.accept();
accepted = true;
if (limitTotalNumberOfCnxns()) {
throw new IOException("Too many connections max allowed is " + maxCnxns);
}
InetAddress ia = sc.socket().getInetAddress();
int cnxncount = getClientCnxnCount(ia);

Expand Down Expand Up @@ -634,6 +637,7 @@ public void configure(InetSocketAddress addr, int maxcc, int backlog, boolean se
configureSaslLogin();

maxClientCnxns = maxcc;
initMaxCnxns();
sessionlessCnxnTimeout = Integer.getInteger(ZOOKEEPER_NIO_SESSIONLESS_CNXN_TIMEOUT, 10000);
// We also use the sessionlessCnxnTimeout as expiring interval for
// cnxnExpiryQueue. These don't need to be the same, but the expiring
Expand Down
Expand Up @@ -186,6 +186,11 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception {
}

final Channel channel = ctx.channel();
if (limitTotalNumberOfCnxns()) {
ServerMetrics.getMetrics().CONNECTION_REJECTED.add(1);
channel.close();
return;
}
InetAddress addr = ((InetSocketAddress) channel.remoteAddress()).getAddress();
if (maxClientCnxns > 0 && getClientCnxnCount(addr) >= maxClientCnxns) {
ServerMetrics.getMetrics().CONNECTION_REJECTED.add(1);
Expand Down Expand Up @@ -524,6 +529,7 @@ public void closeAll(ServerCnxn.DisconnectReason reason) {
@Override
public void configure(InetSocketAddress addr, int maxClientCnxns, int backlog, boolean secure) throws IOException {
configureSaslLogin();
initMaxCnxns();
localAddress = addr;
this.maxClientCnxns = maxClientCnxns;
this.secure = secure;
Expand Down
Expand Up @@ -40,6 +40,8 @@
public abstract class ServerCnxnFactory {

public static final String ZOOKEEPER_SERVER_CNXN_FACTORY = "zookeeper.serverCnxnFactory";
private static final String ZOOKEEPER_MAX_CONNECTION = "zookeeper.maxCnxns";
public static final int ZOOKEEPER_MAX_CONNECTION_DEFAULT = 0;

private static final Logger LOG = LoggerFactory.getLogger(ServerCnxnFactory.class);

Expand All @@ -51,6 +53,9 @@ public abstract class ServerCnxnFactory {
*/
static final ByteBuffer closeConn = ByteBuffer.allocate(0);

// total number of connections accepted by the ZooKeeper server
protected int maxCnxns;

// sessionMap is used by closeSession()
final ConcurrentHashMap<Long, ServerCnxn> sessionMap = new ConcurrentHashMap<Long, ServerCnxn>();

Expand Down Expand Up @@ -287,4 +292,40 @@ public static String getUserName() {
return loginUser;
}

/**
* Maximum number of connections allowed in the ZooKeeper system
*/
public int getMaxCnxns() {
return maxCnxns;
}

protected void initMaxCnxns() {
maxCnxns = Integer.getInteger(ZOOKEEPER_MAX_CONNECTION, ZOOKEEPER_MAX_CONNECTION_DEFAULT);
if (maxCnxns < 0) {
maxCnxns = ZOOKEEPER_MAX_CONNECTION_DEFAULT;
LOG.warn("maxCnxns should be greater than or equal to 0, using default vlaue {}.",
ZOOKEEPER_MAX_CONNECTION_DEFAULT);
} else if (maxCnxns == ZOOKEEPER_MAX_CONNECTION_DEFAULT) {
LOG.warn("maxCnxns is not configured, using default value {}.",
ZOOKEEPER_MAX_CONNECTION_DEFAULT);
} else {
LOG.info("maxCnxns configured value is {}.", maxCnxns);
}
}

/**
* Ensure total number of connections are less than the maxCnxns
*/
protected boolean limitTotalNumberOfCnxns() {
if (maxCnxns <= 0) {
// maxCnxns limit is disabled
return false;
}
int cnxns = getNumAliveConnections();
if (cnxns >= maxCnxns) {
LOG.error("Too many connections " + cnxns + " - max is " + maxCnxns);
return true;
}
return false;
}
}

0 comments on commit 40bc44c

Please sign in to comment.