Skip to content

Commit 8c5e37c

Browse files
author
Sophie Guo
committed
pass in md5 in request internal header for secondary router
1 parent 0a6a01a commit 8c5e37c

File tree

13 files changed

+43
-28
lines changed

13 files changed

+43
-28
lines changed

ambry-api/src/main/java/com/github/ambry/rest/RestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ public static final class InternalKeys {
554554
/**
555555
* The key is to help identify get content or get md5. If the value is true, it means get md5 only for a getContent call.
556556
*/
557-
public static final String REQUEST_MD5_ONLY = KEY_PREFIX + "request-md5-only";
557+
public static final String BLOB_MD5 = KEY_PREFIX + "blob-md5";
558558
}
559559

560560
/**

ambry-frontend/src/main/java/com/github/ambry/frontend/DeleteBlobHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.github.ambry.rest.RestUtils;
3636
import com.github.ambry.router.Router;
3737
import com.github.ambry.utils.Pair;
38-
import java.io.IOException;
3938
import java.util.GregorianCalendar;
4039
import java.util.Map;
4140
import org.slf4j.Logger;

ambry-frontend/src/main/java/com/github/ambry/frontend/FrontendRestRequestService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public void start() throws InstantiationException {
199199

200200
getBlobHandler =
201201
new GetBlobHandler(frontendConfig, router, securityService, idConverter, accountAndContainerInjector,
202-
frontendMetrics, clusterMap, quotaManager, accountService);
202+
frontendMetrics, clusterMap, quotaManager, accountService, namedBlobDb);
203203
postBlobHandler =
204204
new PostBlobHandler(securityService, idConverter, idSigningService, router, accountAndContainerInjector,
205205
SystemTime.getInstance(), frontendConfig, frontendMetrics, clusterName, quotaManager);

ambry-frontend/src/main/java/com/github/ambry/frontend/GetBlobHandler.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.github.ambry.commons.Callback;
2424
import com.github.ambry.config.FrontendConfig;
2525
import com.github.ambry.messageformat.BlobInfo;
26+
import com.github.ambry.named.NamedBlobDb;
27+
import com.github.ambry.protocol.GetOption;
2628
import com.github.ambry.quota.QuotaManager;
2729
import com.github.ambry.quota.QuotaUtils;
2830
import com.github.ambry.rest.RequestPath;
@@ -73,10 +75,11 @@ public class GetBlobHandler {
7375
private final QuotaManager quotaManager;
7476
private final GetReplicasHandler getReplicasHandler;
7577
private final AccountService accountService;
78+
private final NamedBlobDb namedBlobDb;
7679

7780
GetBlobHandler(FrontendConfig frontendConfig, Router router, SecurityService securityService, IdConverter idConverter,
7881
AccountAndContainerInjector accountAndContainerInjector, FrontendMetrics metrics, ClusterMap clusterMap,
79-
QuotaManager quotaManager, AccountService accountService) {
82+
QuotaManager quotaManager, AccountService accountService, NamedBlobDb namedBlobDb) {
8083
this.frontendConfig = frontendConfig;
8184
this.router = router;
8285
this.securityService = securityService;
@@ -87,6 +90,7 @@ public class GetBlobHandler {
8790
this.quotaManager = quotaManager;
8891
getReplicasHandler = new GetReplicasHandler(metrics, clusterMap);
8992
this.accountService = accountService;
93+
this.namedBlobDb = namedBlobDb;
9094
}
9195

9296
public void handle(RequestPath requestPath, RestRequest restRequest, RestResponseChannel restResponseChannel,
@@ -100,6 +104,18 @@ public void handle(RequestPath requestPath, RestRequest restRequest, RestRespons
100104
if (requestPath.matchesOperation(Operations.NAMED_BLOB)) {
101105
accountAndContainerInjector.injectAccountContainerForNamedBlob(restRequest, metricsGroup);
102106
}
107+
if (RestUtils.isS3Request(restRequest)) {
108+
NamedBlobPath namedBlobPath = NamedBlobPath.parse(getRequestPath(restRequest), restRequest.getArgs());
109+
GetOption getOption = RestUtils.getGetOption(restRequest, GetOption.None);
110+
if (namedBlobDb != null) {
111+
namedBlobDb.get(namedBlobPath.getAccountName(), namedBlobPath.getContainerName(), namedBlobPath.getBlobName(),
112+
getOption, false).thenAccept(record -> {
113+
if (record != null) {
114+
restRequest.setArg(BLOB_MD5, record.getDigest());
115+
}
116+
});
117+
}
118+
}
103119
restRequest.getMetricsTracker().injectMetrics(restRequestMetrics);
104120
new CallbackChain(restRequest, restResponseChannel, metricsGroup, requestPath, subResource, options,
105121
callback).start();

ambry-frontend/src/main/java/com/github/ambry/frontend/ListDatasetVersionHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.github.ambry.router.ReadableStreamChannel;
2727
import java.util.GregorianCalendar;
2828
import java.util.function.Function;
29-
import org.json.JSONObject;
3029
import org.slf4j.Logger;
3130
import org.slf4j.LoggerFactory;
3231

ambry-frontend/src/main/java/com/github/ambry/frontend/TtlUpdateHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.slf4j.LoggerFactory;
3737

3838
import static com.github.ambry.frontend.FrontendUtils.*;
39-
import static com.github.ambry.rest.RestUtils.InternalKeys.*;
4039

4140

4241
/**

ambry-frontend/src/main/java/com/github/ambry/frontend/s3/S3MultipartListPartsHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.github.ambry.rest.RestRequest;
2727
import com.github.ambry.rest.RestResponseChannel;
2828
import com.github.ambry.rest.RestServiceException;
29-
import com.github.ambry.rest.RestUtils;
3029
import com.github.ambry.router.ReadableStreamChannel;
3130
import java.io.ByteArrayOutputStream;
3231
import java.io.IOException;

ambry-frontend/src/test/java/com/github/ambry/frontend/FrontendUtilsTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.github.ambry.rest.RestServiceException;
2424
import com.github.ambry.utils.TestUtils;
2525
import java.io.IOException;
26+
import java.security.NoSuchAlgorithmException;
2627
import java.util.Arrays;
2728
import java.util.List;
2829
import java.util.stream.Collectors;
@@ -106,4 +107,17 @@ private void assertBlobIdFieldValues(BlobId blobId, BlobId.BlobIdType type, byte
106107
assertEquals("Wrong container id in blobId: " + blobId, containerId, blobId.getContainerId());
107108
assertEquals("Wrong isEncrypted value in blobId: " + blobId, isEncrypted, BlobId.isEncrypted(blobId.getID()));
108109
}
110+
111+
/**
112+
*
113+
* @param content
114+
* @return String of md5
115+
* @throws NoSuchAlgorithmException
116+
*/
117+
public static String calculateMD5(byte[] content) throws NoSuchAlgorithmException {
118+
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
119+
byte[] digest = md.digest(content);
120+
return org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(digest);
121+
}
122+
109123
}

ambry-frontend/src/test/java/com/github/ambry/frontend/NamedBlobPutHandlerTest.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import org.json.JSONObject;
7878
import org.junit.Test;
7979

80+
import static com.github.ambry.frontend.FrontendUtilsTest.*;
8081
import static org.junit.Assert.*;
8182

8283

@@ -677,18 +678,6 @@ private void putBlobAndVerifyDigest(ThrowingConsumer<ExecutionException> errorCh
677678
}
678679
}
679680

680-
/**
681-
*
682-
* @param content
683-
* @return String of md5
684-
* @throws NoSuchAlgorithmException
685-
*/
686-
private String calculateMD5(byte[] content) throws NoSuchAlgorithmException {
687-
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
688-
byte[] digest = md.digest(content);
689-
return org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString(digest);
690-
}
691-
692681
/**
693682
* Make a stitch blob call using {@link PostBlobHandler} and verify the result of the operation.
694683
* @param errorChecker if non-null, expect an exception to be thrown by the post flow and verify it using this

ambry-frontend/src/test/java/com/github/ambry/frontend/PostBlobHandlerTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import com.github.ambry.rest.RestUtils;
5151
import com.github.ambry.router.ChunkInfo;
5252
import com.github.ambry.router.FutureResult;
53-
import com.github.ambry.router.GetBlobResult;
5453
import com.github.ambry.router.InMemoryRouter;
5554
import com.github.ambry.router.PutBlobOptionsBuilder;
5655
import com.github.ambry.router.ReadableStreamChannel;
@@ -67,7 +66,6 @@
6766
import java.nio.charset.StandardCharsets;
6867
import java.util.ArrayList;
6968
import java.util.Arrays;
70-
import java.util.Base64;
7169
import java.util.Collections;
7270
import java.util.HashMap;
7371
import java.util.LinkedList;
@@ -79,17 +77,14 @@
7977
import java.util.concurrent.TimeUnit;
8078
import java.util.stream.Collectors;
8179
import java.util.stream.Stream;
82-
import org.apache.commons.lang3.tuple.Pair;
8380
import org.json.JSONObject;
8481
import org.junit.Test;
8582
import org.junit.runner.RunWith;
8683
import org.junit.runners.Parameterized;
8784
import org.mockito.Mockito;
8885

8986
import static com.github.ambry.frontend.FrontendRestRequestServiceTest.*;
90-
import static com.github.ambry.rest.RestUtils.InternalKeys.*;
9187
import static org.junit.Assert.*;
92-
import static org.mockito.Mockito.*;
9388

9489

9590
/**
@@ -401,7 +396,7 @@ private void initGetBlobHandler(Properties properties) {
401396
VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
402397
frontendConfig = new FrontendConfig(verifiableProperties);
403398
getBlobHandler = new GetBlobHandler(frontendConfig, router, securityServiceFactory.getSecurityService(),
404-
idConverterFactory.getIdConverter(), injector, metrics, CLUSTER_MAP, QUOTA_MANAGER, ACCOUNT_SERVICE);
399+
idConverterFactory.getIdConverter(), injector, metrics, CLUSTER_MAP, QUOTA_MANAGER, ACCOUNT_SERVICE, null);
405400
}
406401

407402
private void initDeleteBlobHandler(Properties props) {

0 commit comments

Comments
 (0)