Return-Path: X-Original-To: apmail-hadoop-common-user-archive@www.apache.org Delivered-To: apmail-hadoop-common-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 39163DAD0 for ; Tue, 24 Jul 2012 14:47:01 +0000 (UTC) Received: (qmail 54875 invoked by uid 500); 24 Jul 2012 14:46:57 -0000 Delivered-To: apmail-hadoop-common-user-archive@hadoop.apache.org Received: (qmail 54728 invoked by uid 500); 24 Jul 2012 14:46:57 -0000 Mailing-List: contact common-user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-user@hadoop.apache.org Delivered-To: mailing list common-user@hadoop.apache.org Received: (qmail 54709 invoked by uid 99); 24 Jul 2012 14:46:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jul 2012 14:46:56 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FSL_RCVD_USER,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of edlinuxguru@gmail.com designates 209.85.160.176 as permitted sender) Received: from [209.85.160.176] (HELO mail-gh0-f176.google.com) (209.85.160.176) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Jul 2012 14:46:50 +0000 Received: by ghbz10 with SMTP id z10so7849206ghb.35 for ; Tue, 24 Jul 2012 07:46:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=v7bTBHRCWbMAHpvMSkhKwbhyo2z2W5U7T4QWgHlYseg=; b=qTDpUvkco7eK53GVNnqz4S13RpGQ8PWFrhA3b2HENat8Fi08LLkLZ9eXMnQ4YN2fs9 HOBPBh+3+ykyLNH/45TFN74FnqRA/wAejnjQFns9PUcmrUPb1+yaQ+XCNFYfopBVcnZW TSWsZ0EtfKInmO2KshWfO/qDUWuL8TZO5tNuWNXhEpNgSqq52QurAwBAcOoYvnNKJwbd v4fCYyScobUQRKcmuFJWd/NLVIUjTYbgnoK3cIipvhF49b3qas7S7RFeFDNTScZUUB7W kKrI7wVCgxns31LjGnbG+0U6gwBFCF5lV+7g3Y6MXP2QYMFB3WkHw7xJqSOFwkJYah2+ OOOw== MIME-Version: 1.0 Received: by 10.43.92.67 with SMTP id bp3mr15728779icc.16.1343141188920; Tue, 24 Jul 2012 07:46:28 -0700 (PDT) Received: by 10.64.25.162 with HTTP; Tue, 24 Jul 2012 07:46:28 -0700 (PDT) In-Reply-To: References: Date: Tue, 24 Jul 2012 10:46:28 -0400 Message-ID: Subject: Re: hadoop FileSystem.close() From: Edward Capriolo To: common-user@hadoop.apache.org Content-Type: text/plain; charset=ISO-8859-1 In all my experience you let FileSystem instances close themselves. On Tue, Jul 24, 2012 at 10:34 AM, Koert Kuipers wrote: > Since FileSystem is a Closeable i would expect code using it to be like > this: > > FileSystem fs = path.getFileSystem(conf); > try { > // do something with fs, such as read from the path > } finally { > fs.close() > } > > However i have repeatedly gotten into trouble with this approach. In one > situation it turned out that when i closed a FileSystem other operations > that were using their own FileSystems (pointing to the same real-world HDFS > filesystem) also saw their FileSystems closed, leading to very confusing > read and write errors. This led me to believe that FileSystem should never > be closed since it seemed to act like some sort of Singleton. However now > was just looking at some code (Hoop server, to be precise) and noticed that > FileSystems were indeed closed, but they were always threadlocal. Is this > the right approach? > > And if FileSystem is threadlocal, is this safe (assuming fs1 and fs2 could > point to the same real-world filesystem)? > > FileSystem fs1 = path.getFileSystem(conf); > try { > FileSystem fs2 = path.getFileSystem(conf); > try { > // do something with fs2, such as read from the path > } finally { > fs2.close() > } > // do something with fs1, such as read from the path (note, fs2 is > closed here, and i wouldn't be surprised if fs1 by now is also closed given > my experience) > } finally { > fs1.close() > }