File: multi_backend.schema

package info (click to toggle)
erlang-bitcask 2.0.8%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,612 kB
  • sloc: erlang: 7,929; ansic: 2,954; makefile: 229; exp: 86; sh: 14
file content (39 lines) | stat: -rw-r--r-- 1,585 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
%% -*- erlang -*-

%% Yo, this is just a test backend for bitcask's multi_backend schema. It's not real
%% If you really care about multi_backend, have a look at riak_kv/priv/multi_backend.schema

%% @doc Storage_backend specifies the Erlang module defining the storage
%% mechanism that will be used on this node.
{mapping, "multi_backend.$name.storage_backend", "riak_kv.multi_backend", [
  {default, bitcask},
  {datatype, {enum, [bitcask, leveldb, memory]}},
  hidden
]}.

{translation, "riak_kv.multi_backend",
 fun(Conf, Schema) ->
  %% group by $name into list, also cut the "multi_backend.$name" off every key
  BackendNames = cuttlefish_variable:fuzzy_matches(["multi_backend","$name","storage_backend"], Conf),
  %% for each in list, case statement on backend type
  Backends = [ begin
    BackendConfigName = ["multi_backend", Name],
    {BackendModule, BackendConfig} = case cuttlefish:conf_get(BackendConfigName ++ ["storage_backend"], Conf) of
      bitcask ->
        BackendConfigPrefix = BackendConfigName ++ ["bitcask"],
        SubConf = [ begin
          {Key -- BackendConfigName, Value}
        end || {Key, Value} <- cuttlefish_variable:filter_by_prefix(BackendConfigPrefix, Conf)],

        case cuttlefish_generator:map(Schema, SubConf) of
            BackendProplist ->
                {riak_kv_bitcask_backend, proplists:get_value(bitcask, BackendProplist)}
        end
    end,
    {list_to_binary(Name),  BackendModule, BackendConfig}
  end || {"$name", Name} <- BackendNames],
  case Backends of
      [] -> throw(unset);
      _ -> Backends
  end
 end}.