分布式系統
谷歌三劍客
Distributed File System(Google FIle System)
如何有效存儲數據? Nosql底層需要一個文件系統
Bigtable = Nosql database
怎么鏈接底層存儲和上層數據
Map Reduce
怎么快速處理數據
GFS C++ Google
HDFS Java Yahoo
scenario
用戶寫入一個文件,用戶讀取一個文件。 >1000T
多臺機器存儲
service
client + server
社會主義: client找任何一個機器,平級
peer 2 peer: 優勢,一臺機器掛了還可以工作。劣勢,多臺機器需要經常通信保持數據一致
資本主義: master + slave ?
優勢,simple design,數據容易一直。劣勢, 單master掛(重啟)
storage
大文件存在哪?硬盤,內存存不下
怎么設計GFS?
metadata訪問常常多余內容的訪問。
?文件metadata....(反應速度快) + 實際內容... or 穿插(找metadata尋軌時間長)
機械硬盤,磁頭到某一軌道需要尋軌時間
文件內容1+2+3... or ?文件內容1-1 + 1-2 + 2-1 + 2-2 + 1-3... (方便修改,順次寫)
頻繁修改文件,要刪掉重新找位置。
metadata
file info: name = xx.mp4, createdTime = xxx, size = xx, index block11 ->diskOffset1, block12 -> diskOffset2...
blocks 1block = 4kb = 4096 bytes
100T文件,block數量太多了
增加block大小 1chunk = 64M = 64*1024k (4k -> 64k)
pros: reduce size of metadata, cons: waste space for small files
10P文件
1臺服務器最多插10個硬盤, 10 * 10T = 100T = 0.1P
100臺
master - slave通訊模式 one master + many slave servers(chunk servers)
master:
meta data: name, createTime, size
index: chunk01 -> cs5 chunk02 -> cs5 chunk03 -> cs5 ...(節省master存儲空間)
slaveServer5:
index: xx.mp4-chunk-01-offset3, xx.mp4-chunk-01-offset5 (節省通訊成本)
offset1.. offset3: xx.mp4-chunck-01
master存儲10P文件的metadata需要多少容量: 1 chunk = 64MB needs 64B 的meta data, 10 P needs 10G meta data(內存存的下)
How to write a file?
一次寫入 or ?拆分成多份多次寫入(寫入過程出錯,可以重新傳一下一小部分)
每一份傳輸大小單位是chunk
chunk怎么寫入server?
直接寫到chunk server(master變成瓶頸,都傳master) or ?先和master溝通,分配chunk server,再寫入chunk server
client to master 1.write file_name = xx.mp4, chunk index = 1
master to client 2. assign chunk server_locations=US, CS1
client to CS1 3. transfer data = gfs/home/xx.mp4-01-of-09
chunk server1 to clientr and master 4. write finish
修改xx.mp4怎么辦
chunk變大
chunk變小
一次寫入多次讀取,先刪掉文件,重新把整個寫一遍
How to read from a file
client to master 1. filename=/gfs/home/xx.mp4
master to client 2. return a chunk list
client to CS1 3. read /gfs/home/xx.mpt-00-of-09 in CS1
CS1 to client 4. return data /gfs/home/xx.mpt-00-of-09
scale
單master夠不夠, 90%都系統都采用單master
How to identify whether a chunk on the disk is broken?
check sum
寫入一塊chunk順便寫check sum
讀入這一塊數據檢查,重新讀數據并且計算現在都checksum,比較
周期性檢查
How to avoid chunk data loss when a chunk server is down/fail?
replica做備份
存三份,兩個備份相對比較近(一個機架),另一個較遠
ask master for help
chunk03->CS3,CS5,CS4
How to find whether a Chunk Server is down?
heart beat chunk servers -> master
How to solve client bottle neck?
client -> CS1 隊長 -> CS2 (內網傳快)
-> CS3
怎么選隊長? 1.找距離最近的(快) 2.找現在不干活的(平衡traffic)
浙公網安備 33010602011771號