HDFS文件在線編輯的實現思路

今天思考到一個問題,HDFS文件怎麼實現的在線編輯?

hdfs 有個 -put 命令,允許攜帶一些參數完成特殊的需求:

  1. 上傳文件
    hdfs dfs -put
  2. 在文件中追加
    hdfs dfs -appendToFile
  3. 強制更新
    hdfs dfs -put -f

首先上傳了一個文件到HDFS上:hdfs dfs -put test1File /haddop/test1File

然後需要在這個文件中進行內容追加:hdfs dfs -appendToFile test2File /hadoop/test1File

最後需要重置hdfs上的文件內容:hdfs dfs -put -f test1File /hadoop/test1File

下面是測試的過程:

[hdfs@potter hdfs]$ cat test1File 
hello
[hdfs@potter hdfs]$ cat test2File 
Hey
[hdfs@potter hdfs]$ hdfs dfs -mkdir hdfs://cluster:8020/data/test11
[hdfs@potter hdfs]$ hdfs dfs -put test1File hdfs://cluster:8020/data/test11/
[hdfs@potter hdfs]$ hdfs dfs -cat hdfs://cluster:8020/data/test11/test1File
hello
[hdfs@potter hdfs]$ hdfs dfs -appendToFile test2File hdfs://cluster:8020/data/test11/test1File
[hdfs@potter hdfs]$ hdfs dfs -cat hdfs://cluster:8020/data/test11/test1File
hello
Hey
[hdfs@potter hdfs]$ hdfs dfs -put -f test1File hdfs://cluster:8020/data/test11/test1File
[hdfs@potter hdfs]$ hdfs dfs -cat hdfs://cluster:8020/data/test11/test1File
hello

最後,在線編輯文件的方式,可以通過覆蓋命令實現:hdfs dfs -put -f <修改過的文件> <線上已經存在的文件>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章