Bladeren bron

chore(dsstore): describe `store_global/3` and friends with comments

Andrew Mayorov 1 jaar geleden
bovenliggende
commit
5386720490
1 gewijzigde bestanden met toevoegingen van 15 en 0 verwijderingen
  1. 15 0
      apps/emqx_durable_storage/src/emqx_ds_storage_layer.erl

+ 15 - 0
apps/emqx_durable_storage/src/emqx_ds_storage_layer.erl

@@ -685,6 +685,19 @@ delete_next(
             {ok, end_of_stream}
     end.
 
+%% @doc Persist a bunch of key/value pairs in the storage globally, in the "outside
+%% of specific generation" sense. Once persisted, values can be read back by calling
+%% `fetch_global/2`.
+%%
+%% Adding or dropping generations won't affect persisted key/value pairs, hence the
+%% purpose: keep state that needs to be tied to the shard itself and outlive any
+%% generation.
+%%
+%% This operation is idempotent, previous values associated with existing keys are
+%% overwritten. While atomicity of the operation can be specifically requested through
+%% `atomic` option, it is atomic by default: either all of pairs are persisted, or none
+%% at all. Writes are durable by default, but this is optional, see `batch_store_opts()`
+%% for details.
 -spec store_global(shard_id(), _KVs :: #{binary() => binary()}, batch_store_opts()) ->
     ok | emqx_ds:error(_).
 store_global(ShardId, KVs, Options) ->
@@ -704,6 +717,8 @@ store_global(ShardId, KVs, Options) ->
         rocksdb:release_batch(Batch)
     end.
 
+%% @doc Retrieve a value for a single key from the storage written there previously by
+%% `store_global/3`.
 -spec fetch_global(shard_id(), _Key :: binary()) ->
     {ok, _Value :: binary()} | not_found | emqx_ds:error(_).
 fetch_global(ShardId, K) ->