Coverage Report

Created: 2026-09-30 20:03

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/io/hdfs_util.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "io/hdfs_util.h"
19
20
#include <bthread/bthread.h>
21
#include <bthread/butex.h>
22
#include <bvar/latency_recorder.h>
23
#include <gen_cpp/cloud.pb.h>
24
25
#include <ostream>
26
#include <thread>
27
28
#include "common/logging.h"
29
#include "core/string_ref.h"
30
#include "io/fs/err_utils.h"
31
#include "io/hdfs_builder.h"
32
33
namespace doris::io {
34
35
namespace hdfs_bvar {
36
bvar::LatencyRecorder hdfs_read_latency("hdfs_read");
37
bvar::LatencyRecorder hdfs_write_latency("hdfs_write");
38
bvar::LatencyRecorder hdfs_create_dir_latency("hdfs_create_dir");
39
bvar::LatencyRecorder hdfs_open_latency("hdfs_open");
40
bvar::LatencyRecorder hdfs_close_latency("hdfs_close");
41
bvar::LatencyRecorder hdfs_flush_latency("hdfs_flush");
42
bvar::LatencyRecorder hdfs_hflush_latency("hdfs_hflush");
43
bvar::LatencyRecorder hdfs_hsync_latency("hdfs_hsync");
44
bvar::LatencyRecorder hdfs_get_path_info_latency("hdfs_get_path_info");
45
}; // namespace hdfs_bvar
46
47
2
Path convert_path(const Path& path, const std::string& namenode) {
48
2
    std::string fs_path;
49
2
    if (path.native().find(namenode) != std::string::npos) {
50
        // `path` is uri format, remove the namenode part in `path`
51
        // FIXME(plat1ko): Not robust if `namenode` doesn't appear at the beginning of `path`
52
2
        fs_path = path.native().substr(namenode.size());
53
2
    } else {
54
0
        fs_path = path;
55
0
    }
56
57
    // Always use absolute path (start with '/') in hdfs
58
2
    if (fs_path.empty() || fs_path[0] != '/') {
59
0
        fs_path.insert(fs_path.begin(), '/');
60
0
    }
61
2
    return fs_path;
62
2
}
63
64
0
bool is_hdfs(const std::string& path_or_fs) {
65
0
    return path_or_fs.rfind("hdfs://") == 0;
66
0
}
67
68
0
THdfsParams to_hdfs_params(const cloud::HdfsVaultInfo& vault) {
69
0
    THdfsParams params;
70
0
    auto build_conf = vault.build_conf();
71
0
    params.__set_fs_name(build_conf.fs_name());
72
0
    if (build_conf.has_user()) {
73
0
        params.__set_user(build_conf.user());
74
0
    }
75
0
    if (build_conf.has_hdfs_kerberos_principal()) {
76
0
        params.__set_hdfs_kerberos_principal(build_conf.hdfs_kerberos_principal());
77
0
    }
78
0
    if (build_conf.has_hdfs_kerberos_keytab()) {
79
0
        params.__set_hdfs_kerberos_keytab(build_conf.hdfs_kerberos_keytab());
80
0
    }
81
0
    std::vector<THdfsConf> tconfs;
82
0
    for (const auto& confs : vault.build_conf().hdfs_confs()) {
83
0
        THdfsConf conf;
84
0
        conf.__set_key(confs.key());
85
0
        conf.__set_value(confs.value());
86
0
        tconfs.emplace_back(conf);
87
0
    }
88
0
    params.__set_hdfs_conf(tconfs);
89
0
    return params;
90
0
}
91
92
} // namespace doris::io