You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/07/30 04:15:21 UTC

[james-project] 08/12: JAMES-3317 use Storage strategy from BlobStoreConfiguration when instantiating the blobstore

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

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

commit d6ac26ff738d4bef849fc4511a13ae50a6c6a71b
Author: RĂ©mi Kowalski <rk...@linagora.com>
AuthorDate: Wed Jul 22 16:05:29 2020 +0200

    JAMES-3317 use Storage strategy from BlobStoreConfiguration when instantiating the blobstore
---
 .../modules/blobstore/BlobStoreModulesChooser.java | 45 +++++++++++++++++-----
 src/site/xdoc/server/config-blobstore.xml          |  9 +++++
 2 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java
index c0cdcc2..323f6c5 100644
--- a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java
+++ b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/modules/blobstore/BlobStoreModulesChooser.java
@@ -29,6 +29,8 @@ import org.apache.james.blob.objectstorage.ObjectStorageBlobStore;
 import org.apache.james.modules.mailbox.CassandraBlobStoreDependenciesModule;
 import org.apache.james.modules.objectstorage.ObjectStorageDependenciesModule;
 import org.apache.james.server.blob.deduplication.DeDuplicationBlobStore;
+import org.apache.james.server.blob.deduplication.PassThroughBlobStore;
+import org.apache.james.server.blob.deduplication.StorageStrategy;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.ImmutableList;
@@ -37,20 +39,16 @@ import com.google.inject.Module;
 import com.google.inject.name.Names;
 
 public class BlobStoreModulesChooser {
-    static class CassandraDeclarationModule extends AbstractModule {
+    static class CassandraDumbBlobStoreDeclarationModule extends AbstractModule {
         @Override
         protected void configure() {
             install(new CassandraBlobStoreDependenciesModule());
 
             bind(DumbBlobStore.class).to(CassandraDumbBlobStore.class);
-
-            bind(BlobStore.class)
-                .annotatedWith(Names.named(CachedBlobStore.BACKEND))
-                .to(DeDuplicationBlobStore.class);
         }
     }
 
-    static class ObjectStorageDeclarationModule extends AbstractModule {
+    static class ObjectStorageDumdBlobStoreDeclarationModule extends AbstractModule {
         @Override
         protected void configure() {
             install(new ObjectStorageDependenciesModule());
@@ -63,13 +61,40 @@ public class BlobStoreModulesChooser {
 
     @VisibleForTesting
     public static List<Module> chooseModules(BlobStoreConfiguration choosingConfiguration) {
-        switch (choosingConfiguration.getImplementation()) {
+        ImmutableList.Builder<Module> moduleBuilder = ImmutableList.<Module>builder().add(
+            chooseDumBlobStoreModule(choosingConfiguration.getImplementation()));
+
+        //TODO JAMES-3028 add the storage policy module for all implementation and unbind the ObjectStorageBlobStore
+        if (choosingConfiguration.getImplementation() == BlobStoreConfiguration.BlobStoreImplName.CASSANDRA) {
+            moduleBuilder.add(
+                chooseStoragePolicyModule(choosingConfiguration.storageStrategy()));
+        }
+        return moduleBuilder.build();
+    }
+
+    public static Module chooseDumBlobStoreModule(BlobStoreConfiguration.BlobStoreImplName implementation) {
+        switch (implementation) {
             case CASSANDRA:
-                return ImmutableList.of(new CassandraDeclarationModule());
+                return new CassandraDumbBlobStoreDeclarationModule();
             case OBJECTSTORAGE:
-                return ImmutableList.of(new ObjectStorageDeclarationModule());
+                return new ObjectStorageDumdBlobStoreDeclarationModule();
+            default:
+                throw new RuntimeException("Unsupported blobStore implementation " + implementation);
+        }
+    }
+
+    private static Module chooseStoragePolicyModule(StorageStrategy storageStrategy) {
+        switch (storageStrategy) {
+            case DEDUPLICATION:
+                return binder -> binder.bind(BlobStore.class)
+                    .annotatedWith(Names.named(CachedBlobStore.BACKEND))
+                    .to(DeDuplicationBlobStore.class);
+            case PASSTHROUGH:
+                return binder -> binder.bind(BlobStore.class)
+                    .annotatedWith(Names.named(CachedBlobStore.BACKEND))
+                    .to(PassThroughBlobStore.class);
             default:
-                throw new RuntimeException("Unsuported blobStore implementation " + choosingConfiguration.getImplementation());
+                throw new RuntimeException("Unknown storage strategy " + storageStrategy.name());
         }
     }
 }
diff --git a/src/site/xdoc/server/config-blobstore.xml b/src/site/xdoc/server/config-blobstore.xml
index 299d764..a6f1a1b 100644
--- a/src/site/xdoc/server/config-blobstore.xml
+++ b/src/site/xdoc/server/config-blobstore.xml
@@ -46,6 +46,15 @@
                 <dt><strong>implementation</strong></dt>
                 <dd>cassandra: use cassandra based BlobStore</dd>
                 <dd>objectstorage: use Swift/AWS S3 based BlobStore</dd>
+
+                <dt><strong>deduplication/enable</strong></dt>
+                <dd>Mandatory. Supported value: true and false.</dd>
+                <dd>If you choose to enable deduplication, the mails with the same content will be stored only once.</dd>
+                <dd>Warning: Once this feature is enabled, there is no turning back as turning it off will lead to the deletion of all</dd>
+                <dd>the mails sharing the same content once one is deleted.</dd>
+                <dd>This feature also requires a garbage collector mechanism to effectively drop blobs, which is not implemented yet.</dd>
+                <dd>Consequently, all the requested deletions will not be performed, meaning that blobstore will only grow.</dd>
+                <dd>Upgrade note: If you are upgrading from James 3.5 or older, the deduplication was enabled.</dd>
             </dl>
 
 


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