livy-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-livy] wypoon commented on a change in pull request #284: [LIVY-752][THRIFT] Fix implementation of limits on connections.
Date Mon, 09 Mar 2020 23:55:42 GMT
wypoon commented on a change in pull request #284: [LIVY-752][THRIFT] Fix implementation of
limits on connections.
URL: https://github.com/apache/incubator-livy/pull/284#discussion_r390023915
 
 

 ##########
 File path: thriftserver/server/src/main/scala/org/apache/livy/thriftserver/LivyThriftSessionManager.scala
 ##########
 @@ -412,37 +413,24 @@ class LivyThriftSessionManager(val server: LivyThriftServer, val livyConf:
LivyC
     }
   }
 
-  // Taken from Hive
-  @throws[HiveSQLException]
-  private def incrementConnections(
-      username: String,
-      ipAddress: String,
-      forwardedAddresses: util.List[String]): Unit = {
-    val clientIpAddress: String = getOriginClientIpAddress(ipAddress, forwardedAddresses)
-    val violation = anyViolations(username, clientIpAddress)
-    // increment the counters only when there are no violations
-    if (violation.isEmpty) {
-      if (trackConnectionsPerUser(username)) incrementConnectionsCount(username)
-      if (trackConnectionsPerIpAddress(clientIpAddress)) incrementConnectionsCount(clientIpAddress)
-      if (trackConnectionsPerUserIpAddress(username, clientIpAddress)) {
-        incrementConnectionsCount(username + ":" + clientIpAddress)
-      }
-    } else {
-      error(violation.get)
-      throw new HiveSQLException(violation.get)
-    }
+  private def incrementConnectionsCount(key: String): Long = {
+    // Increment the count, returning the new value.
+    val count = connectionsCount.putIfAbsent(key, new AtomicLong(1L))
+    if (count != null) count.incrementAndGet()
 
 Review comment:
   I'm fine to put the braces in for if-else. I didn't because the code this replaces has
exactly this kind of if-else (no braces, each clause being a single line), so I thought that
was the project style!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message