Introduction to Greenplum
Greenplum Database 系統(tǒng)架構(gòu)概述
Greenplum Database 通過將負(fù)載分布到數(shù)臺server上來存儲和處理大量數(shù)據(jù)。在Greenplum上,一個邏輯database是指 一組獨立的PostgreSQL databases 一起提供服務(wù),表現(xiàn)為一個獨立database image。Master是Greenplum Database system的入口,是一個用戶連接和提交SQL的database實例。Master協(xié)調(diào)將工作負(fù)載分布到系統(tǒng)內(nèi)的其他database實例上,稱為segments,負(fù)責(zé)數(shù)據(jù)處理和存儲。 Segments通過Greenplum Database的網(wǎng)絡(luò)層連接其他實例和master。

Greenplum Database 是軟件解決方案; 硬件和數(shù)據(jù)庫軟件不包含在內(nèi)。 Greenplum Database工作在Greenplum認(rèn)證過的供應(yīng)商的一系列普通服務(wù)器上。性能取決于硬件配置。因為在Greenplum Database,數(shù)據(jù)庫被分布在多臺設(shè)備上,硬件的選擇、配置對是否達到最佳性能至關(guān)重要。
這個章節(jié)描述了Greenplum Database system的主要組件,硬件的選型,和各組件的工作關(guān)聯(lián)關(guān)系。Master,Segments ,Interconnect是三大組件。另外,可選ETL Hosts for Data Loading和topic_e5t_whm_kbb(監(jiān)控查詢的工作負(fù)載和性能)組件。
The Greenplum Master
Master是 Greenplum Database system的入口。它是一臺接受客戶端連接和處理SQL命令的數(shù)據(jù)庫服務(wù)器。Users 通過master連接到 Greenplum Database,使用PostgreSQL兼容的客戶端程序,比如psql或 ODBC。
Master維護著system catalog (一系列包含著Greenplum Database system元數(shù)據(jù)的表), 但是master不包含任何用戶數(shù)據(jù)。用戶數(shù)據(jù)僅保存在segments上。Master認(rèn)證客戶端連接,處理提交的SQL命令,在 segments間分布工作負(fù)載,將每個segment提交的結(jié)果整合作為最終結(jié)果提交客戶端程序。
因為master不包含任何用戶數(shù)據(jù),所以其占用磁盤不高。Master需要快速的,獨立的CPU來處理數(shù)據(jù)加載,連接管理,查詢計劃。因為額外的空間在加載文件和備份的時候是必要的,特別是在生產(chǎn)環(huán)境??蛻粢部梢栽趍aster上運行ETL和報表工具,這會需要更多磁盤空間和處理能力。
Master Redundancy
可選的,可以部署master實例的備份或鏡像。Backup master提供warm standby如果primary master不再工作??梢詫tandby master部署在冗余master主機或者一個segment主機上。
Standby master通過transaction log replication進程來更新。進程運行在standby master上,同步primary 和 standby master 之間的數(shù)據(jù)。如果primary master 故障,日志復(fù)制進程會關(guān)閉,administrator激活standby master。當(dāng)standby master被激活,復(fù)制的日志會重建master狀態(tài),到最后成功提交事務(wù)的時間 。
既然master不包含用戶數(shù)據(jù),僅僅system catalog tables需要在主備間同步。當(dāng)tables被更新,變更會自動拷貝到standby master,這樣會一直與primary保持同步。
Figure 1. Master Mirroring in Greenplum Database

The Segments
在Greenplum Database中,segments是數(shù)據(jù)存儲和大部分查詢進程發(fā)生的地方。 用戶定義的表和它們的索引分布在可用的 segments 上。; 每個 segment 包含著一份特定的分配的數(shù)據(jù)。Segment instances 是提供segments服務(wù)的一系列數(shù)據(jù)庫服務(wù)器。在Greenplum Database system,Users 不能直接訪問segments,必須通過 master。
在Greenplum Database 硬件配置的參考文檔中,每個segment host負(fù)載的segment instances數(shù)量,取決于有效的CPU或core數(shù)量。比如,如果你的segment hosts有2顆雙核處理器,你可以在每臺host上設(shè)置2或者4個primary segments。如果你的segment hosts有三顆4核處理器,你可以在每臺host設(shè)置3,6,12個segments。性能測試會幫助確定在選定的硬件平臺上的最佳segments數(shù)量。
Segment Redundancy
當(dāng)你部署Greenplum Database system, 你可以選擇是否配置 鏡像mirror segments。 Mirror segments 允許數(shù)據(jù)庫查詢當(dāng)primary segment不可用的時候切換到backup segment 。
一個mirror segment必須與primary segment分布于不通的host。 Mirror segments 可以以一或兩種標(biāo)準(zhǔn)配置分布于系統(tǒng)內(nèi)的hosts上,或者自定義配置。
默認(rèn)配置, 稱為 group mirroring,將所有primary segments 的 mirror segments 放置于另外一臺host上。
另外一種, 稱為 spread mirroring,spreads 將每臺host的primary segments 鏡像分布到其他hosts上。 Spread mirroring 需要比primary segments占用的hosts更多的hosts。
如果hosts 是多網(wǎng)卡配置,primary 和 mirror segments 會平等的分布于每個網(wǎng)卡接口上。
Figure 2展示了在默認(rèn)group mirroring配置下,table data是怎么分布于segments的。
Figure 2. Data Mirroring in Greenplum Database

Segment Failover and Recovery
當(dāng)Greenplum Database system開啟了mirroring功能,如果primary copy變成不可用,那么系統(tǒng)會自動切換到mirror copy。 如果一個segment instance或者host宕機了,Greenplum Database system任然保持可用, 但是其他所有存活的segments的分配的數(shù)據(jù)必須在可用狀態(tài)。
如果master不能連到segment instance,它會在Greenplum Database system catalog標(biāo)記這個segment instance為invalid(無效,下線)狀態(tài)。這個segment instance 會保持invalid狀態(tài),并且不可操作,直到administrator重新設(shè)置上線。Administrator可以在系統(tǒng)運行的時候,修復(fù)故障的segment。修復(fù)進程僅僅拷貝在不可操作期間丟失的變更。
如果你沒有開啟mirroring功能,當(dāng)某segment變成invalid狀態(tài),整個系統(tǒng)會自動 shut down。直到administrator 修復(fù)所有故障的segments ,才可以繼續(xù)正常的操作。
Example Segment Host Hardware Stack
不管你硬件平臺怎么選,生產(chǎn)的Greenplum Database processing node (a segment host) 的典型配置如下。
Segment hosts處理了大多數(shù)數(shù)據(jù)庫進程,所以segment host 服務(wù)器會被優(yōu)化配置以達到最佳性能。Greenplum Database 的性能取決于最慢的segment server。因此,底層硬件和操作系統(tǒng)需要被優(yōu)化在最佳性能狀態(tài),這是很重要的。 建議,所有的 segment hosts使用同樣的硬件資源和配置。
Segment hosts被設(shè)計僅用于Greenplum Database 操作。為達到最佳性能,請不要再運行其他程序、任務(wù)。
如下圖示,一個Greenplum Database segment host的硬件棧范例。Host的有效CPU數(shù)量,是決定運行多少primary Greenplum Database segment instances的決定性因素。這個范例中,host擁有2顆有效CPU(1顆雙核CPU)。每顆CPU core運行一個primary segment instance 。
Figure 3. Example Greenplum Database Segment Host Configuration

Example Segment Disk Layout
每顆CPU都會被映射到一個邏輯盤。一個邏輯盤由一個通過I/O channel或者disk controller連到物理磁盤陣列的primary file system(mirror file system)構(gòu)成。這個邏輯盤和文件系統(tǒng)是由操作系統(tǒng)提供的。大部分操作系統(tǒng)提供邏輯盤驅(qū)動,來使用一組物理磁盤組成的RAID陣列。
Figure 4. Logical Disk Layout in Greenplum Database
取決于硬件平臺的選型,不通的RAID配置提供不通的性能和容量。 Greenplum 提供和認(rèn)證了一些參考硬件選型和操作系統(tǒng)。請于聯(lián)系銷售獲取推薦配置。
The Interconnect
Interconnect是Greenplum Database的網(wǎng)絡(luò)層。當(dāng)一個用戶連到數(shù)據(jù)庫,提交一個查詢,進程會在每個 segments 創(chuàng)建來處理這個查詢?nèi)蝿?wù)。 Interconnect 用于segments間的信息交換,正如網(wǎng)絡(luò)連接依賴于網(wǎng)絡(luò)基礎(chǔ)架構(gòu)。Interconnect 使用標(biāo)準(zhǔn)10G以太光纖卡。
默認(rèn),Greenplum Database interconnect使用帶流量控制的UDP協(xié)議來通過網(wǎng)絡(luò)發(fā)送消息。Greenplum software做了UDP不能實現(xiàn)的,額外的包確認(rèn)和檢查工作,所以可靠性等同于TCP協(xié)議,性能和擴展性又超過了TCP。 查看Greenplum Database支持的interconnect類型,請查看Greenplum Database Reference Guide中的服務(wù)器配置參數(shù) gp_interconnect_type 內(nèi)容。
Interconnect Redundancy
高可用 interconnect 可以通過部署雙交換機,來實現(xiàn)Greenplum Database master到segment host servers間的10G冗余的連接 。
Network Interface Configuration
一臺segment host通常有多塊網(wǎng)卡設(shè)計用于interconnect通信。Master host 通常會有連接擴展網(wǎng)絡(luò)接口來用于interconnect通信。
取決于可用網(wǎng)絡(luò)接口數(shù)量,你可以將網(wǎng)絡(luò)通信分布于多個可用接口上。 通過將segment instances分配到特定的網(wǎng)卡上并確保primary segments均衡的平衡負(fù)載在這些可用網(wǎng)絡(luò)接口上來實現(xiàn)。
通過給每個網(wǎng)絡(luò)接口創(chuàng)建不同的host address實現(xiàn)。比如,如果一臺host有4個網(wǎng)絡(luò)接口,那么它將會被分配4個相匹配的host address,每個都映射到1個或多個primary segments。/etc/hosts 文件將配置為不僅包含一個host name ,而是用于Greenplum Database hosts (master, standby master, segments, and ETL hosts)的所有的接口地址。
這樣配置后,操作系統(tǒng)會自動選擇到目標(biāo)的最優(yōu)路徑。 Greenplum Database 自動負(fù)載均衡網(wǎng)絡(luò)來實現(xiàn)最大并行。
Figure 5. Example Network Interface Architecture

Switch Configuration
當(dāng)在Greenplum Database 中使用多個 10G以太交換機,在每個交換機上均衡的劃分子網(wǎng)數(shù)量。在這個范例中,假設(shè)有2臺交換機, 每臺host的 NICs 1 and 2 會連到 switch 1 , NICs 3 and 4會連到 switch 2。Master host 的host name會被綁定到 NIC 1 (因此會使用 switch 1),對整個服務(wù)組而言這是最重要的master host name。因此,如果要部署一個warm standby master, 這個 standby master應(yīng)該綁定到不跟primary master連到同一個交換機上的網(wǎng)卡上。
Figure 6. Example Switch Configuration

ETL Hosts for Data Loading
Greenplum通過external tables特性支持快速、并行的 data loading(數(shù)據(jù)加載) 。通過使用 external tables以及同時工作的Greenplum Database 并行文件服務(wù)器 (gpfdist), administrators可以達到最大的并行和數(shù)據(jù)加載帶寬。很多生產(chǎn)系統(tǒng)都部署了 ETL servers 用于 data loading 。 這些機器運行 Greenplum parallel file server (gpfdist),而不是Greenplum Database instances。
使用gpfdist file server program 的一個優(yōu)勢就是,當(dāng)從external table的數(shù)據(jù)文件讀取數(shù)據(jù),可以確保所有的segments都被使用了。
Gpfdist program 發(fā)送數(shù)據(jù)到segment instances 的平均速度 可以達到 350 MB/s (delimited text formatted files)或者 200 MB/s ( CSV formatted files)。 因此,當(dāng)在ETL系統(tǒng)中使用gpfdist以最大化網(wǎng)絡(luò)帶寬占用,你需要考慮如下選項:
- 如果你的 ETL 機器配置了多塊網(wǎng)卡(NICs) 并且在網(wǎng)卡配置文件中配置了。在ETL host 上運行一個gpfdist實例 ,并且定義 external table definition,這樣每個網(wǎng)卡的host name都在 LOCATION clause 被聲明了(參考Greenplum Database Reference Guide的
CREATE EXTERNAL TABLE部分)。 這可以讓Greenplum segment hosts 和 ETL host之間的網(wǎng)絡(luò)通信同時使用所有網(wǎng)卡。
Figure 7. External Table Using Single gpfdist Instance with Multiple NICs

- 在ETL host運行多個gpfdist實例,將external data files均衡的分布到每個實例。比如,如果ETL系統(tǒng)有兩張網(wǎng)卡 (NICs),那么在那臺機器上你可以運行兩個 gpfdist 實例以最大化加載性能。然后,將external table data files 在兩個gpfdist programs上均衡的分開部署 。
Figure 8. External Tables Using Multiple gpfdist Instances with Multiple NICs
