From 9dabd3c53f60fde6686f39da170147de528c7769 Mon Sep 17 00:00:00 2001 From: VictorCavichioli Date: Wed, 20 Nov 2024 18:06:40 -0300 Subject: [PATCH] Fix Wrong Lock Configuration --- .gitignore | 21 +++++++ .../config/repair/GlobalRepairConfig.java | 15 +++++ application/src/main/resources/ecc.yml | 33 ++++------ .../locks/CombinedRepairResourceFactory.java | 60 +++++++++++++++++++ .../DataCenterRepairResourceFactory.java | 40 +++++++++++++ .../core/impl/locks/RepairLockType.java | 41 +++++++++++++ .../locks/VnodeRepairResourceFactory.java | 42 +++++++++++++ 7 files changed, 232 insertions(+), 20 deletions(-) create mode 100644 .gitignore create mode 100644 core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CombinedRepairResourceFactory.java create mode 100644 core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/DataCenterRepairResourceFactory.java create mode 100644 core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/RepairLockType.java create mode 100644 core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/VnodeRepairResourceFactory.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e4278723 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +target/ +META-INF/ +OSGI-INF/ +build.properties +pom.xml.versionsBackup +dependency-reduced-pom.xml +*~ +*.bak +.checkstyle +.classpath +.project +.settings/ +.toDelete +*.pyc +.idea/ +*.iml +.coverage +*htmlcov +application/statistics/ +statistics/ +.python-version \ No newline at end of file diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/repair/GlobalRepairConfig.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/repair/GlobalRepairConfig.java index 7daa7250..6b4954e4 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/repair/GlobalRepairConfig.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/repair/GlobalRepairConfig.java @@ -15,7 +15,9 @@ package com.ericsson.bss.cassandra.ecchronos.application.config.repair; import com.ericsson.bss.cassandra.ecchronos.application.spring.AbstractRepairConfigurationProvider; +import com.ericsson.bss.cassandra.ecchronos.core.impl.locks.RepairLockType; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Locale; import org.springframework.context.ApplicationContext; import java.util.concurrent.TimeUnit; @@ -28,6 +30,7 @@ public class GlobalRepairConfig extends RepairConfig FileBasedRepairConfiguration.class; private Interval myRepairHistoryLookback = new Interval(THIRTY_DAYS, TimeUnit.DAYS); private RepairHistory myRepairHistory = new RepairHistory(); + private RepairLockType myRepairLockType = RepairLockType.VNODE; @JsonProperty("provider") public final Class getRepairConfigurationClass() @@ -67,5 +70,17 @@ public final void setRepairHistory(final RepairHistory repairHistory) { myRepairHistory = repairHistory; } + + @JsonProperty("lock_type") + public final RepairLockType getRepairLockType() + { + return myRepairLockType; + } + + @JsonProperty("lock_type") + public final void setRepairLockType(final String repairLockType) + { + myRepairLockType = RepairLockType.valueOf(repairLockType.toUpperCase(Locale.US)); + } } diff --git a/application/src/main/resources/ecc.yml b/application/src/main/resources/ecc.yml index efe4f39c..7112da3d 100644 --- a/application/src/main/resources/ecc.yml +++ b/application/src/main/resources/ecc.yml @@ -98,13 +98,6 @@ connection: connectionDelay: time: 45 unit: MINUTES - ## - ## Allow routing requests directly to a remote datacenter. - ## This allows locks for other datacenters to be taken in that datacenter instead of via the local datacenter. - ## If clients are prevented from connecting directly to Cassandra nodes in other sites this is not possible. - ## If remote routing is disabled, instead SERIAL consistency will be used for those request. - ## - remoteRouting: true jmx: ## ## The class used to provide JMX connections to Apache Cassandra. @@ -278,19 +271,19 @@ rest_server: host: localhost port: 8080 - lock_factory: - cas: - ## - ## The keyspace used for the CAS lock factory tables. - ## - keyspace: ecchronos - ## - ## The number of seconds until the lock failure cache expires. - ## If an attempt to secure a lock is unsuccessful, - ## all subsequent attempts will be failed until - ## the cache expiration time is reached. - ## - cache_expiry_time_in_seconds: 30 +lock_factory: + cas: + ## + ## The keyspace used for the CAS lock factory tables. + ## + keyspace: ecchronos + ## + ## The number of seconds until the lock failure cache expires. + ## If an attempt to secure a lock is unsuccessful, + ## all subsequent attempts will be failed until + ## the cache expiration time is reached. + ## + cache_expiry_time_in_seconds: 30 ## ## Allow to override consistency level for LWT (lightweight transactions). Possible values are: ## "DEFAULT" - Use consistency level based on the `datacenterAware` agent type. diff --git a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CombinedRepairResourceFactory.java b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CombinedRepairResourceFactory.java new file mode 100644 index 00000000..ee28f593 --- /dev/null +++ b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CombinedRepairResourceFactory.java @@ -0,0 +1,60 @@ +/* + * Copyright 2024 Telefonaktiebolaget LM Ericsson + * + * Licensed 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 com.ericsson.bss.cassandra.ecchronos.core.impl.locks; + +import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairResource; +import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairResourceFactory; +import com.ericsson.bss.cassandra.ecchronos.core.state.ReplicaRepairGroup; +import java.util.HashSet; +import java.util.Set; +import com.google.common.collect.ImmutableSet; + +/** + * Repair resource factory that creates a combination of repair resources based on other implementations. + */ +public class CombinedRepairResourceFactory implements RepairResourceFactory +{ + private final ImmutableSet myRepairResourceFactories; + + /** + * Constructor. + * + * @param repairResourceFactories Repair resource factories + */ + public CombinedRepairResourceFactory(final RepairResourceFactory... repairResourceFactories) + { + myRepairResourceFactories = ImmutableSet.copyOf(repairResourceFactories); + } + + /** + * Get repair resources. + * + * @param replicaRepairGroup The replica repair group. + * @return Repair resources + */ + @Override + public Set getRepairResources(final ReplicaRepairGroup replicaRepairGroup) + { + Set repairResources = new HashSet<>(); + + for (RepairResourceFactory repairResourceFactory : myRepairResourceFactories) + { + repairResources.addAll(repairResourceFactory.getRepairResources(replicaRepairGroup)); + } + + return repairResources; + } +} + diff --git a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/DataCenterRepairResourceFactory.java b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/DataCenterRepairResourceFactory.java new file mode 100644 index 00000000..2450fd4e --- /dev/null +++ b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/DataCenterRepairResourceFactory.java @@ -0,0 +1,40 @@ +/* + * Copyright 2024 Telefonaktiebolaget LM Ericsson + * + * Licensed 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 com.ericsson.bss.cassandra.ecchronos.core.impl.locks; + +import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairResource; +import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairResourceFactory; +import com.ericsson.bss.cassandra.ecchronos.core.state.ReplicaRepairGroup; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Repair resource factory that generates one repair resource per data center involved in the repair. + */ +public class DataCenterRepairResourceFactory implements RepairResourceFactory +{ + @Override + public final Set getRepairResources(final ReplicaRepairGroup replicaRepairGroup) + { + return replicaRepairGroup.getDataCenters().stream() + .map(this::dataCenterToRepairResource) + .collect(Collectors.toSet()); + } + + private RepairResource dataCenterToRepairResource(final String dataCenter) + { + return new RepairResource(dataCenter, dataCenter); + } +} diff --git a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/RepairLockType.java b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/RepairLockType.java new file mode 100644 index 00000000..fe41ca45 --- /dev/null +++ b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/RepairLockType.java @@ -0,0 +1,41 @@ +/* + * Copyright 2024 Telefonaktiebolaget LM Ericsson + * + * Licensed 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 com.ericsson.bss.cassandra.ecchronos.core.impl.locks; + +import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairResourceFactory; +import java.util.function.Supplier; + +/** + * The type of locking to use for repair jobs. + */ +public enum RepairLockType +{ + DATACENTER(DataCenterRepairResourceFactory::new), + VNODE(VnodeRepairResourceFactory::new), + DATACENTER_AND_VNODE(() -> new CombinedRepairResourceFactory(new DataCenterRepairResourceFactory(), + new VnodeRepairResourceFactory())); + + private final Supplier myRepairLockingFactoryProvider; + + RepairLockType(final Supplier repairLockingProvider) + { + myRepairLockingFactoryProvider = repairLockingProvider; + } + + RepairResourceFactory getLockFactory() + { + return myRepairLockingFactoryProvider.get(); + } +} diff --git a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/VnodeRepairResourceFactory.java b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/VnodeRepairResourceFactory.java new file mode 100644 index 00000000..0153ad71 --- /dev/null +++ b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/VnodeRepairResourceFactory.java @@ -0,0 +1,42 @@ +/* + * Copyright 2024 Telefonaktiebolaget LM Ericsson + * + * Licensed 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 com.ericsson.bss.cassandra.ecchronos.core.impl.locks; + +import com.ericsson.bss.cassandra.ecchronos.core.metadata.DriverNode; +import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairResource; +import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairResourceFactory; +import com.ericsson.bss.cassandra.ecchronos.core.state.ReplicaRepairGroup; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Repair resource factory that generates one repair resource per replica involved in the repair. + */ +public class VnodeRepairResourceFactory implements RepairResourceFactory +{ + @Override + public final Set getRepairResources(final ReplicaRepairGroup replicaRepairGroup) + { + return replicaRepairGroup.getReplicas().stream() + .map(this::replicaToRepairResource) + .collect(Collectors.toSet()); + } + + private RepairResource replicaToRepairResource(final DriverNode node) + { + return new RepairResource(node.getDatacenter(), node.getId().toString()); + } +} +