From 71d8b33a60307a674df5d40c7299d96b165da7fb Mon Sep 17 00:00:00 2001 From: sajid riaz Date: Mon, 4 Nov 2024 15:31:41 +0100 Subject: [PATCH] Cassandra based distributed locking mechanism # 741 - Cassandra tables called lock and lock_priority, to manage task execution and synchronization across multiple nodes. --- CHANGES.md | 1 + .../ecchronos/core/impl/locks/CASLock.java | 3 +-- .../core/impl/locks/CASLockFactory.java | 10 +++++----- .../ecchronos/core/impl/locks/LockCache.java | 3 +-- .../core/impl/utils/package-info.java | 1 + .../core/impl/locks/TestCASLockFactory.java | 3 +-- .../core/impl/locks/TestLockCache.java | 2 +- .../ecchronos/core/locks/LockFactory.java | 3 +-- .../ecchronos/core/utils/package-info.java | 18 ------------------ .../utils/exceptions}/LockException.java | 2 +- 10 files changed, 13 insertions(+), 33 deletions(-) delete mode 100644 core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/package-info.java rename {core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils => utils/src/main/java/com/ericsson/bss/cassandra/ecchronos/utils/exceptions}/LockException.java (94%) diff --git a/CHANGES.md b/CHANGES.md index fb1d475b..0bd5e6e4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## Version 1.0.0 (Not yet Released) +* Cassandra-Based Distributed Locks #741 * Investigate Creation of RepairScheduler and ScheduleManager #714 * Implement ScheduledJobQueue for Prioritized Job Management and Execution - Issue #740 * Implement RepairGroup Class for Managing and Executing Repair Tasks - Issue #738 diff --git a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CASLock.java b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CASLock.java index 6a1cb0b8..34e610fe 100644 --- a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CASLock.java +++ b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CASLock.java @@ -30,7 +30,7 @@ import com.datastax.oss.driver.api.core.cql.ResultSet; import com.datastax.oss.driver.api.core.cql.Row; -import com.ericsson.bss.cassandra.ecchronos.core.utils.LockException; +import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.LockException; /** * Represents a container for builder configurations and state for the CASLock. @@ -213,5 +213,4 @@ int getFailedAttempts() { return myFailedUpdateAttempts.get(); } - } diff --git a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CASLockFactory.java b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CASLockFactory.java index 9a5c1948..51fb3f5c 100644 --- a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CASLockFactory.java +++ b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/CASLockFactory.java @@ -23,9 +23,9 @@ import com.datastax.oss.driver.api.core.metadata.TokenMap; import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata; import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; -import com.ericsson.bss.cassandra.ecchronos.core.utils.LockException; -import com.ericsson.bss.cassandra.ecchronos.core.locks.HostStates; import com.ericsson.bss.cassandra.ecchronos.core.locks.LockFactory; +import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.LockException; +import com.ericsson.bss.cassandra.ecchronos.core.locks.HostStates; import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.slf4j.Logger; @@ -140,9 +140,9 @@ private int getDefaultTimeToLiveFromLockTable() @Override public DistributedLock tryLock(final String dataCenter, - final String resource, - final int priority, - final Map metadata) + final String resource, + final int priority, + final Map metadata) throws LockException { return myCasLockFactoryCacheContext.getLockCache() diff --git a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/LockCache.java b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/LockCache.java index e34f6fc0..7f8f76a6 100644 --- a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/LockCache.java +++ b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/LockCache.java @@ -15,8 +15,7 @@ package com.ericsson.bss.cassandra.ecchronos.core.impl.locks; import static com.ericsson.bss.cassandra.ecchronos.core.locks.LockFactory.DistributedLock; - -import com.ericsson.bss.cassandra.ecchronos.core.utils.LockException; +import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.LockException; import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import org.slf4j.Logger; diff --git a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/utils/package-info.java b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/utils/package-info.java index 796be8fd..7f486977 100644 --- a/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/utils/package-info.java +++ b/core.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/impl/utils/package-info.java @@ -16,3 +16,4 @@ * Contains utilities classes. */ package com.ericsson.bss.cassandra.ecchronos.core.impl.utils; + diff --git a/core.impl/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/TestCASLockFactory.java b/core.impl/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/TestCASLockFactory.java index 6c729c1a..da0e1d1c 100644 --- a/core.impl/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/TestCASLockFactory.java +++ b/core.impl/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/TestCASLockFactory.java @@ -28,6 +28,7 @@ import com.ericsson.bss.cassandra.ecchronos.core.impl.utils.ConsistencyType; import com.ericsson.bss.cassandra.ecchronos.core.locks.HostStates; import com.ericsson.bss.cassandra.ecchronos.core.locks.LockFactory; +import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.LockException; import java.io.IOException; import java.util.Arrays; import java.util.Collection; @@ -69,8 +70,6 @@ import org.junit.Before; import org.junit.Test; -import com.ericsson.bss.cassandra.ecchronos.core.utils.LockException; - import net.jcip.annotations.NotThreadSafe; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; diff --git a/core.impl/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/TestLockCache.java b/core.impl/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/TestLockCache.java index 112365ea..2f88964a 100644 --- a/core.impl/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/TestLockCache.java +++ b/core.impl/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/impl/locks/TestLockCache.java @@ -14,7 +14,7 @@ */ package com.ericsson.bss.cassandra.ecchronos.core.impl.locks; -import com.ericsson.bss.cassandra.ecchronos.core.utils.LockException; +import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.LockException; import com.ericsson.bss.cassandra.ecchronos.core.locks.LockFactory.DistributedLock; import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Before; diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/locks/LockFactory.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/locks/LockFactory.java index c6b09c3b..39afa9ac 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/locks/LockFactory.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/locks/LockFactory.java @@ -17,8 +17,7 @@ import java.io.Closeable; import java.util.Map; import java.util.Optional; - -import com.ericsson.bss.cassandra.ecchronos.core.utils.LockException; +import com.ericsson.bss.cassandra.ecchronos.utils.exceptions.LockException; /** * Interface for distributed lock factories. diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/package-info.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/package-info.java deleted file mode 100644 index a86eb8b1..00000000 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/package-info.java +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ -/** - * Contains utilities classes. - */ -package com.ericsson.bss.cassandra.ecchronos.core.utils; \ No newline at end of file diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/LockException.java b/utils/src/main/java/com/ericsson/bss/cassandra/ecchronos/utils/exceptions/LockException.java similarity index 94% rename from core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/LockException.java rename to utils/src/main/java/com/ericsson/bss/cassandra/ecchronos/utils/exceptions/LockException.java index bae8ce59..e968341b 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/LockException.java +++ b/utils/src/main/java/com/ericsson/bss/cassandra/ecchronos/utils/exceptions/LockException.java @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.ericsson.bss.cassandra.ecchronos.core.utils; +package com.ericsson.bss.cassandra.ecchronos.utils.exceptions; /** * Exception thrown when a lock factory is unable to get a lock.