Return-Path: Delivered-To: apmail-lucene-hadoop-commits-archive@locus.apache.org Received: (qmail 50117 invoked from network); 30 May 2006 22:42:01 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 30 May 2006 22:42:01 -0000 Received: (qmail 50772 invoked by uid 500); 30 May 2006 22:42:01 -0000 Delivered-To: apmail-lucene-hadoop-commits-archive@lucene.apache.org Received: (qmail 50719 invoked by uid 500); 30 May 2006 22:42:01 -0000 Mailing-List: contact hadoop-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hadoop-dev@lucene.apache.org Delivered-To: mailing list hadoop-commits@lucene.apache.org Received: (qmail 50709 invoked by uid 99); 30 May 2006 22:42:01 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 May 2006 15:42:00 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 30 May 2006 15:42:00 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 14C781A983A; Tue, 30 May 2006 15:41:40 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r410397 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/dfs/DFSShell.java Date: Tue, 30 May 2006 22:41:39 -0000 To: hadoop-commits@lucene.apache.org From: cutting@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060530224140.14C781A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: cutting Date: Tue May 30 15:41:39 2006 New Revision: 410397 URL: http://svn.apache.org/viewvc?rev=410397&view=rev Log: HADOOP-222. Add -setrep option to the dfs commands that alters file replication levels. Modified: lucene/hadoop/trunk/CHANGES.txt lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java Modified: lucene/hadoop/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?rev=410397&r1=410396&r2=410397&view=diff ============================================================================== --- lucene/hadoop/trunk/CHANGES.txt (original) +++ lucene/hadoop/trunk/CHANGES.txt Tue May 30 15:41:39 2006 @@ -73,10 +73,13 @@ nodes. This, together with HADOOP-195, greatly improves the performance of these transfers. (omalley via cutting) -20. HADOOP-163. Cause datanodes that are unable to either read or +20. HADOOP-163. Cause datanodes that\ are unable to either read or write data to exit, so that the namenode will no longer target them for new blocks and will replicate their data on other nodes. (Hairong Kuang via cutting) + +21. HADOOP-222. Add a -setrep option to the dfs commands that alters + file replication levels. (Johan Oskarson via cutting) Release 0.2.1 - 2006-05-12 Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java?rev=410397&r1=410396&r2=410397&view=diff ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DFSShell.java Tue May 30 15:41:39 2006 @@ -16,7 +16,6 @@ package org.apache.hadoop.dfs; import java.io.*; -import java.util.*; import org.apache.hadoop.conf.*; import org.apache.hadoop.fs.*; @@ -83,6 +82,83 @@ } /** + * Parse the incoming command string + * @param cmd + * @param pos ignore anything before this pos in cmd + * @throws IOException + */ + private void setReplication(String[] cmd, int pos) throws IOException { + if(cmd.length-pos<2 || (cmd.length-pos==2 && cmd[pos].equalsIgnoreCase("-R"))) { + System.err.println("Usage: [-R] "); + System.exit(-1); + } + + boolean recursive = false; + short rep = 3; + + if("-R".equalsIgnoreCase(cmd[pos])) { + recursive=true; + pos++; + + } + + try { + rep = Short.parseShort(cmd[pos]); + pos++; + } catch (NumberFormatException e) { + System.err.println("Cannot set replication to: " + cmd[pos]); + System.exit(-1); + } + + setReplication(rep, new Path(cmd[pos]), recursive); + } + + /** + * Set the replication for the path argument + * if it's a directory and recursive is true, + * set replication for all the subdirs and those files too + */ + public void setReplication(short newRep, Path src, boolean recursive) throws IOException { + + if(!fs.isDirectory(src)) { + setFileReplication(src, newRep); + return; + } + + Path items[] = fs.listPaths(src); + if (items == null) { + System.out.println("Could not get listing for " + src); + } else { + + for (int i = 0; i < items.length; i++) { + Path cur = items[i]; + if(!fs.isDirectory(cur)) { + setFileReplication(cur, newRep); + } else if(recursive) { + setReplication(newRep, cur, recursive); + } + } + } + } + + /** + * Actually set the replication for this file + * If it fails either throw IOException or print an error msg + * @param file + * @param newRep + * @throws IOException + */ + private void setFileReplication(Path file, short newRep) throws IOException { + + if(fs.setReplication(file, newRep)) { + System.out.println("Replication " + newRep + " set: " + file); + } else { + System.err.println("Could not set replication for: " + file); + } + } + + + /** * Get a listing of all files in DFS at the indicated name */ public void ls(String src, boolean recursive) throws IOException { @@ -224,7 +300,7 @@ " [-ls ] [-lsr ] [-du ] [-mv ] [-cp ] [-rm ]" + " [-put ] [-copyFromLocal ] [-moveFromLocal ]" + " [-get ] [-cat ] [-copyToLocal ] [-moveToLocal ]" + - " [-mkdir ] [-report]"); + " [-mkdir ] [-report] [-setrep [-R] ]"); return; } @@ -245,6 +321,8 @@ tc.cat(argv[i++]); } else if ("-moveToLocal".equals(cmd)) { tc.moveToLocal(argv[i++], new Path(argv[i++])); + } else if ("-setrep".equals(cmd)) { + tc.setReplication(argv, i); } else if ("-ls".equals(cmd)) { String arg = i < argv.length ? argv[i++] : ""; tc.ls(arg, false); @@ -273,4 +351,5 @@ fs.close(); } } + }