Skip to content

Commit 2b2e86d

Browse files
code refactoring based on latest review comments
1 parent e12aa82 commit 2b2e86d

15 files changed

Lines changed: 132 additions & 703 deletions

File tree

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/util/BlobConstants.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,6 @@ public final class BlobConstants {
3131
* The number of buffers to use if none is specified on the buffered upload method.
3232
*/
3333
public static final int BLOB_DEFAULT_NUMBER_OF_BUFFERS = 8;
34-
/**
35-
* The legacy default number of concurrent transfers for download operations.
36-
*/
37-
public static final int BLOB_LEGACY_DEFAULT_CONCURRENT_TRANSFERS_COUNT = 5;
38-
/**
39-
* The default range size used for download operations when no checksum validation is requested.
40-
*/
41-
public static final long BLOB_DEFAULT_DOWNLOAD_RANGE_SIZE = 4L * Constants.MB;
42-
/**
43-
* The default initial range size used for download operations when no checksum validation is requested.
44-
*/
45-
public static final long BLOB_DEFAULT_INITIAL_DOWNLOAD_RANGE_SIZE = 256L * Constants.MB;
46-
/**
47-
* The maximum range size used for download operations.
48-
*/
49-
public static final long BLOB_MAX_DOWNLOAD_BYTES = 256L * Constants.MB;
50-
/**
51-
* The maximum range size used when requesting a transactional checksum during download.
52-
*/
53-
public static final long BLOB_MAX_HASH_REQUEST_DOWNLOAD_RANGE = 4L * Constants.MB;
5434
/**
5535
* If a blob is known to be greater than 100MB, using a larger block size will trigger some server-side
5636
* optimizations. If the block size is not set and the size of the blob is known to be greater than 100MB, this

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/util/BuilderHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public static HttpPipeline buildPipeline(StorageSharedKeyCredential storageShare
116116
}
117117
policies.add(new MetadataValidationPolicy());
118118

119+
policies.add(new StorageContentValidationDecoderPolicy());
120+
119121
if (storageSharedKeyCredential != null) {
120122
policies.add(new StorageSharedKeyCredentialPolicy(storageSharedKeyCredential));
121123
}
@@ -134,8 +136,6 @@ public static HttpPipeline buildPipeline(StorageSharedKeyCredential storageShare
134136
policies.add(new AzureSasCredentialPolicy(new AzureSasCredential(sasToken), false));
135137
}
136138

137-
policies.add(new StorageContentValidationDecoderPolicy());
138-
139139
policies.addAll(perRetryPolicies);
140140

141141
HttpPolicyProviders.addAfterRetryPolicies(policies);

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/util/ChunkedDownloadUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ && extractTotalBlobLength(
122122

123123
BiFunction<BlobRange, BlobRequestConditions, Mono<BlobDownloadAsyncResponse>> fallbackDownloader
124124
= emptyBlobDownloader != null ? emptyBlobDownloader : downloader;
125-
return fallbackDownloader.apply(new BlobRange(0), requestConditions)
125+
return fallbackDownloader.apply(new BlobRange(0, 0L), requestConditions)
126126
// Subscribe on boundElastic instead of elastic as elastic is deprecated and boundElastic
127127
// provided the same functionality with the added benefit that it won't infinitely create
128128
// threads if needed and will instead queue.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.storage.blob.implementation.util;
5+
6+
import com.azure.core.util.Context;
7+
import com.azure.storage.common.StorageChecksumAlgorithm;
8+
import com.azure.storage.common.implementation.Constants;
9+
import com.azure.storage.common.policy.AggregateCrcState;
10+
11+
import java.util.concurrent.atomic.AtomicReference;
12+
13+
import com.azure.storage.common.policy.DecoderState;
14+
15+
/**
16+
* Centralizes download content validation decisions based on {@link StorageChecksumAlgorithm}.
17+
* <p>
18+
* Mirrors the pattern established by {@code ContentValidationModeResolver} for uploads.
19+
* <p>
20+
* RESERVED FOR INTERNAL USE.
21+
*/
22+
public final class DownloadValidationUtils {
23+
24+
private DownloadValidationUtils() {
25+
}
26+
27+
/**
28+
* Whether the algorithm requires structured message decoding (CRC64 / AUTO).
29+
*/
30+
public static boolean isStructuredMessageAlgorithm(StorageChecksumAlgorithm algorithm) {
31+
return algorithm == StorageChecksumAlgorithm.CRC64 || algorithm == StorageChecksumAlgorithm.AUTO;
32+
}
33+
34+
/**
35+
* Resolves the effective algorithm, defaulting null to NONE.
36+
*/
37+
public static StorageChecksumAlgorithm resolveAlgorithm(StorageChecksumAlgorithm algorithm) {
38+
return algorithm != null ? algorithm : StorageChecksumAlgorithm.NONE;
39+
}
40+
41+
/**
42+
* Adds structured message decoding context keys when CRC64/AUTO validation is active.
43+
*
44+
* @param context The base context to augment. Null is treated as {@link Context#NONE}.
45+
* @param algorithm The resolved checksum algorithm.
46+
* @param decoderStateRef Holder for decoder state, populated by the policy.
47+
* @param aggregateCrcState CRC aggregation state across retries.
48+
* @return The augmented context.
49+
*/
50+
public static Context applyStructuredMessageContext(Context context, StorageChecksumAlgorithm algorithm,
51+
AtomicReference<DecoderState> decoderStateRef, AggregateCrcState aggregateCrcState) {
52+
Context base = context == null ? Context.NONE : context;
53+
if (!isStructuredMessageAlgorithm(algorithm)) {
54+
return base;
55+
}
56+
return base.addData(Constants.STRUCTURED_MESSAGE_RESPONSE_SCOPED_CONTEXT_KEY, true)
57+
.addData(Constants.STRUCTURED_MESSAGE_DECODING_CONTEXT_KEY, true)
58+
.addData(Constants.STRUCTURED_MESSAGE_DECODER_STATE_REF_CONTEXT_KEY, decoderStateRef)
59+
.addData(Constants.STRUCTURED_MESSAGE_AGGREGATE_CRC_CONTEXT_KEY, aggregateCrcState);
60+
}
61+
}

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/util/ModelHelper.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ public static ParallelTransferOptions populateAndApplyDefaults(ParallelTransferO
111111
blockSize = (long) BlobAsyncClient.BLOB_DEFAULT_UPLOAD_BLOCK_SIZE;
112112
}
113113

114-
Long initialTransferSize = other.getInitialTransferSizeLong();
115-
116114
Integer maxConcurrency = other.getMaxConcurrency();
117115
if (maxConcurrency == null) {
118116
maxConcurrency = BlobAsyncClient.BLOB_DEFAULT_NUMBER_OF_BUFFERS;
@@ -126,8 +124,7 @@ public static ParallelTransferOptions populateAndApplyDefaults(ParallelTransferO
126124
return new ParallelTransferOptions().setBlockSizeLong(blockSize)
127125
.setMaxConcurrency(maxConcurrency)
128126
.setProgressListener(other.getProgressListener())
129-
.setMaxSingleUploadSizeLong(maxSingleUploadSize)
130-
.setInitialTransferSizeLong(initialTransferSize);
127+
.setMaxSingleUploadSizeLong(maxSingleUploadSize);
131128
}
132129

133130
/**
@@ -146,8 +143,6 @@ public static ParallelTransferOptions populateAndApplyDefaults(ParallelTransferO
146143
blockSize = (long) BlobAsyncClient.BLOB_DEFAULT_UPLOAD_BLOCK_SIZE;
147144
}
148145

149-
Long initialTransferSize = other.getInitialTransferSizeLong();
150-
151146
Integer maxConcurrency = other.getMaxConcurrency();
152147
if (maxConcurrency == null) {
153148
maxConcurrency = BlobAsyncClient.BLOB_DEFAULT_NUMBER_OF_BUFFERS;
@@ -161,8 +156,7 @@ public static ParallelTransferOptions populateAndApplyDefaults(ParallelTransferO
161156
return new com.azure.storage.common.ParallelTransferOptions().setBlockSizeLong(blockSize)
162157
.setMaxConcurrency(maxConcurrency)
163158
.setProgressListener(other.getProgressListener())
164-
.setMaxSingleUploadSizeLong(maxSingleUploadSize)
165-
.setInitialTransferSizeLong(initialTransferSize);
159+
.setMaxSingleUploadSizeLong(maxSingleUploadSize);
166160
}
167161

168162
/**
@@ -175,8 +169,7 @@ public static ParallelTransferOptions populateAndApplyDefaults(ParallelTransferO
175169
return new com.azure.storage.common.ParallelTransferOptions().setBlockSizeLong(blobOptions.getBlockSizeLong())
176170
.setMaxConcurrency(blobOptions.getMaxConcurrency())
177171
.setProgressListener(blobOptions.getProgressListener())
178-
.setMaxSingleUploadSizeLong(blobOptions.getMaxSingleUploadSizeLong())
179-
.setInitialTransferSizeLong(blobOptions.getInitialTransferSizeLong());
172+
.setMaxSingleUploadSizeLong(blobOptions.getMaxSingleUploadSizeLong());
180173
}
181174

182175
/**

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/models/ParallelTransferOptions.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
public final class ParallelTransferOptions {
1818

1919
private Long blockSize;
20-
private Long initialTransferSize;
2120
private Integer maxConcurrency;
2221
private ProgressReceiver progressReceiver;
2322
private Long maxSingleUploadSize;
@@ -102,29 +101,6 @@ public Long getBlockSizeLong() {
102101
return this.blockSize;
103102
}
104103

105-
/**
106-
* Gets the size of the first range requested when downloading.
107-
* @return The initial transfer size.
108-
*/
109-
public Long getInitialTransferSizeLong() {
110-
return this.initialTransferSize;
111-
}
112-
113-
/**
114-
* Sets the size of the first range requested when downloading.
115-
* This value may be larger than the block size used for subsequent ranges.
116-
*
117-
* @param initialTransferSize The initial transfer size.
118-
* @return The ParallelTransferOptions object itself.
119-
*/
120-
public ParallelTransferOptions setInitialTransferSizeLong(Long initialTransferSize) {
121-
if (initialTransferSize != null) {
122-
StorageImplUtils.assertInBounds("initialTransferSize", initialTransferSize, 1, Long.MAX_VALUE);
123-
}
124-
this.initialTransferSize = initialTransferSize;
125-
return this;
126-
}
127-
128104
/**
129105
* Sets the block size (chunk size) to transfer at a time.
130106
* For upload, The block size is the size of each block that will be staged. This value also determines the number

0 commit comments

Comments
 (0)