Skip to content

antony@notes:~/data-platform$ cat "看見-HDFS-底層運作.md"

看見 HDFS 底層運作

2023-02-07· data-platform ·資料科技平台

看見 HDFS 底層運作

:::spoiler 目錄 ( 點我可展開 )

[TOC]


:::

HDFS 分散檔案系統 - 寫入檔案

  • Client 在 dta1 虛擬主機,使用者為資料管理師 or 資料分析師 or 資料科學家
  • wget File.txt 上網要分析的資料集,檔名為 File.txt ,由 client 端的使用者下載
  • hdfs dfs -put File.txt mydataset/
    • 當檔案寫入 hdfs 時,會先在 client 所在的本機 (dta1),將檔案切割成好幾個 block ( 資料區塊 )
      • 切割方法 : 128 mb 為一個單位 ( hadoop 內定預設值 ),只要超過 1 個 byte ,就會被多切一個 block 出來。
      • 以圖為例 : File.txt 有 3 個 block ,所以它的檔案大小在 256 mb < x <= 384 mb
      • sector , 硬碟最小儲存物理量,約 512 bytes。
    • 切割後,會去找 dtm1 的 Name Node ( a Java program ),跟它說我這個檔案有 3 個 block 要儲存在 HDFS 檔案系統中
    • Client 端得到 Name Node 同意後,會依照 Name Node 的一份清單,將檔案分別存在不同的 Data Node,
      • Name Node 儲存規則 : 每一個 block 會找不同的 3 台 Data Node 主機儲存
      • 所以檔案有可能會存在 3 ~ 9 台機器
      • 以圖為例,block A 存在 Data Node 1 和 Data Node 5 以及 Data Node 6
      • Rack ,機櫃的意思
      • Data node 分別存在一台 Server 裡面,在我們的環境裡,就是 dtw1, dtw2, dtw3 這三台 VM
      • 在 client 端的 /opt/hadoop-3.3.4/etc/hadoop/hdfs-site.xmldfs.replication 項目裡可設定一個 block 要複製幾份。
    • 資料傳遞的方法 : Client 所在的主機會透過網路傳資料給 Data Node 1 後,當 Data Node 1 收到 64 kb 的資料後,就會在接收資料的同時,將檔案同步再傳給 Data Node 5,當 Data Node 5 收到 64 kb 後,又會在接收資料的同時,再將資料傳給 Data Node 6 。
    • 這種資料傳遞的方法可以在最短時間內讓 3 台 Data Node 都擁有資料。
  • 以上儲存資料的方式是 Replication 不是 back up ,兩者最大的差別在於 Replication 的資料在正常運作中也會被使用,而 back up 的資料是放著等運作中的資料掛了,才會拿來用。
  • Hadoop 的容錯機制 : 當其中一台 Data node 掛了, hadoop 會自動幫我們修復,允許我們一個 block 壞兩台 Data node,如果 3 台 Data node 掛了,就真的沒了,所以 hadoop 的資料也要備份。
    • hadoop 的資料備份,將原始未被切割的檔案壓縮,壓縮比 10 : 1 ,進行備份。
  • Name Node ,負責儲存 檔案的 MetaData,其中包含檔案的權限,檔案的屬性,檔案的名字 ( File name ) …等,所以檔案的 metadata 會存在 dtm1 這台機器中。
  • 檔案的資料,分散儲存在不同的 Data Node 所在的主機。

提問 : 要處理 20 T 的資料,只能買 4 台 Server ,請問一台 Server 硬碟多大 ? 需考慮

  1. hdfs 檔案系統,一個 block 存 3 分 —> 20*3 = 60
  2. 分析檔案所需的分析空間,且因 Hadoop 支援協同作業,所以須看幾個人且分析的資料量來決定

HDFS Architecture 官網連結


HDFS 分散檔案系統 - 讀取檔案

當 Client 端 ( dta1 ) 要讀取 HDFS 分散式檔案系統的資料時 ( hdfs dfs -get mydataset/Result.txt )

  • Client 端會問 Name Node ,我的 Results.txt 資料存在哪 ?
  • Name Node 會回報一個清單,每個 Block 分別存在哪幾台機器
    • 以圖的清單為例 :
    • block A = 1, 5, 6
    • block B = 8, 1, 2
    • block C = 5, 8, 9
  • Client 端會根據清單的第一順位,將檔案讀取回來
    • 以圖為例 : client 端會去 Data Node 1 找 block A , Data Node 8 找 Block B , Data Node 5 找 Block C ,最後得到 Results.txt
    • 如果第一順位的電腦掛了,會再自動根據清單的第二順位讀取
    • 多人同時讀取同一個檔案時,後者得到的清單第一順位,為前者的第二順位
      • 以上的功能就是 round-robin scheduling 來達到 平衡附載 load balancing

HDFS 檔案系統的重點功能

  • 支援協同作業。
  • 容錯機制 : 因檔案分散存在不同 Data Node
  • 多人讀取資料,多台電腦同時出來服務,使用的技術 : round-robin scheduling

HDFS 系統資訊

VMware 的硬碟,超用實體 Host 主機的硬碟 ok,但記憶體超用,不行 !

NAT 的功能,封包偽裝,封包偽裝可以偽裝很多次,但速度就會變慢

檢視hdfs 的資訊,以及每一台 DataNode 的狀態

$ hdfs dfsadmin -report

output :

Configured Capacity: 1578555604992 (1.44 TB)  ---> 總量可存 1.44 TB
Present Capacity: 1485476061184 (1.35 TB)
DFS Remaining: 1485474889728 (1.35 TB)
DFS Used: 1171456 (1.12 MB)
DFS Used%: 0.00%
Replicated Blocks:
        Under replicated blocks: 0
        Blocks with corrupt replicas: 0
        Missing blocks: 0
        Missing blocks (with replication factor 1): 0
        Low redundancy blocks with highest priority to recover: 0
        Pending deletion blocks: 0
Erasure Coded Block Groups:
        Low redundancy block groups: 0
        Block groups with corrupt internal blocks: 0
        Missing block groups: 0
        Low redundancy blocks with highest priority to recover: 0
        Pending deletion blocks: 0

-------------------------------------------------
Live datanodes (3):  ---> 活著的 Data node 有 3 台

Name: 192.168.61.6:9866 (dtw1)
Hostname: dtw1
Decommission Status : Normal
Configured Capacity: 526185201664 (490.05 GB)
DFS Used: 540672 (528 KB)
Non DFS Used: 4222566400 (3.93 GB)
DFS Remaining: 495158132736 (461.15 GB)
DFS Used%: 0.00%
DFS Remaining%: 94.10%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 0
Last contact: Thu Jul 14 10:15:23 CST 2022
Last Block Report: Thu Jul 14 09:00:55 CST 2022
Num of Blocks: 8


Name: 192.168.61.7:9866 (dtw2)
Hostname: dtw2
Decommission Status : Normal
Configured Capacity: 526185201664 (490.05 GB)
DFS Used: 413696 (404 KB)
Non DFS Used: 4222566400 (3.93 GB)
DFS Remaining: 495158259712 (461.15 GB)
DFS Used%: 0.00%
DFS Remaining%: 94.10%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 0
Last contact: Thu Jul 14 10:15:22 CST 2022
Last Block Report: Thu Jul 14 09:41:04 CST 2022
Num of Blocks: 7


Name: 192.168.61.8:9866 (dtw3)
Hostname: dtw3
Decommission Status : Normal
Configured Capacity: 526185201664 (490.05 GB)
DFS Used: 217088 (212 KB)
Non DFS Used: 4222525440 (3.93 GB)
DFS Remaining: 495158497280 (461.15 GB)
DFS Used%: 0.00%
DFS Remaining%: 94.10%
Configured Cache Capacity: 0 (0 B)
Cache Used: 0 (0 B)
Cache Remaining: 0 (0 B)
Cache Used%: 100.00%
Cache Remaining%: 0.00%
Xceivers: 0
Last contact: Thu Jul 14 10:15:22 CST 2022
Last Block Report: Thu Jul 14 07:27:37 CST 2022
Num of Blocks: 7

Name Node 目錄內容

$ ssh dtm1  tree  nn
nn
├── current
│   ├── VERSION
│   ├── edits_0000000000000000001-0000000000000000009
│   ├── edits_0000000000000000010-0000000000000000011
│   ├── edits_inprogress_0000000000000000012
│   ├── fsimage_0000000000000000000
│   ├── fsimage_0000000000000000000.md5
│   └── seen_txid
└── in_use.lock

1 directory, 10 files
  • edits | 存放對 Hadoop 下達過的命令,例 : hdfs dfs -put, -cat, ...
  • fsimage | 紀錄 metadata ( 檔案、目錄的資訊,檔名, 權限資訊…等 )
  • fsimage*.md5 | 每筆 metadata 的身分證字號,防止 metadata 被串改
  • 所有 block 的清單存在 memory,沒有存在目錄裡。
  • SecondaryNameNode | 會按時根據 edits_inprogress 的內容,更新到下一個 fsimage ,這個動作稱為 checkpoint (舊版的關聯式資料庫都會有這種動作)
  • 以上結果可以得知,Hdfs 分散式檔案系統是建構在 Linux ext4 檔案系統之上
$ ssh dtm1  cat  nn/current/VERSION
#Wed Jul 13 10:13:08 CST 2022
namespaceID=1746295848
clusterID=cute
cTime=1657592975551
storageType=NAME_NODE
blockpoolID=BP-1975272387-192.168.61.4-1657592975551
layoutVersion=-66
  • 當我們 formathdfs 時,就會在 namenode 重新產生一個 VERSION
  • namespaceID | hadoop 系統的識別代號
  • clusterID | hadoop Cluster 的名稱,一般以公司的簡稱命名
  • blockpoolID | namenode 的識別代號,DataNode 會根據這個名稱來幫 namenode 服務

DataNode 目錄內容

$ ssh dtw1 tree dn
dn
├── current
│   ├── BP-1975272387-192.168.61.4-1657592975551
│   │   ├── current
│   │   │   ├── VERSION
│   │   │   ├── dfsUsed
│   │   │   ├── finalized
│   │   │   │   └── subdir0
│   │   │   │       └── subdir0
│   │   │   │           ├── blk_1073741836
│   │   │   │           ├── blk_1073741836_1012.meta
│   │   │   │           ├── blk_1073741837
│   │   │   │           ├── blk_1073741837_1013.meta
│   │   │   │           ├── blk_1073741844
│   │   │   │           ├── blk_1073741844_1020.meta
│   │   │   │           ├── blk_1073741846
│   │   │   │           ├── blk_1073741846_1022.meta
│   │   │   │           ├── blk_1073741847
│   │   │   │           ├── blk_1073741847_1023.meta
│   │   │   │           ├── blk_1073741849
│   │   │   │           ├── blk_1073741849_1025.meta
│   │   │   │           ├── blk_1073741850
│   │   │   │           ├── blk_1073741850_1026.meta
│   │   │   │           ├── blk_1073741853
│   │   │   │           └── blk_1073741853_1029.meta
│   │   │   └── rbw
│   │   ├── scanner.cursor
│   │   └── tmp
│   └── VERSION
└── in_use.lock

8 directories, 21 files
  • dn | linux 系統中的目錄,存放 Data Node 的資料
  • BP-1975272387-192.168.61.4-1657592975551 | NameNode 的識別碼,目前這台 Data Node 為這個 NameNode 服務
  • 一個 block 存三份,他們的代號一樣
  • blk_XXX.meta | 有一個演算法會得出一個值,由這個值我們可以得知檔案是否被修改

HDFS 容錯處理 - 遺失資料區塊

# 檢查 hdfs 檔案系統有無 /tmp 目錄
$ hdfs dfs -ls /
Found 8 items
drwxr-xr-x   - bigred bigboss          0 2022-07-13 15:07 /app
drwxrwxr-x+  - bigred bigboss          0 2022-07-13 16:25 /apps
drwxr-xr-x   - bigred bigboss          0 2022-07-13 15:50 /dataset
drwxr-xr-x   - bigred bigboss          0 2022-07-13 16:07 /elt
drwxr-xr-x   - bigred bigboss          0 2022-07-13 16:07 /metadata
drwxr-xr-x   - bigred bigboss          0 2022-07-13 16:06 /raw
drwxrwxrwx   - bigred bigboss          0 2022-07-13 16:07 /tmp
drwxr-xr-x   - bigred bigboss          0 2022-07-13 14:54 /user

# 將 /etc/passwd 丟到 hdfs 檔案系統的 /tmp 目錄下
$ hdfs dfs -put /etc/passwd /tmp/

# 檢查是否符合預期
# /tmp/passwd 檔案大小 1744 byte ---> 只有一個 block
$ hdfs dfs -ls /tmp/
Found 4 items
drwxrwxrwx   - bigred bigboss          0 2022-07-12 10:30 /tmp/hadoop-yarn
drwxrwxrwx   - bigred bigboss          0 2022-07-13 16:07 /tmp/hive
-rw-r--r--   2 bigred bigboss       1744 2022-07-14 11:22 /tmp/passwd
drwxrwxrwx   - bigred bigboss          0 2022-07-12 10:41 /tmp/spark-events

跟 name node 要 /tmp/passwd 的 metadata

$ hdfs fsck  /tmp/passwd  -files  -blocks  -locations
  • fsck ,file system check
  • -files -blocks -locations , print out locations for every block

output :

...
BP-1975272387-192.168.61.4-1657592975551:blk_1073741856_1032 len=1744 Live_repl=2  [DatanodeInfoWithStorage[192.168.61.8:9866,DS-32e4459d-a2f0-4885-be2d-43814c5aeac3,DISK], DatanodeInfoWithStorage[192.168.61.7:9866,DS-980b49ce-18f7-4283-b202-753842be315b,DISK]]
...
  • blk_1073741856_1032 | 可以看到 block 的代號 1856
  • Live_repl=2 | 活著的 block 有 2 份
  • block 存在哪一台 Data Node
$ ssh dtw3 tree dn
dn
├── current
│   ├── BP-1975272387-192.168.61.4-1657592975551
│   │   ├── current
│   │   │   ├── VERSION
│   │   │   ├── dfsUsed
│   │   │   ├── finalized
│   │   │   │   └── subdir0
│   │   │   │       └── subdir0
...中間省略
│   │   │   │           ├── blk_1073741856  --- > /tmp/passwd 的 blk 代號
│   │   │   │           └── blk_1073741856_1032.meta
│   │   │   └── rbw
│   │   ├── scanner.cursor
│   │   └── tmp
│   └── VERSION
└── in_use.lock

8 directories, 21 files

連線到 dtw3 ,將以上這個 blk 刪除

$ rm dn/current/BP-1975272387-192.168.61.4-1657592975551/current/finalized/subdir0/subdir0/blk_1073741856*

檢查是否符合預期,1856 的 blk 代號已刪除

$ tree dn
dn
├── current
│   ├── BP-1975272387-192.168.61.4-1657592975551
│   │   ├── current
│   │   │   ├── VERSION
│   │   │   ├── dfsUsed
│   │   │   ├── finalized
│   │   │   │   └── subdir0
│   │   │   │       └── subdir0
│   │   │   │           ├── blk_1073741844
│   │   │   │           ├── blk_1073741844_1020.meta
│   │   │   │           ├── blk_1073741845
│   │   │   │           ├── blk_1073741845_1021.meta
│   │   │   │           ├── blk_1073741849
│   │   │   │           ├── blk_1073741849_1025.meta
│   │   │   │           ├── blk_1073741850
│   │   │   │           ├── blk_1073741850_1026.meta
│   │   │   │           ├── blk_1073741851
│   │   │   │           ├── blk_1073741851_1027.meta
│   │   │   │           ├── blk_1073741853
│   │   │   │           ├── blk_1073741853_1029.meta
│   │   │   │           ├── blk_1073741855
│   │   │   │           └── blk_1073741855_1031.meta
│   │   │   └── rbw
│   │   ├── scanner.cursor
│   │   └── tmp
│   └── VERSION
└── in_use.lock

8 directories, 19 files

在原地看 /tmp/passwd

$ hdfs dfs -cat /tmp/passwd
root:x:0:0:root:/root:/bin/ash
bin:x:1:1:bin:/bin:/sbin/nologin
...以下省略

在檢查 dn 目錄,blk 是否有還原

$ tree dn
dn
├── current
│   ├── BP-1975272387-192.168.61.4-1657592975551
│   │   ├── current
│   │   │   ├── VERSION
│   │   │   ├── dfsUsed
│   │   │   ├── finalized
│   │   │   │   └── subdir0
│   │   │   │       └── subdir0
│   │   │   │           ├── blk_1073741844
│   │   │   │           ├── blk_1073741844_1020.meta
│   │   │   │           ├── blk_1073741845
│   │   │   │           ├── blk_1073741845_1021.meta
│   │   │   │           ├── blk_1073741849
│   │   │   │           ├── blk_1073741849_1025.meta
│   │   │   │           ├── blk_1073741850
│   │   │   │           ├── blk_1073741850_1026.meta
│   │   │   │           ├── blk_1073741851
│   │   │   │           ├── blk_1073741851_1027.meta
│   │   │   │           ├── blk_1073741853
│   │   │   │           ├── blk_1073741853_1029.meta
│   │   │   │           ├── blk_1073741855
│   │   │   │           └── blk_1073741855_1031.meta
│   │   │   └── rbw
│   │   ├── scanner.cursor
│   │   └── tmp
│   └── VERSION
└── in_use.lock

如果在原地發現沒還原,可能的情況有 :

  1. block 還原到其他 Datanode
  2. 清單的第一順位已讀取到,故不會還原

在 bigred 再次詢問 namenode

$ hdfs fsck  /tmp/passwd  -files  -blocks  -locations

output :

BP-1975272387-192.168.61.4-1657592975551:blk_1073741856_1032 len=1744 Live_repl=2  [DatanodeInfoWithStorage[192.168.61.7:9866,DS-980b49ce-18f7-4283-b202-753842be315b,DISK], DatanodeInfoWithStorage[192.168.61.6:9866,DS-4742e5e8-949e-4c34-89fb-8afdef10b61c,DISK]]

可以發現備份到其他 data node 了

如果將 blk 存的兩份都刪除呢?

# 刪除在 dtw2 的 block
$ ssh dtw2 rm ~/dn/current/BP-1975272387-192.168.61.4-1657592975551/current/finalized/subdir0/subdir0/blk_1073741856*

# 刪除在 dtw1 的 block
$ ssh dtw1 rm ~/dn/current/BP-1975272387-192.168.61.4-1657592975551/current/finalized/subdir0/subdir0/blk_1073741856*

# 檢查是否真的刪除 dtw2 上的 block
$ ssh dtw2 tree dn
dn
├── current
│   ├── BP-1975272387-192.168.61.4-1657592975551
│   │   ├── current
│   │   │   ├── VERSION
│   │   │   ├── dfsUsed
│   │   │   ├── finalized
│   │   │   │   └── subdir0
│   │   │   │       └── subdir0
│   │   │   │           ├── blk_1073741836
│   │   │   │           ├── blk_1073741836_1012.meta
│   │   │   │           ├── blk_1073741837
│   │   │   │           ├── blk_1073741837_1013.meta
│   │   │   │           ├── blk_1073741845
│   │   │   │           ├── blk_1073741845_1021.meta
│   │   │   │           ├── blk_1073741846
│   │   │   │           ├── blk_1073741846_1022.meta
│   │   │   │           ├── blk_1073741847
│   │   │   │           ├── blk_1073741847_1023.meta
│   │   │   │           ├── blk_1073741851
│   │   │   │           ├── blk_1073741851_1027.meta
│   │   │   │           ├── blk_1073741855
│   │   │   │           └── blk_1073741855_1031.meta
│   │   │   └── rbw
│   │   ├── scanner.cursor
│   │   └── tmp
│   └── VERSION
└── in_use.lock

8 directories, 19 files

# 檢查是否真的刪除 dtw1 上的 block
$ ssh dtw1 tree dn
dn
├── current
│   ├── BP-1975272387-192.168.61.4-1657592975551
│   │   ├── current
│   │   │   ├── VERSION
│   │   │   ├── dfsUsed
│   │   │   ├── finalized
│   │   │   │   └── subdir0
│   │   │   │       └── subdir0
│   │   │   │           ├── blk_1073741836
│   │   │   │           ├── blk_1073741836_1012.meta
│   │   │   │           ├── blk_1073741837
│   │   │   │           ├── blk_1073741837_1013.meta
│   │   │   │           ├── blk_1073741844
│   │   │   │           ├── blk_1073741844_1020.meta
│   │   │   │           ├── blk_1073741846
│   │   │   │           ├── blk_1073741846_1022.meta
│   │   │   │           ├── blk_1073741847
│   │   │   │           ├── blk_1073741847_1023.meta
│   │   │   │           ├── blk_1073741849
│   │   │   │           ├── blk_1073741849_1025.meta
│   │   │   │           ├── blk_1073741850
│   │   │   │           ├── blk_1073741850_1026.meta
│   │   │   │           ├── blk_1073741853
│   │   │   │           └── blk_1073741853_1029.meta
│   │   │   └── rbw
│   │   ├── scanner.cursor
│   │   └── tmp
│   └── VERSION
└── in_use.lock

8 directories, 21 files

確認都刪除後,再看一次 hdfs 檔案系統中的 /tmp/passswd 檔案的內容

$ hdfs dfs -cat /tmp/passwd
cat: Could not obtain block: BP-1975272387-192.168.61.4-1657592975551:blk_1073741856_1032 file=/tmp/passwd No live nodes contain current block Block locations: Dead nodes:

可以看到 /tmp/passwd 的 檔案內容已被刪除,所以我們看不到

找 namenode 再要一次 /tmp/passwd 的資訊

$ hdfs fsck  /tmp/passwd  -files  -blocks  -locations

output :

...以上省略
The filesystem under path '/tmp/passwd' is CORRUPT

/tmp/passwd 檔案毀損

唯一的補救做法,刪除 /tmp/passwd 的 metadata

$ hdfs dfs -rm /tmp/passwd
Deleted /tmp/passwd

檢視 NameNode MetaData

請 name node 進入 安全模式

$ hdfs dfsadmin -safemode enter  
  • safemode 安全模式 : 不提供 新增、刪除、新改 檔案或目錄 的狀態,但允許讀取資料

檢查是否符合預期

$ hdfs dfs -mkdir /tmp/zzz
mkdir: Cannot create directory /tmp/zzz. Name node is in safe mode.

$ hdfs dfs -cat mydataset/customer.csv
4000001,Kristina,Chung,55,Pilot
4000002,Paige,Chen,74,Teacher
4000003,Sherri,Melton,34,Firefighter
...以下省略
  • 如果沒有按照正常程序關機,重開機後 hadoop 可能會自動進入安全模式,讓 Data node 做資料的更新。
$ hdfs dfsadmin -saveNamespace
Save namespace successful
  • 會立即將記憶體中的資料寫入一個新的 fsimage 檔中,寫入的動作一樣會記錄在 edits

離開安全模式

$ hdfs dfsadmin -safemode leave 

從 dtm1 取出 fsimage 檔, 並將之轉換成 csv 格式檔,最後透過網路拷貝到 dta1 的 /tmp 目錄中

$ hdfs dfsadmin -fetchImage  /tmp/

檢查是否符合預期

$ dir /tmp
total 396K
...
-rw-r--r--  1 bigred bigred 3.4K Jul 14 13:51 fsimage_0000000000000000847
...

fsimage_* 這個檔案轉成 csv 檔

# HDFS Offline Image Viewer
$ hdfs oiv -i /tmp/fsimage_0000000000000000847 -o /tmp/fsimage.csv -p Delimited -delimiter ","
  • -i ,指定 fsimage 或 xml 檔
  • -o ,要輸出的檔名
  •  -p,--processor <arg>   Select which type of processor to apply
                         against image file. (XML|FileDistribution|
                         ReverseXML|Web|Delimited|DetectCorruption)
                         The default is Web.
     -delimiter <arg>       Delimiting string to use with Delimited or
                         DetectCorruption processor.

看檔案內容

$ cat /tmp/fsimage.csv 

:::spoiler output ( fsimage 的真面目 ) :

Path,Replication,ModificationTime,AccessTime,PreferredBlockSize,BlocksCount,FileSize,NSQUOTA,DSQUOTA,Permission,UserName,GroupName
/,0,2022-07-13 16:07,1970-01-01 08:00,0,0,0,9223372036854775807,-1,drwxr-xr-x,bigred,bigboss
/tmp,0,2022-07-14 13:31,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn,0,2022-07-12 10:30,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging,0,2022-07-12 10:40,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging/history,0,2022-07-12 10:30,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging/history/done,0,2022-07-12 10:42,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging/history/done_intermediate,0,2022-07-12 10:40,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/user,0,2022-07-13 14:54,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,bigred,bigboss
/user/bigred,0,2022-07-13 10:32,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,bigred,bigboss
/tmp/hadoop-yarn/staging/bigred,0,2022-07-12 10:40,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging/bigred/.staging,0,2022-07-12 10:40,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging/history/done_intermediate/bigred,0,2022-07-12 10:42,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging/history/done/2022/07/12/000000/job_1657593022842_0001-1657593622915-bigred-QuasiMonteCarlo-1657593635730-2-1-SUCCEEDED-root.bigred-1657593627728.jhist,2,2022-07-12 10:40,2022-07-12 10:40,134217728,1,26266,0,0,-rwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging/history/done/2022/07/12/000000/job_1657593022842_0001_conf.xml,2,2022-07-12 10:40,2022-07-12 10:40,134217728,1,274268,0,0,-rwxrwxrwx,bigred,bigboss
/tmp/spark-events,0,2022-07-12 10:41,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/user/bigred/.sparkStaging,0,2022-07-12 10:41,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,bigred,bigboss
/tmp/spark-events/application_1657593022842_0002,2,2022-07-12 10:41,2022-07-12 10:40,134217728,1,119259,0,0,-rwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging/history/done/2022,0,2022-07-12 10:42,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging/history/done/2022/07,0,2022-07-12 10:42,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging/history/done/2022/07/12,0,2022-07-12 10:42,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/tmp/hadoop-yarn/staging/history/done/2022/07/12/000000,0,2022-07-12 10:42,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/user/bigred/mydataset,0,2022-07-13 11:31,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,bigred,bigboss
/user/bigred/mydataset/customer.csv,2,2022-07-13 10:36,2022-07-13 10:36,134217728,1,695,0,0,-rw-r--r--,bigred,bigboss
/user/bigred/mydataset/US,0,2022-07-13 10:47,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,bigred,bigboss
/user/bigred/mydataset/TW,0,2022-07-13 11:44,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,bigred,bigboss
/user/bigred/mydataset/TW/hosts,2,2022-07-13 10:49,2022-07-13 10:49,134217728,1,216,0,0,-rw-r--r--,bigred,bigboss
/user/bigred/mydataset/103u.txt,2,2022-07-13 11:31,2022-07-13 11:31,134217728,1,20807,0,0,-rw-r--r--,bigred,bigboss
/user/bigred/mydataset/TW/radio.txt,2,2022-07-13 11:44,2022-07-13 11:44,134217728,1,31,0,0,-rw-r--r--,bigred,bigboss
/user/rbean,0,2022-07-13 15:51,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,rbean,rbean
/user/gbean,0,2022-07-13 14:54,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,gbean,gbean
/user/ybean,0,2022-07-13 14:54,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,ybean,ybean
/app,0,2022-07-13 15:07,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,bigred,bigboss
/app/mkuser,2,2022-07-13 15:07,2022-07-13 15:07,134217728,1,568,0,0,-rw-r--r--,bigred,bigboss
/app/rmuser,2,2022-07-13 15:07,2022-07-13 15:07,134217728,1,471,0,0,-rw-r--r--,bigred,bigboss
/dataset,0,2022-07-13 15:50,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,bigred,bigboss
/dataset/customer.csv,2,2022-07-13 15:50,2022-07-13 15:50,134217728,1,695,0,0,-rw-r--r--,bigred,bigboss
/user/rbean/mydata,0,2022-07-13 16:05,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,rbean,rbean
/raw,0,2022-07-13 16:06,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,bigred,bigboss
/elt,0,2022-07-13 16:07,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,bigred,bigboss
/apps,0,2022-07-13 16:25,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxr-x+,bigred,bigboss
/metadata,0,2022-07-13 16:07,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,bigred,bigboss
/tmp/hive,0,2022-07-13 16:07,1970-01-01 08:00,0,0,0,-1,-1,drwxrwxrwx,bigred,bigboss
/apps/sh,0,2022-07-13 16:23,1970-01-01 08:00,0,0,0,-1,-1,drwxr-xr-x,rbean,bigboss
/apps/sysinfo,2,2022-07-13 16:25,2022-07-13 16:25,134217728,1,264,0,0,-rw-r--r--,rbean,bigboss

:::

重新設定 HDFS Replication ( 一個檔案存幾個 block )

Replication | 備份的資料不是躺在硬碟哩,也會出來作戰

在 dta1 主機, 執行以下命令 :

$ sudo nano /opt/hadoop-3.3.3/etc/hadoop/hdfs-site.xml 
  • xml 檔 | 標籤比內容多,現已被新的系統工程被淘汰,注意 xml 的內容,多一個"空格"或 “?” 就會導致系統 run 不起來
  • yaml 檔 | 新的系統工程專用的設定檔, 全名 : “Yet Another Markup Language”

如何證明一個 block 可以存 3 份 ?

$ hdfs fsck  /tmp/group  -files  -blocks  -locations
<?xml version="1.0" encoding="UTF-8"?>
.........
<configuration>
  <property>
    <name>dfs.replication</name>
    <value>3</value>
  </property>
...........
</configuration>

output :

BP-1975272387-192.168.61.4-1657592975551:blk_1073741857_1033 len=905 Live_repl=3  [DatanodeInfoWithStorage[192.168.61.8:9866,DS-32e4459d-a2f0-4885-be2d-43814c5aeac3,DISK], DatanodeInfoWithStorage[192.168.61.7:9866,DS-980b49ce-18f7-4283-b202-753842be315b,DISK], DatanodeInfoWithStorage[192.168.61.6:9866,DS-4742e5e8-949e-4c34-89fb-8afdef10b61c,DISK]]

在 client 端 (dta1) 修改 dfs.replication 數值後, 不需重新啟動 HDFS 分散檔案系統, 設定值直接生效

  • hdfs 的檔案系統,由多台 linux ext4 的檔案系統 + Java program 組成
tags: 資料科技平台