david-streamlio commented on a change in pull request #2865: Refactored JCloud 
Tiered Storage
URL: https://github.com/apache/pulsar/pull/2865#discussion_r239079196
 
 

 ##########
 File path: 
tiered-storage/jcloud/src/main/java/org/apache/bookkeeper/mledger/offload/jcloud/impl/BlobStoreManagedLedgerOffloader.java
 ##########
 @@ -483,59 +227,37 @@ public String getOffloadDriverName() {
         return promise;
     }
 
-    String getReadRegion(Map<String, String> offloadDriverMetadata) {
-        return offloadDriverMetadata.getOrDefault(METADATA_FIELD_REGION, 
writeRegion);
-    }
-
-    String getReadBucket(Map<String, String> offloadDriverMetadata) {
-        return offloadDriverMetadata.getOrDefault(METADATA_FIELD_BUCKET, 
writeBucket);
-    }
-
-    String getReadEndpoint(Map<String, String> offloadDriverMetadata) {
-        return offloadDriverMetadata.getOrDefault(METADATA_FIELD_ENDPOINT, 
writeEndpoint);
-    }
-
-    BlobStore getReadBlobStore(Map<String, String> offloadDriverMetadata) {
-        BlobStoreLocation location = BlobStoreLocation.of(
-            getReadRegion(offloadDriverMetadata),
-            getReadEndpoint(offloadDriverMetadata)
-        );
-        BlobStore blobStore = readBlobStores.get(location);
-        if (null == blobStore) {
-            blobStore = createBlobStore(
-                offloadDriverName,
-                location.getRegion(),
-                location.getEndpoint(),
-                credentials,
-                maxBlockSize
-            ).getRight();
-            BlobStore existingBlobStore = readBlobStores.putIfAbsent(location, 
blobStore);
-            if (null == existingBlobStore) {
-                return blobStore;
-            } else {
-                return existingBlobStore;
-            }
-        } else {
-            return blobStore;
-        }
+    /**
+     * Attempts to create a BlobStoreLocation from the values in the 
offloadDriverMetadata,
+     * however, if no values are available, it defaults to the currently 
configured
+     * provider, region, bucket, etc.
+     *
+     * @param offloadDriverMetadata
+     * @return
+     */
+    private BlobStoreLocation getBlobStoreLocation(Map<String, String> 
offloadDriverMetadata) {
+        return (!offloadDriverMetadata.isEmpty()) ? new 
BlobStoreLocation(offloadDriverMetadata) :
+            new BlobStoreLocation(getOffloadDriverMetadata());
     }
 
     @Override
     public CompletableFuture<ReadHandle> readOffloaded(long ledgerId, UUID uid,
                                                        Map<String, String> 
offloadDriverMetadata) {
-        String readBucket = getReadBucket(offloadDriverMetadata);
-        BlobStore readBlobstore = getReadBlobStore(offloadDriverMetadata);
+
+        BlobStoreLocation bsKey = getBlobStoreLocation(offloadDriverMetadata);
+        String readBucket = bsKey.getBucket();
+        BlobStore readBlobstore = blobStore;
 
 Review comment:
   I will limit the scope of the BlobStoreRepository.  Without it, all of the 
unit tests that interact with the blobstore more than once, i.e write, then 
read to verify the results, fail. This is due to the fact that for the unit 
tests I use the transient blog store, so every invocation of the getBlobStore() 
method creates a new instance, which doesn't have the data that was written to 
the previous blogStore.  This isn't an issue for AWS, etc blog stores, as the 
same configuration points to the same location on S3.
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to