Coverage Report

Created: 2026-09-02 00:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/io/hdfs_builder.h
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
#pragma once
19
20
#include <gen_cpp/PlanNodes_types.h>
21
22
#include <map>
23
#include <string>
24
25
#include "common/status.h"
26
#include "io/fs/hdfs.h" // IWYU pragma: keep
27
28
struct hdfsBuilder;
29
30
namespace doris {
31
32
const std::string FS_KEY = "fs.defaultFS";
33
const std::string USER = "hadoop.username";
34
const std::string KERBEROS_PRINCIPAL = "hadoop.kerberos.principal";
35
const std::string KERBEROS_KEYTAB = "hadoop.kerberos.keytab";
36
const std::string HADOOP_SECURITY_AUTHENTICATION = "hadoop.security.authentication";
37
const std::string FALLBACK_TO_SIMPLE_AUTH_ALLOWED = "ipc.client.fallback-to-simple-auth-allowed";
38
const std::string TRUE_VALUE = "true";
39
40
class HDFSCommonBuilder {
41
    friend Status create_hdfs_builder(const THdfsParams& hdfsParams, const std::string& fs_name,
42
                                      HDFSCommonBuilder* builder);
43
    friend Status create_hdfs_builder(const std::map<std::string, std::string>& properties,
44
                                      HDFSCommonBuilder* builder);
45
46
public:
47
0
    HDFSCommonBuilder() {}
48
    // hdfsBuilderConnect() takes the builder over and frees it, so there is only something to
49
    // free here on the paths that never reach it: create_hdfs_builder() allocates the builder
50
    // first and can still fail afterwards - a catalog with a principal but no keytab does
51
    // exactly that - and used to leak one hdfsBuilder per such query.
52
0
    ~HDFSCommonBuilder() {
53
0
        if (hdfs_builder != nullptr) {
54
0
            hdfsFreeBuilder(hdfs_builder);
55
0
        }
56
0
    }
57
58
    HDFSCommonBuilder(const HDFSCommonBuilder&) = delete;
59
    HDFSCommonBuilder& operator=(const HDFSCommonBuilder&) = delete;
60
61
    // Must call this to init hdfs_builder first.
62
    Status init_hdfs_builder();
63
64
0
    hdfsBuilder* get() { return hdfs_builder; }
65
    // Hands the builder to hdfsBuilderConnect(), which frees it. Call it at that one call site
66
    // and nowhere else; anything else that took the pointer out of get() would double-free.
67
0
    hdfsBuilder* release() {
68
0
        hdfsBuilder* released = hdfs_builder;
69
0
        hdfs_builder = nullptr;
70
0
        return released;
71
0
    }
72
0
    bool is_kerberos() const { return kerberos_login; }
73
    Status check_krb_params();
74
75
    Status set_kerberos_ticket_cache();
76
    void set_hdfs_conf(const std::string& key, const std::string& val);
77
    std::string get_hdfs_conf_value(const std::string& key, const std::string& default_val) const;
78
    void set_hdfs_conf_to_hdfs_builder();
79
80
private:
81
    hdfsBuilder* hdfs_builder = nullptr;
82
    bool kerberos_login {false};
83
84
    // We should save these info from thrift,
85
    // so that the lifecycle of these will same as hdfs_builder
86
    std::string fs_name;
87
    std::string hadoop_user;
88
    std::string hdfs_kerberos_keytab;
89
    std::string hdfs_kerberos_principal;
90
    std::unordered_map<std::string, std::string> hdfs_conf;
91
};
92
93
THdfsParams parse_properties(const std::map<std::string, std::string>& properties);
94
95
Status create_hdfs_builder(const THdfsParams& hdfsParams, HDFSCommonBuilder* builder);
96
Status create_hdfs_builder(const std::map<std::string, std::string>& properties,
97
                           HDFSCommonBuilder* builder);
98
99
} // namespace doris