frankgh commented on code in PR #3706:
URL: https://github.com/apache/cassandra/pull/3706#discussion_r1894316030


##########
src/java/org/apache/cassandra/service/StorageService.java:
##########
@@ -4969,6 +4969,13 @@ public void clearConnectionHistory()
         daemon.clearConnectionHistory();
         logger.info("Cleared connection history");
     }
+
+    public void disconnectInvalidRoles()
+    {
+        logger.info("Disconnecting invalid roles");

Review Comment:
   maybe move this to debug?



##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -5349,4 +5349,28 @@ public static boolean 
isPasswordValidatorReconfigurationEnabled()
     {
         return conf.password_validator_reconfiguration_enabled;
     }
+
+    public static long getInvalidClientDisconnectPeriod(TimeUnit unit)
+    {
+        return conf.invalid_client_disconnect_period.to(unit);
+    }
+
+    public static void setInvalidClientDisconnectPeriod(TimeUnit unit, long 
duration)
+    {
+        long prevDuration = conf.invalid_client_disconnect_period.to(unit);
+        logger.info("invalid_client_disconnect_period set from {} to {}", 
prevDuration, duration == 0 ? "disabled" : String.format("%s %s", duration, 
unit));

Review Comment:
   NIT to avoid the string concat, although we don't save much here
   ```suggestion
           logger.info("invalid_client_disconnect_period set from {} to {} 
({})", prevDuration, duration == 0 ? "disabled" : duration, unit);
   ```
   
   The unit shows all uppercase but that's fine, I don't want to do a lowercase 
here.



##########
src/java/org/apache/cassandra/auth/CassandraRoleManager.java:
##########
@@ -732,4 +747,76 @@ public Supplier<Map<RoleResource, Set<Role>>> bulkLoader()
             return entries;
         };
     }
+
+    protected void disconnectInvalidRoles()
+    {
+        // This should always run with jitter, otherwise there's a risk that 
all nodes disconnect clients at the same time
+        StorageService.instance.disconnectInvalidRoles();
+    }
+
+    protected void invalidRoleDisconnectTask(LongSupplier delayMillis, 
ScheduledExecutorService executor)
+    {
+        try
+        {
+            disconnectInvalidRoles();
+        }
+        catch (Exception e)
+        {
+            logger.warn("Failed to disconnect invalid roles", e);
+        }
+
+        long nextDelayMillis = delayMillis.getAsLong();
+        logger.info("Scheduling next invalid role disconnection in {} millis", 
nextDelayMillis);
+        this.invalidRoleDisconnectTask = executor.schedule(() -> 
invalidRoleDisconnectTask(delayMillis, executor), nextDelayMillis, 
TimeUnit.MILLISECONDS);
+    }
+
+    protected void scheduleDisconnectInvalidRoleTask()
+    {
+        // Cancel any pending execution if it exists, since we may have 
changed period / jitter parameters
+        if (this.invalidRoleDisconnectTask != null)
+        {
+            logger.debug("Canceling previous invalidRoleDisconnectTask");
+            this.invalidRoleDisconnectTask.cancel(true);
+        }
+
+        long period = getInvalidClientDisconnectPeriodMillis();
+        long jitter = getInvalidClientDisconnectJitterMillis();
+        if (period <= 0)
+        {
+            logger.info("Invalid role disconnection is disabled");
+            return;
+        }
+        LongSupplier delayMillis = () -> period + 
ThreadLocalRandom.current().nextLong(0, jitter);
+        long firstDelayMillis = delayMillis.getAsLong();
+        ScheduledExecutorPlus executor = ScheduledExecutors.optionalTasks;
+
+        logger.info("Scheduling first invalid role disconnection in {} 
millis", firstDelayMillis);

Review Comment:
   should we move to debug level?



##########
src/java/org/apache/cassandra/auth/CassandraRoleManagerMBean.java:
##########
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.auth;
+
+public interface CassandraRoleManagerMBean

Review Comment:
   can we add javadocs on public interfaces and its methods?



##########
src/java/org/apache/cassandra/config/DatabaseDescriptor.java:
##########
@@ -5349,4 +5349,28 @@ public static boolean 
isPasswordValidatorReconfigurationEnabled()
     {
         return conf.password_validator_reconfiguration_enabled;
     }
+
+    public static long getInvalidClientDisconnectPeriod(TimeUnit unit)
+    {
+        return conf.invalid_client_disconnect_period.to(unit);
+    }
+
+    public static void setInvalidClientDisconnectPeriod(TimeUnit unit, long 
duration)
+    {
+        long prevDuration = conf.invalid_client_disconnect_period.to(unit);
+        logger.info("invalid_client_disconnect_period set from {} to {}", 
prevDuration, duration == 0 ? "disabled" : String.format("%s %s", duration, 
unit));
+        conf.invalid_client_disconnect_period = new 
DurationSpec.LongMillisecondsBound(duration, unit);
+    }
+
+    public static long getInvalidClientDisconnectJitter(TimeUnit unit)
+    {
+        return conf.invalid_client_disconnect_jitter.to(unit);
+    }
+
+    public static void setInvalidClientDisconnectJitter(TimeUnit unit, long 
duration)
+    {
+        long prevDuration = conf.invalid_client_disconnect_jitter.to(unit);
+        logger.info("invalid_client_disconnect_jitter set from {} to {} {}", 
prevDuration, duration, unit);

Review Comment:
   NIT
   ```suggestion
           logger.info("invalid_client_disconnect_jitter set from {} to {} 
({})", prevDuration, duration, unit);
   ```



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to