# FixHoodieMetaFile工具
#### 功能说明
根据Hive Metastore中保存的表信息恢复丢失的hoodie.properties、hoodie.index.properties元数据文件。工具不支持备份恢复。
#### 约束
不支持properties文件损坏或无权限等异常修复，只解决文件丢失问题。如果文件存在异常请先备份删除文件后，再使用工具进行恢复。
#### 命令格式
```
spark-submit \
--master yarn \
--driver-memory 2G \
--num-executors 3 \
--executor-memory 4G \
--class com.huawei.mrs.hudi.tools.FixHoodieMetaFile \
/opt/hudi-fix-tools-1.0.jar \
${命令} ${库名.表名} [${表属性}...]
```
#### 参数说明
| **参数**   | **是否必选** | **参数说明**                                                                                                                                                                                                                                                                                                                                              |
|:---|:---|:---|
| ${命令}    | 是        | - check：检测并输出hoodie.properties、hoodie.index.properties文件是否存在。  - fix：重新生成不存在的元数据文件。   |
| ${库名.表名} | 是        | 需要处理的Hudi表名，格式为库名.表名。                                                                                                                                                                                                                                                                                                                                 |
| ${表属性}   | 否        | 以key=value形式提供的额外表属性，用于恢复hoodie.index.properties时补充缺失的索引信息。可输入多个，格式为key1=value1 key2=value2。仅包含一个=的参数有效，key=value=extra格式会被静默忽略。                                                                                                                                                                                                                      |
   
#### 输出结果说明
| **字段**  | **说明**                      |
|:---|:---|
| RESULT  | success表示执行成功，failed表示执行失败。 |
| MESSAGE | 检测、执行结果信息或执行失败信息。           |
   
**check命令的MESSAGE**：
| **MESSAGE**                                                              | **说明**                       |
|:---|:---|
| No problems found.                                                       | 两个文件均存在。                     |
| ERROR: The hoodie.properties file does not exist.                        | hoodie.properties文件缺失。       |
| ERROR: The hoodie.index.properties file does not exist.                  | hoodie.index.properties文件缺失。 |
| ERROR: The hoodie.properties and hoodie.index.properties does not exist. | 两个文件均缺失。                     |
   
#### 使用样例
- 检查元数据文件是否存在：
  ```
  spark-submit --master yarn --driver-memory 2G --num-executors 3 --executor-memory 4G \
  --class com.huawei.mrs.hudi.tools.FixHoodieMetaFile \
  /opt/hudi-fix-tools-1.0.jar \
  check mydb.mytable
  ```
  
- 恢复缺失的元数据文件（Hive Metastore中包含完整索引信息）：
  ```
  spark-submit --master yarn --driver-memory 2G --num-executors 3 --executor-memory 4G \
  --class com.huawei.mrs.hudi.tools.FixHoodieMetaFile \
  /opt/hudi-fix-tools-1.0.jar \
  fix mydb.mytable
  ```
  
- 恢复缺失的元数据文件（Hive Metastore中缺少索引信息，需手动提供）：
  ```
  spark-submit --master yarn --driver-memory 2G --num-executors 3 --executor-memory 4G \
  --class com.huawei.mrs.hudi.tools.FixHoodieMetaFile \
  /opt/hudi-fix-tools-1.0.jar \
  fix mydb.mytable hoodie.index.type=BUCKET hoodie.bucket.index.num.buckets=4
  ```
  
 
