a database should be branchable without copying its object-storage files

Đang mở
#6,464 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
8/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Sôi nổi
Lĩnh vực
databases

Hướng nghiên cứu

This is an unresolved design proposal, not a scoped change: Q5 (pin versus follow) is still open and both approaches were only spiked. Start by reading dev/doc/gc.allium and dev/doc/block-gc.allium alongside the storage-root and epoch handling in DatabaseConfig and Database.validateOffsets, then the current deep-copy path (export-snapshot!) that the design would replace. Done is defined in the issue's P1-P6 properties: branch creation without O(N) object-store writes, writes invisible to the parent, and a parent GC run past garbage_lifetime breaking no branch query.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

You can't branch, clone or fork an XTDB database into a writable copy for testing without copying all of its object-storage files.

  • Prod testing needs a writable copy of prod's data that can never change prod.
    Examples: rehearsing a migration, trialling a new release against real data, reproducing a customer's bug.

  • The storage files are immutable, so a branch could share them (copy-on-write) rather than copy them.
    What gets in the way is ownership: a database assumes every file under its storage root is its own to compact and garbage-collect, and that nothing outside it reads those files.

Problem

The only writable copy available today is a deep copy: export-snapshot!, or a bucket-level copy of the storage root, followed by a log epoch bump on the copy. Both copy every live data and meta file, so the time and storage a copy costs scale with the size of the parent rather than with what the test writes.

A copy also represents the parent's latest block at the moment it ran. The user can't choose an earlier point.

Current state
  • A database's files carry no record of which database wrote them.
    A database owns one storage root and one log, both named in its DatabaseConfig, and every path it reads or writes (tables/<slug>/data|meta/<trie-key>.arrow, tables/<slug>/blocks/b<idx>.binpb, blocks/b<idx>.binpb) is relative to that root. accidental. It bears on P2 and P3: a database can't tell a file it may delete from one it only reads.

  • Nothing outside a database can hold back its trie GC.
    The leader deletes a superseded data/meta file once it is more than blocks_to_keep blocks plus garbage_lifetime old (defaults 10 blocks and 24h, per GarbageCollectorConfig), consulting only its own trie catalog (dev/doc/gc.allium). accidental. It bears on P2.

  • A block file more than ten blocks old can't be used as a starting point.
    Block GC deletes block files older than blocks_to_keep blocks, with no replica-log coordination (dev/doc/block-gc.allium), and a database hydrates its catalogs from them at startup. accidental. It bears on P4.

  • A database's current files hold its whole system-time history, except what was erased.
    It bears on P4: a branch point in the past needn't depend on superseded files surviving.

    • Data files hold events, not resolved rows: each row carries _iid, _system_from, _valid_from/_valid_to, op and, once historical, _recency. System-time-to is derived at read time.
    • Compaction supersedes files without dropping events other than those ERASE removes → the current files answer any FOR SYSTEM_TIME AS OF query back to the first transaction. essential.
  • A database can resume from its storage on a fresh log by bumping the log epoch (Database.validateOffsets).
    On a later epoch, offset validation is skipped and message IDs continue above the storage watermark. Deep copies use this today.

  • A database's file names don't identify the database that wrote them.
    Trie keys are l<level>-r<recency|c>[-p<part>]-b<blockIdx>, and a branch and its parent both continue block numbering from the branch point, so their keys collide. accidental. It bears on P2 and P3: an inherited file's identity has to include the root it lives in.

  • The primary database's catalog carries the full config of every other attached database (secondaryDatabases in its block file, prod log and bucket included).
    A writable copy of the primary opens all of them read-write, joining their leader election and running their GC. readOnlyDatabases is safe today only because it forces them read-only. accidental. It bears on P3.

  • Recency pruning assumes "superseded" means superseded in this database.
    Current-time queries skip historical files and recency cells. A branch reading its parent's later files would wrongly skip rows the parent superseded after the branch point. accidental.

  • A second cluster can already read a database's storage and log without leading it, via readOnlyDatabases.
    Such a reader never compacts or runs GC, so it covers the read side of P3 and P6; it has no writes of its own.

Properties of a good solution

P1–P3 are linked: each is required, and the set is complete. P4–P6 are conductive: weighed against each other and against cost.

  • P1 creating a branch copies no data or meta file.
    Its cost is a bounded amount of metadata, independent of the parent's data volume.

  • P2 the parent never deletes a file a branch still reads.

  • P3 a branch can't change its parent.
    It writes only under its own storage root, and its compaction and GC touch only files it wrote.

  • P4 the user chooses the branch point, as a system time or a transaction.

  • P5 the parent pays nothing it didn't configure — no extra retention, and no slowdown of ingestion or GC.

  • P6 a branch can run in a different cluster from its parent, holding only read access to the parent's storage.
    P3 then holds by IAM as well as by code.

  • Done when:
    a branch of a database with N GB in object storage is created without O(N) object-store writes, writes on the branch are invisible to the parent, and the parent compacting and running GC for longer than garbage_lifetime breaks no query on the branch.

Prior art

Survey taken 2026-11-23 from vendor docs.

  • Every system that shares files keeps them from GC by treating each branch as a root.

    • Iceberg and lakeFS delete a file only once no retained ref can reach it, and each ref carries its own retention (max-ref-age-ms, per-branch retention_days).
    • Snowflake and Aurora track ownership per micro-partition or page, and pass it to surviving clones when the owner is dropped.
    • Neon keeps any parent layer a child's branch LSN needs, and refuses to delete a branch with children.
    • Databricks Unity Catalog keeps a file while it is within retention for the source or for any shallow clone. Open-source Delta doesn't, and its shallow clones break when the source runs VACUUM: the failure P2 rules out.
    • We share their constraint: one GC deciding over files another database reads. We don't share their single control plane. An XTDB branch in another cluster has no catalog in common with its parent, so a root has to be expressed through storage the parent can read.
  • Every branch point is bounded by history retention — Neon's history window, Snowflake Time Travel (≤90 days), Delta's VACUUM horizon, Turso's PITR window.
    Those systems store history as versions that expire. XTDB keeps system-time history in its current files, so it doesn't share the constraint, except for ERASE.

  • Cross-account clones are rare.
    Only Aurora does it, through AWS RAM, at most 15 per clone family, with a shared customer KMS key. P6 asks for a weaker form: read-only access to the parent's bucket, with no ownership transfer.

  • None merge data except Dolt, lakeFS and Iceberg (fast-forward only).

  • The DDL takes one of three shapes.

    • Clone-as-create: Snowflake CREATE DATABASE b CLONE a AT (TIMESTAMP => …), Delta CREATE TABLE b SHALLOW CLONE a TIMESTAMP AS OF ….
    • Attach-as: SingleStore ATTACH DATABASE a AS b AT TIME ….
    • A ref on the object: Iceberg ALTER TABLE t CREATE BRANCH b AS OF VERSION n RETAIN 7 DAYS.

Out of scope

Rule: what a reader expecting git-style branching would assume.

  • Merging a branch back into its parent.
    Prod-testing branches are discarded once the test is done. Merging two bitemporal histories needs semantics nobody here needs.

  • Schema-only branching.
    This is about branching data.

Alternative approaches

Rule: what a branch inherits from its parent. Both roads were spiked on 2026-11-23 from 52fc7c2. Neither is chosen yet (Q5).

  • Pin the parent's files at block B — tried, works on local storage.
    The branch copies the parent's block files at B, keeps a manifest of the inherited paths, and reads them through a read-only BufferPool layered under its own. A pin object in the parent's root (pins/b<idx>_<name>) makes the parent's trie GC and block GC keep everything at or below the lowest pinned block.

    • Without the pin, the branch failed after the parent compacted and ran GC: Object tables/public$foo/data/l01-rc-b00.arrow doesn't exist.
    • Classifying inherited files by key (blockIdx <= B) failed. The base block is written before that block's L0→L1C job, so the branch re-derives keys ≤ B into its own root.
    • Costs: the parent retains every file live at B for the branch's life (P5). The pin needs write access to the parent's storage, or a parent-side step (P6). And a past branch point is limited to ~10 blocks back.
  • Follow the parent under a system-time ceiling — tried, single node.
    The branch reads the parent's current files, dropping events with _system_from >= T per page before bitemporal resolution (Segment.Page.systemTimeCeiling, filtered in EntityMerge). Its own files stay a separate set.

    • Results matched the parent's FOR SYSTEM_TIME AS OF T row for row across current-time, valid-time-all and system-time-all queries over compacted historical files. Branch writes layered on top matched a from-scratch replay.
    • Recency pruning had to treat inherited recency > T as current: without it, current queries returned 24 of 57 rows.
    • ERASE must stay exempt from the ceiling. So a parent erasure after T reaches the branch (Q2).
    • Costs: every branch query reads the parent's churn since T and discards it. On the spike's data that was 20 files against the parent's 1, the same as the parent's own AS OF T. Read-only access only, and no per-branch state in the parent.
    • A second spike (2026-11-24) ran it across two databases: the branch was an attached database with its own root and log, and its inherited trie and table catalog was loaded read-only from the parent's latest block. Queries, restart and refresh across parent compaction and GC worked.
    • The parent's latest block lags its own compactions: outputs and TriesDeleted reach storage only at the next block. A branch refreshing from it failed with Object tables/public$docs/data/l01-r20200224-b09.arrow doesn't exist. A branch-agnostic parent GC rule fixed it: never delete a file the latest block still names.
    • Page filtering has to see inherited and own files in one pass; filtered separately, a valid-time supersession of an inherited row gave the wrong _valid_from.
    • The branch's log epoch has to exceed the epoch inside the branch point's tx id, or ingestion stops (txId 0 <= latestTxId 89299).
  • Deep copy — today's route.
    export-snapshot! plus a log epoch bump. O(data), latest block only, partition 0 only (#5838).

Open questions

  • Q1 must a branch keep working indefinitely, or within a lease it renews?
    Pinning the parent's files for the branch's whole life satisfies P2 at P5's expense; a lease the branch must renew satisfies P5 and bounds P2 by the renewal interval. Settled by the design.

  • Q2 should an ERASE the parent makes after the branch point remove the data from the branch too?
    A branch reading the parent's current files gets this for free; a branch pinning the files at its branch point doesn't. (for the user)

  • Q3 what happens to live branches when their parent's storage is deleted?
    DETACH DATABASE deletes no files, so a branch survives its parent's detach. Deleting the parent's bucket or prefix breaks every branch, and nothing warns the operator. Settled by the design: whether a branch can be materialised (its inherited files copied into its own root) before that.

  • Q4 can a branch itself be branched?
    Settled by the design: it decides whether a branch's inherited files can come from more than one ancestor.

  • Q5 pin or follow? (for the user)
    Pinning makes the parent pay in retained storage; following makes the branch pay in reads. Both are proportional to the parent's churn since T. Settled by deciding whether branches need only read access to the parent, and how long they live.


Generated by Claude Code

Ngôn ngữ chính
Clojure
Star
3.1k
Fork
193
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
73

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của xtdb/xtdb

Tất cả issue của xtdb/xtdb

Issue tương tự

Thêm issue về Clojure

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.