Coverage Report

Created: 2024-11-21 13:02

/root/doris/be/src/common/utils.h
Line
Count
Source (jump to first uncovered line)
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 <string>
21
22
namespace doris {
23
24
#ifndef ARRAY_SIZE
25
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
26
#endif
27
28
struct AuthInfo {
29
    std::string user;
30
    std::string passwd;
31
    std::string cluster;
32
    std::string user_ip;
33
    // -1 as unset
34
    int64_t auth_code = -1;
35
    std::string token;
36
};
37
38
template <class T>
39
1
void set_request_auth(T* req, const AuthInfo& auth) {
40
1
    if (auth.auth_code != -1) {
41
        // if auth_code is set, no need to set other info
42
1
        req->__set_auth_code(auth.auth_code);
43
        // user name and passwd is unused, but they are required field.
44
        // so they have to be set.
45
1
        req->user = "";
46
1
        req->passwd = "";
47
1
    } else if (auth.token != "") {
48
0
        req->__isset.token = true;
49
0
        req->token = auth.token;
50
0
    } else {
51
0
        req->user = auth.user;
52
0
        req->passwd = auth.passwd;
53
0
        if (!auth.cluster.empty()) {
54
0
            req->__set_cluster(auth.cluster);
55
0
        }
56
0
        req->__set_user_ip(auth.user_ip);
57
0
    }
58
1
}
Unexecuted instantiation: _ZN5doris16set_request_authINS_20TLoadTxnBeginRequestEEEvPT_RKNS_8AuthInfoE
Unexecuted instantiation: _ZN5doris16set_request_authINS_18TLoadTxn2PCRequestEEEvPT_RKNS_8AuthInfoE
_ZN5doris16set_request_authINS_21TLoadTxnCommitRequestEEEvPT_RKNS_8AuthInfoE
Line
Count
Source
39
1
void set_request_auth(T* req, const AuthInfo& auth) {
40
1
    if (auth.auth_code != -1) {
41
        // if auth_code is set, no need to set other info
42
1
        req->__set_auth_code(auth.auth_code);
43
        // user name and passwd is unused, but they are required field.
44
        // so they have to be set.
45
1
        req->user = "";
46
1
        req->passwd = "";
47
1
    } else if (auth.token != "") {
48
0
        req->__isset.token = true;
49
0
        req->token = auth.token;
50
0
    } else {
51
0
        req->user = auth.user;
52
0
        req->passwd = auth.passwd;
53
0
        if (!auth.cluster.empty()) {
54
0
            req->__set_cluster(auth.cluster);
55
0
        }
56
0
        req->__set_user_ip(auth.user_ip);
57
0
    }
58
1
}
Unexecuted instantiation: _ZN5doris16set_request_authINS_23TLoadTxnRollbackRequestEEEvPT_RKNS_8AuthInfoE
Unexecuted instantiation: _ZN5doris16set_request_authINS_21TStreamLoadPutRequestEEEvPT_RKNS_8AuthInfoE
59
60
// This is the threshold used to periodically release the memory occupied by the expression.
61
// RELEASE_CONTEXT_COUNTER should be power of 2
62
// GCC will optimize the modulo operation to &(release_context_counter - 1)
63
// _conjunct_ctxs will free local alloc after this probe calculations
64
static constexpr int RELEASE_CONTEXT_COUNTER = 1 << 7;
65
static_assert((RELEASE_CONTEXT_COUNTER & (RELEASE_CONTEXT_COUNTER - 1)) == 0,
66
              "should be power of 2");
67
68
template <typename To, typename From>
69
To convert_to(From from) {
70
    union {
71
        From _from;
72
        To _to;
73
    };
74
    _from = from;
75
    return _to;
76
}
77
78
} // namespace doris