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 @@ -510,10 +510,11 @@ disk-level and server-level settings surface.
is committed to the pool (never the object-storage key prefix). Defaults to
`<clickhouse-path>/disks/<disk_name>/cas_scratch/`. A relative override is anchored to the server
data path, not the process's current working directory.
- `cas_staging_backend` — `local` (default) or `s3`. Selects where in-flight part data is staged before
being committed into the pool; `local` is byte-for-byte the original write path, `s3` enables
S3-native staging. A writable disk configured with `s3` must support native same-store copy and
fails closed instead of falling back to client-side copy.
- `cas_staging_backend` — `local` (default) or `s3`. Selects where CAS stages part files that always
use blob placement, such as column data and marks. A writable disk configured with `s3` requires native
same-store copy. Files eligible for inline placement stay in memory up to 1 MiB per file.
Crossing that threshold spills the file to local temporary storage with either backend. At commit,
CAS can also select smaller files for blob placement to fit the 16 MiB inline budget per manifest.
- `cas_blob_hash` — `cityhash128` (default), `xxh3-128`, or `sha256`. Selects the pool's blob
content-hash function. The choice is fixed at pool creation; a reopen whose `cas_blob_hash` disagrees
with the pool's recorded algorithm fails closed. See
Expand Down
6 changes: 6 additions & 0 deletions docs/en/antalya/metrics_and_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ This counter covers batch deletion of write-once keys.
| --- | --- | --- |
| `CASBulkDeleteRequests` | `Number` | Number of CAS batch delete requests: one DeleteObjects carrying up to 1000 write-once keys (manifest bodies, ref logs, ref snapshots). The per-key class counters (CASManifestDelete, CASRootDelete) say how many keys each request carried. |

#### Manifest inline budget {#cas-manifest-inline-budget}

| Event | Type | Description |
| --- | --- | --- |
| `CASManifestInlineEntriesSelectedForBlob` | `Number` | Number of staged CAS file entries selected for blob placement because their manifest exceeded the total inline byte budget. |

#### Manifest requests {#cas-manifest-requests}

These counters total object-store requests for manifest keys.
Expand Down
1 change: 1 addition & 0 deletions src/Common/ProfileEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ The server successfully detected this situation and will download merged part fr
M(CASRefRepoint, "Number of CAS committed-reference repoints that republish a manifest. Growth indicates standalone part updates or removals.", ValueType::Number) \
M(CASRefMove, "Number of CAS committed-reference renames done as one ref-log owner move, with no manifest republication.", ValueType::Number) \
M(CASOwnershipConflict, "Number of CAS operations refused with CAS_OWNERSHIP_CONFLICT: the committed reference the writer had read was moved, dropped or repointed before its change landed.", ValueType::Number) \
M(CASManifestInlineEntriesSelectedForBlob, "Number of staged CAS file entries selected for blob placement because their manifest exceeded the total inline byte budget.", ValueType::Number) \
M(CASManifestPut, "Number of CAS manifest PUT requests. Grows with manifest creation and indicates metadata write traffic.", ValueType::Number) \
M(CASManifestPutDeduplicated, "Number of CAS deduplicating manifest PUT requests. Grows when existing manifests are reused.", ValueType::Number) \
M(CASManifestOverwrite, "Number of CAS manifest overwrite requests. Growing values indicate repeated manifest replacement.", ValueType::Number) \
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace DB
/// `Cas::PartWriteTxn`, created lazily before the first staged dependency, so the durable manifest
/// edge is established before the pool observes or uploads a new blob.
///
/// Content blobs are first represented by local or S3 staging objects and are uploaded only during
/// publication. Inline entries remain in the manifest tree when they fit `INLINE_CAP`. The
/// File writes stage blobs locally or on S3. During publication the transaction also moves
/// excess inline entries into blobs, uploading them directly from their buffered bytes. The
/// destructor removes the transaction's local and S3 staging and abandons any open part builds;
/// it never publishes an uncommitted ref.
class ContentAddressedTransaction : public IMetadataTransaction
Expand Down Expand Up @@ -86,8 +86,8 @@ class ContentAddressedTransaction : public IMetadataTransaction
const std::string & path, size_t buf_size, WriteMode mode,
const WriteSettings & settings, bool autocommit) override;

/// Creates the inner buffer for a content-addressed path. Part blobs are hashed while being
/// staged, small metadata files are accumulated in memory and classified at finalize, and
/// Creates the inner buffer for a content-addressed path. Inline candidates that outgrow
/// the per-file limit stream to local staging. Part blobs are hashed as they are written, and
/// verbatim namespace or mountpoint files are read-modify-written when append is requested.
std::unique_ptr<WriteBufferFromFileBase> writeFile(
const std::string & path,
Expand Down Expand Up @@ -223,9 +223,9 @@ class ContentAddressedTransaction : public IMetadataTransaction
/// The refs of `st`'s pending uploads, collected once per publication.
using PendingRefs = std::unordered_set<Cas::BlobRef, Cas::BlobRefHash>;
/// Confirms each distinct committed source of `st`'s adopted entries, skipping entries whose ref is in
/// `pending_refs`. Runs after the precommit of `st.build` is durable and before its promote; on a refusal it
/// `blob_refs_with_upload_requests`. Runs after the precommit of `st.build` is durable and before its promote; on a refusal it
/// abandons the build and throws `NO_REPLICA_HAS_PART`, and on a failed read it abandons the build and rethrows.
void confirmCopySources(const Cas::RootNamespace & ns, const std::string & ref, PartStaging & st, const PendingRefs & pending_refs);
void confirmCopySources(const Cas::RootNamespace & ns, const std::string & ref, PartStaging & st, const PendingRefs & blob_refs_with_upload_requests);
/// After this transaction renamed `from` to `to`, points the borrow of `from` at `to`, when the rename moved the
/// manifest the borrow read and `to` still commits the manifest the rename produced. Any other borrow keeps its
/// source, and its confirmation refuses it.
Expand All @@ -249,15 +249,12 @@ class ContentAddressedTransaction : public IMetadataTransaction
/// alike. S3 deletes are best-effort; a lost delete leaves debris for the mount-start sweep.
void cleanupPendingTempFiles() noexcept;

/// Uploads through `st.build` only the pending blobs still referenced by `st.entries`. An entry
/// removed by `unlinkFile` or `replaceFile` is skipped, but its staging resource is still cleaned
/// by `cleanupPendingTempFiles`. Used for both new refs and committed-ref repoints.
void uploadPendingBlobs(PartStaging & st);
/// Append sources from local or S3 staging only for blob refs still named by the staged entries.
void appendStagedBlobUploads(const PartStaging & st, std::vector<Cas::BlobUploadRequest> & blob_upload_requests) const;

/// Stages `st.entries` as a manifest of `st.build`, precommits it at `ref`, confirms the copy sources and uploads
/// the pending blobs, in that order. Returns the staged manifest's id.
/// Stage the manifest and precommit its blob refs before confirming copied files and uploading payloads.
Cas::ManifestId precommitAndUpload(const Cas::RootNamespace & ns, const std::string & ref, PartStaging & st,
const PendingRefs & pending_refs);
const PendingRefs & blob_refs_with_upload_requests, const std::vector<Cas::BlobUploadRequest> & blob_upload_requests);

/// Adopts a manifest entry into another part while preserving its storage state. For a pending
/// blob, `copy_pending` controls whether the staging record is copied (hardlink semantics) or
Expand Down Expand Up @@ -297,15 +294,15 @@ namespace DB::Cas
/// Part files that must NOT be inlined into the tree: per-column data (`.bin`) and marks (`.mrk*`/
/// `.cmrk*`) — inlining them would force a full-part fetch and destroy column-read selectivity — plus
/// `primary.idx`, which can be large (a size-threshold inlining of small primary.idx is a follow-up).
/// Everything else (the small eager metadata files) is an inline candidate, subject to INLINE_CAP.
/// Other files are inline candidates, subject to the per-entry and total manifest byte limits.
bool partFileMustStayBlob(std::string_view file_name);

/// Opens a locally staged blob payload of `payload_size` bytes for upload, with a read buffer no larger
/// than the payload.
std::unique_ptr<ReadBuffer> openLocalStagedBlobPayload(const std::string & path, uint64_t payload_size);

/// Test-only fault-injection seams for the intra-part blob-upload fan-out. Inert in production
/// (`ContentAddressedTransaction::uploadPendingBlobs` passes `nullptr`).
/// (`ContentAddressedTransaction::precommitAndUpload` passes `nullptr`).
struct BlobUploadFanoutHooksForTest
{
/// Invoked ONCE per DISPATCHED task, on the calling (dispatch) thread, immediately before the task
Expand Down Expand Up @@ -453,10 +450,7 @@ class CaContentWriteBuffer : public WriteBufferFromFileBase
std::function<void()> check_fence_before_finalize;
};

/// Write buffer for bytes that live INSIDE pool metadata (a small inline part file staged into the
/// manifest tree, or a verbatim namespace file PUT on finalize). Accumulates in memory (the bytes are
/// tiny) and hands them to the callback at finalize; the callback decides where they go and whether
/// they are durable immediately (verbatim) or at commit (staged into the part's manifest entries).
/// Accumulates a verbatim namespace or mountpoint file for the write performed at finalize.
class CaInlineWriteBuffer : public WriteBufferFromFileBase
{
public:
Expand All @@ -471,8 +465,7 @@ class CaInlineWriteBuffer : public WriteBufferFromFileBase
private:
/// Appends bytes to the in-memory payload under the base write-buffer contract.
void nextImpl() override;
/// Hands the complete inline payload to the callback; the callback decides whether it is staged
/// in a manifest or written immediately as a verbatim file.
/// Passes the complete verbatim payload to the callback.
void finalizeImpl() override;

OnInlined on_inlined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ namespace

/// Backpressure caps, enforced fail-closed in stageManifest before the body write returns.
constexpr uint64_t kMaxManifestEntries = 1048576;
constexpr uint64_t kMaxManifestInlineBytesTotal = 16ULL << 20; /// 16 MiB
constexpr uint64_t kMaxLargestInlineEntryBytes = 1ULL << 20; /// 1 MiB

/// Two thread_local_rng draws composed into a UInt128. Used both to mint build ids and to mint, on
/// every upload/re-upload, a FRESH incarnation_tag (W-FRESH-TAG).
Expand Down Expand Up @@ -169,11 +167,23 @@ BlobSource BlobSource::fromString(String bytes)
{
BlobSource source;
source.size = bytes.size();
/// Owning reader: `ReadBufferFromString` only borrows, and this factory outlives no single call
/// -- an owning copy per attempt removes the question entirely for a source that is small by
/// construction (this helper exists for tests and inline payloads).
source.open = [b = std::move(bytes)]() -> std::unique_ptr<ReadBuffer>
{ return std::make_unique<ReadBufferFromOwnString>(b); };
/// Requests copied into the upload queue and readers opened on retry share the payload.
/// Each reader owns a reference independently of the lifetime of the request.
class Reader final : public ReadBufferFromString
{
public:
explicit Reader(std::shared_ptr<const String> bytes_)
: ReadBufferFromString(*bytes_), payload_owner(std::move(bytes_))
{
}

private:
std::shared_ptr<const String> payload_owner;
};
source.open = [owner = std::make_shared<const String>(std::move(bytes))]
{
return std::make_unique<Reader>(owner);
};
return source;
}

Expand Down Expand Up @@ -627,10 +637,10 @@ ManifestId PartWriteTxn::stageManifest(std::vector<ManifestEntry> entries)
{
if (e.placement == EntryPlacement::Inline)
{
if (e.inline_bytes.size() > kMaxLargestInlineEntryBytes)
if (e.inline_bytes.size() > kMaxManifestInlineEntryBytes)
throw Exception(ErrorCodes::LIMIT_EXCEEDED,
"stageManifest: inline entry '{}' of {} bytes exceeds cap {}",
e.path, e.inline_bytes.size(), kMaxLargestInlineEntryBytes);
e.path, e.inline_bytes.size(), kMaxManifestInlineEntryBytes);
inline_total += e.inline_bytes.size();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace DB { class WriteBuffer; }
namespace DB::Cas
{

inline constexpr uint64_t kMaxManifestInlineEntryBytes = 1ULL << 20; /// 1 MiB
inline constexpr uint64_t kMaxManifestInlineBytesTotal = 16ULL << 20; /// 16 MiB

/// Re-readable source for one content-addressed blob upload.
///
/// `open` returns a fresh reader over exactly `size` logical bytes and may be called more than once.
Expand Down
3 changes: 2 additions & 1 deletion src/Disks/IO/WriteBufferInlineOrBlob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ void WriteBufferInlineOrBlob::spill()
underlying = create_underlying();
if (!accumulated.empty())
underlying->write(accumulated.data(), accumulated.size());
accumulated.clear();

String{}.swap(accumulated);
}

void WriteBufferInlineOrBlob::nextImpl()
Expand Down
Loading
Loading