Return-Path: Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: (qmail 19630 invoked from network); 27 Sep 2010 15:49:17 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 27 Sep 2010 15:49:17 -0000 Received: (qmail 28000 invoked by uid 500); 27 Sep 2010 15:49:16 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 27837 invoked by uid 500); 27 Sep 2010 15:49:14 -0000 Mailing-List: contact dev-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 dev@couchdb.apache.org Received: (qmail 27641 invoked by uid 99); 27 Sep 2010 15:49:14 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Sep 2010 15:49:14 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of fdmanana@gmail.com designates 209.85.215.180 as permitted sender) Received: from [209.85.215.180] (HELO mail-ey0-f180.google.com) (209.85.215.180) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Sep 2010 15:49:06 +0000 Received: by eya25 with SMTP id 25so1895492eya.11 for ; Mon, 27 Sep 2010 08:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:content-type:content-transfer-encoding; bh=w7mSrsR48eWhBHGNfogGM77EVmIBBvSSuyhtjZVwid0=; b=PjsZdLAAKF/fgxcL/5iOccjS8HyaS3H5YtxTMBSDM56trzDatyhtgmRZoo3hqF1BYN IMaDpNVEfy5TqXqYnO0Q+vSKpZsO3SHsLIsDatTTIQNBwDiH5kgYeKk/U5b8B3KpM9lx n5z9hH/bpd3c2HF+bX1MDtttRBfjyhCZQ0P0o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; b=djeg5g3A0GFAXEojhQbPf3BpYzmp8xxdReRb+uEz8OdhsEHfTRbUp7KS9CGEHA6Xmq YLSVJ9zDVbMwLfpVkLTaKY/uVnPOT5QQSKIxi2MLcBdJX924Ot38qEvrsnqC3aoOqIkw k78MwToBmG/aSgu/+o59ljbRYpJpMoJpLipM8= MIME-Version: 1.0 Received: by 10.213.36.15 with SMTP id r15mr3319156ebd.65.1285602525720; Mon, 27 Sep 2010 08:48:45 -0700 (PDT) Sender: fdmanana@gmail.com Received: by 10.213.104.131 with HTTP; Mon, 27 Sep 2010 08:48:45 -0700 (PDT) In-Reply-To: References: <20100925112640.3FF8123889DD@eris.apache.org> Date: Mon, 27 Sep 2010 16:48:45 +0100 X-Google-Sender-Auth: f6R78_76Qscg88-jespn6d4d3j0 Message-ID: Subject: Re: svn commit: r1001196 - /couchdb/trunk/src/couchdb/couch_file.erl From: Filipe David Manana To: dev@couchdb.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Mon, Sep 27, 2010 at 3:34 PM, Adam Kocoloski wrote= : > Hi Filipe, I'm quite certain that the file_descriptor is closed when couc= h_file dies. =C2=A0I believe what the man page means by that statement is t= hat if you don't supply the 'raw' option, Erlang will spawn a process to ha= ndle IO for the file. =C2=A0That is, couch_file will send a message to anot= her process which owns the port, rather than couch_file owning the port its= elf. =C2=A0Regards, Right. Digging into OTP's code (R14B actually, but I guess it didn't change much from R13), when the option 'raw' is not given, file.erl ( lib/kernel/src/file.erl) will use a process (the gen_server defined in lib/kernel/src/file_server.erl) to access the file. This server will handle process EXIT messages and do the necessary cleanups. When using the 'raw' flag, file.erl will do the file operations through a port (erts/preloaded/src/prim_file.erl) - this is why I have a hunch that in this case we need to explicitely close the file, which will send the 'close' command to the port and close the port. From prim_file.erl: close(#file_descriptor{module =3D ?MODULE, data =3D {Port, _}}) -> case drv_command(Port, <>) of ok -> drv_close(Port); Error -> Error end; I'm not 100% sure of course, but anyway, it doesn't hurt to explicitely close the file. cheers > > Adam > > On Sep 25, 2010, at 7:26 AM, fdmanana@apache.org wrote: > >> Author: fdmanana >> Date: Sat Sep 25 11:26:39 2010 >> New Revision: 1001196 >> >> URL: http://svn.apache.org/viewvc?rev=3D1001196&view=3Drev >> Log: >> Explicitely close the file descriptor. It doesn't hurt. >> Also, since we open the file in 'raw' mode, I suspect the file descripto= r is not closed when the couch_file server dies. >> >> From erl -man file: >> >> "The raw option allows faster access to a file, because no Erlang proces= s is needed to handle the file." >> >> For me, no Erlang process handling the file means that it's likely the f= ile is not closed by any other process. >> >> >> >> Modified: >> =C2=A0 =C2=A0couchdb/trunk/src/couchdb/couch_file.erl >> >> Modified: couchdb/trunk/src/couchdb/couch_file.erl >> URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_file.e= rl?rev=3D1001196&r1=3D1001195&r2=3D1001196&view=3Ddiff >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D >> --- couchdb/trunk/src/couchdb/couch_file.erl (original) >> +++ couchdb/trunk/src/couchdb/couch_file.erl Sat Sep 25 11:26:39 2010 >> @@ -278,8 +278,8 @@ maybe_track_open_os_files(FileOptions) - >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 couch_stats_collector:track_process_count({c= ouchdb, open_os_files}) >> =C2=A0 =C2=A0 end. >> >> -terminate(_Reason, _Fd) -> >> - =C2=A0 =C2=A0ok. >> +terminate(_Reason, #file{fd =3D Fd}) -> >> + =C2=A0 =C2=A0ok =3D file:close(Fd). >> >> >> handle_call({pread_iolist, Pos}, _From, File) -> >> >> > > --=20 Filipe David Manana, fdmanana@gmail.com, fdmanana@apache.org "Reasonable men adapt themselves to the world. =C2=A0Unreasonable men adapt the world to themselves. =C2=A0That's why all progress depends on unreasonable men."