feat(ds_schema): Add schema for builtin_local backend
This commit is contained in:
parent
8990b1312b
commit
4484f30021
|
@ -18,7 +18,7 @@
|
||||||
-module(emqx_ds_schema).
|
-module(emqx_ds_schema).
|
||||||
|
|
||||||
%% API:
|
%% API:
|
||||||
-export([schema/0, translate_builtin_raft/1]).
|
-export([schema/0, translate_builtin_raft/1, translate_builtin_local/1]).
|
||||||
|
|
||||||
%% Behavior callbacks:
|
%% Behavior callbacks:
|
||||||
-export([fields/1, desc/1, namespace/0]).
|
-export([fields/1, desc/1, namespace/0]).
|
||||||
|
@ -32,6 +32,14 @@
|
||||||
%% Type declarations
|
%% Type declarations
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
|
||||||
|
-if(defined(EMQX_RELEASE_EDITION) andalso EMQX_RELEASE_EDITION == ee).
|
||||||
|
-define(DEFAULT_BACKEND, builtin_raft).
|
||||||
|
-define(BUILTIN_BACKENDS, [ref(builtin_raft), ref(builtin_local)]).
|
||||||
|
-else.
|
||||||
|
-define(DEFAULT_BACKEND, builtin_local).
|
||||||
|
-define(BUILTIN_BACKENDS, [ref(builtin_local)]).
|
||||||
|
-endif.
|
||||||
|
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
%% API
|
%% API
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
@ -45,29 +53,26 @@ translate_builtin_raft(
|
||||||
layout := Layout
|
layout := Layout
|
||||||
}
|
}
|
||||||
) ->
|
) ->
|
||||||
Storage =
|
|
||||||
case Layout of
|
|
||||||
#{
|
|
||||||
type := wildcard_optimized,
|
|
||||||
bits_per_topic_level := BitsPerTopicLevel,
|
|
||||||
epoch_bits := EpochBits,
|
|
||||||
topic_index_bytes := TIBytes
|
|
||||||
} ->
|
|
||||||
{emqx_ds_storage_bitfield_lts, #{
|
|
||||||
bits_per_topic_level => BitsPerTopicLevel,
|
|
||||||
topic_index_bytes => TIBytes,
|
|
||||||
epoch_bits => EpochBits
|
|
||||||
}};
|
|
||||||
#{type := reference} ->
|
|
||||||
{emqx_ds_storage_reference, #{}}
|
|
||||||
end,
|
|
||||||
#{
|
#{
|
||||||
backend => builtin_raft,
|
backend => builtin_raft,
|
||||||
n_shards => NShards,
|
n_shards => NShards,
|
||||||
n_sites => NSites,
|
n_sites => NSites,
|
||||||
replication_factor => ReplFactor,
|
replication_factor => ReplFactor,
|
||||||
replication_options => maps:get(replication_options, Backend, #{}),
|
replication_options => maps:get(replication_options, Backend, #{}),
|
||||||
storage => Storage
|
storage => translate_layout(Layout)
|
||||||
|
}.
|
||||||
|
|
||||||
|
translate_builtin_local(
|
||||||
|
#{
|
||||||
|
backend := builtin_local,
|
||||||
|
n_shards := NShards,
|
||||||
|
layout := Layout
|
||||||
|
}
|
||||||
|
) ->
|
||||||
|
#{
|
||||||
|
backend => builtin_local,
|
||||||
|
n_shards => NShards,
|
||||||
|
storage => translate_layout(Layout)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
@ -83,13 +88,37 @@ schema() ->
|
||||||
ds_schema(#{
|
ds_schema(#{
|
||||||
default =>
|
default =>
|
||||||
#{
|
#{
|
||||||
<<"backend">> => builtin_raft
|
<<"backend">> => ?DEFAULT_BACKEND
|
||||||
},
|
},
|
||||||
importance => ?IMPORTANCE_MEDIUM,
|
importance => ?IMPORTANCE_MEDIUM,
|
||||||
desc => ?DESC(messages)
|
desc => ?DESC(messages)
|
||||||
})}
|
})}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
fields(builtin_local) ->
|
||||||
|
%% Schema for the builtin_raft backend:
|
||||||
|
[
|
||||||
|
{backend,
|
||||||
|
sc(
|
||||||
|
builtin_local,
|
||||||
|
#{
|
||||||
|
'readOnly' => true,
|
||||||
|
default => builtin_local,
|
||||||
|
importance => ?IMPORTANCE_MEDIUM,
|
||||||
|
desc => ?DESC(backend_type)
|
||||||
|
}
|
||||||
|
)},
|
||||||
|
{'_config_handler',
|
||||||
|
sc(
|
||||||
|
{module(), atom()},
|
||||||
|
#{
|
||||||
|
'readOnly' => true,
|
||||||
|
default => {?MODULE, translate_builtin_local},
|
||||||
|
importance => ?IMPORTANCE_HIDDEN
|
||||||
|
}
|
||||||
|
)}
|
||||||
|
| common_builtin_fields()
|
||||||
|
];
|
||||||
fields(builtin_raft) ->
|
fields(builtin_raft) ->
|
||||||
%% Schema for the builtin_raft backend:
|
%% Schema for the builtin_raft backend:
|
||||||
[
|
[
|
||||||
|
@ -259,6 +288,8 @@ common_builtin_fields() ->
|
||||||
|
|
||||||
desc(builtin_raft) ->
|
desc(builtin_raft) ->
|
||||||
?DESC(builtin_raft);
|
?DESC(builtin_raft);
|
||||||
|
desc(builtin_local) ->
|
||||||
|
?DESC(builtin_local);
|
||||||
desc(builtin_write_buffer) ->
|
desc(builtin_write_buffer) ->
|
||||||
?DESC(builtin_write_buffer);
|
?DESC(builtin_write_buffer);
|
||||||
desc(layout_builtin_wildcard_optimized) ->
|
desc(layout_builtin_wildcard_optimized) ->
|
||||||
|
@ -272,12 +303,27 @@ desc(_) ->
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%%================================================================================
|
%%================================================================================
|
||||||
|
|
||||||
|
translate_layout(
|
||||||
|
#{
|
||||||
|
type := wildcard_optimized,
|
||||||
|
bits_per_topic_level := BitsPerTopicLevel,
|
||||||
|
epoch_bits := EpochBits,
|
||||||
|
topic_index_bytes := TIBytes
|
||||||
|
}
|
||||||
|
) ->
|
||||||
|
{emqx_ds_storage_bitfield_lts, #{
|
||||||
|
bits_per_topic_level => BitsPerTopicLevel,
|
||||||
|
topic_index_bytes => TIBytes,
|
||||||
|
epoch_bits => EpochBits
|
||||||
|
}};
|
||||||
|
translate_layout(#{type := reference}) ->
|
||||||
|
{emqx_ds_storage_reference, #{}}.
|
||||||
|
|
||||||
ds_schema(Options) ->
|
ds_schema(Options) ->
|
||||||
sc(
|
sc(
|
||||||
hoconsc:union([
|
hoconsc:union(
|
||||||
ref(builtin_raft)
|
?BUILTIN_BACKENDS ++ emqx_schema_hooks:injection_point('durable_storage.backends', [])
|
||||||
| emqx_schema_hooks:injection_point('durable_storage.backends', [])
|
),
|
||||||
]),
|
|
||||||
Options
|
Options
|
||||||
).
|
).
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,13 @@ messages.desc:
|
||||||
builtin_raft.label: "Builtin backend with Raft replication"
|
builtin_raft.label: "Builtin backend with Raft replication"
|
||||||
builtin_raft.desc:
|
builtin_raft.desc:
|
||||||
"""~
|
"""~
|
||||||
Builtin session storage backend utilizing embedded RocksDB key-value store.~"""
|
Builtin storage backend utilizing embedded RocksDB key-value store.~"""
|
||||||
|
|
||||||
|
builtin_local.label: "Builtin backend"
|
||||||
|
builtin_local.desc:
|
||||||
|
"""~
|
||||||
|
Builtin storage backend utilizing embedded RocksDB key-value store.
|
||||||
|
This backend doesn't support clustering.~"""
|
||||||
|
|
||||||
backend_type.label: "Backend type"
|
backend_type.label: "Backend type"
|
||||||
backend_type.desc:
|
backend_type.desc:
|
||||||
|
|
Loading…
Reference in New Issue