Skip to content

Commit

Permalink
HELP-3044: do not cache false and flush data plan cache in maintenanc… (
Browse files Browse the repository at this point in the history
#3790)

* HELP-3044: do not cache false and flush data plan cache in maintenance flush

* HELP-30444: support flushing caches independently
  • Loading branch information
k-anderson authored and lazedo committed Jun 3, 2017
1 parent 8f1c685 commit a0fcdba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
31 changes: 22 additions & 9 deletions core/kazoo_data/src/kazoo_data_maintenance.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,41 @@

-include("kz_data.hrl").

-export([flush/0
,flush/1
,flush/2

,trace_module/1
-export([flush/0]).
-export([flush_data_plans/0]).
-export([flush_docs/0
,flush_docs/1
,flush_docs/2
]).
-export([trace_module/1
,trace_function/1, trace_function/2
,trace_pid/1
,stop_trace/1
]).

-spec flush() -> 'ok'.
-spec flush(ne_binary()) -> 'ok'.
-spec flush(ne_binary(), ne_binary()) -> 'ok'.
flush() ->
_ = kz_datamgr:flush_cache_docs(),
_ = kzs_plan:flush(),
io:format("flushed all data manager caches~n").

-spec flush_data_plans() -> 'ok'.
flush_data_plans() ->
_ = kzs_plan:flush(),
io:format("flushed all data plans~n").

-spec flush_docs() -> 'ok'.
-spec flush_docs(ne_binary()) -> 'ok'.
-spec flush_docs(ne_binary(), ne_binary()) -> 'ok'.
flush_docs() ->
_ = kz_datamgr:flush_cache_docs(),
io:format("flushed all cached docs~n").

flush(Account) ->
flush_docs(Account) ->
_ = kz_datamgr:flush_cache_docs(kz_util:format_account_db(Account)),
io:format("flushed all docs cached for account ~s~n", [Account]).

flush(Account, DocId) ->
flush_docs(Account, DocId) ->
_ = kz_datamgr:flush_cache_doc(kz_util:format_account_db(Account), DocId),
io:format("flushed cached doc ~s for account ~s~n", [DocId, Account]).

Expand Down
14 changes: 9 additions & 5 deletions core/kazoo_data/src/kzs_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,23 @@ db_info(#{server := {App, Conn}}) -> App:db_info(Conn).
db_info(#{server := {App, Conn}}, DbName) -> App:db_info(Conn, DbName).

-spec db_exists(map(), ne_binary()) -> boolean().
db_exists(#{server := {App, Conn}}, DbName) ->
db_exists(#{server := {App, Conn}}=Server, DbName) ->
case kz_cache:fetch_local(?KAZOO_DATA_PLAN_CACHE, {'database', {App, Conn}, DbName}) of
{'ok', Exists} -> Exists;
_ ->
case App:db_exists(Conn, DbName) of
{'error', 'resource_not_available'} -> 'true';
Exists ->
Props = [{'origin', {'db', DbName}}],
kz_cache:store_local(?KAZOO_DATA_PLAN_CACHE, {'database', {App, Conn}, DbName}, Exists, Props),
Exists
Exists -> maybe_cache_db_exists(Exists, Server, DbName)
end
end.

-spec maybe_cache_db_exists(boolean(), map(), ne_binary()) -> boolean().
maybe_cache_db_exists('false', _, _) -> 'false';
maybe_cache_db_exists('true', #{server := {App, Conn}}, DbName) ->
Props = [{'origin', {'db', DbName}}],
kz_cache:store_local(?KAZOO_DATA_PLAN_CACHE, {'database', {App, Conn}, DbName}, 'true', Props),
'true'.

-spec db_exists_all(map(), ne_binary()) -> boolean().
db_exists_all(Map, DbName) ->
case kz_cache:fetch_local(?KAZOO_DATA_PLAN_CACHE, {'database', DbName}) of
Expand Down

0 comments on commit a0fcdba

Please sign in to comment.