You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ra...@apache.org on 2013/01/26 15:30:29 UTC
[1/2] git commit: consolidate two similar handle_info clauses
consolidate two similar handle_info clauses
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/10a052a3
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/10a052a3
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/10a052a3
Branch: refs/heads/1305-fix-isolate-db-crashes
Commit: 10a052a3eddbd7e89b553966895ee38a9ce439d4
Parents: 6f3feb0
Author: Randall Leeds <ra...@apache.org>
Authored: Sat Jan 26 06:25:23 2013 -0800
Committer: Randall Leeds <ra...@apache.org>
Committed: Sat Jan 26 06:25:23 2013 -0800
----------------------------------------------------------------------
src/couchdb/couch_server.erl | 71 +++++++++++++++++++-----------------
1 files changed, 37 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/10a052a3/src/couchdb/couch_server.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl
index c9ffeab..daa3f37 100644
--- a/src/couchdb/couch_server.erl
+++ b/src/couchdb/couch_server.erl
@@ -426,51 +426,54 @@ code_change(_OldVsn, State, _Extra) ->
handle_info({'EXIT', _Pid, config_change}, Server) ->
{noreply, shutdown, Server};
-handle_info({'EXIT', Pid, snappy_nif_not_loaded}, Server) ->
- Server2 = case ets:lookup(couch_dbs_by_pid, Pid) of
- [{Pid, Db}] ->
- [{Db, {opening, Pid, Froms}}] = ets:lookup(couch_dbs_by_name, Db),
- Msg = io_lib:format("To open the database `~s`, Apache CouchDB "
- "must be built with Erlang OTP R13B04 or higher.", [Db]),
- ?LOG_ERROR(Msg, []),
- lists:foreach(
- fun(F) -> gen_server:reply(F, {bad_otp_release, Msg}) end,
- Froms),
- true = ets:delete(couch_dbs_by_name, Db),
- true = ets:delete(couch_dbs_by_pid, Pid),
- case ets:lookup(couch_sys_dbs, Db) of
- [{Db, _}] ->
- true = ets:delete(couch_sys_dbs, Db),
- Server;
- [] ->
- Server#server{dbs_open = Server#server.dbs_open - 1}
- end;
- _ ->
- Server
- end,
- {noreply, Server2};
handle_info({'EXIT', Pid, Reason}=Error, Server) ->
- case ets:lookup(couch_dbs_by_pid, Pid) of
+ Server2 = case ets:lookup(couch_dbs_by_pid, Pid) of
[{Pid, Db}] ->
DbName = Db#db.name,
- ?LOG_ERROR(
- "Unexpected exit of database process ~p [~p], restarting: ~p",
- [Pid, DbName, Reason]
- ),
+
% If the Pid is known, the name should be as well.
- % If not, that's an error we'll let crash out on this case statement.
+ % If not, that's an error, which is why there is no [] clause.
case ets:lookup(couch_dbs_by_name, DbName) of
- [{_, {opening, Pid, _Froms}}] ->
- ok;
+ [{_, {opening, Pid, Froms}}] ->
+ Msg = case Reason of
+ snappy_nif_not_loaded ->
+ io_lib:format(
+ "To open the database `~s`, Apache CouchDB "
+ "must be built with Erlang OTP R13B04 or higher.",
+ [Db]
+ );
+ true ->
+ io_lib:format("Error opening database ~p: ~p", [DbName, Reason])
+ end,
+ ?LOG_ERROR(Msg, []),
+ lists:foreach(
+ fun(F) -> gen_server:reply(F, {bad_otp_release, Msg}) end,
+ Froms
+ );
[{_, {opened, Pid, LruTime}}] ->
+ ?LOG_ERROR(
+ "Unexpected exit of database process ~p [~p]: ~p",
+ [Pid, DbName, Reason]
+ ),
true = ets:delete(couch_dbs_by_lru, LruTime)
end,
+
+ true = ets:delete(couch_dbs_by_pid, DbName),
true = ets:delete(couch_dbs_by_name, DbName),
- true = ets:delete(couch_dbs_by_pid, DbName);
+
+ case ets:lookup(couch_sys_dbs, DbName) of
+ [{Db, _}] ->
+ true = ets:delete(couch_sys_dbs, DbName),
+ Server;
+ [] ->
+ Server#server{dbs_open = Server#server.dbs_open - 1}
+ end;
true ->
- ?LOG_ERROR("Unexpected message, restarting couch_server: ~p", [Error])
+ ?LOG_ERROR("Unexpected message, restarting couch_server: ~p", [Error]),
+ exit(kill),
+ Server
end,
- {noreply, Server};
+ {noreply, Server2};
handle_info(Error, _Server) ->
?LOG_ERROR("Unexpected message, restarting couch_server: ~p", [Error]),
exit(kill).