Skip to content

Commit

Permalink
Support adding revision for dataset version auto incr
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Guo committed Nov 22, 2024
1 parent d33bb81 commit b73936b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.github.ambry.account.AccountCollectionSerde;
import com.github.ambry.account.Container;
import com.github.ambry.account.ContainerBuilder;
import com.github.ambry.account.DatasetBuilder;
import com.github.ambry.account.InMemAccountService;
import com.github.ambry.account.InMemAccountServiceFactory;
import com.github.ambry.clustermap.ClusterMap;
Expand Down Expand Up @@ -89,7 +90,7 @@
import org.junit.runners.Parameterized;
import com.github.ambry.account.Dataset;


import static com.github.ambry.rest.RestUtils.Headers.*;
import static com.github.ambry.utils.TestUtils.*;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
Expand Down Expand Up @@ -297,7 +298,49 @@ public void datasetTest() throws Exception {
doDeleteDatasetAndVerify(refAccount.getName(), namedBlobOptionalContainer.getName(), datasetList);
//After delete, it should have an empty list.
doListDatasetAndVerify(refAccount.getName(), namedBlobOptionalContainer.getName(), new ArrayList<>());
}

@Ignore
@Test
public void datasetOutOfRetentionTest() throws Exception {
Account refAccount = ACCOUNT_SERVICE.createAndAddRandomAccount();
Container namedBlobOptionalContainer =
new ContainerBuilder((short) 11, "optional", Container.ContainerStatus.ACTIVE, "",
refAccount.getId()).setNamedBlobMode(Container.NamedBlobMode.OPTIONAL).build();
ACCOUNT_SERVICE.updateContainers(refAccount.getName(), Arrays.asList(namedBlobOptionalContainer));
String contentType = "application/octet-stream";
String ownerId = "datasetTest";
String accountName = refAccount.getName();
String containerName = namedBlobOptionalContainer.getName();
String datasetName = "datasetNameRetention";
Dataset dataset = new DatasetBuilder(accountName, containerName, datasetName).setVersionSchema(
Dataset.VersionSchema.SEMANTIC_LONG).setRetentionCount(1).build();
HttpHeaders headers = new DefaultHttpHeaders();
//Test put dataset
putDatasetAndVerify(dataset, headers, false);
List<Dataset> datasetList = new ArrayList<>();
datasetList.add(dataset);
//put dataset version
headers = new DefaultHttpHeaders();
setAmbryHeadersForPut(headers, (long)-1, false, accountName, contentType, ownerId, null, null);
headers.add(RestUtils.Headers.DATASET_VERSION_QUERY_ENABLED, true);
int contentSize = 100;
ByteBuffer content = ByteBuffer.wrap(TestUtils.getRandomBytes(contentSize));
String version1 = "1.2.3.4";
putDatasetVersionAndVerify(dataset, version1, headers, content, contentSize, -1);
String version2 = "1.2.3.5";
putDatasetVersionAndVerify(dataset, version2, headers, content, contentSize, -1);

//Test List dataset version
InMemAccountService.PAGE_SIZE = -1;
HttpHeaders listHeaders = new DefaultHttpHeaders();
listHeaders.add(TARGET_ACCOUNT_NAME, dataset.getAccountName());
listHeaders.add(TARGET_CONTAINER_NAME, dataset.getContainerName());
listHeaders.add(TARGET_DATASET_NAME, dataset.getDatasetName());
listHeaders.add(ENABLE_DATASET_VERSION_LISTING, true);
listHeaders.add(RestUtils.Headers.DATASET_VERSION_QUERY_ENABLED, true);
List<Pair<String, String>> datasetVersions = listDatasetVersions(dataset, listHeaders);
assertEquals("Should only have 1 version", 1, datasetVersions.size());
}

@Ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ static RestRequestMetricsGroup getMetricsGroupForGet(FrontendMetrics frontendMet
*/
static void replaceRequestPathWithNewOperationOrBlobIdIfNeeded(RestRequest restRequest,
DatasetVersionRecord datasetVersionRecord, String version) throws RestServiceException {
if (version.equals("LATEST") || version.equals("MAJOR") || version.equals("MINOR") || version.equals("PATCH")) {
if (version.equals("LATEST") || version.equals("MAJOR") || version.equals("MINOR") || version.equals("PATCH")
|| version.equals("REVISION")) {
RequestPath originalRequestPath = (RequestPath) restRequest.getArgs().get(REQUEST_PATH);
String originalOperationOrBlobId = originalRequestPath.getOperationOrBlobId(false);
int index = originalOperationOrBlobId.lastIndexOf(PATH_SEPARATOR_STRING);
Expand Down Expand Up @@ -223,10 +224,10 @@ public static void reconstructRestRequest(RestRequest restRequest, DatasetVersio
restRequest.setArg(InternalKeys.REQUEST_PATH, newRequestPath);
restRequest.setArg(Headers.DATASET_VERSION_QUERY_ENABLED, "true");
if (restRequest.getArgs().get(InternalKeys.TARGET_ACCOUNT_KEY) != null) {
restRequest.setArg(InternalKeys.TARGET_ACCOUNT_KEY, null);
restRequest.removeArg(InternalKeys.TARGET_ACCOUNT_KEY);
}
if (restRequest.getArgs().get(InternalKeys.TARGET_CONTAINER_KEY) != null) {
restRequest.setArg(InternalKeys.TARGET_CONTAINER_KEY, null);
restRequest.removeArg(InternalKeys.TARGET_CONTAINER_KEY);
}
restRequest.setArg(Headers.DATASET_VERSION_QUERY_ENABLED, "true");
}
Expand Down

0 comments on commit b73936b

Please sign in to comment.