Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class FrontendConfig {
public static final String MAX_JSON_REQUEST_SIZE_BYTES_KEY = PREFIX + "max.json.request.size.bytes";
public static final String ENABLE_UNDELETE = PREFIX + "enable.undelete";
public static final String NAMED_BLOB_DB_FACTORY = PREFIX + "named.blob.db.factory";
public static final String NAMED_BLOB_RETIREMENT_NAMESPACE = PREFIX + "named.blob.retirement.namespace";
public static final String NAMED_BLOB_RETIREMENT_PAUSED = PREFIX + "named.blob.retirement.paused";
public static final String CONTAINER_METRICS_EXCLUDED_ACCOUNTS = PREFIX + "container.metrics.excluded.accounts";
public static final String CONTAINER_METRICS_AGGREGATED_ACCOUNTS = PREFIX + "container.metrics.aggregated.accounts";
public static final String INVALID_ASCII_BLOB_NAME_CHARS = PREFIX + "invalid.ascii.blob.name.chars";
Expand Down Expand Up @@ -335,6 +337,16 @@ public class FrontendConfig {
@Default("null")
public final String namedBlobDbFactory;

/** One account/container for single-object named DELETE retirement. Empty disables it. */
@Config(NAMED_BLOB_RETIREMENT_NAMESPACE)
@Default("")
public final String namedBlobRetirementNamespace;

/** Reject named DELETE in the configured retirement namespace without restoring legacy DELETE. */
@Config(NAMED_BLOB_RETIREMENT_PAUSED)
@Default("false")
public final boolean namedBlobRetirementPaused;

/**
* The comma separated list of account names for which container metrics should not be generated.
*/
Expand Down Expand Up @@ -451,6 +463,14 @@ public FrontendConfig(VerifiableProperties verifiableProperties) {
accountStatsStoreFactory =
verifiableProperties.getString(ACCOUNT_STATS_STORE_FACTORY, DEFAULT_ACCOUNT_STATS_STORE_FACTORY);
namedBlobDbFactory = verifiableProperties.getString(NAMED_BLOB_DB_FACTORY, null);
namedBlobRetirementNamespace = verifiableProperties.getString(NAMED_BLOB_RETIREMENT_NAMESPACE, "");
if (!namedBlobRetirementNamespace.isEmpty() && !namedBlobRetirementNamespace.matches("[^/]+/[^/]+")) {
throw new IllegalArgumentException(NAMED_BLOB_RETIREMENT_NAMESPACE + " must be empty or account/container");
}
namedBlobRetirementPaused = verifiableProperties.getBoolean(NAMED_BLOB_RETIREMENT_PAUSED, false);
if (namedBlobRetirementPaused && namedBlobRetirementNamespace.isEmpty()) {
throw new IllegalArgumentException(NAMED_BLOB_RETIREMENT_PAUSED + " requires " + NAMED_BLOB_RETIREMENT_NAMESPACE);
}
containerMetricsExcludedAccounts =
Utils.splitString(verifiableProperties.getString(CONTAINER_METRICS_EXCLUDED_ACCOUNTS, ""), ",");
containerMetricsAggregatedAccounts =
Expand Down
19 changes: 19 additions & 0 deletions ambry-api/src/main/java/com/github/ambry/named/NamedBlobDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import com.github.ambry.frontend.Page;
import com.github.ambry.protocol.GetOption;
import com.github.ambry.protocol.NamedBlobState;
import com.github.ambry.rest.RestServiceErrorCode;
import com.github.ambry.rest.RestServiceException;
import com.github.ambry.store.StoreKey;
import com.github.ambry.store.StoreKeyFactory;
import java.io.Closeable;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -108,6 +112,21 @@ default CompletableFuture<PutResult> put(NamedBlobRecord record) {
*/
CompletableFuture<DeleteResult> delete(String accountName, String containerName, String blobName);

/**
* Retire the unfenced versions of the authorized name without deleting data. Blocks on the caller's worker.
* The loader must return the full ordered child list of the exact root, decoding at most the supplied limit.
* A publication is successful only after commit or positive confirmation of the original intent.
*/
default void retire(Container container, String blobName, StoreKeyFactory keyFactory, RetirementLoader loader)
throws Exception {
throw new RestServiceException("Named retirement is unavailable", RestServiceErrorCode.ServiceUnavailable);
}

@FunctionalInterface
interface RetirementLoader {
List<? extends StoreKey> load(StoreKey root, int maxChildren) throws Exception;
}

/**
* Pull the stale blobs that need to be cleaned up
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ public static final class InternalKeys {
* The internal header to determine if the delete request is coming from a dataset deletion.
*/
public static final String DATASET_DELETE_ENABLED = KEY_PREFIX + "dataset-delete-enabled";
public static final String S3_BATCH_DELETE_SUBREQUEST = KEY_PREFIX + "s3-batch-delete-subrequest";


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class GetBlobOptions {
private final boolean rawMode;
private final int blobSegmentIdx;
private final RestRequest restRequest;
private final int maxChunkIds;
private final boolean bypassNotFoundCache;
static final int NO_CHUNK_ID_LIMIT = -1;
public static final int NO_BLOB_SEGMENT_IDX_SPECIFIED = -1;

/**
Expand All @@ -51,6 +54,13 @@ public class GetBlobOptions {
*/
public GetBlobOptions(OperationType operationType, GetOption getOption, ByteRange range,
boolean resolveRangeOnEmptyBlob, boolean rawMode, int blobSegmentIdx, RestRequest restRequest) {
this(operationType, getOption, range, resolveRangeOnEmptyBlob, rawMode, blobSegmentIdx, restRequest,
NO_CHUNK_ID_LIMIT, false);
}

GetBlobOptions(OperationType operationType, GetOption getOption, ByteRange range,
boolean resolveRangeOnEmptyBlob, boolean rawMode, int blobSegmentIdx, RestRequest restRequest, int maxChunkIds,
boolean bypassNotFoundCache) {
if (operationType == null || getOption == null) {
throw new IllegalArgumentException("operationType and getOption must be defined");
}
Expand All @@ -60,6 +70,12 @@ public GetBlobOptions(OperationType operationType, GetOption getOption, ByteRang
if (rawMode && operationType != OperationType.All) {
throw new IllegalArgumentException("Raw mode can be used only with OperationType.ALL");
}
if (maxChunkIds != NO_CHUNK_ID_LIMIT && (operationType != OperationType.BlobChunkIds || range != null
|| blobSegmentIdx != NO_BLOB_SEGMENT_IDX_SPECIFIED)) {
throw new IllegalArgumentException("maxChunkIds requires BlobChunkIds without a range or segment");
}
this.maxChunkIds = maxChunkIds;
this.bypassNotFoundCache = bypassNotFoundCache;
this.operationType = operationType;
this.getOption = getOption;
this.range = range;
Expand Down Expand Up @@ -126,10 +142,33 @@ public RestRequest getRestRequest() {
return restRequest;
}

/**
* @return whether the caller supplied a chunk ID limit.
*/
public boolean hasMaxChunkIds() {
return maxChunkIds != NO_CHUNK_ID_LIMIT;
}

/**
* @return the maximum number of child IDs to decode, or {@code -1} if no limit was supplied.
*/
public int getMaxChunkIds() {
return maxChunkIds;
}

/**
* @return whether the router should query storage despite a cached not-found result.
*/
public boolean shouldBypassNotFoundCache() {
return bypassNotFoundCache;
}

@Override
public String toString() {
return "GetBlobOptions{operationType=" + operationType + ", getOption=" + getOption + ", range=" + range
+ ", rawMode=" + rawMode + ", blobSegmentIdx=" + blobSegmentIdx + ", restRequest=" + restRequest + '}';
+ ", rawMode=" + rawMode + ", blobSegmentIdx=" + blobSegmentIdx + ", restRequest=" + restRequest
+ (hasMaxChunkIds() ? ", maxChunkIds=" + maxChunkIds : "")
+ (bypassNotFoundCache ? ", bypassNotFoundCache=true" : "") + '}';
}

@Override
Expand All @@ -141,14 +180,17 @@ public boolean equals(Object o) {
return false;
}
GetBlobOptions that = (GetBlobOptions) o;
return resolveRangeOnEmptyBlob == that.resolveRangeOnEmptyBlob && rawMode == that.rawMode
&& blobSegmentIdx == that.blobSegmentIdx && operationType == that.operationType && getOption == that.getOption
return maxChunkIds == that.maxChunkIds && bypassNotFoundCache == that.bypassNotFoundCache
&& resolveRangeOnEmptyBlob == that.resolveRangeOnEmptyBlob
&& rawMode == that.rawMode && blobSegmentIdx == that.blobSegmentIdx && operationType == that.operationType
&& getOption == that.getOption
&& Objects.equals(range, that.range) && Objects.equals(restRequest, that.restRequest);
}

@Override
public int hashCode() {
return Objects.hash(operationType, getOption, range, resolveRangeOnEmptyBlob, rawMode, blobSegmentIdx, restRequest);
return Objects.hash(operationType, getOption, range, resolveRangeOnEmptyBlob, rawMode, blobSegmentIdx, restRequest,
maxChunkIds, bypassNotFoundCache);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class GetBlobOptionsBuilder {
private boolean rawMode = false;
private RestRequest restRequest = null;
private int blobSegmentIdx = NO_BLOB_SEGMENT_IDX_SPECIFIED;
private int maxChunkIds = NO_CHUNK_ID_LIMIT;
private boolean bypassNotFoundCache;

/**
* @param operationType the {@link GetBlobOptions.OperationType} for this request.
Expand Down Expand Up @@ -100,11 +102,35 @@ public GetBlobOptionsBuilder blobSegment(int blobSegmentIdx) {
return this;
}

/**
* Limit an exact, whole-blob {@link GetBlobOptions.OperationType#BlobChunkIds} request.
* The request returns no data channel and fails with {@link RouterErrorCode#BlobTooLarge} if the metadata
* declares more child IDs than the limit. A limit of zero permits blobs with no child IDs.
* @param maxChunkIds the nonnegative remaining child ID budget.
* @return this builder
*/
public GetBlobOptionsBuilder maxChunkIds(int maxChunkIds) {
if (maxChunkIds < 0) {
throw new IllegalArgumentException("maxChunkIds must be nonnegative");
}
this.maxChunkIds = maxChunkIds;
return this;
}

/**
* @param bypassNotFoundCache whether to ignore cached not-found results when starting the GET.
* @return this builder
*/
public GetBlobOptionsBuilder bypassNotFoundCache(boolean bypassNotFoundCache) {
this.bypassNotFoundCache = bypassNotFoundCache;
return this;
}

/**
* @return the {@link GetBlobOptions} built.
*/
public GetBlobOptions build() {
return new GetBlobOptions(operationType, getOption, range, resolveRangeOnEmptyBlob, rawMode, blobSegmentIdx,
restRequest);
restRequest, maxChunkIds, bypassNotFoundCache);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
*/
public class FrontendConfigTest {

@Test
public void testRetirementPauseRejectsMissingNamespace() {
Properties properties = new Properties();
properties.setProperty(FrontendConfig.NAMED_BLOB_RETIREMENT_PAUSED, "true");
try {
new FrontendConfig(new VerifiableProperties(properties));
Assert.fail("A pause without a configured namespace would permit legacy DELETE");
} catch (IllegalArgumentException expected) {
Assert.assertTrue(expected.getMessage().contains(FrontendConfig.NAMED_BLOB_RETIREMENT_NAMESPACE));
}
}

@Test
public void testNamedBlobCleanupContainerDelaySeconds() {
Properties properties = new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ public void testRawModeWithInvalidCombinations() throws Exception {
TestUtils.assertException(IllegalArgumentException.class, () -> options.build(), null);
}

@Test
public void testMaxChunkIdsOption() throws Exception {
assertFalse(new GetBlobOptionsBuilder().build().hasMaxChunkIds());
GetBlobOptionsBuilder options = new GetBlobOptionsBuilder();
TestUtils.assertException(IllegalArgumentException.class, () -> options.maxChunkIds(-1), null);
for (GetBlobOptions.OperationType type : GetBlobOptions.OperationType.values()) {
if (type != GetBlobOptions.OperationType.BlobChunkIds) {
TestUtils.assertException(IllegalArgumentException.class,
() -> options.operationType(type).maxChunkIds(0).build(), null);
}
}
options.operationType(GetBlobOptions.OperationType.BlobChunkIds);
GetBlobOptions unbounded =
new GetBlobOptionsBuilder().operationType(GetBlobOptions.OperationType.BlobChunkIds).build();
GetBlobOptions bounded = options.maxChunkIds(0).build();
assertTrue(bounded.hasMaxChunkIds());
assertEquals(0, bounded.getMaxChunkIds());
assertOptionsAreDistinct(unbounded, bounded);
assertOptionsAreDistinct(bounded, options.maxChunkIds(1).build());
TestUtils.assertException(IllegalArgumentException.class,
() -> options.range(ByteRanges.fromLastNBytes(1)).build(), null);
TestUtils.assertException(IllegalArgumentException.class, () -> options.range(null).blobSegment(0).build(), null);
}

/**
* Test toString, equals, and hashCode methods.
*/
Expand Down
Loading
Loading