Skip to content

decdn origin import: seed a cache origin store (sharded blob + .obao4), fs-first #1904

Closed

Description

@alpergundogdu

Summary

Add a first-party command to import local content into a cache origin store,
producing the exact object layout the daemon reads: the sharded data object
and its sibling .obao4 outboard. When handed a directory, also emit a
bundle manifest and import that too, so an operator can seed a whole tree and
hand out a single hash.

fs-first: v1 populates a filesystem origin (cache.origin.kind = "fs"); the
--to target is designed so an S3 origin is an additive follow-up, since the
two backends share an identical object layout (see Backend-agnostic below).

Proposed spelling — a new offline origin command group (see Placement):

decdn origin import -i <path> --to <target> [--move] [--bundle <out.json>]

where --to selects the backend to populate:

  • --to fs:<dir> — a local filesystem origin store. Implemented first.
  • --to s3://<bucket>/<prefix> — an S3 origin store. Fast follow (see
    Backend-agnostic below).

fs-first. v1 implements only the fs: target. The signature is designed so
S3 is an additive follow-up, not a rewrite.

Config-free by design. The command reads no node config and does no
auto-resolution — the target is an explicit required argument. It's a pure local
content tool: it works before a node is configured, on a build/CI box that has
no node.toml. Nothing about it depends on a running or even installed daemon.
(An s3: target still takes S3 credentials — via the standard AWS env/chain the
s3 origin adapter already uses — but no node config.)

Motivation

Operators running a serving node with a filesystem pull-through origin
([cache.origin] kind = "fs", path = /var/lib/decdn/origin) currently have
no supported way to populate it. The layout is precise and unforgiving:

  • Data object at {base}/{hex[0..2]}/{hex} where hex is the 64-char lowercase
    BLAKE3 of the content (crates/cache/src/origin/fs.rs::path_for).
  • Sibling pre-order bao outboard at {base}/{hex[0..2]}/{hex}.obao4
    (obao4_path_for, per ADR 037 §Origin-tier pull-through).

The data object is a plain cp once you know the hash, but the .obao4 is a
bao_tree::io::outboard::PreOrderMemOutboard built at
IROH_BLOCK_SIZE = BlockSize::from_chunk_log(4) (16 KiB chunk groups, pinned
equal to iroh_blobs::store::IROH_BLOCK_SIZE). A stock bao encode --outboard
uses a different chunk group size and produces a file the daemon rejects as a
malformed/foreign .obao4 (length + verify mismatch in crates/bao-range).
So the outboard cannot be produced by generic shell tooling — it needs the
node's own bao encoding. Today the only reference implementation is a test
helper (fs.rs::seed_blob_with_outboard).

The .obao4 is optional for correctness — FilesystemOrigin::fetch_outboard
returning NotFound degrades the node to a whole-blob fetch that re-derives the
outboard in memory — but it is required to serve verified byte ranges from
the origin without the node first holding the whole blob. A serving node that
expects range traffic wants the sibling present.

Backend-agnostic content prep, pluggable writer

An origin store is content-addressed and the object layout is shared across
the fs and s3 backends by construction
: s3.rs::key_for produces
{prefix}{hex[0..2]}/{hex} to mirror FilesystemOrigin::path_for, and it
imports OBAO4_SUFFIX straight from fs.rs — the code comment is explicit that
this is "so operators aws s3 sync-ing between backends keep the same object
names."

So the expensive, tricky part of import — compute the BLAKE3 hash, compute the
IROH_BLOCK_SIZE pre-order outboard, decide the object names — is identical
for every backend
. Only the final write differs: a local write vs an S3
PutObject. That is why this is origin import with a --to target rather than
an fs-only command: the writer is a thin, swappable tail on shared prep.

  • fs target: implemented first (this issue's deliverable).
  • s3 target: a follow-up that adds only the PutObject writer + reuses the
    s3 origin adapter's client/credential config.
  • http is not a write target — an HTTP origin is a read-only static server
    the operator runs. You "import to http" by writing the fs: layout onto the
    disk that server serves. Documented so no one expects --to http://….

Proposed behavior

decdn origin import -i <path> --to <target>:

Single file (-i file):

  1. Stream the file, compute its BLAKE3 root hash and the pre-order outboard at
    IROH_BLOCK_SIZE in one pass (reuse the exact encoder behind
    seed_blob_with_outboard) — backend-independent.
  2. Write the data object and {hex}.obao4 to the target. For fs: write
    {dir}/{hex[0..2]}/{hex} atomically (temp file + rename into the shard dir;
    create_dir_all the shard).
  3. --move renames/removes the source instead of copying (fs: fall back to
    copy+unlink across filesystems; s3: delete source after a verified put).
  4. Idempotent: if the target object + outboard already exist and verify, it's a
    no-op; refuse to overwrite a mismatching object without --force.

Directory (-i dir):

  1. Walk the tree (reuse bundle create's walk: same symlink containment rules,
    --follow-symlinks, --exclude).
  2. Import every regular file as above.
  3. Emit a canonical bundle manifest (identical bytes to bundle create) and, if
    --bundle <out.json> is given, write it there; also import the manifest
    blob itself
    into the target (it's a BLAKE3-addressed blob) so the whole
    tree is retrievable by the single bundle hash.
  4. Report the bundle hash (the one publishers distribute) in the summary.

--json status line mirroring bundle create, e.g.
{"imported":<n>,"bytes":<total>,"origin":"<dir>","bundle_hash":"b3:<hex>","moved":<bool>}.

Placement

A new decdn origin command group, distinct from decdn node. Every
existing decdn node subcommand talks to a running node over the loopback
admin surface (ADR 025); import is offline local filesystem work that needs no
daemon and no config, so it doesn't belong there. A dedicated origin group
scoped to the fs origin store also leaves room for obvious companions
(origin verify, origin gc, origin ls).

Considered and rejected: decdn node import (category mismatch, per above) and
top-level decdn import (less discoverable, no room to grow related origin
subcommands).

Notes / scope

  • Reuses existing building blocks: the outboard encoder (seed_blob_with_outboard
    logic), the directory walk + manifest emitter (bundle create), and the path
    helpers (path_for / obao4_path_for) — arguably those should move out of
    #[cfg(test)] / crate-private into a small reusable seeder.
  • No chain interaction, no daemon RPC. The fs: target needs no secrets at all;
    an s3: target (follow-up) takes only standard AWS credentials, not node config.
  • An origin verify <dir> companion (re-hash objects, re-check every .obao4
    length + root) would pair naturally but can be a follow-up.

References

  • Layout + outboard: crates/cache/src/origin/fs.rs (path_for,
    obao4_path_for, OBAO4_SUFFIX, seed_blob_with_outboard).
  • Shared fs/s3 layout: crates/cache/src/origin/s3.rs (key_for mirrors
    path_for; imports OBAO4_SUFFIX from fs.rs).
  • Block size: crates/bao-range/src/lib.rs (IROH_BLOCK_SIZE, chunk_log(4)).
  • Optional-at-runtime outboard: fs.rs::fetch_outboard (NotFound ⇒ whole-blob).
  • Existing dir→manifest: crates/common/src/cli/bundle.rs (bundle create).
  • ADR 037 §Origin-tier pull-through.

Activity

  1. added
    kind:feature
    area:cli
    on Sep 2, 2026
  2. changed the title [-]decdn origin import: seed a filesystem cache origin (sharded blob + .obao4) and bundle a directory[/-] [+]decdn origin import: seed a cache origin store (sharded blob + .obao4), fs-first[/+] on Sep 2, 2026
  3. moved this from Backlog to In progress in deCDNon Sep 2, 2026
  4. self-assigned this
    on Sep 2, 2026
  5. moved this from In progress to Done in deCDNon Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:clikind:feature

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions