Skip to content

Commit

Permalink
OAK-10050 - Enable access to the secondary Azure blobstore service en…
Browse files Browse the repository at this point in the history
…dpoint in Oak segment node store (#820)
  • Loading branch information
dulceanu committed Mar 27, 2023
1 parent 0b1e9ad commit 1446e1b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
package org.apache.jackrabbit.oak.segment.azure;

import com.microsoft.azure.storage.CloudStorageAccount;
import com.microsoft.azure.storage.LocationMode;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.BlobRequestOptions;
import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.blob.CloudBlobContainer;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.oak.segment.spi.persistence.SegmentNodeStorePersistence;
Expand Down Expand Up @@ -52,6 +55,8 @@ public class AzureSegmentStoreService {

public static final String DEFAULT_ROOT_PATH = "/oak";

public static final boolean DEFAULT_ENABLE_SECONDARY_LOCATION = false;

private ServiceRegistration registration;

@Activate
Expand Down Expand Up @@ -103,7 +108,7 @@ private static AzurePersistence createPersistenceFromSasUri(Configuration config
if (!StringUtils.isBlank(configuration.blobEndpoint())) {
connectionString.append("BlobEndpoint=").append(configuration.blobEndpoint()).append(';');
}
return createAzurePersistence(connectionString.toString(), configuration, false);
return createAzurePersistence(connectionString.toString(), configuration, false);
}

@NotNull
Expand All @@ -120,7 +125,15 @@ private static AzurePersistence createAzurePersistence(
try {
CloudStorageAccount cloud = CloudStorageAccount.parse(connectionString);
log.info("Connection string: '{}'", cloud);
CloudBlobContainer container = cloud.createCloudBlobClient().getContainerReference(configuration.containerName());
CloudBlobClient cloudBlobClient = cloud.createCloudBlobClient();
BlobRequestOptions blobRequestOptions = new BlobRequestOptions();

if (configuration.enableSecondaryLocation()) {
blobRequestOptions.setLocationMode(LocationMode.PRIMARY_THEN_SECONDARY);
}
cloudBlobClient.setDefaultRequestOptions(blobRequestOptions);

CloudBlobContainer container = cloudBlobClient.getContainerReference(configuration.containerName());
if (createContainer) {
container.createIfNotExists();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,10 @@
"services in order to create services composed of multiple persistence instances. " +
"E.g. a SplitPersistence composed of a TAR persistence and an Azure persistence.")
String role() default "";

@AttributeDefinition(
name = "Azure segment store property to enable fallback to the secondary location",
description = "When set to true specifies that requests will be attempted in primary, then in secondary region." +
"Default value is '" + AzureSegmentStoreService.DEFAULT_ENABLE_SECONDARY_LOCATION + "'.")
boolean enableSecondaryLocation() default AzureSegmentStoreService.DEFAULT_ENABLE_SECONDARY_LOCATION;
}

0 comments on commit 1446e1b

Please sign in to comment.