華能 + Alluxio | 數字化浪潮下跨地域資料聯邦訪問與分析
1. 數字化轉型與國產化程序推進
為了響應國家“十四五”數字經濟發展規劃的號召,中國企業推動創新資源共建共享,促進創新模式開放化演進,在資訊化、數字化、智慧化的強烈需求下,中國龍頭企業統籌全渠道的技術能力,逐漸形成了一套覆蓋集團業務發展、經營管理等核心發展戰略需要的戰略方向。
數字化轉型初見成效,資料能力不斷挖掘與創新;大資料技術推陳出新,國產化步伐日益加快。無論是網際網路企業還是傳統行業下的領導企業,有什麼資料,如何使用資料,如何更加智慧地利用資料這些議題被不斷挖掘與迭代。
在東數西算的理念下,資料跨平臺、跨機房、跨地域的技術問題與挑戰逐漸浮現出來。這篇文章我們主要從技術的角度,對跨地域的資料聯邦,或者說總公司和分公司不同資料域的互聯互通進行討論,研究相關技術可行性與分享整個研究過程。為了加快國產化軟硬體的推進,本次實踐採用國產化硬體ARM伺服器(鯤鵬920)以及國產化作業系統統信進行相關的技術驗證。
2. 原型目標與設計
通過對跨地域資料聯邦的調研,我們發現中國很多企業面臨的業務挑戰雖然不同,但是技術難點是相似的,主要有:
挑戰一:總公司通過傳統的ETL作業採集分公司資料(比如通過Informatica、Kettle、DataX等),這些作業往往是按需定製,並且定期執行的;當有新的資料合規要求或者總公司資料分析要求時,都需要進行定製開發、測試、部署,這對資料彙總的時效性帶來了很大的負面影響。另外通過ETL作業採集的分公司資料,在遇到分公司資料更新時,非常容易造成總公司與分公司之間的資料不一致,導致分析結果有所紕漏。
挑戰二:子公司的自助式查詢,一方面是對總公司的資料申請,很多時候整個資料訪問鏈路是斷裂的,往往需要通過流程篩查、繁瑣的資料同步手段進行(比如通過FTP傳輸,甚至是物理介質的長途運輸)。考慮到資料安全以及國家審計合規的要求,總公司資料是否可以在子公司持久化儲存、資料訪問脫敏、許可權管控等等也都是當前中國企業面臨的具體技術挑戰。
因此我們本次的研究主要會關注在資料流的雙向流動方面。
2.1 研究原型技術選型
當前大資料技術已經成為企業內部典型的資料分析手段,因此在原型實現的過程中,我們主要使用開源的大資料技術,從儲存、計算(分析)、編排3個維度進行選型。其中每個維度我們選擇時下最主流的元件,以確保該原型的通用性。
資料儲存:
√ HDFS:Hadoop分散式檔案系統(Distributed File System)
資料分析(以SQL分析為主):
√ Hive:構建於Hadoop之上的資料倉庫,通過一種類SQL語言HiveQL為使用者提供資料的歸納、查詢和分析等功能。
資料編排:
√ lluxio:Alluxio是一個開源的虛擬分散式檔案系統( Virtual Distributed File System, VDFS),位於大資料棧中的計算和儲存之間。它為計算框架提供了資料抽象層,使得應用能夠通過一個共同的介面連線底層不同的儲存系統。
環境模擬:總公司/分公司-1/分公司-2
√ 每個公司有自建的HDFS叢集;
√ 每個公司有自建的Alluxio叢集:用於實現與本公司HDFS叢集和其他公司HDFS叢集的資料聯邦;
√ 每個公司有自建的Hive叢集。
備註: CPU型號: 鯤鵬920 HDFS 3.1.1 Hive 3.1.0 Alluxio 2.8
2.2 資料流定義
使用HDFS、Hive、Alluxio定義資料持久化與資料訪問鏈路。在總公司和分公司構建統一的技術棧(技術標準),實現資料共享閉環: 1 在總公司資料域,實現分公司資料聯邦,允許總公司實現全域資料訪問與分析;
2 在分公司資料域,合規訪問總公司資料湖,並結合子公司私有資料進行自助化分析;
3. Alluxio在ARM環境下的基本測試
3.1 Alluxio基於ARM編譯
## 編譯
mvn -T2C -DskipTests -Dmaven.javadoc.skip -Dlicense.skip -
Dcheckstyle.skip -Dfindbugs.skip clean install
3.2 Alluxio基於ARM伺服器的部署與基本測試
## 基本測試
[[email protected] ~]# alluxio runTests
3.3 Alluxio分散式高可用性驗證(自動切換+手動切換)
## 管理命令獲取元資料高可用資訊
[[email protected] ~]# alluxio fsadmin journal quorum info -domain MASTER
Journal domain : MASTER
Quorum size : 3
Quorum leader : node1:19200
STATE | PRIORITY | SERVER ADDRESS
AVAILABLE | 0 | node1:19200
AVAILABLE | 0 | node2:19200
AVAILABLE | 0 | node3:19200
## 關閉主管理節點
[[email protected] ~]# alluxio-stop.sh master
Successfully Killed 1 process(es) successfully on node1
## 管理命令獲取元資料高可用資訊,檢查管理節點自動切換狀態
[[email protected] ~]# alluxio fsadmin journal quorum info -domain MASTER
Journal domain : MASTER
Quorum size : 3
Quorum leader : node2:19200
STATE | PRIORITY | SERVER ADDRESS
UNAVAILABLE | 0 | node1:19200
AVAILABLE | 0 | node2:19200
AVAILABLE | 0 | node3:19200
[[email protected] ~]#
## 管理命令獲取元資料高可用資訊
[[email protected] ~]# alluxio fsadmin journal quorum info -domain MASTER
Journal domain : MASTER
Quorum size : 3
Quorum leader : node2:19200
STATE | PRIORITY | SERVER ADDRESS
AVAILABLE | 0 | node1:19200
AVAILABLE | 0 | node2:19200
AVAILABLE | 0 | node3:19200
## 手動切換主節點
[[email protected] ~]# alluxio fsadmin journal quorum elect -address node3:19200
Initiating transfer of leadership to node3:19200
Successfully elected node3:19200 as the new leader
Resetting priorities of masters after successful transfer of leadership
Quorum priorities were reset to 1
## 管理命令獲取元資料高可用資訊,檢查管理節點切換狀態
[[email protected] ~]# alluxio fsadmin journal quorum info -domain MASTER
Journal domain : MASTER
Quorum size : 3
Quorum leader : node3:19200
STATE | PRIORITY | SERVER ADDRESS
AVAILABLE | 1 | node1:19200
AVAILABLE | 1 | node2:19200
AVAILABLE | 1 | node3:19200
[[email protected] ~]#
3.4 Alluxio與HDFS整合
## HDFS資料查詢
[[email protected] alluxio]# hdfs dfs -ls /test/
Found 1 items
-rw-r--r-- 1 root hdfsadmingroup 53136 2022-07-22 16:57 /test/pom.xml
## Alluxio資料掛載對映
[[email protected] alluxio]# alluxio fs mount /test/ hdfs://node1:9000/test
Mounted hdfs://node1:9000/test at /test
## Alluxio資料查詢
[[email protected] alluxio]# alluxio fs ls -R /test
-rw-r--r-- root hdfsadmingroup 53136 PERSISTED 07-22-2022 16:57:23:651 0% /test/pom.xml
[[email protected] alluxio]#
3.5 Alluxio與Hive整合
## 建立Hive表
hive> create table test.test(id int) location 'alluxio://node1:19998/test/test';
OK
Time taken: 0.116 seconds
hive>
3.6 Alluxio基於ACL的許可權控制
## 預設其他使用者可以訪問,禁止其他使用者可以訪問
[[email protected] ~]# alluxio fs setfacl -m user::--- /test
[[email protected] ~]# alluxio fs setfacl -m other::--- /test
## user1 使用者訪問失敗
[email protected] ~]$ alluxio fs ls /test
Permission denied: user=user1, access=r--, path=/test: failed at test, inode owner=root, inode group=root, inode mode=---r-x—
[[email protected] ~]$
## user1 使用者授權,訪問成功
[email protected] ~]# alluxio fs setfacl -m user:user1:rwx /test
[[email protected] ~]$ alluxio fs ls /test
-rw-r--r-- root root 1726 PERSISTED 07-25-2022 14:50:51:180 100% /test/run-presto.pl
[[email protected] ~]$
## user2 使用者未授權訪問失敗
[[email protected] ~]$ alluxio fs ls /test
Permission denied: user=user2, access=r--, path=/test: failed at test, inode owner=root, inode group=root, inode mode=---r-x---
[[email protected] ~]$
## 取消授權user1,訪問失敗
[email protected] ~]# alluxio fs setfacl -b /test
[[email protected] ~]$ alluxio fs ls /test
Permission denied: user=user1, access=r--, path=/test: failed at test, inode owner=root, inode group=root, inode mode=---r-x---
[[email protected] ~]$
## 檢視目錄許可權
[[email protected] ~]# alluxio fs getfacl /test
# file: /test
# owner: root
# group: root
user::---
group::r-x
other::---
mask::rwx
[[email protected] ~]#
4. 資料域聯邦場景研究
4.1 分公司資料彙總與總公司集中式分析
資料流驗證:在總公司資料域,實現分公司資料聯邦,允許總公司實現全域資料訪問與分析:
√ 構建總公司分公司模擬環境;
√ 總公司基於Alluxio建立資料表T3,建立分割槽x, y, z;
√ 分公司-1將HDFS目錄X對映到總公司Alluxio分割槽x,準備模擬資料;
√ 分公司-2將HDFS目錄Y對映到總公司Alluxio分割槽y,準備模擬資料;
√ 總公司使用Hive讀取T3資料,驗證:訪問分公司-1與分公司-2的所有資料正常;
√ 分公司-2將目錄Y的資料進行更新;
√ 通知總公司資料表T3 y分割槽資料變更(元資料失效);
√ 總公司使用Hive讀取T3資料,驗證:訪問分公司-1與分公司-2(更新後)的所有資料正常。
## 總公司建立t3 表
hive> create external table group_company.t3(value string)
> partitioned by (part string)
> location 'alluxio://node1:19998/group_company/t3';
OK
Time taken: 0.069 seconds
hive>
## 分公司1 分割槽x掛載到總公司 alluxio
[[email protected] ~]# hdfs dfs -put part\=x/ hdfs://node3:9000/regional_company_1/t3
[[email protected] ~]# hdfs dfs -put part\=y/ hdfs://node5:9000/regional_company_2/t3
[[email protected] ~]#
[[email protected] ~]# alluxio fs mount \
> /group_company/t3/part=x \
> hdfs://node3:9000/regional_company_1/t3/part=x
Mounted hdfs://node3:9000/regional_company_1/t3/part=x at /group_company/t3/part=x
[[email protected] ~]#
## 查詢資料
hive> MSCK REPAIR TABLE group_company.t3;
OK
Partitions not in metastore: t3:part=x
Repair: Added partition to metastore t3:part=x
Time taken: 0.169 seconds, Fetched: 2 row(s)
hive> select * from group_company.t3;
OK
1abc x
Time taken: 0.108 seconds, Fetched: 1 row(s)
hive>
## 分公司2 分割槽y掛載到總公司 alluxio
[[email protected] ~]# alluxio fs mount \
> /group_company/t3/part=y \
> hdfs://node5:9000/regional_company_2/t3/part=y
Mounted hdfs://node5:9000/regional_company_2/t3/part=y at /group_company/t3/part=y
[r[email protected] ~]#
## 查詢資料
hive> MSCK REPAIR TABLE group_company.t3;
OK
Partitions not in metastore: t3:part=y
Repair: Added partition to metastore t3:part=y
Time taken: 0.153 seconds, Fetched: 2 row(s)
hive> select * from group_company.t3;
OK
1abc x
2def y
Time taken: 0.137 seconds, Fetched: 2 row(s)
hive>
## 更新分割槽y 資料
[[email protected] ~]# hdfs dfs -cat hdfs://node5:9000/regional_company_2/t3/part=y/000000_0
2def
[[email protected] ~]# hdfs dfs -get hdfs://node5:9000/regional_company_2/t3/part=y/000000_0
[[email protected] ~]# echo '1111' > 000000_0
[[email protected] ~]# hdfs dfs -rm hdfs://node5:9000/regional_company_2/t3/part=y/000000_0
Deleted hdfs://node5:9000/regional_company_2/t3/part=y/000000_0
[[email protected] ~]# hdfs dfs -put 000000_0 hdfs://node5:9000/regional_company_2/t3/part=y/
[[email protected] ~]# hdfs dfs -cat hdfs://node5:9000/regional_company_2/t3/part=y/000000_0
1111
[[email protected] ~]#
## 更新查詢資料
hive> select * from group_company.t3;
OK
1abc x
2def y
Time taken: 0.112 seconds, Fetched: 2 row(s)
hive>
## 通知總公司更新資料
[[email protected] ~]# alluxio fs loadMetadata -F /group_company/t3
[[email protected] ~]#
## 總更新資料後查詢
hive> select * from group_company.t3;
OK
1abc x
1111 y
Time taken: 0.1 seconds, Fetched: 2 row(s)
hive>
4.2 總公司資料分發與分公司自助分析
資料流驗證:在分公司資料域,合規訪問總公司資料湖,並結合私有資料進行自助化分析:
√ 構建總公司分公司模擬環境;
√ 總公司基於HDFS建立資料表T1,建立分割槽a, b, c;
√ 分公司-1基於Alluxio使用資料表T1元資料建立相應表格T1’;
√ 總公司掛載分割槽a到分公司-1的Alluxio相關目錄;
√ 分公司-1的Hive, 訪問T1’,驗證:訪問分割槽a的資料正常;
√ 總公司掛載分割槽c到分公司-1的Alluxio相關目錄;
√ 通過分公司-1的Hive, 訪問T1’,驗證:訪問分割槽a/c的資料正常;
√ 總公司將掛載的分割槽c從分公司1撤回;
√ 通過分公司-1的Hive, 訪問T1’,驗證:僅能正常訪問分割槽a的資料;
√ 分公司建立資料表T2,完成資料表之間的join型別SQL,驗證:總公司資料與分公司自有資料聯邦訪問正常。
## 總公司建立 t1 表 三個分割槽 a b c
hive> create database group_company location '/user/hive/group_company.db';
OK
Time taken: 0.017 seconds
hive> create external table group_company.t1(value string) partitioned by (part string);
OK
Time taken: 0.144 seconds
hive> insert into table group_company.t1 partition(part='a') values('1abc');
hive> insert into table group_company.t1 partition(part='b') values('2def');
hive> insert into table group_company.t1 partition(part='c') values('3ghi');
hive> select * from group_company.t1;
OK
1abc a
2def b
3ghi c
Time taken: 0.142 seconds, Fetched: 3 row(s)
## 分公司1 掛載總表分割槽 a
[[email protected] alluxio]# bin/alluxio fs mkdir /regional_company_1/t1/
Successfully created directory /regional_company_1/t1
[[email protected] alluxio]#
[[email protected] alluxio]# bin/alluxio fs mount \
> /regional_company_1/t1/part=a \
> hdfs://node1:9000/user/hive/group_company.db/t1/part=a
Mounted hdfs://node1:9000/user/hive/group_company.db/t1/part=a at /regional_company_1/t1/part=a
[[email protected] alluxio]#
## 建立表查詢資料
hive> create external table t1(value string)
> partitioned by (part string)
> location 'alluxio://node3:19998/regional_company_1/t1';
OK
Time taken: 0.972 seconds
hive> select * from t1;
OK
Time taken: 1.282 seconds
hive> MSCK REPAIR TABLE t1;
OK
Partitions not in metastore: t1:part=a
Repair: Added partition to metastore t1:part=a
Time taken: 0.235 seconds, Fetched: 2 row(s)
hive> select * from t1;
OK
1abc a
Time taken: 0.137 seconds, Fetched: 1 row(s)
hive>
## 分公司1 掛載總表分割槽 c
[[email protected] alluxio]# bin/alluxio fs mount \
> /regional_company_1/t1/part=c \
> hdfs://node1:9000/user/hive/group_company.db/t1/part=c
Mounted hdfs://node1:9000/user/hive/group_company.db/t1/part=c at /regional_company_1/t1/part=c
[[email protected] alluxio]#
## 查詢資料
hive> MSCK REPAIR TABLE t1;
OK
Partitions not in metastore: t1:part=c
Repair: Added partition to metastore t1:part=c
Time taken: 0.244 seconds, Fetched: 2 row(s)
hive> select * from t1;
OK
1abc a
3ghi c
Time taken: 0.145 seconds, Fetched: 2 row(s)
hive>
## 撤回
[[email protected] alluxio]# bin/alluxio fs unmount /regional_company_1/t1/part=c
Unmounted /regional_company_1/t1/part=c
[[email protected] alluxio]#
hive> select * from t1;
OK
1abc a
Time taken: 2.281 seconds, Fetched: 1 row(s)
hive>
## join t2 表
hive> select * from t2;
OK
5678 a
1234 d
Time taken: 0.082 seconds, Fetched: 2 row(s)
hive>
hive> select * from (
> select * from t1
> ) t1
> join (
> select * from t2
> ) t2
> on t1.part = t2.part;
Query ID = root_20220720135305_c5730dc3-a46a-478a-a368-2e0343385700
Total jobs = 1
Hadoop job information for Stage-3: number of mappers: 1; number of reducers: 0
2022-07-20 13:53:26,621 Stage-3 map = 0%, reduce = 0%
2022-07-20 13:53:31,775 Stage-3 map = 100%, reduce = 0%, Cumulative CPU 2.42 sec
MapReduce Total cumulative CPU time: 2 seconds 420 msec
Ended Job = job_1658118353477_0009
MapReduce Jobs Launched:
Stage-Stage-3: Map: 1 Cumulative CPU: 2.42 sec HDFS Read: 8876 HDFS Write: 113 SUCCESS
Total MapReduce CPU Time Spent: 2 seconds 420 msec
OK
1abc a 5678 a
Time taken: 27.333 seconds, Fetched: 1 row(s)
hive>
5. 總結
通過本次研究發現:
1 我們在國產化軟硬體環境中(ARM+統信)對當前主流元件完成了適配和基本驗證,Hive+Alluxio+HDFS的技術棧可以在國產化環境下正常執行;
2 通過Alluxio資料編排實現跨地域的資料聯邦,實現總公司與分公司之間不同物理資料域的互聯互通,提供企業內部完整的資料鏈路;
3 通過Alluxio自身的ACL控制,以及Alluxio與底層UFS(本次驗證是HDFS)的掛載設定進行資料邏輯對映的控制;
在技術可行性方面的驗證,也為我們日後的原型優化提供了更多的思路:
1 考慮新的資料合規要求,設定Alluxio中資料的TTL控制資料訪問生命週期;
2 資料更新的機制,無論是利用UFS自身的變更通知還是外圍的訊息機制,更好地保障企業內部跨資料域的資料訪問一致性;
3 更加細粒度的資料訪問控制,通過更多的資料語義理解,提高對資料管理的靈活度;
想要獲取更多有趣有料的【活動資訊】【技術文章】【大咖觀點】,請關注[Alluxio智庫]
- Alluxio跨叢集同步機制的設計與實現
- 如何借力Alluxio推動大資料產品效能提升與成本優化?
- 2023年五大趨勢預測 | 大資料分析、人工智慧和雲產業展望
- 如何用Alluxio加速雲上深度學習訓練?
- 【螞蟻】Alluxio在螞蟻集團大規模訓練中的應用
- 從博士論文到被各大廠應用,Alluxio 如何走過 7 年創業路
- Presto on Alluxio By Alluxio SDS 單節點搭建
- Alluxio Local Cache 監控指南 Alluxio Alluxio
- 幫助 Meta 解決 Presto 中的資料孤島問題
- B站基於Iceberg Alluxio助力湖倉一體專案落地實踐
- 【聯通】資料編排技術在聯通的應用
- 【聯通】資料編排技術在聯通的應用
- Alluxio 原始碼完整解析 | 你不知道的開源資料編排系統(下篇)
- Alluxio 原始碼完整解析 | 你不知道的開源資料編排系統 (上篇)
- Meta(Facebook): 基於Alluxio Shadow Cache優化Presto架構決策
- Apache頂級專案Ranger和Alluxio的最佳實踐(附教程)
- 金山雲團隊分享 | 5000字讀懂Presto如何與Alluxio搭配
- 2min速覽:從設計、實現和優化角度淺談Alluxio元資料同步
- 華能 Alluxio | 數字化浪潮下跨地域資料聯邦訪問與分析
- 什麼是一致性雜湊?可以應用在哪些場景?