Return-Path: X-Original-To: apmail-hadoop-hdfs-dev-archive@minotaur.apache.org Delivered-To: apmail-hadoop-hdfs-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F20D81063A for ; Thu, 2 May 2013 16:28:51 +0000 (UTC) Received: (qmail 82408 invoked by uid 500); 2 May 2013 16:28:51 -0000 Delivered-To: apmail-hadoop-hdfs-dev-archive@hadoop.apache.org Received: (qmail 82304 invoked by uid 500); 2 May 2013 16:28:51 -0000 Mailing-List: contact hdfs-dev-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hdfs-dev@hadoop.apache.org Delivered-To: mailing list hdfs-dev@hadoop.apache.org Received: (qmail 82295 invoked by uid 99); 2 May 2013 16:28:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 May 2013 16:28:51 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of todd@cloudera.com designates 209.85.217.177 as permitted sender) Received: from [209.85.217.177] (HELO mail-lb0-f177.google.com) (209.85.217.177) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 May 2013 16:28:47 +0000 Received: by mail-lb0-f177.google.com with SMTP id 13so704764lba.8 for ; Thu, 02 May 2013 09:28:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type:x-gm-message-state; bh=BjXZbKg2KBIggeYoRrGcnAXGjzjre6A9BFTGw4rs7cI=; b=fFdpOZ11NqgLGjpE0GlQqpxwDqO1FZ8eIDQruIctzhHPzLIatuGbf0mwn8YJ5nR/jt KfLyGvAZGON4mSxK788+Nhf7zCfFM6P8knD7CkAL2cHFU0H6KZsGT/2fYTvlEuEi1hbf PXfWXjE+Ihw7AcpYSDbbYs3zRaGxsy0+nTbNnNvXmEbnNkqC6geRvQEyTf3qatcXpO4m bNLxZ2msnVp3p3x95surodq4JSxbzTmjbc9Hwa9ZlHbDjydmoGNGgSijrEUZNII7evDJ 4+/4npTN3y45ywPgPaAg3MykYWr1T4lhiMdEVZdizInc9F28dAJnuxgJ9XOz/5njnnd1 reEw== X-Received: by 10.112.35.11 with SMTP id d11mr2960258lbj.108.1367512105569; Thu, 02 May 2013 09:28:25 -0700 (PDT) MIME-Version: 1.0 Received: by 10.112.13.230 with HTTP; Thu, 2 May 2013 09:28:05 -0700 (PDT) In-Reply-To: <975535892.8541494.1367511502391.JavaMail.root@redhat.com> References: <770152377.8528073.1367510470358.JavaMail.root@redhat.com> <975535892.8541494.1367511502391.JavaMail.root@redhat.com> From: Todd Lipcon Date: Thu, 2 May 2013 09:28:05 -0700 Message-ID: Subject: Re: DistributedFileSystem.listStatus() - Why does it do partial listings then assemble? To: hdfs-dev@hadoop.apache.org Content-Type: multipart/alternative; boundary=14dae93d8f564761b404dbbeb91b X-Gm-Message-State: ALoCoQkd212CgZUSVKsf+7H3NjQSeRRkRr/3YRSX0Tlm8zAo5zWCPYn2z1Njqp7tgX/6CArF+cX9 X-Virus-Checked: Checked by ClamAV on apache.org --14dae93d8f564761b404dbbeb91b Content-Type: text/plain; charset=ISO-8859-1 Hi Brad, The reasoning is that the NameNode locking is somewhat coarse grained. In older versions of Hadoop, before it worked this way, we found that listing large directories (eg with 100k+ files) could end up holding the namenode's lock for a quite long period of time and starve other clients. Additionally, I believe there is a second API that does the "on-demand" fetching of the next set of files from the listing as well, no? As for the consistency argument, you're correct that you may have a non-atomic view of the directory contents, but I can't think of any applications where this would be problematic. -Todd On Thu, May 2, 2013 at 9:18 AM, Brad Childs wrote: > Could someone explain why the DistributedFileSystem's listStatus() method > does a piecemeal assembly of a directory listing within the method? > > Is there a locking issue? What if an element is added to the the directory > during the operation? What if elements are removed? > > It would make sense to me that the FileSystem class listStatus() method > returned an Iterator allowing only partial fetching/chatter as needed. But > I dont understand why you'd want to assemble a giant array of the listing > chunk by chunk. > > > Here's the source of the listStatus() method, and I've linked the entire > class below. > > > --------------------------------- > > public FileStatus[] listStatus(Path p) throws IOException { > String src = getPathName(p); > > // fetch the first batch of entries in the directory > DirectoryListing thisListing = dfs.listPaths( > src, HdfsFileStatus.EMPTY_NAME); > > if (thisListing == null) { // the directory does not exist > return null; > } > > HdfsFileStatus[] partialListing = thisListing.getPartialListing(); > if (!thisListing.hasMore()) { // got all entries of the directory > FileStatus[] stats = new FileStatus[partialListing.length]; > for (int i = 0; i < partialListing.length; i++) { > stats[i] = makeQualified(partialListing[i], p); > } > statistics.incrementReadOps(1); > return stats; > } > > // The directory size is too big that it needs to fetch more > // estimate the total number of entries in the directory > int totalNumEntries = > partialListing.length + thisListing.getRemainingEntries(); > ArrayList listing = > new ArrayList(totalNumEntries); > // add the first batch of entries to the array list > for (HdfsFileStatus fileStatus : partialListing) { > listing.add(makeQualified(fileStatus, p)); > } > statistics.incrementLargeReadOps(1); > > // now fetch more entries > do { > thisListing = dfs.listPaths(src, thisListing.getLastName()); > > if (thisListing == null) { > return null; // the directory is deleted > } > > partialListing = thisListing.getPartialListing(); > for (HdfsFileStatus fileStatus : partialListing) { > listing.add(makeQualified(fileStatus, p)); > } > statistics.incrementLargeReadOps(1); > } while (thisListing.hasMore()); > > return listing.toArray(new FileStatus[listing.size()]); > } > > -------------------------------------------- > > > > > > Ref: > > https://svn.apache.org/repos/asf/hadoop/common/tags/release-1.0.4/src/hdfs/org/apache/hadoop/hdfs/DistributedFileSystem.java > http://docs.oracle.com/javase/6/docs/api/java/util/Iterator.html > > > thanks! > > -bc > -- Todd Lipcon Software Engineer, Cloudera --14dae93d8f564761b404dbbeb91b--