Просмотр исходного кода

feat(ds): Allow incremental update of the LTS trie

ieQu1 1 год назад
Родитель
Сommit
1ddbbca90e
1 измененных файлов с 6 добавлено и 1 удалено
  1. 6 1
      apps/emqx_durable_storage/src/emqx_ds_lts.erl

+ 6 - 1
apps/emqx_durable_storage/src/emqx_ds_lts.erl

@@ -21,6 +21,7 @@
     trie_create/1, trie_create/0,
     destroy/1,
     trie_restore/2,
+    trie_update/2,
     trie_copy_learned_paths/2,
     topic_key/3,
     match_topics/2,
@@ -126,7 +127,11 @@ destroy(#trie{trie = Trie, stats = Stats}) ->
 %% @doc Restore trie from a dump
 -spec trie_restore(options(), [{_Key, _Val}]) -> trie().
 trie_restore(Options, Dump) ->
-    Trie = trie_create(Options),
+    trie_update(trie_create(Options), Dump).
+
+%% @doc Update a trie with a dump of operations (used for replication)
+-spec trie_update(trie(), [{_Key, _Val}]) -> trie().
+trie_update(Trie, Dump) ->
     lists:foreach(
         fun({{StateFrom, Token}, StateTo}) ->
             trie_insert(Trie, StateFrom, Token, StateTo)