loonfs-core 0.2.0

Core LoonFS engine: namespace metadata, commits, replay, and maintenance.
Documentation

Core LoonFS namespace operations.

loonfs-core is the low-level API for building directly on the LoonFS metadata protocol. Most callers should start with [NamespaceEngine].

A namespace is one durable filesystem history. File bytes are written to object storage first, then metadata is published as a committed namespace mutation. Reads rebuild or reuse a verified view of the namespace before walking paths.

Example

Commits are published as candidate batches through [publish::NamespaceCommitEngine]; day-to-day reads and writes should go through the loonfs crate's FsReader/FsWriter handles, which wrap this crate with caching and batching.

use loonfs_api::{AbsolutePath, CommitId, NamespaceId};
use loonfs_core::publish::{
    FilesystemOperation, CommitRequest, NamespaceCommitEngine, CommitCandidate,
    PublishTailOptions,
};
use loonfs_core::{BootstrapOptions, MutationContext, NamespaceEngine};
use loonfs_objectstore::local_fs_store::LocalFsStore;

let store = LocalFsStore::new(std::env::temp_dir()).expect("store");
let namespace = NamespaceId::parse("docs").expect("valid namespace id");

let engine = NamespaceEngine::builder(store)
    .namespace_id(namespace.clone())
    .writer_id("example-writer")
    .build()
    .expect("engine");
let _ = engine.bootstrap_namespace(BootstrapOptions::default());

let publish_store = LocalFsStore::new(std::env::temp_dir()).expect("store");
let context = MutationContext {
    writer_id: "example-writer".to_owned(),
    now_ms: 0,
};
let mut publisher = NamespaceCommitEngine::new(namespace);
let _ = publisher.publish_batch(
    &publish_store,
    vec![CommitCandidate::new(CommitRequest::single(
        CommitId::generate(),
        None,
        FilesystemOperation::CreateDirectory {
            path: AbsolutePath::parse("/plans").expect("path"),
            parents: false,
        },
    ))],
    &context,
    &PublishTailOptions::default(),
);