livy-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [incubator-livy] mgaido91 commented on a change in pull request #284: [LIVY-752][THRIFT] Fix implementation of limits on connections.
Date Mon, 09 Mar 2020 22:09:39 GMT
mgaido91 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_r389981413
 
 

 ##########
 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()
+    else 1L
   }
 
-  // Taken from Hive
-  private def incrementConnectionsCount(key: String): Unit = {
-    if (!connectionsCount.containsKey(key)) connectionsCount.get(key).incrementAndGet
-    else connectionsCount.put(key, new AtomicLong)
-  }
-
-  // Taken from Hive
   private def decrementConnectionsCount(key: String): Unit = {
-    if (!connectionsCount.containsKey(key)) connectionsCount.get(key).decrementAndGet
-    else connectionsCount.put(key, new AtomicLong)
+    // Decrement the count. Remove the entry if the count reaches zero.
+    val decrementCount = new BiFunction[String, AtomicLong, AtomicLong] {
+      override def apply(unused: String, count: AtomicLong): AtomicLong = {
+        val countValue = count.decrementAndGet()
+        debug(s"Connection count for $key is $countValue")
+        if (countValue == 0L) null
 
 Review comment:
   ditto

----------------------------------------------------------------
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