josh-mckenzie commented on a change in pull request #1204:
URL: https://github.com/apache/cassandra/pull/1204#discussion_r743743805
##########
File path: src/java/org/apache/cassandra/config/DatabaseDescriptor.java
##########
@@ -1350,6 +1370,16 @@ public static int setCredentialsCacheMaxEntries(int
maxEntries)
return conf.credentials_cache_max_entries = maxEntries;
}
+ public static boolean getCredentialsCacheActiveUpdate()
+ {
+ return conf.credentials_cache_active_update;
+ }
+
+ public static void setCredentialsCacheActiveUpdate(boolean activeUpdate)
Review comment:
I think "nitty nit" is my new favorite term.
##########
File path: conf/cassandra.yaml
##########
@@ -203,16 +225,27 @@ permissions_validity_in_ms: 2000
# underlying table, it may not bring a significant reduction in the
# latency of individual authentication attempts.
# Defaults to 2000, set to 0 to disable credentials caching.
+# For a long-running cache using credentials_cache_active_update, consider
+# setting to something longer such as a daily validation: 86400000
credentials_validity_in_ms: 2000
# Refresh interval for credentials cache (if enabled).
# After this interval, cache entries become eligible for refresh. Upon next
# access, an async reload is scheduled and the old value returned until it
# completes. If credentials_validity_in_ms is non-zero, then this must be
# also.
+# This setting is also used to inform the interval of auto-updating if
+# using credentials_cache_active_update.
# Defaults to the same value as credentials_validity_in_ms.
+# For a longer-running permissions cache, consider setting to update hourly
(60000)
# credentials_update_interval_in_ms: 2000
+# If true, cache contents are actively updated by a background task at the
+# interval set by credentials_update_interval_in_ms. If false, cache entries
+# become eligible for refresh after their update interval. Upon next access,
+# an async reload is scheduled and the old value returned until it completes.
+# credentials_cache_active_update: true
Review comment:
At the very least, the default value in Config.java needs to match
what's in our .yaml. It strikes me that this would be something we could pretty
easily lint in the future (both variable names and also consistent defaults).
##########
File path: src/java/org/apache/cassandra/auth/AuthCache.java
##########
@@ -78,6 +94,8 @@ public static void shutdownAllAndWait(long timeout, TimeUnit
unit) throws Interr
* @param getUpdateIntervalDelegate Getter for update interval
* @param setMaxEntriesDelegate Used to set max # entries in cache. See
{@link com.github.benmanes.caffeine.cache.Policy.Eviction#setMaximum(long)}
* @param getMaxEntriesDelegate Getter for max entries.
+ * @param setActiveUpdate Actively update the cache before expiry
Review comment:
I'm struggling with the text here as well. Landed on " * @param
setActiveUpdate Method to process config to actively update the auth cache
prior to configured cache expiration"
##########
File path: src/java/org/apache/cassandra/auth/CacheRefresher.java
##########
@@ -0,0 +1,94 @@
+/*
+ * 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;
+
+import java.util.Set;
+import java.util.function.BiPredicate;
+import java.util.function.BooleanSupplier;
+
+import com.github.benmanes.caffeine.cache.LoadingCache;
+import com.google.common.annotations.VisibleForTesting;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.service.StorageService;
+
+public class CacheRefresher<K, V> implements Runnable
+{
+ private static final Logger logger =
LoggerFactory.getLogger(CacheRefresher.class);
+
+ private final String name;
+ private final LoadingCache<K, V> cache;
+ private final BiPredicate<K, V> invalidationCondition;
+ private final BooleanSupplier skipCondition;
+
+ private CacheRefresher(String name, LoadingCache<K, V> cache,
BiPredicate<K, V> invalidationCondition, BooleanSupplier skipCondition)
+ {
+ this.name = name;
+ this.cache = cache;
+ this.invalidationCondition = invalidationCondition;
+ this.skipCondition = skipCondition;
+ }
+
+ public void run()
+ {
+ try
+ {
+ logger.debug("Refreshing {} cache", name);
+ Set<K> ks = cache.asMap().keySet();
+ for (K key : ks)
+ {
+ if (skipCondition.getAsBoolean())
+ {
+ logger.debug("Skipping {} cache refresh", name);
+ return;
+ }
Review comment:
Nope. Moved it; cleaner.
##########
File path: src/java/org/apache/cassandra/auth/AuthCache.java
##########
@@ -212,6 +277,20 @@ public int getMaxEntries()
return getMaxEntriesDelegate.getAsInt();
}
+ public boolean getActiveUpdate()
+ {
+ return getActiveUpdate.getAsBoolean();
+ }
+
+ public void setActiveUpdate(boolean update)
+ {
+ if
(Boolean.getBoolean("cassandra.disable_auth_caches_remote_configuration"))
+ throw new UnsupportedOperationException("Remote configuration of
auth caches is disabled");
+
+ setActiveUpdate.accept(update);
+ cache = initCache(cache);
Review comment:
Looks like we also `initCache()` and assign in `setValidity()` and
`setUpdateInterval()` as well. I see value in longer-blocking on these methods
to make sure that, in the face of multiple operators calling JMX ops against
these methods, we have a linearalizable set of operations that's occurred
against the cache instead of indeterminate raciness.
--
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]