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/04/27 02:19:46 UTC

[james-project] 10/14: JAMES-3140 CachedBlobStore should rely on backend for defaultBucket

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 f39fe01acc113112d5327c7150fd1b48be2db9d1
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Apr 23 11:48:39 2020 +0700

    JAMES-3140 CachedBlobStore should rely on backend for defaultBucket
---
 .../james/blob/cassandra/cache/CachedBlobStore.java   | 19 ++++++-------------
 .../blob/cassandra/cache/CachedBlobStoreTest.java     |  2 +-
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/cache/CachedBlobStore.java b/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/cache/CachedBlobStore.java
index 2639c64..d8fc908 100644
--- a/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/cache/CachedBlobStore.java
+++ b/server/blob/blob-cassandra/src/main/java/org/apache/james/blob/cassandra/cache/CachedBlobStore.java
@@ -28,7 +28,6 @@ import java.util.Arrays;
 import java.util.Optional;
 
 import javax.inject.Inject;
-import javax.inject.Named;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.james.blob.api.BlobId;
@@ -43,22 +42,16 @@ import com.google.common.base.Preconditions;
 import reactor.core.publisher.Mono;
 
 public class CachedBlobStore implements BlobStore {
-
-    private static final String DEFAULT_BUCKET = "cassandraDefault";
-
     private final BlobStoreCache cache;
     private final BlobStore backend;
     private final Integer sizeThresholdInBytes;
-    private final BucketName defaultBucket;
 
     @Inject
     public CachedBlobStore(BlobStoreCache cache, BlobStore backend,
-                           CassandraCacheConfiguration cacheConfiguration,
-                           @Named(DEFAULT_BUCKET) BucketName defaultBucket) {
+                           CassandraCacheConfiguration cacheConfiguration) {
         this.cache = cache;
         this.backend = backend;
         this.sizeThresholdInBytes = cacheConfiguration.getSizeThresholdInBytes();
-        this.defaultBucket = defaultBucket;
     }
 
     @Override
@@ -66,7 +59,7 @@ public class CachedBlobStore implements BlobStore {
         Preconditions.checkNotNull(bucketName, "bucketName should not be null");
 
         return Mono.just(bucketName)
-            .filter(defaultBucket::equals)
+            .filter(backend.getDefaultBucketName()::equals)
             .flatMap(ignored ->
                 Mono.from(cache.read(blobId))
                     .<InputStream>flatMap(bytes -> Mono.fromCallable(() -> new ByteArrayInputStream(bytes))))
@@ -78,7 +71,7 @@ public class CachedBlobStore implements BlobStore {
     @Override
     public Mono<byte[]> readBytes(BucketName bucketName, BlobId blobId) {
         return Mono.just(bucketName)
-            .filter(defaultBucket::equals)
+            .filter(backend.getDefaultBucketName()::equals)
             .flatMap(ignored -> Mono.from(cache.read(blobId)))
             .switchIfEmpty(Mono.from(backend.readBytes(bucketName, blobId)));
     }
@@ -119,14 +112,14 @@ public class CachedBlobStore implements BlobStore {
 
     @Override
     public BucketName getDefaultBucketName() {
-        return defaultBucket;
+        return backend.getDefaultBucketName();
     }
 
     @Override
     public Mono<Void> delete(BucketName bucketName, BlobId blobId) {
         return Mono.from(backend.delete(bucketName, blobId))
             .then(Mono.just(bucketName)
-                .filter(defaultBucket::equals)
+                .filter(backend.getDefaultBucketName()::equals)
                 .flatMap(ignored -> Mono.from(cache.remove(blobId)))
                 .then());
     }
@@ -166,6 +159,6 @@ public class CachedBlobStore implements BlobStore {
     }
 
     private boolean isAbleToCache(BucketName bucketName, StoragePolicy storagePolicy) {
-        return defaultBucket.equals(bucketName) && !storagePolicy.equals(LOW_COST);
+        return backend.getDefaultBucketName().equals(bucketName) && !storagePolicy.equals(LOW_COST);
     }
 }
diff --git a/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/cache/CachedBlobStoreTest.java b/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/cache/CachedBlobStoreTest.java
index 1ca51df..debea77 100644
--- a/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/cache/CachedBlobStoreTest.java
+++ b/server/blob/blob-cassandra/src/test/java/org/apache/james/blob/cassandra/cache/CachedBlobStoreTest.java
@@ -71,7 +71,7 @@ public class CachedBlobStoreTest implements BlobStoreContract {
             .sizeThresholdInBytes(EIGHT_KILOBYTES.length + 1)
             .build();
         cache = new CassandraBlobStoreCache(cassandra.getConf(), cacheConfig);
-        testee = new CachedBlobStore(cache, backend, cacheConfig, DEFAULT);
+        testee = new CachedBlobStore(cache, backend, cacheConfig);
     }
 
     @Override


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