You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2024/03/07 02:23:34 UTC

(james-project) branch master updated: [FIX] Enforce a separate keyspace for blob store cache (#2060)

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git


The following commit(s) were added to refs/heads/master by this push:
     new 956cf750ba [FIX] Enforce a separate keyspace for blob store cache (#2060)
956cf750ba is described below

commit 956cf750baa7dce08cc63052e5b5d52de78d2241
Author: Benoit TELLIER <bt...@linagora.com>
AuthorDate: Thu Mar 7 03:23:29 2024 +0100

    [FIX] Enforce a separate keyspace for blob store cache (#2060)
    
    This was broken, likely upon the cassandra driver upgrade
---
 .../backends/cassandra/init/ResilientClusterProvider.java    | 12 +++++++++++-
 .../james/modules/mailbox/CassandraCacheSessionModule.java   | 11 +++--------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ResilientClusterProvider.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ResilientClusterProvider.java
index 684b1327a8..cb4410ba2c 100644
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ResilientClusterProvider.java
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ResilientClusterProvider.java
@@ -48,11 +48,13 @@ public class ResilientClusterProvider implements Provider<CqlSession> {
     private static final Logger LOGGER = LoggerFactory.getLogger(ResilientClusterProvider.class);
 
     private final CqlSession cluster;
+    private final ClusterConfiguration clusterConfiguration;
 
     @VisibleForTesting
     @Inject
     ResilientClusterProvider(ClusterConfiguration configuration, KeyspaceConfiguration keyspaceConfiguration) {
-        Duration waitDelay = Duration.ofMillis(configuration.getMinDelay());
+        clusterConfiguration = configuration;
+        Duration waitDelay = Duration.ofMillis(clusterConfiguration.getMinDelay());
         cluster = Mono.fromCallable(getClusterRetryCallable(configuration, keyspaceConfiguration))
             .doOnError(e -> LOGGER.warn("Error establishing Cassandra connection. Next retry scheduled in {} ms", waitDelay, e))
             .retryWhen(Retry.backoff(configuration.getMaxRetry(), waitDelay).scheduler(Schedulers.boundedElastic()))
@@ -80,6 +82,14 @@ public class ResilientClusterProvider implements Provider<CqlSession> {
         return cluster;
     }
 
+    public CqlSession get(KeyspaceConfiguration keyspaceConfiguration) {
+        Duration waitDelay = Duration.ofMillis(clusterConfiguration.getMinDelay());
+        return Mono.fromCallable(getClusterRetryCallable(clusterConfiguration, keyspaceConfiguration))
+            .doOnError(e -> LOGGER.warn("Error establishing Cassandra connection. Next retry scheduled in {} ms", waitDelay, e))
+            .retryWhen(Retry.backoff(clusterConfiguration.getMaxRetry(), waitDelay).scheduler(Schedulers.boundedElastic()))
+            .block();
+    }
+
     @PreDestroy
     public void stop() {
         cluster.closeAsync();
diff --git a/server/container/guice/cassandra/src/main/java/org/apache/james/modules/mailbox/CassandraCacheSessionModule.java b/server/container/guice/cassandra/src/main/java/org/apache/james/modules/mailbox/CassandraCacheSessionModule.java
index 7d3cc250f3..16b4778e50 100644
--- a/server/container/guice/cassandra/src/main/java/org/apache/james/modules/mailbox/CassandraCacheSessionModule.java
+++ b/server/container/guice/cassandra/src/main/java/org/apache/james/modules/mailbox/CassandraCacheSessionModule.java
@@ -22,9 +22,8 @@ package org.apache.james.modules.mailbox;
 import java.util.Set;
 
 import org.apache.james.backends.cassandra.components.CassandraModule;
-import org.apache.james.backends.cassandra.init.KeyspaceFactory;
+import org.apache.james.backends.cassandra.init.ResilientClusterProvider;
 import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory;
-import org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration;
 import org.apache.james.backends.cassandra.init.configuration.InjectionNames;
 import org.apache.james.backends.cassandra.init.configuration.KeyspaceConfiguration;
 
@@ -72,12 +71,8 @@ public class CassandraCacheSessionModule extends AbstractModule {
         private final CqlSession cluster;
 
         @Inject
-        private InitializedCacheCluster(CqlSession cluster, ClusterConfiguration clusterConfiguration, KeyspacesConfiguration keyspacesConfiguration) {
-            this.cluster = cluster;
-
-            if (clusterConfiguration.shouldCreateKeyspace()) {
-                KeyspaceFactory.createKeyspace(keyspacesConfiguration.cacheKeyspaceConfiguration(), cluster).block();
-            }
+        private InitializedCacheCluster(ResilientClusterProvider sessionProvider, KeyspacesConfiguration keyspacesConfiguration) {
+            this.cluster = sessionProvider.get(keyspacesConfiguration.cacheKeyspaceConfiguration());
         }
     }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org