Github user hanm commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/673#discussion_r230276535
--- Diff:
zookeeper-server/src/main/java/org/apache/zookeeper/server/ServerCnxn.java ---
@@ -68,8 +68,39 @@
private volatile boolean stale = false;
+ AtomicLong outstandingCount = new AtomicLong();
+
+ /** The ZooKeeperServer for this connection. May be null if the server
+ * is not currently serving requests (for example if the server is not
+ * an active quorum participant.
+ */
+ final ZooKeeperServer zkServer;
+
+ public ServerCnxn(final ZooKeeperServer zkServer) {
+ this.zkServer = zkServer;
+ }
+
abstract int getSessionTimeout();
+ public void incrOutstandingAndCheckThrottle(RequestHeader h) {
+ if (h.getXid() <= 0) {
+ return;
+ }
+ if (zkServer.shouldThrottle(outstandingCount.incrementAndGet())) {
+ disableRecv(false);
+ }
+ }
+
+ // will be called from zkServer.processPacket
+ public void decrOutstandingAndCheckThrottle(ReplyHeader h) {
--- End diff --
This is a good suggestion. This PR focus on consolidating and refactoring
existing logic, and we usually prefer doing one thing at a time (so the patch
is easier to review and land). Feel free to fire a PR for improvements after
this patch is merged!
---