kzalys commented on code in PR #3306: URL: https://github.com/apache/cassandra/pull/3306#discussion_r1602260358
########## src/java/org/apache/cassandra/repair/autorepair/AutoRepairConfig.java: ########## @@ -0,0 +1,354 @@ +/* + * 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.repair.autorepair; + +import java.io.Serializable; +import java.util.EnumMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; +import java.util.stream.Stream; + +import com.google.common.annotations.VisibleForTesting; + +import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.exceptions.ConfigurationException; + +public class AutoRepairConfig implements Serializable +{ + // enable/disable auto repair globally, overrides all other settings. Cannot be modified dynamically. + public final Boolean enabled; + // the interval in seconds between checks for eligible repair operations. Cannot be modified dynamically. + public final Integer repair_check_interval_in_sec = 300; // 5 minutes + // configures how long repair history is kept for a replaced node + public volatile Integer history_clear_delete_hosts_buffer_in_sec = 60 * 60 * 2; // two hours + // global_settings overides Options.defaultOptions for all repair types + public volatile Options global_settings; + + public enum RepairType + {full, incremental} + + // repair_type_overrides overrides the global_settings for a specific repair type + public volatile Map<RepairType, Options> repair_type_overrides = new EnumMap<>(RepairType.class); + + public AutoRepairConfig() + { + this(false); + } + + public AutoRepairConfig(boolean enabled) + { + this.enabled = enabled; + global_settings = Options.getDefaultOptions(); + for (RepairType type : RepairType.values()) + { + repair_type_overrides.put(type, new Options()); + } + } + + public int getRepairCheckIntervalInSec() + { + return repair_check_interval_in_sec; + } + + public boolean isAutoRepairSchedulingEnabled() + { + return enabled; + } + + public int getAutoRepairHistoryClearDeleteHostsBufferInSec() + { + return history_clear_delete_hosts_buffer_in_sec; + } + + public void setAutoRepairHistoryClearDeleteHostsBufferInSec(int seconds) + { + history_clear_delete_hosts_buffer_in_sec = seconds; + } + + public boolean isAutoRepairEnabled(RepairType repairType) + { + return enabled && applyOverrides(repairType, opt -> opt.enabled); + } + + public void setAutoRepairEnabled(RepairType repairType, boolean enabled) + { + if (enabled && repairType == RepairType.incremental && + (DatabaseDescriptor.getMaterializedViewsEnabled() || DatabaseDescriptor.isCDCEnabled())) + throw new ConfigurationException("Cannot enable incremental repair with materialized views or CDC enabled"); + + repair_type_overrides.get(repairType).enabled = enabled; + } + + public void setRepairByKeyspace(RepairType repairType, boolean repairByKeyspace) + { + repair_type_overrides.get(repairType).repair_by_keyspace = repairByKeyspace; + } + + public boolean getRepairByKeyspace(RepairType repairType) + { + return applyOverrides(repairType, opt -> opt.repair_by_keyspace); + } + + public int getRepairThreads(RepairType repairType) + { + return applyOverrides(repairType, opt -> opt.number_of_repair_threads); + } + + public void setRepairThreads(RepairType repairType, int repairThreads) + { + repair_type_overrides.get(repairType).number_of_repair_threads = repairThreads; + } + + public int getRepairSubRangeNum(RepairType repairType) + { + return applyOverrides(repairType, opt -> opt.number_of_subranges); + } + + public void setRepairSubRangeNum(RepairType repairType, int repairSubRanges) + { + repair_type_overrides.get(repairType).number_of_subranges = repairSubRanges; + } + + public int getRepairMinIntervalInHours(RepairType repairType) + { + return applyOverrides(repairType, opt -> opt.min_repair_interval_in_hours); + } + + public void setRepairMinIntervalInHours(RepairType repairType, int repairMinFrequencyInHours) + { + repair_type_overrides.get(repairType).min_repair_interval_in_hours = repairMinFrequencyInHours; Review Comment: Though this only affects nodetool functionality -- 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]

