From b6d105f099e9c50d6257a7ec3331fc3e36a6d013 Mon Sep 17 00:00:00 2001 From: VictorCavichioli Date: Sun, 18 Feb 2024 17:42:27 -0300 Subject: [PATCH 1/8] Separe serial consistency from remoteRouting - Issue #633 To decouple the consistency definition in lightweight transactions, introduce a new property configurable by ecc.yml that allows consistency to be overridden by the values DEFAULT/SERIAL/LOCAL. Closes #633 --- CHANGES.md | 3 +- .../DefaultNativeConnectionProvider.java | 8 ++ .../config/connection/NativeConnection.java | 13 +++ application/src/main/resources/ecc.yml | 14 ++- .../application/config/TestConfig.java | 10 ++ application/src/test/resources/all_set.yml | 1 + .../impl/LocalNativeConnectionProvider.java | 26 ++++- .../OSGiLocalNativeConnectionProvider.java | 13 ++- .../connection/NativeConnectionProvider.java | 2 + .../ecchronos/core/CASLockFactory.java | 22 ++++- .../ecchronos/core/AbstractCassandraTest.java | 5 + .../ecchronos/core/TestCASLockFactory.java | 95 +++++++++++++++++++ ...estDefaultRepairConfigurationProvider.java | 5 + docs/autogenerated/EccYamlFile.md | 31 +++++- pmd-rules.xml | 6 +- 15 files changed, 243 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 221761b39..d49d76deb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,10 +2,11 @@ ## Version 5.0.1 (Not yet released) +* Separate serial consistency configuration from remoteRouting functionality - Issue #633 * Improve hang preventing task - Issue #544 * Improve Description of unwind_ratio - Issue #628 -## Version 5.0.0 (Not yet released) +## Version 5.0.0 * Build Ecchronos with Java 11 - Issue 616 * Bump logback from 1.2.10 to 1.2.13 (CVE-2023-6378) - Issue #622 diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java index aff933b80..1dcba0ae2 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java @@ -52,6 +52,7 @@ public DefaultNativeConnectionProvider(final Config config, String host = nativeConfig.getHost(); int port = nativeConfig.getPort(); boolean remoteRouting = nativeConfig.getRemoteRouting(); + String consistencySerial = nativeConfig.getConsistencySerial(); Security.CqlSecurity cqlSecurity = cqlSecuritySupplier.get(); boolean authEnabled = cqlSecurity.getCqlCredentials().isEnabled(); boolean tlsEnabled = cqlSecurity.getCqlTlsConfig().isEnabled(); @@ -73,6 +74,7 @@ public DefaultNativeConnectionProvider(final Config config, .withLocalhost(host) .withPort(port) .withRemoteRouting(remoteRouting) + .withConsistencySerial(consistencySerial) .withAuthProvider(authProvider) .withSslEngineFactory(sslEngineFactory) .withMetricsEnabled(config.getStatisticsConfig().isEnabled()) @@ -147,6 +149,12 @@ public final boolean getRemoteRouting() return myLocalNativeConnectionProvider.getRemoteRouting(); } + @Override + public final String getSerialConsistency() + { + return myLocalNativeConnectionProvider.getSerialConsistency(); + } + @Override public final void close() { diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java index e015fa5e7..cceb49474 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java @@ -32,6 +32,7 @@ public class NativeConnection extends Connection private Class myDecoratorClass = NoopStatementDecorator.class; private boolean myRemoteRouting = true; + private String myConsistencySerial = "DEFAULT"; public NativeConnection() { @@ -74,6 +75,18 @@ public final void setRemoteRouting(final boolean remoteRouting) myRemoteRouting = remoteRouting; } + @JsonProperty("consistencySerial") + public final String getConsistencySerial() + { + return myConsistencySerial; + } + + @JsonProperty("consistencySerial") + public final void setConsistencySerial(final String consistencySerial) + { + myConsistencySerial = consistencySerial; + } + @Override protected final Class[] expectedConstructor() { diff --git a/application/src/main/resources/ecc.yml b/application/src/main/resources/ecc.yml index 6b8600155..937717cce 100644 --- a/application/src/main/resources/ecc.yml +++ b/application/src/main/resources/ecc.yml @@ -53,10 +53,20 @@ connection: ## 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 its not possible to use LOCAL_SERIAL consistency for the locking, - ## instead SERIAL consistency will be used for those request. + ## If remote routing is disabled, instead SERIAL consistency will be used for those request. ## remoteRouting: true + ## + # # Allow to override consistency level for LWT (lightweight transactions). Possible values are: + # # "DEFAULT" - Use consistency level based on remoteRouting. + # # "SERIAL" - Use SERIAL consistency for LWT regardless of remoteRouting. + # # "LOCAL_SERIAL" - Use LOCAL_SERIAL consistency for LWT regardless of remoteRouting. + ## + # # if you use remoteRouting: false and LOCAL_SERIAL then all locks will be taken locally + # # in DC. I.e There's a risk that multiple nodes in different datacenters will be able to lock the + # # same nodes causing multiple repairs on the same range/node at the same time. + ## + consistencySerial: "DEFAULT" jmx: ## ## Host and port properties for JMX. diff --git a/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java b/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java index 504f75a8e..d4cd6011d 100644 --- a/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java +++ b/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java @@ -89,6 +89,7 @@ public void testAllValues() throws Exception assertThat(nativeConnection.getHost()).isEqualTo("127.0.0.2"); assertThat(nativeConnection.getPort()).isEqualTo(9100); assertThat(nativeConnection.getRemoteRouting()).isFalse(); + assertThat(nativeConnection.getConsistencySerial().equals("LOCAL")).isTrue(); assertThat(nativeConnection.getTimeout().getConnectionTimeout(TimeUnit.SECONDS)).isEqualTo(5); assertThat(nativeConnection.getProviderClass()).isEqualTo(TestNativeConnectionProvider.class); assertThat(nativeConnection.getCertificateHandlerClass()).isEqualTo(TestCertificateHandler.class); @@ -185,6 +186,7 @@ public void testWithDefaultFile() throws Exception assertThat(nativeConnection.getHost()).isEqualTo("localhost"); assertThat(nativeConnection.getPort()).isEqualTo(9042); assertThat(nativeConnection.getRemoteRouting()).isTrue(); + assertThat(nativeConnection.getConsistencySerial().equals("DEFAULT")).isTrue(); assertThat(nativeConnection.getTimeout().getConnectionTimeout(TimeUnit.MILLISECONDS)).isEqualTo(0); assertThat(nativeConnection.getProviderClass()).isEqualTo(DefaultNativeConnectionProvider.class); assertThat(nativeConnection.getCertificateHandlerClass()).isEqualTo(ReloadingCertificateHandler.class); @@ -271,6 +273,8 @@ public void testDefault() throws Exception assertThat(nativeConnection.getHost()).isEqualTo("localhost"); assertThat(nativeConnection.getPort()).isEqualTo(9042); assertThat(nativeConnection.getRemoteRouting()).isTrue(); + + assertThat(nativeConnection.getConsistencySerial().equals("DEFAULT")).isTrue(); assertThat(nativeConnection.getTimeout().getConnectionTimeout(TimeUnit.MILLISECONDS)).isEqualTo(0); assertThat(nativeConnection.getProviderClass()).isEqualTo(DefaultNativeConnectionProvider.class); assertThat(nativeConnection.getCertificateHandlerClass()).isEqualTo(ReloadingCertificateHandler.class); @@ -403,6 +407,12 @@ public boolean getRemoteRouting() { throw new UnsupportedOperationException(); } + + @Override + public String getSerialConsistency() + { + throw new UnsupportedOperationException(); + } } public static class TestCertificateHandler implements CertificateHandler diff --git a/application/src/test/resources/all_set.yml b/application/src/test/resources/all_set.yml index f72fb74ff..3ce21636b 100644 --- a/application/src/test/resources/all_set.yml +++ b/application/src/test/resources/all_set.yml @@ -24,6 +24,7 @@ connection: certificateHandler: com.ericsson.bss.cassandra.ecchronos.application.config.TestConfig$TestCertificateHandler decoratorClass: com.ericsson.bss.cassandra.ecchronos.application.config.TestConfig$TestStatementDecorator remoteRouting: false + consistencySerial: "LOCAL" jmx: host: 127.0.0.3 port: 7100 diff --git a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java index c9ac49a3b..3c5b14130 100644 --- a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java +++ b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java @@ -72,12 +72,19 @@ public final class LocalNativeConnectionProvider implements NativeConnectionProv private final CqlSession mySession; private final Node myLocalNode; private final boolean myRemoteRouting; - - private LocalNativeConnectionProvider(final CqlSession session, final Node node, final boolean remoteRouting) + private final String mySerialConsistencyLevel; + + private LocalNativeConnectionProvider( + final CqlSession session, + final Node node, + final boolean remoteRouting, + final String serialConsistencyLevel + ) { mySession = session; myLocalNode = node; myRemoteRouting = remoteRouting; + mySerialConsistencyLevel = serialConsistencyLevel; } @Override @@ -98,6 +105,12 @@ public boolean getRemoteRouting() return myRemoteRouting; } + @Override + public String getSerialConsistency() + { + return mySerialConsistencyLevel; + } + @Override public void close() { @@ -116,6 +129,7 @@ public static class Builder private String myLocalhost = DEFAULT_LOCAL_HOST; private int myPort = DEFAULT_NATIVE_PORT; private boolean myRemoteRouting = true; + private String mySerialConsistency = "DEFAULT"; private boolean myIsMetricsEnabled = true; private AuthProvider myAuthProvider = null; private SslEngineFactory mySslEngineFactory = null; @@ -141,6 +155,12 @@ public final Builder withRemoteRouting(final boolean remoteRouting) return this; } + public final Builder withConsistencySerial(final String serialConsistency) + { + mySerialConsistency = serialConsistency; + return this; + } + public final Builder withAuthProvider(final AuthProvider authProvider) { this.myAuthProvider = authProvider; @@ -181,7 +201,7 @@ public final LocalNativeConnectionProvider build() { CqlSession session = createSession(this); Node node = resolveLocalhost(session, localEndPoint()); - return new LocalNativeConnectionProvider(session, node, myRemoteRouting); + return new LocalNativeConnectionProvider(session, node, myRemoteRouting, mySerialConsistency); } private EndPoint localEndPoint() diff --git a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java index e941fc3ad..0bc7ea534 100644 --- a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java +++ b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java @@ -50,11 +50,13 @@ public final synchronized void activate(final Configuration configuration) String localhost = configuration.localHost(); int port = configuration.nativePort(); boolean remoteRouting = configuration.remoteRouting(); + String serialConsistency = configuration.serialConsistency(); LocalNativeConnectionProvider.Builder builder = LocalNativeConnectionProvider.builder() .withLocalhost(localhost) .withPort(port) - .withRemoteRouting(remoteRouting); + .withRemoteRouting(remoteRouting) + .withConsistencySerial(serialConsistency); if (!configuration.credentialsFile().isEmpty()) { @@ -100,6 +102,12 @@ public final boolean getRemoteRouting() return myDelegateNativeConnectionProvider.getRemoteRouting(); } + @Override + public final String getSerialConsistency() + { + return myDelegateNativeConnectionProvider.getSerialConsistency(); + } + @ObjectClassDefinition public @interface Configuration { @@ -117,5 +125,8 @@ public final boolean getRemoteRouting() @AttributeDefinition(name = "Remote routing", description = "Enables remote routing between datacenters") boolean remoteRouting() default true; + + @AttributeDefinition(name = "Serial consistency", description = "Define serial consistency level used") + String serialConsistency() default "DEFAULT"; } } diff --git a/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java index 10ae256be..e5b97d367 100644 --- a/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java +++ b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java @@ -31,6 +31,8 @@ public interface NativeConnectionProvider extends Closeable boolean getRemoteRouting(); + String getSerialConsistency(); + @Override default void close() throws IOException { diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java index 1009d1077..58efabb6b 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java @@ -102,6 +102,7 @@ public final class CASLockFactory implements LockFactory, Closeable private final StatementDecorator myStatementDecorator; private final HostStates myHostStates; private final boolean myRemoteRouting; + private final String mySerialConsistency; private final CqlSession mySession; private final String myKeyspaceName; @@ -114,6 +115,8 @@ public final class CASLockFactory implements LockFactory, Closeable private final PreparedStatement myRemoveLockPriorityStatement; private final CASLockFactoryCacheContext myCasLockFactoryCacheContext; + private final ConsistencyLevel serialConsistencyLevel; + private CASLockFactory(final Builder builder) { myStatementDecorator = builder.myStatementDecorator; @@ -124,12 +127,23 @@ private CASLockFactory(final Builder builder) mySession = builder.myNativeConnectionProvider.getSession(); myRemoteRouting = builder.myNativeConnectionProvider.getRemoteRouting(); + mySerialConsistency = builder.myNativeConnectionProvider.getSerialConsistency(); verifySchemasExists(); - ConsistencyLevel serialConsistencyLevel = myRemoteRouting + if ("DEFAULT".equals(mySerialConsistency)) + { + serialConsistencyLevel = myRemoteRouting + ? ConsistencyLevel.LOCAL_SERIAL + : ConsistencyLevel.SERIAL; + } + else + { + serialConsistencyLevel = "LOCAL".equals(mySerialConsistency) ? ConsistencyLevel.LOCAL_SERIAL : ConsistencyLevel.SERIAL; + } + SimpleStatement insertLockStatement = QueryBuilder.insertInto(myKeyspaceName, TABLE_LOCK) .value(COLUMN_RESOURCE, bindMarker()) .value(COLUMN_NODE, bindMarker()) @@ -320,6 +334,12 @@ UUID getHostId() return myUuid; } + @VisibleForTesting + ConsistencyLevel getSerialConsistencyLevel() + { + return serialConsistencyLevel; + } + @VisibleForTesting CASLockFactoryCacheContext getCasLockFactoryCacheContext() { diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java index 7dc24abc1..bf03cce09 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java @@ -77,6 +77,11 @@ public boolean getRemoteRouting() { return true; } + + @Override + public String getSerialConsistency(){ + return "DEFAULT"; + } }; } diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java index db42000f0..7c919b0de 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java @@ -17,9 +17,14 @@ import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.bindMarker; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Matchers.any; +import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import java.util.Arrays; @@ -375,6 +380,11 @@ public boolean getRemoteRouting() { return true; } + + @Override + public String getSerialConsistency(){ + return "DEFAULT"; + } }) .withHostStates(hostStates) .withStatementDecorator(s -> s) @@ -382,6 +392,91 @@ public boolean getRemoteRouting() .build()); } + @Test + public void testRemoteRoutingTrueWithDefaultSerialConsistency() { + + myLockFactory = new CASLockFactory.Builder() + .withNativeConnectionProvider(getNativeConnectionProvider()) + .withHostStates(hostStates) + .withStatementDecorator(s -> s) + .withKeyspaceName(myKeyspaceName) + .build(); + + + assertEquals(ConsistencyLevel.LOCAL_SERIAL, myLockFactory.getSerialConsistencyLevel()); + } + + @Test + public void testRemoteRoutingFalseWithDefaultSerialConsistency() { + + Node nodeMock = mock(Node.class); + + NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); + + when(connectionProviderMock.getSession()).thenReturn(mySession); + + when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); + + when(connectionProviderMock.getRemoteRouting()).thenReturn(false); + + when(connectionProviderMock.getSerialConsistency()).thenReturn("DEFAULT"); + + myLockFactory = new CASLockFactory.Builder() + .withNativeConnectionProvider(connectionProviderMock) + .withHostStates(hostStates) + .withStatementDecorator(s -> s) + .withKeyspaceName(myKeyspaceName) + .build(); + + assertEquals(ConsistencyLevel.SERIAL, myLockFactory.getSerialConsistencyLevel()); + } + + @Test + public void testLocalSerialConsistency(){ + + NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); + + Node nodeMock = mock(Node.class); + + when(connectionProviderMock.getSerialConsistency()).thenReturn("LOCAL"); + + when(connectionProviderMock.getSession()).thenReturn(mySession); + + when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); + + myLockFactory = new CASLockFactory.Builder() + .withNativeConnectionProvider(connectionProviderMock) + .withHostStates(hostStates) + .withStatementDecorator(s -> s) + .withKeyspaceName(myKeyspaceName) + .build(); + + assertEquals(ConsistencyLevel.LOCAL_SERIAL, myLockFactory.getSerialConsistencyLevel()); + + } + + @Test + public void testSerialConsistency(){ + NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); + + Node nodeMock = mock(Node.class); + + when(connectionProviderMock.getSerialConsistency()).thenReturn("SERIAL"); + + when(connectionProviderMock.getSession()).thenReturn(mySession); + + when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); + + myLockFactory = new CASLockFactory.Builder() + .withNativeConnectionProvider(connectionProviderMock) + .withHostStates(hostStates) + .withStatementDecorator(s -> s) + .withKeyspaceName(myKeyspaceName) + .build(); + + assertEquals(ConsistencyLevel.SERIAL, myLockFactory.getSerialConsistencyLevel()); + } + private void assertPriorityListEmpty(String resource) { assertThat(getPriorities(resource)).isEmpty(); diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java index 35bdde2c4..696738508 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java @@ -101,6 +101,11 @@ public boolean getRemoteRouting() { return true; } + + @Override + public String getSerialConsistency(){ + return "DEFAULT"; + } }; when(session.getMetadata()).thenReturn(metadata); diff --git a/docs/autogenerated/EccYamlFile.md b/docs/autogenerated/EccYamlFile.md index e6a0bd28d..5f64c934c 100644 --- a/docs/autogenerated/EccYamlFile.md +++ b/docs/autogenerated/EccYamlFile.md @@ -39,10 +39,20 @@ # 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 its not possible to use LOCAL_SERIAL consistency for the locking, -# instead SERIAL consistency will be used for those request. +# If remote routing is disabled, instead SERIAL consistency will be used for those request. # * remoteRouting: true +# +# Allow to override consistency level for LWT (lightweight transactions). Possible values are: +# "DEFAULT" - Use consistency level based on remoteRouting. +# "SERIAL" - Use SERIAL consistency for LWT regardless of remoteRouting. +# "LOCAL_SERIAL" - Use LOCAL_SERIAL consistency for LWT regardless of remoteRouting. +# +# if you use remoteRouting: false and LOCAL_SERIAL then all locks will be taken locally +# in DC. I.e There's a risk that multiple nodes in different datacenters will be able to lock the +# same nodes causing multiple repairs on the same range/node at the same time. +# +* consistencySerial: "DEFAULT" **jmx:** # # Host and port properties for JMX. @@ -124,6 +134,23 @@ # This value is a ratio between 0 -> 100% of the execution time of a repair session. # # 100% means that the executor will wait to run the next session for as long time as the previous session took. +# The 'unwind_ratio' setting configures the wait time between repair tasks as a proportion of the previous task's execution time. +# +# Examples: +# - unwind_ratio: 0 +# Explanation: No wait time between tasks. The next task starts immediately after the previous one finishes. +# Total Repair Time: T1 (10s) + T2 (20s) = 30 seconds. +# +# - unwind_ratio: 1.0 (100%) +# Explanation: The wait time after each task equals its duration. +# Total Repair Time: T1 (10s + 10s wait) + T2 (20s + 20s wait) = 60 seconds. +# +# - unwind_ratio: 0.5 (50%) +# Explanation: The wait time is half of the task's duration. +# Total Repair Time: T1 (10s + 5s wait) + T2 (20s + 10s wait) = 45 seconds. +# +# A higher 'unwind_ratio' reduces system load by adding longer waits, but increases total repair time. +# A lower 'unwind_ratio' speeds up repairs but may increase system load. # * unwind_ratio: 0.0 # diff --git a/pmd-rules.xml b/pmd-rules.xml index 5858cf92b..3e53b6d10 100644 --- a/pmd-rules.xml +++ b/pmd-rules.xml @@ -30,6 +30,10 @@ + + + + @@ -49,4 +53,4 @@ - + \ No newline at end of file From 9472e386a801cd013a04136885174bc7d1c4e083 Mon Sep 17 00:00:00 2001 From: VictorCavichioli Date: Mon, 19 Feb 2024 14:23:13 -0300 Subject: [PATCH 2/8] Fix PMD Violations --- application/src/main/resources/ecc.yml | 14 +++++++------- .../ecchronos/core/AbstractCassandraTest.java | 3 ++- .../ecchronos/core/TestCASLockFactory.java | 15 ++++++++++----- .../TestDefaultRepairConfigurationProvider.java | 3 ++- pmd-rules.xml | 8 ++++---- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/application/src/main/resources/ecc.yml b/application/src/main/resources/ecc.yml index 937717cce..aa44a1aa3 100644 --- a/application/src/main/resources/ecc.yml +++ b/application/src/main/resources/ecc.yml @@ -57,14 +57,14 @@ connection: ## remoteRouting: true ## - # # Allow to override consistency level for LWT (lightweight transactions). Possible values are: - # # "DEFAULT" - Use consistency level based on remoteRouting. - # # "SERIAL" - Use SERIAL consistency for LWT regardless of remoteRouting. - # # "LOCAL_SERIAL" - Use LOCAL_SERIAL consistency for LWT regardless of remoteRouting. + ## Allow to override consistency level for LWT (lightweight transactions). Possible values are: + ## "DEFAULT" - Use consistency level based on remoteRouting. + ## "SERIAL" - Use SERIAL consistency for LWT regardless of remoteRouting. + ## "LOCAL_SERIAL" - Use LOCAL_SERIAL consistency for LWT regardless of remoteRouting. ## - # # if you use remoteRouting: false and LOCAL_SERIAL then all locks will be taken locally - # # in DC. I.e There's a risk that multiple nodes in different datacenters will be able to lock the - # # same nodes causing multiple repairs on the same range/node at the same time. + ## if you use remoteRouting: false and LOCAL_SERIAL then all locks will be taken locally + ## in DC. I.e There's a risk that multiple nodes in different datacenters will be able to lock the + ## same nodes causing multiple repairs on the same range/node at the same time. ## consistencySerial: "DEFAULT" jmx: diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java index bf03cce09..6f1cec412 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java @@ -79,7 +79,8 @@ public boolean getRemoteRouting() } @Override - public String getSerialConsistency(){ + public String getSerialConsistency() + { return "DEFAULT"; } }; diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java index 7c919b0de..f1d7fff53 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java @@ -382,7 +382,8 @@ public boolean getRemoteRouting() } @Override - public String getSerialConsistency(){ + public String getSerialConsistency() + { return "DEFAULT"; } }) @@ -393,7 +394,8 @@ public String getSerialConsistency(){ } @Test - public void testRemoteRoutingTrueWithDefaultSerialConsistency() { + public void testRemoteRoutingTrueWithDefaultSerialConsistency() + { myLockFactory = new CASLockFactory.Builder() .withNativeConnectionProvider(getNativeConnectionProvider()) @@ -407,7 +409,8 @@ public void testRemoteRoutingTrueWithDefaultSerialConsistency() { } @Test - public void testRemoteRoutingFalseWithDefaultSerialConsistency() { + public void testRemoteRoutingFalseWithDefaultSerialConsistency() + { Node nodeMock = mock(Node.class); @@ -432,7 +435,8 @@ public void testRemoteRoutingFalseWithDefaultSerialConsistency() { } @Test - public void testLocalSerialConsistency(){ + public void testLocalSerialConsistency() + { NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); @@ -456,7 +460,8 @@ public void testLocalSerialConsistency(){ } @Test - public void testSerialConsistency(){ + public void testSerialConsistency() + { NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); Node nodeMock = mock(Node.class); diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java index 696738508..ab76dd690 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java @@ -103,7 +103,8 @@ public boolean getRemoteRouting() } @Override - public String getSerialConsistency(){ + public String getSerialConsistency() + { return "DEFAULT"; } }; diff --git a/pmd-rules.xml b/pmd-rules.xml index 3e53b6d10..21e2eeab6 100644 --- a/pmd-rules.xml +++ b/pmd-rules.xml @@ -30,10 +30,10 @@ - - - - + + + + From 6c01cccc326d9e1609758447f93cc023598f317e Mon Sep 17 00:00:00 2001 From: VictorCavichioli Date: Tue, 20 Feb 2024 08:09:55 -0300 Subject: [PATCH 3/8] Use SuppressWarning Annotation to Fix PMD Violations --- .../ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java | 1 + pmd-rules.xml | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java index 58efabb6b..34bd6ba4f 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java @@ -82,6 +82,7 @@ * WITH default_time_to_live = 600 AND gc_grace_seconds = 0; * */ +@SuppressWarnings({"GodClass", "TooManyFields", "SingularField", "ExcessiveMethodLength"}) public final class CASLockFactory implements LockFactory, Closeable { private static final Logger LOG = LoggerFactory.getLogger(CASLockFactory.class); diff --git a/pmd-rules.xml b/pmd-rules.xml index 21e2eeab6..997a605c4 100644 --- a/pmd-rules.xml +++ b/pmd-rules.xml @@ -30,10 +30,6 @@ - - - - From 2584f12ad07ca6282a99ea9800eb80b39bd7a684 Mon Sep 17 00:00:00 2001 From: VictorCavichioli Date: Tue, 20 Feb 2024 09:25:39 -0300 Subject: [PATCH 4/8] Introduce ConsistencyType enum --- .../config/connection/NativeConnection.java | 3 ++- .../impl/LocalNativeConnectionProvider.java | 3 ++- .../OSGiLocalNativeConnectionProvider.java | 2 +- .../ecchronos/core/CASLockFactory.java | 7 ++++--- .../ecchronos/core/utils/ConsistencyType.java | 20 +++++++++++++++++++ 5 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java index cceb49474..a1e46abe0 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java @@ -21,6 +21,7 @@ import com.ericsson.bss.cassandra.ecchronos.connection.NativeConnectionProvider; import com.ericsson.bss.cassandra.ecchronos.connection.StatementDecorator; import com.ericsson.bss.cassandra.ecchronos.core.repair.DefaultRepairConfigurationProvider; +import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; import com.fasterxml.jackson.annotation.JsonProperty; import io.micrometer.core.instrument.MeterRegistry; @@ -32,7 +33,7 @@ public class NativeConnection extends Connection private Class myDecoratorClass = NoopStatementDecorator.class; private boolean myRemoteRouting = true; - private String myConsistencySerial = "DEFAULT"; + private String myConsistencySerial = ConsistencyType.DEFAULT.getStringValue(); public NativeConnection() { diff --git a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java index 3c5b14130..b8cc956aa 100644 --- a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java +++ b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java @@ -68,6 +68,7 @@ public final class LocalNativeConnectionProvider implements NativeConnectionProv public static final int DEFAULT_NATIVE_PORT = 9042; public static final String DEFAULT_LOCAL_HOST = "localhost"; + public static final String DEFAUL_CONSISTENCY_TYPE = "DEFAULT"; private final CqlSession mySession; private final Node myLocalNode; @@ -129,7 +130,7 @@ public static class Builder private String myLocalhost = DEFAULT_LOCAL_HOST; private int myPort = DEFAULT_NATIVE_PORT; private boolean myRemoteRouting = true; - private String mySerialConsistency = "DEFAULT"; + private String mySerialConsistency = DEFAUL_CONSISTENCY_TYPE; private boolean myIsMetricsEnabled = true; private AuthProvider myAuthProvider = null; private SslEngineFactory mySslEngineFactory = null; diff --git a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java index 0bc7ea534..5899e64cf 100644 --- a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java +++ b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java @@ -127,6 +127,6 @@ public final String getSerialConsistency() boolean remoteRouting() default true; @AttributeDefinition(name = "Serial consistency", description = "Define serial consistency level used") - String serialConsistency() default "DEFAULT"; + String serialConsistency() default LocalNativeConnectionProvider.DEFAUL_CONSISTENCY_TYPE; } } diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java index 34bd6ba4f..0bf434622 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java @@ -34,6 +34,7 @@ import com.ericsson.bss.cassandra.ecchronos.connection.StatementDecorator; import com.ericsson.bss.cassandra.ecchronos.core.exceptions.LockException; import com.ericsson.bss.cassandra.ecchronos.core.scheduling.LockFactory; +import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.slf4j.Logger; @@ -82,7 +83,7 @@ * WITH default_time_to_live = 600 AND gc_grace_seconds = 0; * */ -@SuppressWarnings({"GodClass", "TooManyFields", "SingularField", "ExcessiveMethodLength"}) +@SuppressWarnings({"PMD.GodClass", "PMD.TooManyFields", "PMD.SingularField", "PMD.ExcessiveMethodLength"}) public final class CASLockFactory implements LockFactory, Closeable { private static final Logger LOG = LoggerFactory.getLogger(CASLockFactory.class); @@ -132,7 +133,7 @@ private CASLockFactory(final Builder builder) verifySchemasExists(); - if ("DEFAULT".equals(mySerialConsistency)) + if (ConsistencyType.DEFAULT.getStringValue().equals(mySerialConsistency)) { serialConsistencyLevel = myRemoteRouting ? ConsistencyLevel.LOCAL_SERIAL @@ -140,7 +141,7 @@ private CASLockFactory(final Builder builder) } else { - serialConsistencyLevel = "LOCAL".equals(mySerialConsistency) + serialConsistencyLevel = ConsistencyType.LOCAL.getStringValue().equals(mySerialConsistency) ? ConsistencyLevel.LOCAL_SERIAL : ConsistencyLevel.SERIAL; } diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java new file mode 100644 index 000000000..0895f4eb5 --- /dev/null +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java @@ -0,0 +1,20 @@ +package com.ericsson.bss.cassandra.ecchronos.core.utils; + +public enum ConsistencyType +{ + DEFAULT("DEFAULT"), + LOCAL("LOCAL"), + SERIAL("SERIAL"); + + private final String consistencyTypeValue; + + ConsistencyType(final String consistentcyValue) + { + consistencyTypeValue = consistentcyValue; + } + + public final String getStringValue() + { + return consistencyTypeValue; + } +} From 531f7829497d9fc04f93842d69788e060e824b25 Mon Sep 17 00:00:00 2001 From: VictorCavichioli Date: Tue, 20 Feb 2024 09:30:22 -0300 Subject: [PATCH 5/8] Add header in ConsistencyType --- .../ecchronos/core/utils/ConsistencyType.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java index 0895f4eb5..0aceaa2fd 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java @@ -1,3 +1,17 @@ +/* + * Copyright 2023 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.utils; public enum ConsistencyType From de6e5f820d222d0c25321edb7693e90e934fc00a Mon Sep 17 00:00:00 2001 From: VictorCavichioli Date: Tue, 20 Feb 2024 13:05:23 -0300 Subject: [PATCH 6/8] Use consistencySerial as a lock configuration propertie --- .../DefaultNativeConnectionProvider.java | 9 +------ .../application/ECChronosInternals.java | 1 + .../config/connection/NativeConnection.java | 16 ++--------- .../lockfactory/CasLockFactoryConfig.java | 15 +++++++++++ application/src/main/resources/ecc.yml | 22 +++++++-------- .../application/config/TestConfig.java | 14 +++------- application/src/test/resources/all_set.yml | 2 +- .../impl/LocalNativeConnectionProvider.java | 21 ++------------- .../OSGiLocalNativeConnectionProvider.java | 14 ++-------- .../connection/NativeConnectionProvider.java | 2 -- .../ecchronos/core/CASLockFactory.java | 15 ++++++++--- .../ecchronos/core/utils/ConsistencyType.java | 18 +++---------- .../ecchronos/core/AbstractCassandraTest.java | 6 ----- .../ecchronos/core/TestCASLockFactory.java | 27 ++++++++++--------- ...estDefaultRepairConfigurationProvider.java | 7 +---- docs/autogenerated/EccYamlFile.md | 22 +++++++-------- 16 files changed, 80 insertions(+), 131 deletions(-) diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java index 1dcba0ae2..f61a4cb47 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java @@ -25,6 +25,7 @@ import com.ericsson.bss.cassandra.ecchronos.application.config.connection.NativeConnection; import com.ericsson.bss.cassandra.ecchronos.connection.CertificateHandler; import com.ericsson.bss.cassandra.ecchronos.core.repair.DefaultRepairConfigurationProvider; + import io.micrometer.core.instrument.MeterRegistry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,7 +53,6 @@ public DefaultNativeConnectionProvider(final Config config, String host = nativeConfig.getHost(); int port = nativeConfig.getPort(); boolean remoteRouting = nativeConfig.getRemoteRouting(); - String consistencySerial = nativeConfig.getConsistencySerial(); Security.CqlSecurity cqlSecurity = cqlSecuritySupplier.get(); boolean authEnabled = cqlSecurity.getCqlCredentials().isEnabled(); boolean tlsEnabled = cqlSecurity.getCqlTlsConfig().isEnabled(); @@ -74,7 +74,6 @@ public DefaultNativeConnectionProvider(final Config config, .withLocalhost(host) .withPort(port) .withRemoteRouting(remoteRouting) - .withConsistencySerial(consistencySerial) .withAuthProvider(authProvider) .withSslEngineFactory(sslEngineFactory) .withMetricsEnabled(config.getStatisticsConfig().isEnabled()) @@ -149,12 +148,6 @@ public final boolean getRemoteRouting() return myLocalNativeConnectionProvider.getRemoteRouting(); } - @Override - public final String getSerialConsistency() - { - return myLocalNativeConnectionProvider.getSerialConsistency(); - } - @Override public final void close() { diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java index a48acecb7..44b4267ba 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java @@ -85,6 +85,7 @@ public ECChronosInternals(final Config configuration, .withStatementDecorator(statementDecorator) .withKeyspaceName(casLockFactoryConfig.getKeyspaceName()) .withCacheExpiryInSeconds(casLockFactoryConfig.getFailureCacheExpiryTimeInSeconds()) + .withConsistencySerial(casLockFactoryConfig.getConsistencySerial()) .build(); Node node = nativeConnectionProvider.getLocalNode(); diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java index a1e46abe0..27dea4fcf 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java @@ -21,10 +21,11 @@ import com.ericsson.bss.cassandra.ecchronos.connection.NativeConnectionProvider; import com.ericsson.bss.cassandra.ecchronos.connection.StatementDecorator; import com.ericsson.bss.cassandra.ecchronos.core.repair.DefaultRepairConfigurationProvider; -import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; + import com.fasterxml.jackson.annotation.JsonProperty; import io.micrometer.core.instrument.MeterRegistry; + import java.util.function.Supplier; public class NativeConnection extends Connection @@ -33,7 +34,6 @@ public class NativeConnection extends Connection private Class myDecoratorClass = NoopStatementDecorator.class; private boolean myRemoteRouting = true; - private String myConsistencySerial = ConsistencyType.DEFAULT.getStringValue(); public NativeConnection() { @@ -76,18 +76,6 @@ public final void setRemoteRouting(final boolean remoteRouting) myRemoteRouting = remoteRouting; } - @JsonProperty("consistencySerial") - public final String getConsistencySerial() - { - return myConsistencySerial; - } - - @JsonProperty("consistencySerial") - public final void setConsistencySerial(final String consistencySerial) - { - myConsistencySerial = consistencySerial; - } - @Override protected final Class[] expectedConstructor() { diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/lockfactory/CasLockFactoryConfig.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/lockfactory/CasLockFactoryConfig.java index 7150dea35..611fedf22 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/lockfactory/CasLockFactoryConfig.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/lockfactory/CasLockFactoryConfig.java @@ -15,6 +15,8 @@ package com.ericsson.bss.cassandra.ecchronos.application.config.lockfactory; import com.fasterxml.jackson.annotation.JsonProperty; +import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; +import java.util.Locale; public class CasLockFactoryConfig { @@ -22,6 +24,7 @@ public class CasLockFactoryConfig private static final String DEFAULT_KEYSPACE_NAME = "ecchronos"; private String myKeyspaceName = DEFAULT_KEYSPACE_NAME; private long myExpiryTimeInSeconds = DEFAULT_EXPIRY_TIME_IN_SECONDS; + private ConsistencyType myConsistencySerial = ConsistencyType.DEFAULT; public final long getFailureCacheExpiryTimeInSeconds() { @@ -44,4 +47,16 @@ public final void setKeyspaceName(final String keyspaceName) { myKeyspaceName = keyspaceName; } + + @JsonProperty("consistencySerial") + public final ConsistencyType getConsistencySerial() + { + return myConsistencySerial; + } + + @JsonProperty("consistencySerial") + public final void setConsistencySerial(final String consistencySerial) + { + myConsistencySerial = ConsistencyType.valueOf(consistencySerial.toUpperCase(Locale.US)); + } } diff --git a/application/src/main/resources/ecc.yml b/application/src/main/resources/ecc.yml index aa44a1aa3..92ba478a3 100644 --- a/application/src/main/resources/ecc.yml +++ b/application/src/main/resources/ecc.yml @@ -56,17 +56,6 @@ connection: ## If remote routing is disabled, instead SERIAL consistency will be used for those request. ## remoteRouting: true - ## - ## Allow to override consistency level for LWT (lightweight transactions). Possible values are: - ## "DEFAULT" - Use consistency level based on remoteRouting. - ## "SERIAL" - Use SERIAL consistency for LWT regardless of remoteRouting. - ## "LOCAL_SERIAL" - Use LOCAL_SERIAL consistency for LWT regardless of remoteRouting. - ## - ## if you use remoteRouting: false and LOCAL_SERIAL then all locks will be taken locally - ## in DC. I.e There's a risk that multiple nodes in different datacenters will be able to lock the - ## same nodes causing multiple repairs on the same range/node at the same time. - ## - consistencySerial: "DEFAULT" jmx: ## ## Host and port properties for JMX. @@ -282,6 +271,17 @@ lock_factory: ## 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 remoteRouting. + ## "SERIAL" - Use SERIAL consistency for LWT regardless of remoteRouting. + ## "LOCAL_SERIAL" - Use LOCAL_SERIAL consistency for LWT regardless of remoteRouting. + ## + ## if you use remoteRouting: false and LOCAL_SERIAL then all locks will be taken locally + ## in DC. I.e There's a risk that multiple nodes in different datacenters will be able to lock the + ## same nodes causing multiple repairs on the same range/node at the same time. + ## + consistencySerial: "DEFAULT" run_policy: time_based: diff --git a/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java b/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java index d4cd6011d..01db105a4 100644 --- a/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java +++ b/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java @@ -33,7 +33,6 @@ import com.ericsson.bss.cassandra.ecchronos.application.config.metrics.StatisticsConfig; import com.ericsson.bss.cassandra.ecchronos.application.config.repair.GlobalRepairConfig; import com.ericsson.bss.cassandra.ecchronos.application.config.repair.RepairHistory; -import com.ericsson.bss.cassandra.ecchronos.application.config.repair.RepairSchedule; import com.ericsson.bss.cassandra.ecchronos.application.config.rest.RestServerConfig; import com.ericsson.bss.cassandra.ecchronos.application.config.runpolicy.RunPolicyConfig; import com.ericsson.bss.cassandra.ecchronos.application.config.scheduler.SchedulerConfig; @@ -47,6 +46,7 @@ import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairConfiguration; import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairLockType; import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairOptions; +import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReference; import com.ericsson.bss.cassandra.ecchronos.core.utils.UnitConverter; import com.ericsson.bss.cassandra.ecchronos.fm.RepairFaultReporter; @@ -89,7 +89,6 @@ public void testAllValues() throws Exception assertThat(nativeConnection.getHost()).isEqualTo("127.0.0.2"); assertThat(nativeConnection.getPort()).isEqualTo(9100); assertThat(nativeConnection.getRemoteRouting()).isFalse(); - assertThat(nativeConnection.getConsistencySerial().equals("LOCAL")).isTrue(); assertThat(nativeConnection.getTimeout().getConnectionTimeout(TimeUnit.SECONDS)).isEqualTo(5); assertThat(nativeConnection.getProviderClass()).isEqualTo(TestNativeConnectionProvider.class); assertThat(nativeConnection.getCertificateHandlerClass()).isEqualTo(TestCertificateHandler.class); @@ -158,6 +157,7 @@ public void testAllValues() throws Exception LockFactoryConfig lockFactoryConfig = config.getLockFactory(); assertThat(lockFactoryConfig.getCasLockFactoryConfig().getKeyspaceName()).isEqualTo("ecc"); + assertThat(lockFactoryConfig.getCasLockFactoryConfig().getConsistencySerial().equals(ConsistencyType.LOCAL)).isTrue(); RunPolicyConfig runPolicyConfig = config.getRunPolicy(); assertThat(runPolicyConfig.getTimeBasedConfig().getKeyspaceName()).isEqualTo("ecc"); @@ -186,7 +186,6 @@ public void testWithDefaultFile() throws Exception assertThat(nativeConnection.getHost()).isEqualTo("localhost"); assertThat(nativeConnection.getPort()).isEqualTo(9042); assertThat(nativeConnection.getRemoteRouting()).isTrue(); - assertThat(nativeConnection.getConsistencySerial().equals("DEFAULT")).isTrue(); assertThat(nativeConnection.getTimeout().getConnectionTimeout(TimeUnit.MILLISECONDS)).isEqualTo(0); assertThat(nativeConnection.getProviderClass()).isEqualTo(DefaultNativeConnectionProvider.class); assertThat(nativeConnection.getCertificateHandlerClass()).isEqualTo(ReloadingCertificateHandler.class); @@ -245,6 +244,7 @@ public void testWithDefaultFile() throws Exception LockFactoryConfig lockFactoryConfig = config.getLockFactory(); assertThat(lockFactoryConfig.getCasLockFactoryConfig().getKeyspaceName()).isEqualTo("ecchronos"); + assertThat(lockFactoryConfig.getCasLockFactoryConfig().getConsistencySerial().equals(ConsistencyType.DEFAULT)).isTrue(); RunPolicyConfig runPolicyConfig = config.getRunPolicy(); assertThat(runPolicyConfig.getTimeBasedConfig().getKeyspaceName()).isEqualTo("ecchronos"); @@ -274,7 +274,6 @@ public void testDefault() throws Exception assertThat(nativeConnection.getPort()).isEqualTo(9042); assertThat(nativeConnection.getRemoteRouting()).isTrue(); - assertThat(nativeConnection.getConsistencySerial().equals("DEFAULT")).isTrue(); assertThat(nativeConnection.getTimeout().getConnectionTimeout(TimeUnit.MILLISECONDS)).isEqualTo(0); assertThat(nativeConnection.getProviderClass()).isEqualTo(DefaultNativeConnectionProvider.class); assertThat(nativeConnection.getCertificateHandlerClass()).isEqualTo(ReloadingCertificateHandler.class); @@ -331,6 +330,7 @@ public void testDefault() throws Exception LockFactoryConfig lockFactoryConfig = config.getLockFactory(); assertThat(lockFactoryConfig.getCasLockFactoryConfig().getKeyspaceName()).isEqualTo("ecchronos"); + assertThat(lockFactoryConfig.getCasLockFactoryConfig().getConsistencySerial().equals(ConsistencyType.DEFAULT)).isTrue(); RunPolicyConfig runPolicyConfig = config.getRunPolicy(); assertThat(runPolicyConfig.getTimeBasedConfig().getKeyspaceName()).isEqualTo("ecchronos"); @@ -407,12 +407,6 @@ public boolean getRemoteRouting() { throw new UnsupportedOperationException(); } - - @Override - public String getSerialConsistency() - { - throw new UnsupportedOperationException(); - } } public static class TestCertificateHandler implements CertificateHandler diff --git a/application/src/test/resources/all_set.yml b/application/src/test/resources/all_set.yml index 3ce21636b..7d5c4f9c7 100644 --- a/application/src/test/resources/all_set.yml +++ b/application/src/test/resources/all_set.yml @@ -24,7 +24,6 @@ connection: certificateHandler: com.ericsson.bss.cassandra.ecchronos.application.config.TestConfig$TestCertificateHandler decoratorClass: com.ericsson.bss.cassandra.ecchronos.application.config.TestConfig$TestStatementDecorator remoteRouting: false - consistencySerial: "LOCAL" jmx: host: 127.0.0.3 port: 7100 @@ -83,6 +82,7 @@ lock_factory: cas: keyspace: ecc cache_expiry_time_in_seconds: 100 + consistencySerial: "LOCAL" run_policy: diff --git a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java index b8cc956aa..6bbe0e354 100644 --- a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java +++ b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java @@ -68,24 +68,20 @@ public final class LocalNativeConnectionProvider implements NativeConnectionProv public static final int DEFAULT_NATIVE_PORT = 9042; public static final String DEFAULT_LOCAL_HOST = "localhost"; - public static final String DEFAUL_CONSISTENCY_TYPE = "DEFAULT"; private final CqlSession mySession; private final Node myLocalNode; private final boolean myRemoteRouting; - private final String mySerialConsistencyLevel; private LocalNativeConnectionProvider( final CqlSession session, final Node node, - final boolean remoteRouting, - final String serialConsistencyLevel + final boolean remoteRouting ) { mySession = session; myLocalNode = node; myRemoteRouting = remoteRouting; - mySerialConsistencyLevel = serialConsistencyLevel; } @Override @@ -106,12 +102,6 @@ public boolean getRemoteRouting() return myRemoteRouting; } - @Override - public String getSerialConsistency() - { - return mySerialConsistencyLevel; - } - @Override public void close() { @@ -130,7 +120,6 @@ public static class Builder private String myLocalhost = DEFAULT_LOCAL_HOST; private int myPort = DEFAULT_NATIVE_PORT; private boolean myRemoteRouting = true; - private String mySerialConsistency = DEFAUL_CONSISTENCY_TYPE; private boolean myIsMetricsEnabled = true; private AuthProvider myAuthProvider = null; private SslEngineFactory mySslEngineFactory = null; @@ -156,12 +145,6 @@ public final Builder withRemoteRouting(final boolean remoteRouting) return this; } - public final Builder withConsistencySerial(final String serialConsistency) - { - mySerialConsistency = serialConsistency; - return this; - } - public final Builder withAuthProvider(final AuthProvider authProvider) { this.myAuthProvider = authProvider; @@ -202,7 +185,7 @@ public final LocalNativeConnectionProvider build() { CqlSession session = createSession(this); Node node = resolveLocalhost(session, localEndPoint()); - return new LocalNativeConnectionProvider(session, node, myRemoteRouting, mySerialConsistency); + return new LocalNativeConnectionProvider(session, node, myRemoteRouting); } private EndPoint localEndPoint() diff --git a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java index 5899e64cf..3bfbbb1ac 100644 --- a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java +++ b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java @@ -18,6 +18,7 @@ import com.datastax.oss.driver.api.core.auth.ProgrammaticPlainTextAuthProvider; import com.datastax.oss.driver.api.core.metadata.Node; import com.ericsson.bss.cassandra.ecchronos.connection.NativeConnectionProvider; + import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.ConfigurationPolicy; @@ -50,13 +51,11 @@ public final synchronized void activate(final Configuration configuration) String localhost = configuration.localHost(); int port = configuration.nativePort(); boolean remoteRouting = configuration.remoteRouting(); - String serialConsistency = configuration.serialConsistency(); LocalNativeConnectionProvider.Builder builder = LocalNativeConnectionProvider.builder() .withLocalhost(localhost) .withPort(port) - .withRemoteRouting(remoteRouting) - .withConsistencySerial(serialConsistency); + .withRemoteRouting(remoteRouting); if (!configuration.credentialsFile().isEmpty()) { @@ -102,12 +101,6 @@ public final boolean getRemoteRouting() return myDelegateNativeConnectionProvider.getRemoteRouting(); } - @Override - public final String getSerialConsistency() - { - return myDelegateNativeConnectionProvider.getSerialConsistency(); - } - @ObjectClassDefinition public @interface Configuration { @@ -125,8 +118,5 @@ public final String getSerialConsistency() @AttributeDefinition(name = "Remote routing", description = "Enables remote routing between datacenters") boolean remoteRouting() default true; - - @AttributeDefinition(name = "Serial consistency", description = "Define serial consistency level used") - String serialConsistency() default LocalNativeConnectionProvider.DEFAUL_CONSISTENCY_TYPE; } } diff --git a/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java index e5b97d367..10ae256be 100644 --- a/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java +++ b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java @@ -31,8 +31,6 @@ public interface NativeConnectionProvider extends Closeable boolean getRemoteRouting(); - String getSerialConsistency(); - @Override default void close() throws IOException { diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java index 0bf434622..0e279c4fc 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java @@ -104,7 +104,7 @@ public final class CASLockFactory implements LockFactory, Closeable private final StatementDecorator myStatementDecorator; private final HostStates myHostStates; private final boolean myRemoteRouting; - private final String mySerialConsistency; + private final ConsistencyType mySerialConsistency; private final CqlSession mySession; private final String myKeyspaceName; @@ -129,11 +129,11 @@ private CASLockFactory(final Builder builder) mySession = builder.myNativeConnectionProvider.getSession(); myRemoteRouting = builder.myNativeConnectionProvider.getRemoteRouting(); - mySerialConsistency = builder.myNativeConnectionProvider.getSerialConsistency(); + mySerialConsistency = builder.myConsistencyType; verifySchemasExists(); - if (ConsistencyType.DEFAULT.getStringValue().equals(mySerialConsistency)) + if (ConsistencyType.DEFAULT.equals(mySerialConsistency)) { serialConsistencyLevel = myRemoteRouting ? ConsistencyLevel.LOCAL_SERIAL @@ -141,7 +141,7 @@ private CASLockFactory(final Builder builder) } else { - serialConsistencyLevel = ConsistencyType.LOCAL.getStringValue().equals(mySerialConsistency) + serialConsistencyLevel = ConsistencyType.LOCAL.equals(mySerialConsistency) ? ConsistencyLevel.LOCAL_SERIAL : ConsistencyLevel.SERIAL; } @@ -363,6 +363,7 @@ public static class Builder private StatementDecorator myStatementDecorator; private String myKeyspaceName = DEFAULT_KEYSPACE_NAME; private long myCacheExpiryTimeInSeconds = DEFAULT_EXPIRY_TIME_IN_SECONDS; + private ConsistencyType myConsistencyType; public final Builder withNativeConnectionProvider(final NativeConnectionProvider nativeConnectionProvider) { @@ -394,6 +395,12 @@ public final Builder withCacheExpiryInSeconds(final long cacheExpiryInSeconds) return this; } + public final Builder withConsistencySerial(final ConsistencyType consistencyType) + { + myConsistencyType = consistencyType; + return this; + } + public final CASLockFactory build() { if (myNativeConnectionProvider == null) diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java index 0aceaa2fd..35b783657 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java @@ -16,19 +16,7 @@ public enum ConsistencyType { - DEFAULT("DEFAULT"), - LOCAL("LOCAL"), - SERIAL("SERIAL"); - - private final String consistencyTypeValue; - - ConsistencyType(final String consistentcyValue) - { - consistencyTypeValue = consistentcyValue; - } - - public final String getStringValue() - { - return consistencyTypeValue; - } + DEFAULT, + LOCAL, + SERIAL } diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java index 6f1cec412..7dc24abc1 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java @@ -77,12 +77,6 @@ public boolean getRemoteRouting() { return true; } - - @Override - public String getSerialConsistency() - { - return "DEFAULT"; - } }; } diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java index f1d7fff53..022978254 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java @@ -65,6 +65,7 @@ import com.ericsson.bss.cassandra.ecchronos.core.exceptions.LockException; import com.ericsson.bss.cassandra.ecchronos.core.scheduling.LockFactory.DistributedLock; +import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; import net.jcip.annotations.NotThreadSafe; import org.junit.runner.RunWith; @@ -380,12 +381,6 @@ public boolean getRemoteRouting() { return true; } - - @Override - public String getSerialConsistency() - { - return "DEFAULT"; - } }) .withHostStates(hostStates) .withStatementDecorator(s -> s) @@ -397,11 +392,22 @@ public String getSerialConsistency() public void testRemoteRoutingTrueWithDefaultSerialConsistency() { + Node nodeMock = mock(Node.class); + + NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); + + when(connectionProviderMock.getSession()).thenReturn(mySession); + + when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); + + when(connectionProviderMock.getRemoteRouting()).thenReturn(true); + myLockFactory = new CASLockFactory.Builder() .withNativeConnectionProvider(getNativeConnectionProvider()) .withHostStates(hostStates) .withStatementDecorator(s -> s) .withKeyspaceName(myKeyspaceName) + .withConsistencySerial(ConsistencyType.DEFAULT) .build(); @@ -422,13 +428,12 @@ public void testRemoteRoutingFalseWithDefaultSerialConsistency() when(connectionProviderMock.getRemoteRouting()).thenReturn(false); - when(connectionProviderMock.getSerialConsistency()).thenReturn("DEFAULT"); - myLockFactory = new CASLockFactory.Builder() .withNativeConnectionProvider(connectionProviderMock) .withHostStates(hostStates) .withStatementDecorator(s -> s) .withKeyspaceName(myKeyspaceName) + .withConsistencySerial(ConsistencyType.DEFAULT) .build(); assertEquals(ConsistencyLevel.SERIAL, myLockFactory.getSerialConsistencyLevel()); @@ -441,8 +446,6 @@ public void testLocalSerialConsistency() NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); Node nodeMock = mock(Node.class); - - when(connectionProviderMock.getSerialConsistency()).thenReturn("LOCAL"); when(connectionProviderMock.getSession()).thenReturn(mySession); @@ -453,6 +456,7 @@ public void testLocalSerialConsistency() .withHostStates(hostStates) .withStatementDecorator(s -> s) .withKeyspaceName(myKeyspaceName) + .withConsistencySerial(ConsistencyType.LOCAL) .build(); assertEquals(ConsistencyLevel.LOCAL_SERIAL, myLockFactory.getSerialConsistencyLevel()); @@ -466,8 +470,6 @@ public void testSerialConsistency() Node nodeMock = mock(Node.class); - when(connectionProviderMock.getSerialConsistency()).thenReturn("SERIAL"); - when(connectionProviderMock.getSession()).thenReturn(mySession); when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); @@ -477,6 +479,7 @@ public void testSerialConsistency() .withHostStates(hostStates) .withStatementDecorator(s -> s) .withKeyspaceName(myKeyspaceName) + .withConsistencySerial(ConsistencyType.SERIAL) .build(); assertEquals(ConsistencyLevel.SERIAL, myLockFactory.getSerialConsistencyLevel()); diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java index ab76dd690..2bcc344fa 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java @@ -22,6 +22,7 @@ import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; import com.ericsson.bss.cassandra.ecchronos.connection.NativeConnectionProvider; import com.ericsson.bss.cassandra.ecchronos.core.MockTableReferenceFactory; +import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; import com.ericsson.bss.cassandra.ecchronos.core.utils.ReplicatedTableProvider; import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReference; import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReferenceFactory; @@ -101,12 +102,6 @@ public boolean getRemoteRouting() { return true; } - - @Override - public String getSerialConsistency() - { - return "DEFAULT"; - } }; when(session.getMetadata()).thenReturn(metadata); diff --git a/docs/autogenerated/EccYamlFile.md b/docs/autogenerated/EccYamlFile.md index 5f64c934c..8b69c7d31 100644 --- a/docs/autogenerated/EccYamlFile.md +++ b/docs/autogenerated/EccYamlFile.md @@ -42,17 +42,6 @@ # If remote routing is disabled, instead SERIAL consistency will be used for those request. # * remoteRouting: true -# -# Allow to override consistency level for LWT (lightweight transactions). Possible values are: -# "DEFAULT" - Use consistency level based on remoteRouting. -# "SERIAL" - Use SERIAL consistency for LWT regardless of remoteRouting. -# "LOCAL_SERIAL" - Use LOCAL_SERIAL consistency for LWT regardless of remoteRouting. -# -# if you use remoteRouting: false and LOCAL_SERIAL then all locks will be taken locally -# in DC. I.e There's a risk that multiple nodes in different datacenters will be able to lock the -# same nodes causing multiple repairs on the same range/node at the same time. -# -* consistencySerial: "DEFAULT" **jmx:** # # Host and port properties for JMX. @@ -268,6 +257,17 @@ # 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 remoteRouting. +# "SERIAL" - Use SERIAL consistency for LWT regardless of remoteRouting. +# "LOCAL_SERIAL" - Use LOCAL_SERIAL consistency for LWT regardless of remoteRouting. +# +# if you use remoteRouting: false and LOCAL_SERIAL then all locks will be taken locally +# in DC. I.e There's a risk that multiple nodes in different datacenters will be able to lock the +# same nodes causing multiple repairs on the same range/node at the same time. +# +* consistencySerial: "DEFAULT" **run_policy:** **time_based:** From c35da294ac4b43cd0ade8666fe5b531a8a170cc0 Mon Sep 17 00:00:00 2001 From: VictorCavichioli Date: Tue, 20 Feb 2024 14:41:32 -0300 Subject: [PATCH 7/8] Reset unnecessary changes --- .../application/DefaultNativeConnectionProvider.java | 1 - .../application/config/connection/NativeConnection.java | 2 -- .../connection/impl/LocalNativeConnectionProvider.java | 6 +----- .../connection/impl/OSGiLocalNativeConnectionProvider.java | 1 - .../bss/cassandra/ecchronos/core/utils/ConsistencyType.java | 2 +- .../core/repair/TestDefaultRepairConfigurationProvider.java | 1 - pmd-rules.xml | 2 +- 7 files changed, 3 insertions(+), 12 deletions(-) diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java index f61a4cb47..aff933b80 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java @@ -25,7 +25,6 @@ import com.ericsson.bss.cassandra.ecchronos.application.config.connection.NativeConnection; import com.ericsson.bss.cassandra.ecchronos.connection.CertificateHandler; import com.ericsson.bss.cassandra.ecchronos.core.repair.DefaultRepairConfigurationProvider; - import io.micrometer.core.instrument.MeterRegistry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java index 27dea4fcf..e015fa5e7 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/connection/NativeConnection.java @@ -21,11 +21,9 @@ import com.ericsson.bss.cassandra.ecchronos.connection.NativeConnectionProvider; import com.ericsson.bss.cassandra.ecchronos.connection.StatementDecorator; import com.ericsson.bss.cassandra.ecchronos.core.repair.DefaultRepairConfigurationProvider; - import com.fasterxml.jackson.annotation.JsonProperty; import io.micrometer.core.instrument.MeterRegistry; - import java.util.function.Supplier; public class NativeConnection extends Connection diff --git a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java index 6bbe0e354..c9ac49a3b 100644 --- a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java +++ b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java @@ -73,11 +73,7 @@ public final class LocalNativeConnectionProvider implements NativeConnectionProv private final Node myLocalNode; private final boolean myRemoteRouting; - private LocalNativeConnectionProvider( - final CqlSession session, - final Node node, - final boolean remoteRouting - ) + private LocalNativeConnectionProvider(final CqlSession session, final Node node, final boolean remoteRouting) { mySession = session; myLocalNode = node; diff --git a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java index 3bfbbb1ac..e941fc3ad 100644 --- a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java +++ b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java @@ -18,7 +18,6 @@ import com.datastax.oss.driver.api.core.auth.ProgrammaticPlainTextAuthProvider; import com.datastax.oss.driver.api.core.metadata.Node; import com.ericsson.bss.cassandra.ecchronos.connection.NativeConnectionProvider; - import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.ConfigurationPolicy; diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java index 35b783657..341f484e6 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 Telefonaktiebolaget LM Ericsson + * 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. diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java index 2bcc344fa..35bdde2c4 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java @@ -22,7 +22,6 @@ import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata; import com.ericsson.bss.cassandra.ecchronos.connection.NativeConnectionProvider; import com.ericsson.bss.cassandra.ecchronos.core.MockTableReferenceFactory; -import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; import com.ericsson.bss.cassandra.ecchronos.core.utils.ReplicatedTableProvider; import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReference; import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReferenceFactory; diff --git a/pmd-rules.xml b/pmd-rules.xml index 997a605c4..5858cf92b 100644 --- a/pmd-rules.xml +++ b/pmd-rules.xml @@ -49,4 +49,4 @@ - \ No newline at end of file + From 297c3746d47d694fb4103bca75a4e2c78185cff1 Mon Sep 17 00:00:00 2001 From: VictorCavichioli Date: Wed, 21 Feb 2024 08:51:51 -0300 Subject: [PATCH 8/8] Remove unnecessary variables and lines --- .../application/config/TestConfig.java | 1 - .../ecchronos/core/CASLockFactory.java | 22 ++++++++----------- .../ecchronos/core/TestCASLockFactory.java | 15 ------------- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java b/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java index 01db105a4..745005682 100644 --- a/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java +++ b/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java @@ -273,7 +273,6 @@ public void testDefault() throws Exception assertThat(nativeConnection.getHost()).isEqualTo("localhost"); assertThat(nativeConnection.getPort()).isEqualTo(9042); assertThat(nativeConnection.getRemoteRouting()).isTrue(); - assertThat(nativeConnection.getTimeout().getConnectionTimeout(TimeUnit.MILLISECONDS)).isEqualTo(0); assertThat(nativeConnection.getProviderClass()).isEqualTo(DefaultNativeConnectionProvider.class); assertThat(nativeConnection.getCertificateHandlerClass()).isEqualTo(ReloadingCertificateHandler.class); diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java index 0e279c4fc..07ddc431c 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java @@ -104,8 +104,6 @@ public final class CASLockFactory implements LockFactory, Closeable private final StatementDecorator myStatementDecorator; private final HostStates myHostStates; private final boolean myRemoteRouting; - private final ConsistencyType mySerialConsistency; - private final CqlSession mySession; private final String myKeyspaceName; private final PreparedStatement myCompeteStatement; @@ -116,8 +114,7 @@ public final class CASLockFactory implements LockFactory, Closeable private final PreparedStatement myUpdateLockStatement; private final PreparedStatement myRemoveLockPriorityStatement; private final CASLockFactoryCacheContext myCasLockFactoryCacheContext; - - private final ConsistencyLevel serialConsistencyLevel; + private final ConsistencyLevel mySerialConsistencyLevel; private CASLockFactory(final Builder builder) { @@ -129,19 +126,18 @@ private CASLockFactory(final Builder builder) mySession = builder.myNativeConnectionProvider.getSession(); myRemoteRouting = builder.myNativeConnectionProvider.getRemoteRouting(); - mySerialConsistency = builder.myConsistencyType; verifySchemasExists(); - if (ConsistencyType.DEFAULT.equals(mySerialConsistency)) + if (ConsistencyType.DEFAULT.equals(builder.myConsistencyType)) { - serialConsistencyLevel = myRemoteRouting + mySerialConsistencyLevel = myRemoteRouting ? ConsistencyLevel.LOCAL_SERIAL : ConsistencyLevel.SERIAL; } else { - serialConsistencyLevel = ConsistencyType.LOCAL.equals(mySerialConsistency) + mySerialConsistencyLevel = ConsistencyType.LOCAL.equals(builder.myConsistencyType) ? ConsistencyLevel.LOCAL_SERIAL : ConsistencyLevel.SERIAL; } @@ -153,14 +149,14 @@ private CASLockFactory(final Builder builder) .ifNotExists() .build() .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM) - .setSerialConsistencyLevel(serialConsistencyLevel); + .setSerialConsistencyLevel(mySerialConsistencyLevel); SimpleStatement getLockMetadataStatement = QueryBuilder.selectFrom(myKeyspaceName, TABLE_LOCK) .column(COLUMN_METADATA) .whereColumn(COLUMN_RESOURCE) .isEqualTo(bindMarker()) .build() - .setSerialConsistencyLevel(serialConsistencyLevel); + .setSerialConsistencyLevel(mySerialConsistencyLevel); SimpleStatement removeLockStatement = QueryBuilder.deleteFrom(myKeyspaceName, TABLE_LOCK) .whereColumn(COLUMN_RESOURCE) @@ -169,7 +165,7 @@ private CASLockFactory(final Builder builder) .isEqualTo(bindMarker()) .build() .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM) - .setSerialConsistencyLevel(serialConsistencyLevel); + .setSerialConsistencyLevel(mySerialConsistencyLevel); SimpleStatement updateLockStatement = QueryBuilder.update(myKeyspaceName, TABLE_LOCK) .setColumn(COLUMN_NODE, bindMarker()) @@ -180,7 +176,7 @@ private CASLockFactory(final Builder builder) .isEqualTo(bindMarker()) .build() .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM) - .setSerialConsistencyLevel(serialConsistencyLevel); + .setSerialConsistencyLevel(mySerialConsistencyLevel); SimpleStatement competeStatement = QueryBuilder.insertInto(myKeyspaceName, TABLE_LOCK_PRIORITY) .value(COLUMN_RESOURCE, bindMarker()) @@ -339,7 +335,7 @@ UUID getHostId() @VisibleForTesting ConsistencyLevel getSerialConsistencyLevel() { - return serialConsistencyLevel; + return mySerialConsistencyLevel; } @VisibleForTesting diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java index 022978254..1bf6eacee 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java @@ -391,15 +391,11 @@ public boolean getRemoteRouting() @Test public void testRemoteRoutingTrueWithDefaultSerialConsistency() { - Node nodeMock = mock(Node.class); - NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); when(connectionProviderMock.getSession()).thenReturn(mySession); - when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); - when(connectionProviderMock.getRemoteRouting()).thenReturn(true); myLockFactory = new CASLockFactory.Builder() @@ -410,22 +406,17 @@ public void testRemoteRoutingTrueWithDefaultSerialConsistency() .withConsistencySerial(ConsistencyType.DEFAULT) .build(); - assertEquals(ConsistencyLevel.LOCAL_SERIAL, myLockFactory.getSerialConsistencyLevel()); } @Test public void testRemoteRoutingFalseWithDefaultSerialConsistency() { - Node nodeMock = mock(Node.class); - NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); when(connectionProviderMock.getSession()).thenReturn(mySession); - when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); - when(connectionProviderMock.getRemoteRouting()).thenReturn(false); myLockFactory = new CASLockFactory.Builder() @@ -442,13 +433,10 @@ public void testRemoteRoutingFalseWithDefaultSerialConsistency() @Test public void testLocalSerialConsistency() { - NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); - Node nodeMock = mock(Node.class); when(connectionProviderMock.getSession()).thenReturn(mySession); - when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); myLockFactory = new CASLockFactory.Builder() @@ -460,18 +448,15 @@ public void testLocalSerialConsistency() .build(); assertEquals(ConsistencyLevel.LOCAL_SERIAL, myLockFactory.getSerialConsistencyLevel()); - } @Test public void testSerialConsistency() { NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); - Node nodeMock = mock(Node.class); when(connectionProviderMock.getSession()).thenReturn(mySession); - when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); myLockFactory = new CASLockFactory.Builder()