Skip to content

Commit

Permalink
TieredStorage: add debug information (apache#14907)
Browse files Browse the repository at this point in the history
* TieredStorage: add debug information
- enable SLF4 logging in JClouds
- add Pulsar Cluster name in Objects metadata
- log object names during offloading
  • Loading branch information
eolivelli authored Mar 29, 2022
1 parent cffe28a commit 83dad0a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions jclouds-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<artifactId>jclouds-allblobstore</artifactId>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>org.apache.jclouds.driver</groupId>
<artifactId>jclouds-slf4j</artifactId>
<version>${jclouds.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ default CompletableFuture<Boolean> asyncClose() {
// TODO: improve the user metadata in subsequent changes
String METADATA_SOFTWARE_VERSION_KEY = "S3ManagedLedgerOffloaderSoftwareVersion";
String METADATA_SOFTWARE_GITSHA_KEY = "S3ManagedLedgerOffloaderSoftwareGitSha";
String METADATA_PULSAR_CLUSTER_NAME = "pulsarClusterName";

/**
* Get offload driver name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,8 @@ public synchronized LedgerOffloader createManagedLedgerOffloader(OffloadPolicies
offloadPolicies,
ImmutableMap.of(
LedgerOffloader.METADATA_SOFTWARE_VERSION_KEY.toLowerCase(), PulsarVersion.getVersion(),
LedgerOffloader.METADATA_SOFTWARE_GITSHA_KEY.toLowerCase(), PulsarVersion.getGitSha()
LedgerOffloader.METADATA_SOFTWARE_GITSHA_KEY.toLowerCase(), PulsarVersion.getGitSha(),
LedgerOffloader.METADATA_PULSAR_CLUSTER_NAME.toLowerCase(), config.getClusterName()
),
schemaStorage,
getOffloaderScheduler(offloadPolicies));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.common.collect.Lists;
import java.io.IOException;
import java.time.Duration;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -173,14 +174,20 @@ public CompletableFuture<Void> offload(ReadHandle readHandle,
.withDataBlockHeaderLength(BlockAwareSegmentInputStreamImpl.getHeaderSize());
String dataBlockKey = DataBlockUtils.dataBlockOffloadKey(readHandle.getId(), uuid);
String indexBlockKey = DataBlockUtils.indexBlockOffloadKey(readHandle.getId(), uuid);
log.info("ledger {} dataBlockKey {} indexBlockKey {}", readHandle.getId(), dataBlockKey, indexBlockKey);

MultipartUpload mpu = null;
List<MultipartPart> parts = Lists.newArrayList();

// init multi part upload for data block.
try {
BlobBuilder blobBuilder = writeBlobStore.blobBuilder(dataBlockKey);
DataBlockUtils.addVersionInfo(blobBuilder, userMetadata);
Map<String, String> objectMetadata = new HashMap<>(userMetadata);
objectMetadata.put("role", "data");
if (extraMetadata != null) {
objectMetadata.putAll(extraMetadata);
}
DataBlockUtils.addVersionInfo(blobBuilder, objectMetadata);
Blob blob = blobBuilder.build();
mpu = writeBlobStore.initiateMultipartUpload(config.getBucket(), blob.getMetadata(), new PutOptions());
} catch (Throwable t) {
Expand Down Expand Up @@ -243,7 +250,12 @@ public CompletableFuture<Void> offload(ReadHandle readHandle,
IndexInputStream indexStream = index.toStream()) {
// write the index block
BlobBuilder blobBuilder = writeBlobStore.blobBuilder(indexBlockKey);
DataBlockUtils.addVersionInfo(blobBuilder, userMetadata);
Map<String, String> objectMetadata = new HashMap<>(userMetadata);
objectMetadata.put("role", "index");
if (extraMetadata != null) {
objectMetadata.putAll(extraMetadata);
}
DataBlockUtils.addVersionInfo(blobBuilder, objectMetadata);
Payload indexPayload = Payloads.newInputStreamPayload(indexStream);
indexPayload.getContentMetadata().setContentLength((long) indexStream.getStreamSize());
indexPayload.getContentMetadata().setContentType("application/octet-stream");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Properties;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -56,6 +57,7 @@
import org.jclouds.domain.LocationScope;
import org.jclouds.googlecloud.GoogleCredentialsFromJson;
import org.jclouds.googlecloudstorage.GoogleCloudStorageProviderMetadata;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.providers.AnonymousProviderMetadata;
import org.jclouds.providers.ProviderMetadata;
import org.jclouds.s3.S3ApiMetadata;
Expand Down Expand Up @@ -136,6 +138,7 @@ public void validate(TieredStorageConfiguration config) throws IllegalArgumentEx
@Override
public BlobStore getBlobStore(TieredStorageConfiguration config) {
ContextBuilder contextBuilder = ContextBuilder.newBuilder(config.getProviderMetadata());
contextBuilder.modules(Arrays.asList(new SLF4JLoggingModule()));
contextBuilder.overrides(config.getOverrides());

if (config.getProviderCredentials() != null) {
Expand Down Expand Up @@ -201,6 +204,7 @@ public void validate(TieredStorageConfiguration config) throws IllegalArgumentEx
public BlobStore getBlobStore(TieredStorageConfiguration config) {

ContextBuilder builder = ContextBuilder.newBuilder("transient");
builder.modules(Arrays.asList(new SLF4JLoggingModule()));
BlobStoreContext ctx = builder
.buildView(BlobStoreContext.class);

Expand Down Expand Up @@ -283,6 +287,7 @@ public ProviderMetadata getProviderMetadata() {

static final BlobStoreBuilder BLOB_STORE_BUILDER = (TieredStorageConfiguration config) -> {
ContextBuilder contextBuilder = ContextBuilder.newBuilder(config.getProviderMetadata());
contextBuilder.modules(Arrays.asList(new SLF4JLoggingModule()));
contextBuilder.overrides(config.getOverrides());

if (StringUtils.isNotEmpty(config.getServiceEndpoint())) {
Expand Down Expand Up @@ -367,6 +372,7 @@ public String getAWSSecretKey() {

static final BlobStoreBuilder ALIYUN_OSS_BLOB_STORE_BUILDER = (TieredStorageConfiguration config) -> {
ContextBuilder contextBuilder = ContextBuilder.newBuilder(config.getProviderMetadata());
contextBuilder.modules(Arrays.asList(new SLF4JLoggingModule()));
Properties overrides = config.getOverrides();
// For security reasons, OSS supports only virtual hosted style access.
overrides.setProperty(S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "true");
Expand Down

0 comments on commit 83dad0a

Please sign in to comment.