Search documentation of macula

# macula_content_store (macula v0.44.2)

View Source

Content store module for Macula content-addressed storage.

Provides local storage and retrieval of content blocks and manifests. Uses file-based storage with directory sharding (first 2 hex chars of hash) for efficient organization.

### Storage Layout

       {base_dir}/
       ├── blocks/
       │   ├── 5d/
       │   │   └── 5d41402abc4b2a76b9719d911017c592.blk
       │   └── ...
       ├── manifests/
       │   ├── 7f/
       │   │   └── 7f83b1657ff1fc53b92dc18148a1d65d.man
       │   └── ...
       └── index.dets

### Example Usage

       %% Store a block
       Data = <<"content">>,
       MCID = compute_mcid(Data),
       ok = macula_content_store:put_block(MCID, Data),

       %% Retrieve with verification
       {ok, Data} = macula_content_store:get_block(MCID).

# Summary

## Functions

block_path(_)

Get the file path for a block MCID. Uses first 2 hex chars of hash for directory sharding.

delete_block(MCID)

Delete a block from the store.

delete_manifest(MCID)

Delete a manifest from the store.

gc()

Garbage collect orphaned blocks not referenced by any manifest.

get_block(MCID)

Retrieve a block by its MCID. Verifies the retrieved data matches the MCID hash.

get_manifest(MCID)

Retrieve a manifest by its MCID.

handle_call(_, From, State)
handle_cast(Msg, State)
handle_info(Info, State)
has_block(MCID)

Check if a block exists in the store.

init(Opts)
list_manifests()

List all manifest MCIDs.

manifest_path(_)

Get the file path for a manifest MCID.

put_block(MCID, Data)

Store a block by its MCID. Verifies the data matches the MCID hash before storing.

put_manifest(Manifest)

Store a manifest.

start_link(Opts)

Start the content store server.

stats()

Get storage statistics.

stop()

Stop the content store server.

terminate(Reason, State)
verify_integrity()

Verify integrity of all stored blocks.

# Functions

# block_path(_)

    -spec block_path(binary()) -> string().

Get the file path for a block MCID. Uses first 2 hex chars of hash for directory sharding.

# delete_block(MCID)

    -spec delete_block(binary()) -> ok.

Delete a block from the store.

# delete_manifest(MCID)

    -spec delete_manifest(binary()) -> ok.

Delete a manifest from the store.

# gc()

    -spec gc() -> {ok, #{removed := non_neg_integer()}}.

Garbage collect orphaned blocks not referenced by any manifest.

# get_block(MCID)

    -spec get_block(binary()) -> {ok, binary()} | {error, not_found | hash_mismatch}.

Retrieve a block by its MCID. Verifies the retrieved data matches the MCID hash.

# get_manifest(MCID)

    -spec get_manifest(binary()) -> {ok, map()} | {error, not_found}.

Retrieve a manifest by its MCID.

# handle_call(_, From, State)

# handle_cast(Msg, State)

# handle_info(Info, State)

# has_block(MCID)

    -spec has_block(binary()) -> boolean().

Check if a block exists in the store.

# init(Opts)

# list_manifests()

    -spec list_manifests() -> [binary()].

List all manifest MCIDs.

# manifest_path(_)

    -spec manifest_path(binary()) -> string().

Get the file path for a manifest MCID.

# put_block(MCID, Data)

    -spec put_block(binary(), binary()) -> ok | {error, term()}.

Store a block by its MCID. Verifies the data matches the MCID hash before storing.

# put_manifest(Manifest)

    -spec put_manifest(map()) -> ok | {error, term()}.

Store a manifest.

# start_link(Opts)

    -spec start_link(map()) -> {ok, pid()} | {error, term()}.

Start the content store server.

# stats()

    -spec stats() -> map().

Get storage statistics.

# stop()

    -spec stop() -> ok.

Stop the content store server.

# terminate(Reason, State)

# verify_integrity()

    -spec verify_integrity() -> {ok, non_neg_integer()} | {error, {corrupted, [binary()]}}.

Verify integrity of all stored blocks.