Changes between Initial Version and Version 1 of BigThingCamp160227/Lab6


Ignore:
Timestamp:
Feb 27, 2016, 9:43:16 AM (8 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BigThingCamp160227/Lab6

    v1 v1  
     1◢ <[wiki:BigThingCamp160227/Lab5 實作五]> | <[wiki:BigThingCamp160227 回課程大綱]> ▲ | <[wiki:BigThingCamp160227/Lab7 實作七]> ◣
     2
     3= 實作六 Lab6 =
     4
     5{{{
     6#!html
     7<p style="text-align: center;"><big style="font-weight: bold;"><big>Hadoop FileSystem API 原始碼觀察<br>Learn from Apache Hadoop FsShell.java Source Code</big></big></p>
     8}}}
     9
     10[[PageOutline]]
     11
     12== 替 Hadoop 上補丁的方法 ==
     13
     14 * 在前面的範例中,我們使用 Bash 除錯技巧,得知當我們執行 hadoop fs 時,等同呼叫 !FsShell 類別
     15 * 那 !FsShell 類別在 Apache Hadoop 中,放在哪裡呢? 我們可以透過 find 指令查出來。
     16{{{
     17~$ find ~/hadoop/src -name "FsShell.java"
     18/home/user/hadoop/src/core/org/apache/hadoop/fs/FsShell.java
     19}}}
     20 * 現在,我們知道 !FsShell.java 原始碼的位置,我們想要對它做小幅的修正。
     21 * 下一個範例我們使用了一個 update jar 檔的技巧,直接修改 hadoop-core-$VERSION.jar 壓縮檔中某幾個類別(CLASS)的內容,來達成我們觀察 Hadoop 行為模式的目的
     22 * 執行的方式很簡單,請剪貼以下指令:
     23{{{
     24~$ cd ~/hadoop_labs
     25~/hadoop_labs$ lab003/FsShell
     26}}}
     27
     28 * 但是背後的意義是什麼呢?首先,讓我們用 diff 觀察一下原始碼做了什麼修改
     29{{{
     30~$ cd ~/hadoop_labs/lab003/
     31~/hadoop_labs/lab003$ diff -Naur ~/hadoop/src/core/org/apache/hadoop/fs/FsShell.java src/FsShell.java
     32}}}
     33{{{
     34#!diff
     35--- /home/user/hadoop/src/core/org/apache/hadoop/fs/FsShell.java        2012-10-03 13:17:16.000000000 +0800
     36+++ src/FsShell.java    2013-10-19 11:25:16.419320587 +0800
     37@@ -571,6 +571,9 @@
     38     Path srcPath = new Path(srcf);
     39     FileSystem srcFs = srcPath.getFileSystem(this.getConf());
     40     FileStatus[] srcs = srcFs.globStatus(srcPath);
     41+    // Add by Jazz
     42+    System.out.println("srcFs = " + srcFs.getClass().toString());
     43+    System.out.println("Uri   = " + srcFs.getUri().toString());
     44     if (srcs==null || srcs.length==0) {
     45       throw new FileNotFoundException("Cannot access " + srcf +
     46           ": No such file or directory.");
     47@@ -1786,8 +1789,12 @@
     48         exitCode = FsShellPermissions.changePermissions(fs, cmd, argv, i, this);
     49       } else if ("-ls".equals(cmd)) {
     50         if (i < argv.length) {
     51+          // Add by Jazz
     52+          System.out.println("doall("+cmd+","+argv+","+i+")");
     53           exitCode = doall(cmd, argv, i);
     54         } else {
     55+          // Add by Jazz
     56+          System.out.println("ls("+Path.CUR_DIR+",false), Path.CUR_DIR = " + Path.CUR_DIR);
     57           exitCode = ls(Path.CUR_DIR, false);
     58         }
     59       } else if ("-lsr".equals(cmd)) {
     60}}}
     61 * 至於 ant 的 build.xml 中,有一個比較特殊的語法,在第 42 行使用了 update="true" 這個選項,其意義就是呼叫 jar 的 update (-u) 功能
     62{{{
     63#!java
     64 41   <target name="jar" depends="compile,doc" description="Package the classes into a .jar file">
     65 42     <jar update="true" destfile="${jarname}" basedir="${bindir}" />
     66 43   </target>
     67}}}
     68{{{
     69~/hadoop_labs/lab003$ jar
     70用法:jar {ctxui}[vfm0Me] [jar 檔案] [清單檔案] [進入點] [-C 目錄] 檔案 ...
     71選項:
     72    -c  建立新的歸檔
     73    -t  列出歸檔的目錄
     74    -x  從歸檔中擷取已命名的 (或所有) 檔案
     75    -u  更新現有歸檔
     76    -v  在標準輸出中產生詳細輸出
     77    -f  指定歸檔檔案名稱
     78    -m  包含指定清單檔案中的清單資訊
     79    -e  為獨立應用程式指定應用程式進入點
     80        已隨附於可執行 jar 檔案中
     81    -0  僅儲存;不使用 ZIP 壓縮方式
     82    -M  不為項目建立清單檔案
     83    -i  為指定的 jar 檔案產生索引資訊
     84    -C  變更至指定目錄並包含後面所列的檔案
     85}}}
     86
     87 * lab003/FsShell 所做的動作:
     88   1. 安裝 ant
     89   2. 編譯 src/FsShell.java 並使用 jar -u 將產生的 .class 更新到 hadoop-core-$VERSION.jar
     90   3. 顯示 hadoop-core-$VERSION.jar 與原始備份 hadoop-core-$VERSION.jar.org 的差異(請觀察日期)
     91   4. 採用 HADOOP_CONF_DIR 環境變數切換成單機模式,請留意畫面中出現的 srcFS 內容
     92   5. 切換回全分散式模式,請留意畫面中出現的 srcFS 內容
     93
     94== 實作習題 ==
     95
     96 <問題 1> 執行 lab003/FsShell,在單機模式時,srcFs 物件是哪一個 Java 類別
     97{{{
     98#!text
     99      (A) org.apache.hadoop.fs.LocalFileSystem
     100      (B) org.apache.hadoop.hdfs.DistributedFileSystem
     101      (C) org.apache.hadoop.fs.shell.Count
     102      (D) org.apache.hadoop.fs.shell.CommandFormat
     103}}}
     104
     105 <問題 2> 執行 lab003/FsShell,在全分散模式時,srcFs 物件是哪一個 Java 類別
     106{{{
     107#!text
     108      (A) org.apache.hadoop.fs.LocalFileSystem
     109      (B) org.apache.hadoop.hdfs.DistributedFileSystem
     110      (C) org.apache.hadoop.fs.shell.Count
     111      (D) org.apache.hadoop.fs.shell.CommandFormat
     112}}}
     113
     114 <問題 3> 從實作中,我們可以觀察到切換不同的設定時,!FileSystem 父物件參照(Reference)指向子類別實作,會視 Configuration 而有所不同。請參考提示,並根據 ${HOME}/hadoop/src/core/org/apache/hadoop/fs 目錄的內容,試猜測 Hadoop 1.0.4 支援哪幾種檔案系統: (複選)
     115
     116 <提示> http://answers.oreilly.com/topic/456-get-to-know-hadoop-filesystems/
     117{{{
     118#!text
     119      (A) HDFS (hdfs://namenode:port)
     120      (B) Amazon S3 (s3:// , s3n://)
     121      (C) KFS
     122      (D) Local File System (file:///)
     123      (F) FTP (ftp://user:passwd@ftp-server:port)
     124      (G) RAMFS (ramfs://)
     125      (H) HAR (Hadoop Archive Filesystem, har://underlyingfsscheme-host:port/archivepath or har:///archivepath )
     126}}}