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
2 changes: 2 additions & 0 deletions docs/en/antalya/cas/bucket-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Bucket **versioning is not required** — in fact it must be **disabled** on the
dialect (see below), because a token-exact delete on a versioned bucket archives a noncurrent
generation instead of reclaiming storage, silently stopping GC reclamation.

On S3 (`ETag` dialect), an unversioned bucket is the default and recommended setup. If a bucket previously had versioning enabled and is now **`Suspended`**, `DeleteObject` on S3 still creates a `"null"`-version delete marker (`x-amz-delete-marker: true`), which `CasProbe` and GC reject by default (`CAS_DELETE_MARKER` / `NOT_IMPLEMENTED`). When the bucket's versioning status is `Suspended` (never `Enabled`) and an S3 lifecycle rule with `ExpiredObjectDeleteMarker: true` (and `NoncurrentVersionExpiration`) is configured, set `<cas_allow_versioning_suspended>true</cas_allow_versioning_suspended>` on the disk to allow mounting and delete-marker acceptance while still rejecting `Enabled` buckets.

On the generation-token dialect that requirement is checked at mount. A bucket reported as versioned
refuses the mount. A probe that could not answer — the credential may not read the bucket's versioning
configuration (`storage.buckets.get` on GCS), or the backend cannot report it — does not: the mount
Expand Down
1 change: 1 addition & 0 deletions docs/en/antalya/cas/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ entirely before release. Treat this table as a snapshot of the current build, no
| `cas_blob_hash` | `cityhash128` | Pool blob content-hash function (`cityhash128` \| `xxh3-128` \| `sha256`). Recorded in the pool at creation; a mismatching config is refused at mount |
| `cas_blob_hash_allow_new` | `false` | Explicit opt-in to admit a new hash algorithm into an existing pool. One-way: once admitted, the pool carries both algorithms permanently |
| `cas_allow_packed_parts` | `false` | Allow creation of new `Packed` MergeTree parts on this disk. The decision uses the actual destination disk, not every disk in its storage policy. A `type=cache` disk inherits this capability from the wrapped `CAS` disk; set the key in the `metadata_type=cas` disk block. Existing `Packed` parts remain readable when this setting is `false` |
| `cas_allow_versioning_suspended` | `false` | Allow mounting an S3 (`ETag`-dialect) bucket whose versioning status is `Suspended` and accept `"null"`-version delete markers on conditional deletes (`DeleteObject`). Buckets with versioning `Enabled` are still refused. Pair with an S3 lifecycle rule setting `ExpiredObjectDeleteMarker: true` (and `NoncurrentVersionExpiration` for any prior noncurrent versions) |
| `skip_access_check` | `false` | Skip the boot-time capability probe (start now, fix later). Only the preflight probe is skipped — the check that the object storage supports single-attempt conditional writes still runs on every ordinary writable start. **Not available on a writable generation-token (GCS) disk**, which refuses to mount with it: there, the probe battery is the only proof that a token-exact delete carries its generation precondition. Mount such a disk read-only if you need to defer the check |
| `cas_mount_lease_ttl_ms` | `40000` | How long this server may write after its last confirmed renewal; every other server waits at least this long before fencing or reclaiming its slot (≥ 1, at most 600000 — a larger value is clamped to 10 minutes with a warning at startup, so no holder declares a longer lease). Lower values shorten recovery after this server's crash but reduce tolerance for object-storage and scheduling delays. Set `30000` for faster recovery after a crash, at the costs [below](#mount-lease-costs) |
| `cas_mount_renew_period_ms` | `10000` | Milliseconds between background mount-lease renewals (≥ 1). It must leave enough time for two attempt envelopes (a renewal write and its settlement read) and the lease safety margin before the TTL expires: `period + 2 × envelope + margin < TTL` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,32 +128,75 @@ void recordConditionalWriteOutcome(CasWriteOutcome outcome)

ObjectStorageBackend::ObjectStorageBackend(ObjectStoragePtr object_storage_, Mode mode_,
bool single_attempt_control_plane_, uint64_t attempt_timeout_ms_,
uint64_t connect_timeout_cap_ms_)
uint64_t connect_timeout_cap_ms_,
bool allow_versioning_suspended_)
: object_storage(std::move(object_storage_))
, mode(mode_)
, single_attempt_control_plane(single_attempt_control_plane_)
, attempt_timeout_ms(attempt_timeout_ms_)
, connect_timeout_cap_ms(connect_timeout_cap_ms_)
, allow_versioning_suspended(allow_versioning_suspended_)
, emu_root(object_storage->getCommonKeyPrefix())
{
if (mode == Mode::Native && object_storage->conditionalOpsUseGenerationTokens())
native_token_type = Dialect::Generation;
}

/// See Backend::checkPoolPreconditions. Only the Native, generation-dialect (GCS) combination has
/// anything to check: a token-exact DELETE on a versioned bucket archives a noncurrent generation
/// instead of reclaiming storage, so GC "reclaim" would silently stop reclaiming. A bucket VERIFIED
/// to have versioning enabled refuses the mount. A probe that cannot answer does not: it is not
/// evidence of a versioned bucket, its usual cause is a credential without permission to read the
/// bucket configuration, and refusing on it would turn a missing IAM grant into a hard outage. The
/// mount proceeds with a warning that names what was not verified and how the operator can verify it.
/// The probe uses this backend's control-plane profile, because the default client would retry a failed
/// attempt with SDK backoff, outside the mount's attempt budget.
bool ObjectStorageBackend::verifySuspendedVersioningAllowed() const
{
if (!allow_versioning_suspended || mode != Mode::Native || native_token_type == Dialect::Generation)
return false;

if (suspended_delete_markers_checked.load(std::memory_order_acquire))
return suspended_delete_markers_allowed.load(std::memory_order_acquire);

const auto status = object_storage->getBucketVersioningStatus(controlRequest(/*attempt_no=*/0));
if (status == IObjectStorage::BucketVersioningStatus::Enabled)
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED,
"CAS on S3: the bucket has object VERSIONING Enabled. `cas_allow_versioning_suspended=true` "
"only permits Suspended (or unversioned) buckets; an Enabled bucket archives noncurrent "
"versions on every overwrite and delete forever. Suspend or disable versioning and expire "
"noncurrent versions before mounting.");
}

if (status == IObjectStorage::BucketVersioningStatus::Suspended)
{
LOG_WARNING(getLogger("CasObjectStorageBackend"),
"CAS on S3: bucket versioning is Suspended and `cas_allow_versioning_suspended=true`; "
"allowing null-version delete markers on conditional deletes. Configure an S3 lifecycle rule "
"with `ExpiredObjectDeleteMarker: true` (and expire any prior noncurrent versions) so delete "
"markers do not accumulate.");
}
else if (status == IObjectStorage::BucketVersioningStatus::Unknown)
{
LOG_WARNING(getLogger("CasObjectStorageBackend"),
"CAS on S3: could not verify bucket versioning status (GetBucketVersioning failed or "
"unsupported); allowing delete markers because `cas_allow_versioning_suspended=true`. Confirm "
"by hand that versioning is Suspended (never Enabled) and configure an "
"`ExpiredObjectDeleteMarker: true` lifecycle rule.");
}

suspended_delete_markers_allowed.store(true, std::memory_order_release);
suspended_delete_markers_checked.store(true, std::memory_order_release);
return true;
}

/// See Backend::checkPoolPreconditions.
/// - Native + Generation (GCS): refuses Enabled/Suspended buckets; tolerates Unknown with warning.
/// - Native + ETag (S3): when `allow_versioning_suspended` is true, verifies the bucket is not
/// `Enabled` and arms delete-marker acceptance for `Suspended` buckets before the probe runs.
void ObjectStorageBackend::checkPoolPreconditions()
{
if (mode != Mode::Native || native_token_type != Dialect::Generation)
if (mode != Mode::Native)
return;

if (native_token_type != Dialect::Generation)
{
(void)verifySuspendedVersioningAllowed();
return;
}

const auto versioned = object_storage->isBucketVersioningEnabled(controlRequest(/*attempt_no=*/0));
if (!versioned.has_value())
{
Expand Down Expand Up @@ -970,9 +1013,12 @@ Backend::RawRemoval ObjectStorageBackend::removeUnder(
switch (result.outcome)
{
case ConditionalRemoveOutcome::Removed:
/// A delete marker means the storage archived a noncurrent version instead of
/// reclaiming the current object -- a removal that did not reclaim.
return result.created_delete_marker ? RawRemoval::DeleteMarker : RawRemoval::Removed;
/// A delete marker means the storage archived a noncurrent version (or minted a
/// null-version delete marker on a Suspended S3 bucket). Only permit it when
/// `cas_allow_versioning_suspended=true` and `Enabled` versioning has been ruled out.
if (result.created_delete_marker)
return verifySuspendedVersioningAllowed() ? RawRemoval::Removed : RawRemoval::DeleteMarker;
return RawRemoval::Removed;
case ConditionalRemoveOutcome::TokenMismatch:
return RawRemoval::Mismatch;
case ConditionalRemoveOutcome::NotFound:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Backend/CasBackend.h>
#include <Disks/DiskObjectStorage/MetadataStorages/ContentAddressed/Backend/CasRequestBudget.h>
#include <Disks/DiskObjectStorage/ObjectStorages/IObjectStorage.h>
#include <atomic>
#include <deque>
#include <map>
#include <mutex>
Expand Down Expand Up @@ -71,7 +72,8 @@ class ObjectStorageBackend final : public Backend
/// that opens the pool; the defaults are what a narrow unit test constructing a bare backend gets.
ObjectStorageBackend(ObjectStoragePtr object_storage_, Mode mode_,
bool single_attempt_control_plane_ = false, uint64_t attempt_timeout_ms_ = 0,
uint64_t connect_timeout_cap_ms_ = 0);
uint64_t connect_timeout_cap_ms_ = 0,
bool allow_versioning_suspended_ = false);

/// Read the whole object, or return `nullopt` if it is absent. Native mode reads the incarnation
/// value out of the GET response itself, so no HEAD precedes it; a not-found race is reported as
Expand Down Expand Up @@ -225,6 +227,14 @@ class ObjectStorageBackend final : public Backend
const bool single_attempt_control_plane;
const uint64_t attempt_timeout_ms;
const uint64_t connect_timeout_cap_ms;
const bool allow_versioning_suspended;
mutable std::atomic<bool> suspended_delete_markers_checked{false};
mutable std::atomic<bool> suspended_delete_markers_allowed{false};

/// Checks `getBucketVersioningStatus` once when `allow_versioning_suspended` is enabled;
/// always refuses `BucketVersioningStatus::Enabled` and permits `Suspended` (or `Unknown`
/// with an explicit warning) when opted in.
bool verifySuspendedVersioningAllowed() const;
ObjectStorageRetryProfile controlPlaneProfile() const
{
return single_attempt_control_plane ? ObjectStorageRetryProfile::SingleAttempt : ObjectStorageRetryProfile::Default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ Removal removeOrReportDeleteMarker(CasOperation & op, const String & key, const
throw;
throw DB::Exception(DB::ErrorCodes::NOT_IMPLEMENTED,
"CasProbe: remove succeeded but created a versioning delete marker — the bucket has "
"object VERSIONING enabled, and a content-addressed pool cannot run on a versioned bucket: "
"every GC delete would archive a noncurrent version instead of reclaiming storage (the bucket "
"grows forever), and the constantly-rewritten ref objects would pile up versions on every "
"commit. Use a bucket where versioning was NEVER enabled; skip_access_check skips this probe "
"but does not make a versioned bucket usable — note that merely SUSPENDING versioning is not enough (deletes on a "
"versioning-suspended bucket still mint delete markers, so this probe will refuse again)");
"object VERSIONING enabled or suspended, and a content-addressed pool cannot run on an "
"actively versioned bucket: every GC delete would archive a noncurrent version instead of "
"reclaiming storage (the bucket grows forever), and the constantly-rewritten ref objects "
"would pile up versions on every commit. Use an unversioned bucket, or — if versioning is "
"Suspended (never Enabled) and an ExpiredObjectDeleteMarker lifecycle rule is configured — "
"set <cas_allow_versioning_suspended>true</cas_allow_versioning_suspended> on the disk; "
"skip_access_check skips this probe but does not bypass delete-marker refusal");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace ContentAddressedSetting
extern const ContentAddressedSettingsUInt64 mount_lease_ttl_ms;
extern const ContentAddressedSettingsUInt64 mount_renew_period_ms;
extern const ContentAddressedSettingsBool unsafe_remount_no_delay;
extern const ContentAddressedSettingsBool allow_versioning_suspended;
extern const ContentAddressedSettingsUInt64 part_folder_cache_bytes;
extern const ContentAddressedSettingsUInt64 part_folder_cache_max_entries;
extern const ContentAddressedSettingsUInt64 part_folder_cache_max_entry_bytes;
Expand Down Expand Up @@ -311,6 +312,7 @@ ContentAddressedMetadataStorage::ContentAddressedMetadataStorage(
, mount_lease_ttl(std::chrono::milliseconds(settings_[ContentAddressedSetting::mount_lease_ttl_ms].value))
, mount_renew_period(std::chrono::milliseconds(settings_[ContentAddressedSetting::mount_renew_period_ms].value))
, cas_unsafe_remount_no_delay(settings_[ContentAddressedSetting::unsafe_remount_no_delay].value)
, cas_allow_versioning_suspended(settings_[ContentAddressedSetting::allow_versioning_suspended].value)
, cas_part_folder_cache_bytes(settings_[ContentAddressedSetting::part_folder_cache_bytes].value)
, cas_part_folder_cache_max_entries(settings_[ContentAddressedSetting::part_folder_cache_max_entries].value)
, cas_part_folder_cache_max_entry_bytes(settings_[ContentAddressedSetting::part_folder_cache_max_entry_bytes].value)
Expand Down Expand Up @@ -851,7 +853,8 @@ ContentAddressedMetadataStorage::PoolView ContentAddressedMetadataStorage::openP
object_storage, mode,
/*single_attempt_control_plane_=*/!read_only && mode == Cas::ObjectStorageBackend::Mode::Native,
pool_config.cas_request_budget.attempt_timeout_ms,
pool_config.cas_request_budget.connect_timeout_cap_ms.value_or(0));
pool_config.cas_request_budget.connect_timeout_cap_ms.value_or(0),
cas_allow_versioning_suspended);

/// A programmer error, not an input one: the handoff above is code, not configuration. The pool's
/// lease arithmetic was validated against `pool_config.cas_request_budget` alone (never against the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ class ContentAddressedMetadataStorage final : public IMetadataStorage, public IC
/// See `PoolConfig::unsafe_remount_no_delay` -- the operator's explicit acceptance of an
/// unobserved same-uuid reclaim.
const bool cas_unsafe_remount_no_delay;
const bool cas_allow_versioning_suspended;
/// Part-folder view cache settings. `cas_part_folder_cache_bytes == 0` disables retention.
const uint64_t cas_part_folder_cache_bytes;
const uint64_t cas_part_folder_cache_max_entries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ constexpr std::string_view CAS_KEY_PREFIX = "cas_";
DECLARE(UInt64, request_window_ms, 120000, "How long a failing request, including the blob publication loop, keeps retrying before it gives up with a retryable error, in milliseconds, measured from the call's start. Must exceed twice the attempt envelope for a writable disk and the envelope for a read-only one, or the disk refuses to open. The ref-table recovery budget is twice this value", 0) \
DECLARE(UInt64, lease_safety_margin_ms, 2000, "Startup-only margin validated against the mount lease TTL: attempt envelope + this must be strictly less than the TTL, and renew period + 2 × envelope + this too", 0) \
DECLARE(String, staging_backend, "local", "Blob staging backend (local | s3); s3 is opt-in", 0) \
DECLARE(Bool, allow_versioning_suspended, false, "Allow mounting an S3 bucket whose versioning status is Suspended (never Enabled); requires an S3 lifecycle rule expiring null delete markers", 0) \

DECLARE_SETTINGS_TRAITS(ContentAddressedSettingsTraits, LIST_OF_CONTENT_ADDRESSED_SETTINGS, CONTENT_ADDRESSED_SETTINGS_SUPPORTED_TYPES)

Expand Down
19 changes: 19 additions & 0 deletions src/Disks/DiskObjectStorage/ObjectStorages/IObjectStorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,25 @@ class IObjectStorage
/// Unpinned by default, so an ordinary storage's settings and reload behaviour are unchanged.
virtual void pinConditionalOpsGenerationDialect(bool /*expect_generation_tokens*/) {}

/// Bucket object-versioning state reported by object storage backends that expose it.
enum class BucketVersioningStatus : uint8_t
{
Unknown,
Disabled,
Suspended,
Enabled,
};

/// Returns the bucket's object-versioning state when the backend can inspect it.
/// Defaults to mapping `isBucketVersioningEnabled(request)` for test stubs that only override it.
virtual BucketVersioningStatus getBucketVersioningStatus(const ObjectStorageControlRequest & request) const
{
const auto enabled = isBucketVersioningEnabled(request);
if (!enabled.has_value())
return BucketVersioningStatus::Unknown;
return *enabled ? BucketVersioningStatus::Enabled : BucketVersioningStatus::Disabled;
}

/// Whether the underlying bucket has object versioning enabled; nullopt when unknown or not
/// applicable. Used by the CAS capability probe on GCS: a bucket verified as versioned refuses
/// the mount (a token-exact DELETE there archives a noncurrent generation instead of reclaiming
Expand Down
Loading