Return-Path: X-Original-To: apmail-hadoop-hdfs-user-archive@minotaur.apache.org Delivered-To: apmail-hadoop-hdfs-user-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 84711D14B for ; Mon, 6 Aug 2012 17:33:12 +0000 (UTC) Received: (qmail 58502 invoked by uid 500); 6 Aug 2012 17:33:06 -0000 Delivered-To: apmail-hadoop-hdfs-user-archive@hadoop.apache.org Received: (qmail 58394 invoked by uid 500); 6 Aug 2012 17:33:05 -0000 Mailing-List: contact user-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hadoop.apache.org Delivered-To: mailing list user@hadoop.apache.org Received: (qmail 58387 invoked by uid 99); 6 Aug 2012 17:33:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Aug 2012 17:33:05 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=FSL_RCVD_USER,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.161.176] (HELO mail-gg0-f176.google.com) (209.85.161.176) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Aug 2012 17:32:57 +0000 Received: by ggcs6 with SMTP id s6so3255744ggc.35 for ; Mon, 06 Aug 2012 10:32:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:content-type:x-gm-message-state; bh=9EDkmupD3n3por+6WGS6Z6OGKta9NGeARmWnO0WmJfQ=; b=fK0L2Gjeu3RTgjE2ZLDzLYkLO/wIm9skJ1+4/h7hOhlO5t+TthrKJpv6Lb7fsQjIcx 0UPbQsu4EUr3Zvzph2WUSa8wiuA7rKjzZtelpu4/zAegGyx/sSPOVqWKXAO0/aaCx36P 85w1zXbcAVjX4MjKTEnzYjL4q/VEjLafr7X5eUOJptfApCZ6fPUCO9UxlFIC9Nz+kx+/ zXPT/syFTzotqwMuL9X7rip4c3ZgHwnTA0f8dvt2RQO3/IGC2BlugQx7MQ9wHGGKvmYc zonbhPPrU7AfN5jpIw0KkuQr3EoCqEsyx7t72GrAVjLju0C5fvlH+wU/VOg7EVCwyz+q 6JHg== MIME-Version: 1.0 Received: by 10.50.220.225 with SMTP id pz1mr3369352igc.42.1344274356208; Mon, 06 Aug 2012 10:32:36 -0700 (PDT) Received: by 10.231.23.68 with HTTP; Mon, 6 Aug 2012 10:32:36 -0700 (PDT) X-Originating-IP: [208.54.45.243] Received: by 10.231.23.68 with HTTP; Mon, 6 Aug 2012 10:32:36 -0700 (PDT) In-Reply-To: References: Date: Mon, 6 Aug 2012 13:32:36 -0400 Message-ID: Subject: Fwd: fs cache giving me headaches From: Koert Kuipers To: user@hadoop.apache.org Content-Type: multipart/alternative; boundary=f46d043c06b67b836404c69c433c X-Gm-Message-State: ALoCoQkQQSqDfQf1MwEDDffOLsoL/Bur2GjA6GEqVYSX8hBxe2Da7HphkIdfJifagid18fTZFGLN --f46d043c06b67b836404c69c433c Content-Type: text/plain; charset=ISO-8859-1 ---------- Forwarded message ---------- From: "Koert Kuipers" Date: Aug 4, 2012 1:54 PM Subject: fs cache giving me headaches To: nothing has confused me as much in hadoop as FileSystem.close(). any decent java programmer that sees that an object implements Closable writes code like this: Final FileSystem fs = FileSystem.get(conf); try { // do something with fs } finally { fs.close(); } so i started out using hadoop FileSystem like this, and i ran into all sorts of weird errors where FileSystems in unrelated code (sometimes not even my code) started misbehaving and streams where unexpectedly shut. Then i realized that FileSystem uses a cache and close() closes it for everyone! Not pretty in my opinion, but i can live with it. So i checked other code and found that basically nobody closes FileSystems. Apparently the expected way of using FileSystems is to simple never close them. So i adopted this approach (which i think is really contrary to java conventions for a Closeable). Lately i started working on some code for a daemon/server where many FileSystems objects are created for different users (UGIs) that use the service. As it turns out other projects have run into trouble with the FileSystem cache in situations like this (for example, Scribe and Hoop). I imagine the cache can get very large and cause problems (i have not tested this myself). Looking at the code for Hoop i noticed they simply turned off the FileSystem cache and made sure to close every FileSystem. So here the suggested approach to deal with FileSystems seems to be: Final FileSystem fs = FileSystem.newInstance(conf); // or FileSystem.get(conf) but with caching turned off in the conf try { // do something with fs } finally { fs.close(); } This code bypasses the cache if i understand it correctly, avoiding any cache size limitations. However if i adopt this approach i basically can not re-use any existing code or libraries that do not close FileSystems, splitting the codebase into two which is pretty ugly. And this code is not efficient in situations where there are very few used FileSystem objects and a cache would improve performance, so the split works both ways. In short, there is so single way to code with FileSystem that works in both situations! Ideally i would have liked fs.close() to do the right thing depending in the settings: if cache is turned off it closes the FileSystem, and if it is turned on its a NOOP. That way i could always use FileSystem.get(conf) and always close my filesystems, and the code would be usable irrespective of whether the cache is turned on or off. Any insights or suggestions? Thanks! --f46d043c06b67b836404c69c433c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
---------- Forwarded message ----------
From:= "Koert Kuipers" <koert@t= resata.com>
Date: Aug 4, 2012 1:54 PM
Subject: fs cache giving= me headaches
To: <common-user@hadoo= p.apache.org>

nothing has confused me as= much in hadoop as FileSystem.close().
any decent java programmer that s= ees that an object implements Closable writes code like this:
Final FileSystem fs =3D FileSystem.get(conf);
try {
=A0=A0=A0 // do something with fs
} finally {
=A0=A0=A0 fs.close();}

so i started out using hadoop FileSystem like this, and i ran in= to all sorts of weird errors where FileSystems in unrelated code (sometimes= not even my code) started misbehaving and streams where unexpectedly shut.= Then i realized that FileSystem uses a cache and close() closes it for eve= ryone! Not pretty in my opinion, but i can live with it. So i checked other= code and found that basically nobody closes FileSystems. Apparently the ex= pected way of using FileSystems is to simple never close them. So i adopted= this approach (which i think is really contrary to java conventions for a = Closeable).

Lately i started working on some code for a daemon/server where many Fi= leSystems objects are created for different users (UGIs) that use the servi= ce. As it turns out other projects have run into trouble with the FileSyste= m cache in situations like this (for example, Scribe and Hoop). I imagine t= he cache can get very large and cause problems (i have not tested this myse= lf).

Looking at the code for Hoop i noticed they simply turned off the FileS= ystem cache and made sure to close every FileSystem. So here the suggested = approach to deal with FileSystems seems to be:
Final FileSystem fs =3D F= ileSystem.newInstance(conf); // or FileSystem.get(conf) but with caching tu= rned off in the conf
try {
=A0=A0=A0 // do something with fs
} finally {
=A0=A0=A0 fs.close();
}

This code bypasses the cache if i understand it correctly, avoiding any= cache size limitations. However if i adopt this approach i basically can n= ot re-use any existing code or libraries that do not close FileSystems, spl= itting the codebase into two which is pretty ugly. And this code is not eff= icient in situations where there are very few used FileSystem objects and a= cache would improve performance, so the split works both ways.

In short, there is so single way to code with FileSystem that works in = both situations! Ideally i would have liked fs.close() to do the right thin= g depending in the settings: if cache is turned off it closes the FileSyste= m, and if it is turned on its a NOOP. That way i could always use FileSyste= m.get(conf) and always close my filesystems, and the code would be usable i= rrespective of whether the cache is turned on or off.

Any insights or suggestions? Thanks!

--f46d043c06b67b836404c69c433c--