macula_content_store (macula v0.20.5)

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

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

Delete a block from the store.

Delete a manifest from the store.

Garbage collect orphaned blocks not referenced by any manifest.

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

Retrieve a manifest by its MCID.

Check if a block exists in the store.

List all manifest MCIDs.

Get the file path for a manifest MCID.

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

Store a manifest.

Start the content store server.

Get storage statistics.

Stop the content store server.

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.