Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D45AB200C4E for ; Wed, 1 Mar 2017 17:38:53 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D318B160B84; Wed, 1 Mar 2017 16:38:53 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 13699160B56 for ; Wed, 1 Mar 2017 17:38:51 +0100 (CET) Received: (qmail 81690 invoked by uid 500); 1 Mar 2017 16:38:49 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 80697 invoked by uid 99); 1 Mar 2017 16:38:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Mar 2017 16:38:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 98045E00C5; Wed, 1 Mar 2017 16:38:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kocolosk@apache.org To: commits@couchdb.apache.org Date: Wed, 01 Mar 2017 16:39:17 -0000 Message-Id: <366c64004a8b4073abce1ce03c9b7f41@git.apache.org> In-Reply-To: <291c3c1659274535834e6cfd18c686fd@git.apache.org> References: <291c3c1659274535834e6cfd18c686fd@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [30/50] couch commit: updated refs/heads/2971-count-distinct to ee32cd5 archived-at: Wed, 01 Mar 2017 16:38:53 -0000 Don't trap exits in couch_file It turns out to be impossible to trap the exit message from the parent process in a gen_server, which is the only reason couch_file traps exits in the first place (i.e, this has never worked). This commit also changes the hot upgrade code to handle this transition (but not the previous one). COUCHDB-3259 Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/bbc32e16 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/bbc32e16 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/bbc32e16 Branch: refs/heads/2971-count-distinct Commit: bbc32e160562fc2f6233b6f583cdef28ced8ed9f Parents: b8a06c3 Author: Robert Newson Authored: Tue Dec 20 22:32:44 2016 +0000 Committer: Robert Newson Committed: Wed Dec 21 11:32:46 2016 +0000 ---------------------------------------------------------------------- src/couch_file.erl | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/bbc32e16/src/couch_file.erl ---------------------------------------------------------------------- diff --git a/src/couch_file.erl b/src/couch_file.erl index 19e5998..7cf8b02 100644 --- a/src/couch_file.erl +++ b/src/couch_file.erl @@ -21,7 +21,7 @@ -define(MONITOR_CHECK, 10000). -define(SIZE_BLOCK, 16#1000). % 4 KiB -define(READ_AHEAD, 2 * ?SIZE_BLOCK). --define(IS_OLD_STATE(S), tuple_size(S) /= tuple_size(#file{})). +-define(IS_OLD_STATE(S), is_pid(S#file.db_monitor)). -define(PREFIX_SIZE, 5). -define(DEFAULT_READ_COUNT, 1024). @@ -33,7 +33,7 @@ fd, is_sys, eof = 0, - db_pid, + db_monitor, pread_limit = 0 }). @@ -342,7 +342,6 @@ init_status_error(ReturnPid, Ref, Error) -> % server functions init({Filepath, Options, ReturnPid, Ref}) -> - process_flag(trap_exit, true), OpenOptions = file_open_options(Options), Limit = get_pread_limit(), IsSys = lists:member(sys_db, Options), @@ -450,13 +449,13 @@ handle_call({pread_iolist, Pos}, _From, File) -> handle_call(bytes, _From, #file{fd = Fd} = File) -> {reply, file:position(Fd, eof), File}; -handle_call({set_db_pid, Pid}, _From, #file{db_pid=OldPid}=File) -> - case is_pid(OldPid) of - true -> unlink(OldPid); +handle_call({set_db_pid, Pid}, _From, #file{db_monitor=OldRef}=File) -> + case is_reference(OldRef) of + true -> demonitor(OldRef, [flush]); false -> ok end, - link(Pid), - {reply, ok, File#file{db_pid=Pid}}; + Ref = monitor(process, Pid), + {reply, ok, File#file{db_monitor=Ref}}; handle_call(sync, _From, #file{fd=Fd}=File) -> {reply, file:sync(Fd), File}; @@ -517,16 +516,11 @@ handle_info(maybe_close, File) -> {noreply, File} end; -handle_info({'EXIT', Pid, _}, #file{db_pid=Pid}=File) -> +handle_info({'DOWN', Ref, process, _Pid, _Info}, #file{db_monitor=Ref}=File) -> case is_idle(File) of true -> {stop, normal, File}; false -> {noreply, File} - end; - -handle_info({'EXIT', _, normal}, Fd) -> - {noreply, Fd}; -handle_info({'EXIT', _, Reason}, Fd) -> - {stop, Reason, Fd}. + end. find_header(Fd, Block) -> @@ -731,9 +725,10 @@ process_info(Pid) -> {Fd, InitialName} end. -upgrade_state({file, Fd, IsSys, Eof, DbPid}) -> - Limit = get_pread_limit(), - #file{fd=Fd, is_sys=IsSys, eof=Eof, db_pid=DbPid, pread_limit=Limit}; +upgrade_state(#file{db_monitor=DbPid}=File) when is_pid(DbPid) -> + unlink(DbPid), + Ref = monitor(process, DbPid), + File#file{db_monitor=Ref}; upgrade_state(State) -> State.