Skip to content

Commit

Permalink
Moved system properties and envs to CassandraRelevantProperties and C…
Browse files Browse the repository at this point in the history
…assandraRelevantEnv respectively

Patch by Maxim Muzafarov; reviewed by Stefan Miklosovic and Jacek Lewandowski for CASSANDRA-17797
  • Loading branch information
Mmuzaf authored and jacek-lewandowski committed May 11, 2023
1 parent f54ef5e commit f650908
Show file tree
Hide file tree
Showing 236 changed files with 1,768 additions and 1,217 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,4 +1,5 @@
5.0
* Moved system properties and envs to CassandraRelevantProperties and CassandraRelevantEnv respectively (CASSANDRA-17797)
* Add sstablepartitions offline tool to find large partitions in sstables (CASSANDRA-8720)
* Replace usages of json-simple dependency by Jackson (CASSANDRA-16855)
* When decommissioning should set Severity to limit traffic (CASSANDRA-18430)
Expand Down
18 changes: 18 additions & 0 deletions checkstyle.xml
Expand Up @@ -149,6 +149,24 @@
<property name="message" value="Avoid Short() and use Short.valueOf()" />
</module>

<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="checkstyle: suppress below '([\w\|]+)'"/>
<property name="idFormat" value="$1"/>
</module>

<module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat" value="checkstyle: suppress nearby '([\w\|]+)'"/>
<property name="idFormat" value="$1"/>
<property name="influenceFormat" value="0"/>
</module>

<module name="RegexpSinglelineJava">
<property name="id" value="blockSystemPropertyUsage"/>
<property name="format" value="(System\.getenv)|(System\.(getProperty|setProperty))|(Integer\.getInteger)|(Long\.getLong)|(Boolean\.getBoolean)"/>
<property name="ignoreComments" value="true"/>
<property name="message" value="Use the CassandraRelevantProperties or CassandraRelevantEnv instead." />
</module>

<module name="RedundantImport"/>
<module name="UnusedImports"/>
</module>
Expand Down
20 changes: 19 additions & 1 deletion checkstyle_test.xml
Expand Up @@ -99,7 +99,25 @@
<property name="ignoreComments" value="true"/>
<property name="message" value="Avoid Short() and use Short.valueOf()" />
</module>


<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="checkstyle: suppress below '([\w\|]+)'"/>
<property name="idFormat" value="$1"/>
</module>

<module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat" value="checkstyle: suppress nearby '([\w\|]+)'"/>
<property name="idFormat" value="$1"/>
<property name="influenceFormat" value="0"/>
</module>

<module name="RegexpSinglelineJava">
<property name="id" value="blockSystemPropertyUsage"/>
<property name="format" value="(System\.getenv)|(System\.(getProperty|setProperty))|(Integer\.getInteger)|(Long\.getLong)|(Boolean\.getBoolean)"/>
<property name="ignoreComments" value="true"/>
<property name="message" value="Use the CassandraRelevantProperties or CassandraRelevantEnv instead." />
</module>

<module name="RedundantImport"/>
<module name="UnusedImports"/>
</module>
Expand Down
20 changes: 9 additions & 11 deletions src/java/org/apache/cassandra/auth/AuthCache.java
Expand Up @@ -48,18 +48,16 @@

import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.cassandra.concurrent.ExecutorFactory.Global.executorFactory;
import static org.apache.cassandra.config.CassandraRelevantProperties.AUTH_CACHE_WARMING_MAX_RETRIES;
import static org.apache.cassandra.config.CassandraRelevantProperties.AUTH_CACHE_WARMING_RETRY_INTERVAL_MS;
import static org.apache.cassandra.config.CassandraRelevantProperties.DISABLE_AUTH_CACHES_REMOTE_CONFIGURATION;

public class AuthCache<K, V> implements AuthCacheMBean, Shutdownable
{
private static final Logger logger = LoggerFactory.getLogger(AuthCache.class);

public static final String MBEAN_NAME_BASE = "org.apache.cassandra.auth:type=";

// We expect default values on cache retries and interval to be sufficient for everyone but have this escape hatch
// just in case.
static final String CACHE_LOAD_RETRIES_PROPERTY = "cassandra.auth_cache.warming.max_retries";
static final String CACHE_LOAD_RETRY_INTERVAL_PROPERTY = "cassandra.auth_cache.warming.retry_interval_ms";

private volatile ScheduledFuture cacheRefresher = null;

// Keep a handle on created instances so their executors can be terminated cleanly
Expand Down Expand Up @@ -254,7 +252,7 @@ public void invalidate(K k)
*/
public synchronized void setValidity(int validityPeriod)
{
if (Boolean.getBoolean("cassandra.disable_auth_caches_remote_configuration"))
if (DISABLE_AUTH_CACHES_REMOTE_CONFIGURATION.getBoolean())
throw new UnsupportedOperationException("Remote configuration of auth caches is disabled");

setValidityDelegate.accept(validityPeriod);
Expand All @@ -272,7 +270,7 @@ public int getValidity()
*/
public synchronized void setUpdateInterval(int updateInterval)
{
if (Boolean.getBoolean("cassandra.disable_auth_caches_remote_configuration"))
if (DISABLE_AUTH_CACHES_REMOTE_CONFIGURATION.getBoolean())
throw new UnsupportedOperationException("Remote configuration of auth caches is disabled");

setUpdateIntervalDelegate.accept(updateInterval);
Expand All @@ -290,7 +288,7 @@ public int getUpdateInterval()
*/
public synchronized void setMaxEntries(int maxEntries)
{
if (Boolean.getBoolean("cassandra.disable_auth_caches_remote_configuration"))
if (DISABLE_AUTH_CACHES_REMOTE_CONFIGURATION.getBoolean())
throw new UnsupportedOperationException("Remote configuration of auth caches is disabled");

setMaxEntriesDelegate.accept(maxEntries);
Expand All @@ -309,7 +307,7 @@ public boolean getActiveUpdate()

public synchronized void setActiveUpdate(boolean update)
{
if (Boolean.getBoolean("cassandra.disable_auth_caches_remote_configuration"))
if (DISABLE_AUTH_CACHES_REMOTE_CONFIGURATION.getBoolean())
throw new UnsupportedOperationException("Remote configuration of auth caches is disabled");

setActiveUpdate.accept(update);
Expand Down Expand Up @@ -409,8 +407,8 @@ public void warm()
return;
}

int retries = Integer.getInteger(CACHE_LOAD_RETRIES_PROPERTY, 10);
long retryInterval = Long.getLong(CACHE_LOAD_RETRY_INTERVAL_PROPERTY, 1000);
int retries = AUTH_CACHE_WARMING_MAX_RETRIES.getInt(10);
long retryInterval = AUTH_CACHE_WARMING_RETRY_INTERVAL_MS.getLong(1000);

while (retries-- > 0)
{
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/apache/cassandra/auth/AuthKeyspace.java
Expand Up @@ -30,6 +30,7 @@
import org.apache.cassandra.schema.Tables;

import static java.lang.String.format;
import static org.apache.cassandra.config.CassandraRelevantProperties.SUPERUSER_SETUP_DELAY_MS;

public final class AuthKeyspace
{
Expand All @@ -55,7 +56,7 @@ private AuthKeyspace()
public static final String RESOURCE_ROLE_INDEX = "resource_role_permissons_index";
public static final String NETWORK_PERMISSIONS = "network_permissions";

public static final long SUPERUSER_SETUP_DELAY = Long.getLong("cassandra.superuser_setup_delay_ms", 10000);
public static final long SUPERUSER_SETUP_DELAY = SUPERUSER_SETUP_DELAY_MS.getLong();

private static final TableMetadata Roles =
parse(ROLES,
Expand Down
16 changes: 6 additions & 10 deletions src/java/org/apache/cassandra/auth/CassandraRoleManager.java
Expand Up @@ -34,7 +34,6 @@
import org.slf4j.LoggerFactory;

import org.apache.cassandra.concurrent.ScheduledExecutors;
import org.apache.cassandra.config.Config;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.schema.SchemaConstants;
import org.apache.cassandra.cql3.*;
Expand All @@ -49,6 +48,7 @@
import org.apache.cassandra.utils.ByteBufferUtil;
import org.mindrot.jbcrypt.BCrypt;

import static org.apache.cassandra.config.CassandraRelevantProperties.AUTH_BCRYPT_GENSALT_LOG2_ROUNDS;
import static org.apache.cassandra.service.QueryState.forInternalCalls;
import static org.apache.cassandra.utils.Clock.Global.nanoTime;

Expand Down Expand Up @@ -113,19 +113,15 @@ public class CassandraRoleManager implements IRoleManager
}
};

// 2 ** GENSALT_LOG2_ROUNDS rounds of hashing will be performed.
@VisibleForTesting
public static final String GENSALT_LOG2_ROUNDS_PROPERTY = Config.PROPERTY_PREFIX + "auth_bcrypt_gensalt_log2_rounds";
private static final int GENSALT_LOG2_ROUNDS = getGensaltLogRounds();

static int getGensaltLogRounds()
{
int rounds = Integer.getInteger(GENSALT_LOG2_ROUNDS_PROPERTY, 10);
if (rounds < 4 || rounds > 30)
throw new ConfigurationException(String.format("Bad value for system property -D%s." +
"Please use a value between 4 and 30 inclusively",
GENSALT_LOG2_ROUNDS_PROPERTY));
return rounds;
int rounds = AUTH_BCRYPT_GENSALT_LOG2_ROUNDS.getInt(10);
if (rounds < 4 || rounds > 30)
throw new ConfigurationException(String.format("Bad value for system property %s." +
"Please use a value between 4 and 30 inclusively", AUTH_BCRYPT_GENSALT_LOG2_ROUNDS.getKey()));
return rounds;
}

private SelectStatement loadRoleStatement;
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/apache/cassandra/batchlog/BatchlogManager.java
Expand Up @@ -77,6 +77,7 @@

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.apache.cassandra.concurrent.ExecutorFactory.Global.executorFactory;
import static org.apache.cassandra.config.CassandraRelevantProperties.BATCHLOG_REPLAY_TIMEOUT_IN_MS;
import static org.apache.cassandra.cql3.QueryProcessor.executeInternal;
import static org.apache.cassandra.cql3.QueryProcessor.executeInternalWithPaging;
import static org.apache.cassandra.net.Verb.MUTATION_REQ;
Expand All @@ -91,7 +92,7 @@ public class BatchlogManager implements BatchlogManagerMBean

private static final Logger logger = LoggerFactory.getLogger(BatchlogManager.class);
public static final BatchlogManager instance = new BatchlogManager();
public static final long BATCHLOG_REPLAY_TIMEOUT = Long.getLong("cassandra.batchlog.replay_timeout_in_ms", DatabaseDescriptor.getWriteRpcTimeout(MILLISECONDS) * 2);
public static final long BATCHLOG_REPLAY_TIMEOUT = BATCHLOG_REPLAY_TIMEOUT_IN_MS.getLong(DatabaseDescriptor.getWriteRpcTimeout(MILLISECONDS) * 2);

private volatile long totalBatchesReplayed = 0; // no concurrency protection necessary as only written by replay thread.
private volatile TimeUUID lastReplayedUuid = TimeUUID.minAtUnixMillis(0);
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/apache/cassandra/concurrent/SEPWorker.java
Expand Up @@ -30,12 +30,13 @@

import static org.apache.cassandra.concurrent.SEPExecutor.TakeTaskPermitResult.RETURNED_WORK_PERMIT;
import static org.apache.cassandra.concurrent.SEPExecutor.TakeTaskPermitResult.TOOK_PERMIT;
import static org.apache.cassandra.config.CassandraRelevantProperties.SET_SEP_THREAD_NAME;
import static org.apache.cassandra.utils.Clock.Global.nanoTime;

final class SEPWorker extends AtomicReference<SEPWorker.Work> implements Runnable
{
private static final Logger logger = LoggerFactory.getLogger(SEPWorker.class);
private static final boolean SET_THREAD_NAME = Boolean.parseBoolean(System.getProperty("cassandra.set_sep_thread_name", "true"));
private static final boolean SET_THREAD_NAME = SET_SEP_THREAD_NAME.getBoolean();

final Long workerId;
final Thread thread;
Expand Down
17 changes: 16 additions & 1 deletion src/java/org/apache/cassandra/config/CassandraRelevantEnv.java
Expand Up @@ -18,13 +18,19 @@

package org.apache.cassandra.config;

// checkstyle: suppress below 'blockSystemPropertyUsage'

public enum CassandraRelevantEnv
{
/**
* Searching in the JAVA_HOME is safer than searching into System.getProperty("java.home") as the Oracle
* JVM might use the JRE which do not contains jmap.
*/
JAVA_HOME ("JAVA_HOME");
JAVA_HOME ("JAVA_HOME"),
CIRCLECI("CIRCLECI"),
CASSANDRA_SKIP_SYNC("CASSANDRA_SKIP_SYNC")

;

CassandraRelevantEnv(String key)
{
Expand All @@ -38,6 +44,15 @@ public String getString()
return System.getenv(key);
}

/**
* Gets the value of a system env as a boolean.
* @return System env boolean value if it exists, false otherwise.
*/
public boolean getBoolean()
{
return Boolean.parseBoolean(System.getenv(key));
}

public String getKey() {
return key;
}
Expand Down

0 comments on commit f650908

Please sign in to comment.