Skip to content
Browse files

current state of db_update

  • Loading branch information...
1 parent 09b3fdd commit 8672d1098ab63572f99d3437f78a4610f71d9e6d Joachim committed
Showing with 45 additions and 20 deletions.
  1. +9 −0 joachimpd.config
  2. +1 −1 pd.config
  3. +35 −19 src/edis_db.erl
View
9 joachimpd.config
@@ -0,0 +1,9 @@
+[{edis, [{listener_port_range, {6386, 6387}}, {backend, {edis_pd_backend, []}}]},
+ {lager, [
+ {handlers,
+ [
+ {lager_console_backend, [debug,true]}
+ ]}
+ ]},
+ {sasl, [{errlog_type, all},
+ {sasl_error_logger, {file, "logs/pd.edis.sasl.log"}}]}].
View
2 pd.config
@@ -2,7 +2,7 @@
{lager, [
{handlers,
[
- {lager_console_backend, [info,true]}
+ {lager_console_backend, [debug,true]}
]}
]},
{sasl, [{errlog_type, all},
View
54 src/edis_db.erl
@@ -1616,7 +1616,6 @@ handle_call(X, _From, State) ->
handle_cast({db_write, Actions}, State) ->
-
ActionAnalytics = fun({_, Key, EdisItem}) ->
EdisItemLocal = (State#state.backend_mod):get(State#state.backend_ref, Key),
case EdisItemLocal == not_found orelse edis_vclock:descends(EdisItemLocal#edis_item.vclock, EdisItem#edis_item.vclock) of
@@ -1647,7 +1646,6 @@ handle_cast({db_write, Actions}, State) ->
end,
PatchedActions = lists:map(PatchDeletes, Actions),
-
ChooseLocal =
fun({_, Key, EdisItem}) ->
EdisItemLocal = (State#state.backend_mod):get(State#state.backend_ref, Key),
@@ -1681,8 +1679,6 @@ handle_cast({db_write, Actions}, State) ->
end
end,
-
-
case lists:all(fun(X) -> X == local_write end, AnalyticsResult) of
true ->
(State#state.backend_mod):write(State#state.backend_ref, PatchedActions);
@@ -1703,8 +1699,6 @@ handle_cast({db_write, Actions}, State) ->
end
end,
-
-
{noreply, State};
handle_cast({db_put, Destination, EdisItem}, State) ->
@@ -1762,16 +1756,30 @@ handle_cast({db_delete, Destination, EdisItem}, State) ->
{noreply, State};
-handle_cast({db_update, Key}, State) ->
+handle_cast({db_update, Key, EdisItem}, State) ->
EdisItemLocal = (State#state.backend_mod):get(State#state.backend_ref, Key),
- case EdisItemLocal == not_found of
- true ->
- db_delete(Key, State);
- false ->
- db_put(Key, EdisItemLocal, State)
- end,
-{noreply, State}.
+ case {EdisItemLocal,EdisItem} of
+ {not_found,not_found} ->
+ {noreply, State};
+ _ ->
+ case {EdisItemLocal,EdisItem} of
+ {not_found,#edis_item{}} ->
+ db_delete(Key, EdisItem, State),
+ {noreply, State};
+ _ ->
+ case EdisItemLocal of
+ #edis_item{} ->
+ db_put(Key, EdisItemLocal, State),
+ {noreply, State};
+ _ ->
+ {noreply, State}
+ end
+ end
+ end;
+handle_cast(Msg, State) ->
+lager:debug("unknown cast"),
+{noreply, State}.
%% @hidden
-spec handle_info(term(), state()) -> {noreply, state(), hibernate}.
handle_info(_, State) -> {noreply, State, hibernate}.
@@ -1920,9 +1928,14 @@ get_item(State, Type, Key) ->
{error, Reason} ->
{error, Reason}
end,
- db_update(Key, State),
- Result.
- % There is no "end" to this function clause? Why? Also the function has two parts, i thought the syntax to introduce the second part would be to only specify the set of parameters and not the function name again?
+
+ case Result of
+ {error,_} ->
+ Result;
+ _ ->
+ db_update(Key, Result, State),
+ Result
+ end.
%% @private
update(State, Key, Type, Fun) ->
@@ -2159,6 +2172,9 @@ db_put(Destination, EdisItem, State) ->
db_delete(Destination, State) ->
EdisItem = (State#state.backend_mod):get(State#state.backend_ref, Destination),
+ db_delete(Destination, EdisItem, State).
+
+db_delete(Destination, EdisItem, State) ->
case EdisItem of
#edis_item{} ->
NewEdisItem = EdisItem#edis_item{
@@ -2174,8 +2190,8 @@ db_delete(Destination, State) ->
end,
ok.
-db_update(Key, State) ->
- abcast = gen_server:abcast(nodes(), process(State#state.index), {db_update, Key}),
+db_update(Key, EdisItem, State) ->
+ abcast = gen_server:abcast(nodes(), process(State#state.index), {db_update, Key, EdisItem}),
ok.

0 comments on commit 8672d10

Please sign in to comment.
Something went wrong with that request. Please try again.