Coverage Report

Created: 2026-10-13 23:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/thrift_util.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/DataSinks_types.h>
21
#include <gen_cpp/Types_types.h>
22
#include <thrift/TApplicationException.h>
23
#include <thrift/transport/TBufferTransports.h>
24
25
#include <cstdint>
26
#include <cstring>
27
#include <exception>
28
#include <memory>
29
#include <string>
30
#include <vector>
31
32
#include "common/status.h"
33
34
namespace apache::thrift::protocol {
35
class TProtocol;
36
class TProtocolFactory;
37
} // namespace apache::thrift::protocol
38
39
namespace doris {
40
41
class TNetworkAddress;
42
class ThriftServer;
43
44
// Utility class to serialize thrift objects to a binary format.  This object
45
// should be reused if possible to reuse the underlying memory.
46
// Note: thrift will encode NULLs into the serialized buffer so it is not valid
47
// to treat it as a string.
48
class ThriftSerializer {
49
public:
50
    // If compact, the objects will be serialized using the Compact Protocol.  Otherwise,
51
    // we'll use the binary protocol.
52
    // Note: the deserializer must be matching.
53
    ThriftSerializer(bool compact, int initial_buffer_size);
54
55
    // Serializes obj into result.  Result will contain a copy of the memory.
56
    template <class T>
57
    Status serialize(T* obj, std::vector<uint8_t>* result) {
58
        uint32_t len = 0;
59
        uint8_t* buffer = nullptr;
60
        RETURN_IF_ERROR(serialize<T>(obj, &len, &buffer));
61
        result->resize(len);
62
        memcpy(result->data(), buffer, len);
63
        return Status::OK();
64
    }
65
66
    // serialize obj into a memory buffer.  The result is returned in buffer/len.  The
67
    // memory returned is owned by this object and will be invalid when another object
68
    // is serialized.
69
    template <class T>
70
202k
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
202k
        try {
72
202k
            _mem_buffer->resetBuffer();
73
202k
            obj->write(_protocol.get());
74
202k
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
202k
        _mem_buffer->getBuffer(buffer, len);
79
202k
        return Status::OK();
80
202k
    }
_ZN5doris16ThriftSerializer9serializeIKNS_23TReportExecStatusParamsEEENS_6StatusEPT_PjPPh
Line
Count
Source
70
43.1k
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
43.1k
        try {
72
43.1k
            _mem_buffer->resetBuffer();
73
43.1k
            obj->write(_protocol.get());
74
43.1k
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
43.2k
        _mem_buffer->getBuffer(buffer, len);
79
43.2k
        return Status::OK();
80
43.1k
    }
_ZN5doris16ThriftSerializer9serializeINS_12TResultBatchEEENS_6StatusEPT_PjPPh
Line
Count
Source
70
153k
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
153k
        try {
72
153k
            _mem_buffer->resetBuffer();
73
153k
            obj->write(_protocol.get());
74
153k
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
153k
        _mem_buffer->getBuffer(buffer, len);
79
153k
        return Status::OK();
80
153k
    }
_ZN5doris16ThriftSerializer9serializeINS_26TJavaUdfExecutorCtorParamsEEENS_6StatusEPT_PjPPh
Line
Count
Source
70
5.82k
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
5.82k
        try {
72
5.82k
            _mem_buffer->resetBuffer();
73
5.82k
            obj->write(_protocol.get());
74
5.82k
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
5.82k
        _mem_buffer->getBuffer(buffer, len);
79
5.82k
        return Status::OK();
80
5.82k
    }
_ZN5doris16ThriftSerializer9serializeINS_18TIcebergCommitDataEEENS_6StatusEPT_PjPPh
Line
Count
Source
70
6
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
6
        try {
72
6
            _mem_buffer->resetBuffer();
73
6
            obj->write(_protocol.get());
74
6
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
6
        _mem_buffer->getBuffer(buffer, len);
79
6
        return Status::OK();
80
6
    }
_ZN5doris16ThriftSerializer9serializeIKNS_20TPaimonCommitMessageEEENS_6StatusEPT_PjPPh
Line
Count
Source
70
4
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
4
        try {
72
4
            _mem_buffer->resetBuffer();
73
4
            obj->write(_protocol.get());
74
4
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
4
        _mem_buffer->getBuffer(buffer, len);
79
4
        return Status::OK();
80
4
    }
_ZN5doris16ThriftSerializer9serializeINS_19TRuntimeProfileTreeEEENS_6StatusEPT_PjPPh
Line
Count
Source
70
78
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
78
        try {
72
78
            _mem_buffer->resetBuffer();
73
78
            obj->write(_protocol.get());
74
78
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
78
        _mem_buffer->getBuffer(buffer, len);
79
78
        return Status::OK();
80
78
    }
81
82
    template <class T>
83
1.43k
    Status serialize(T* obj, std::string* result) {
84
1.43k
        try {
85
1.43k
            _mem_buffer->resetBuffer();
86
1.43k
            obj->write(_protocol.get());
87
1.43k
        } catch (apache::thrift::TApplicationException& e) {
88
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
89
0
        }
90
91
1.48k
        *result = _mem_buffer->getBufferAsString();
92
1.48k
        return Status::OK();
93
1.43k
    }
94
95
    template <class T>
96
    Status serialize(T* obj) {
97
        try {
98
            _mem_buffer->resetBuffer();
99
            obj->write(_protocol.get());
100
        } catch (apache::thrift::TApplicationException& e) {
101
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
102
        }
103
104
        return Status::OK();
105
    }
106
107
0
    void get_buffer(uint8_t** buffer, uint32_t* length) { _mem_buffer->getBuffer(buffer, length); }
108
109
private:
110
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> _mem_buffer;
111
    std::shared_ptr<apache::thrift::protocol::TProtocol> _protocol;
112
};
113
114
class ThriftDeserializer {
115
public:
116
    ThriftDeserializer(bool compact);
117
118
private:
119
    std::shared_ptr<apache::thrift::protocol::TProtocolFactory> _factory;
120
    std::shared_ptr<apache::thrift::protocol::TProtocol> _tproto;
121
};
122
123
// Utility to create a protocol (deserialization) object for 'mem'.
124
std::shared_ptr<apache::thrift::protocol::TProtocol> create_deserialize_protocol(
125
        std::shared_ptr<apache::thrift::transport::TMemoryBuffer> mem, bool compact);
126
127
// Deserialize a thrift message from buf/len.  buf/len must at least contain
128
// all the bytes needed to store the thrift message.  On return, len will be
129
// set to the actual length of the header.
130
template <class T>
131
Status deserialize_thrift_msg(const uint8_t* buf, uint32_t* len, bool compact,
132
259k
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
259k
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
259k
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
259k
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
259k
            new apache::thrift::transport::TMemoryBuffer(
142
259k
                    const_cast<uint8_t*>(buf), *len,
143
259k
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
259k
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
259k
            create_deserialize_protocol(tmem_transport, compact);
146
147
259k
    try {
148
259k
        deserialized_msg->read(tproto.get());
149
259k
    } catch (std::exception& e) {
150
257
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
257
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
259k
    uint32_t bytes_left = tmem_transport->available_read();
157
259k
    *len = *len - bytes_left;
158
259k
    return Status::OK();
159
259k
}
_ZN5doris22deserialize_thrift_msgIN8tparquet17BloomFilterHeaderEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
29
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
29
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
29
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
29
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
29
            new apache::thrift::transport::TMemoryBuffer(
142
29
                    const_cast<uint8_t*>(buf), *len,
143
29
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
29
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
29
            create_deserialize_protocol(tmem_transport, compact);
146
147
29
    try {
148
29
        deserialized_msg->read(tproto.get());
149
29
    } catch (std::exception& e) {
150
1
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
1
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
28
    uint32_t bytes_left = tmem_transport->available_read();
157
28
    *len = *len - bytes_left;
158
28
    return Status::OK();
159
29
}
_ZN5doris22deserialize_thrift_msgINS_19TRuntimeProfileTreeEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
78
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
78
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
78
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
78
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
78
            new apache::thrift::transport::TMemoryBuffer(
142
78
                    const_cast<uint8_t*>(buf), *len,
143
78
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
78
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
78
            create_deserialize_protocol(tmem_transport, compact);
146
147
78
    try {
148
78
        deserialized_msg->read(tproto.get());
149
78
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
78
    uint32_t bytes_left = tmem_transport->available_read();
157
78
    *len = *len - bytes_left;
158
78
    return Status::OK();
159
78
}
_ZN5doris22deserialize_thrift_msgIN8tparquet10PageHeaderEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
13.7k
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
13.7k
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
13.7k
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
13.7k
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
13.7k
            new apache::thrift::transport::TMemoryBuffer(
142
13.7k
                    const_cast<uint8_t*>(buf), *len,
143
13.7k
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
13.7k
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
13.7k
            create_deserialize_protocol(tmem_transport, compact);
146
147
13.7k
    try {
148
13.7k
        deserialized_msg->read(tproto.get());
149
13.7k
    } catch (std::exception& e) {
150
256
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
256
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
13.4k
    uint32_t bytes_left = tmem_transport->available_read();
157
13.4k
    *len = *len - bytes_left;
158
13.4k
    return Status::OK();
159
13.7k
}
_ZN5doris22deserialize_thrift_msgIN8tparquet12FileMetaDataEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
917
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
917
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
917
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
917
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
917
            new apache::thrift::transport::TMemoryBuffer(
142
917
                    const_cast<uint8_t*>(buf), *len,
143
917
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
917
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
917
            create_deserialize_protocol(tmem_transport, compact);
146
147
917
    try {
148
917
        deserialized_msg->read(tproto.get());
149
917
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
917
    uint32_t bytes_left = tmem_transport->available_read();
157
917
    *len = *len - bytes_left;
158
917
    return Status::OK();
159
917
}
_ZN5doris22deserialize_thrift_msgIN8tparquet11ColumnIndexEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
507
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
507
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
507
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
507
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
507
            new apache::thrift::transport::TMemoryBuffer(
142
507
                    const_cast<uint8_t*>(buf), *len,
143
507
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
507
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
507
            create_deserialize_protocol(tmem_transport, compact);
146
147
507
    try {
148
507
        deserialized_msg->read(tproto.get());
149
507
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
507
    uint32_t bytes_left = tmem_transport->available_read();
157
507
    *len = *len - bytes_left;
158
507
    return Status::OK();
159
507
}
_ZN5doris22deserialize_thrift_msgIN8tparquet11OffsetIndexEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
574
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
574
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
574
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
574
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
574
            new apache::thrift::transport::TMemoryBuffer(
142
574
                    const_cast<uint8_t*>(buf), *len,
143
574
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
574
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
574
            create_deserialize_protocol(tmem_transport, compact);
146
147
574
    try {
148
574
        deserialized_msg->read(tproto.get());
149
574
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
574
    uint32_t bytes_left = tmem_transport->available_read();
157
574
    *len = *len - bytes_left;
158
574
    return Status::OK();
159
574
}
_ZN5doris22deserialize_thrift_msgINS_14TQueryPlanInfoEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
3
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
3
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
3
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
3
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
3
            new apache::thrift::transport::TMemoryBuffer(
142
3
                    const_cast<uint8_t*>(buf), *len,
143
3
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
3
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
3
            create_deserialize_protocol(tmem_transport, compact);
146
147
3
    try {
148
3
        deserialized_msg->read(tproto.get());
149
3
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
3
    uint32_t bytes_left = tmem_transport->available_read();
157
3
    *len = *len - bytes_left;
158
3
    return Status::OK();
159
3
}
_ZN5doris22deserialize_thrift_msgINS_16TDescriptorTableEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
120
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
120
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
120
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
120
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
120
            new apache::thrift::transport::TMemoryBuffer(
142
120
                    const_cast<uint8_t*>(buf), *len,
143
120
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
120
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
120
            create_deserialize_protocol(tmem_transport, compact);
146
147
120
    try {
148
120
        deserialized_msg->read(tproto.get());
149
120
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
120
    uint32_t bytes_left = tmem_transport->available_read();
157
120
    *len = *len - bytes_left;
158
120
    return Status::OK();
159
120
}
_ZN5doris22deserialize_thrift_msgINS_9TExprListEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
120
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
120
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
120
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
120
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
120
            new apache::thrift::transport::TMemoryBuffer(
142
120
                    const_cast<uint8_t*>(buf), *len,
143
120
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
120
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
120
            create_deserialize_protocol(tmem_transport, compact);
146
147
120
    try {
148
120
        deserialized_msg->read(tproto.get());
149
120
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
120
    uint32_t bytes_left = tmem_transport->available_read();
157
120
    *len = *len - bytes_left;
158
120
    return Status::OK();
159
120
}
_ZN5doris22deserialize_thrift_msgINS_13TQueryOptionsEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
120
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
120
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
120
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
120
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
120
            new apache::thrift::transport::TMemoryBuffer(
142
120
                    const_cast<uint8_t*>(buf), *len,
143
120
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
120
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
120
            create_deserialize_protocol(tmem_transport, compact);
146
147
120
    try {
148
120
        deserialized_msg->read(tproto.get());
149
120
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
120
    uint32_t bytes_left = tmem_transport->available_read();
157
120
    *len = *len - bytes_left;
158
120
    return Status::OK();
159
120
}
_ZN5doris22deserialize_thrift_msgINS_9TExprNodeEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
880
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
880
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
880
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
880
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
880
            new apache::thrift::transport::TMemoryBuffer(
142
880
                    const_cast<uint8_t*>(buf), *len,
143
880
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
880
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
880
            create_deserialize_protocol(tmem_transport, compact);
146
147
880
    try {
148
880
        deserialized_msg->read(tproto.get());
149
880
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
880
    uint32_t bytes_left = tmem_transport->available_read();
157
880
    *len = *len - bytes_left;
158
880
    return Status::OK();
159
880
}
_ZN5doris22deserialize_thrift_msgINS_27TPipelineFragmentParamsListEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
240k
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
240k
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
240k
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
240k
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
240k
            new apache::thrift::transport::TMemoryBuffer(
142
240k
                    const_cast<uint8_t*>(buf), *len,
143
240k
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
240k
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
240k
            create_deserialize_protocol(tmem_transport, compact);
146
147
240k
    try {
148
240k
        deserialized_msg->read(tproto.get());
149
240k
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
239k
    uint32_t bytes_left = tmem_transport->available_read();
157
239k
    *len = *len - bytes_left;
158
239k
    return Status::OK();
159
240k
}
_ZN5doris22deserialize_thrift_msgINS_15TResultFileSinkEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
4
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
4
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
4
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
4
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
4
            new apache::thrift::transport::TMemoryBuffer(
142
4
                    const_cast<uint8_t*>(buf), *len,
143
4
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
4
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
4
            create_deserialize_protocol(tmem_transport, compact);
146
147
4
    try {
148
4
        deserialized_msg->read(tproto.get());
149
4
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
4
    uint32_t bytes_left = tmem_transport->available_read();
157
4
    *len = *len - bytes_left;
158
4
    return Status::OK();
159
4
}
_ZN5doris22deserialize_thrift_msgINS_14TFileScanRangeEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
723
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
723
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
723
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
723
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
723
            new apache::thrift::transport::TMemoryBuffer(
142
723
                    const_cast<uint8_t*>(buf), *len,
143
723
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
723
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
723
            create_deserialize_protocol(tmem_transport, compact);
146
147
723
    try {
148
723
        deserialized_msg->read(tproto.get());
149
723
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
723
    uint32_t bytes_left = tmem_transport->available_read();
157
723
    *len = *len - bytes_left;
158
723
    return Status::OK();
159
723
}
_ZN5doris22deserialize_thrift_msgINS_16TTableDescriptorEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
3
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
3
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
3
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
3
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
3
            new apache::thrift::transport::TMemoryBuffer(
142
3
                    const_cast<uint8_t*>(buf), *len,
143
3
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
3
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
3
            create_deserialize_protocol(tmem_transport, compact);
146
147
3
    try {
148
3
        deserialized_msg->read(tproto.get());
149
3
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
3
    uint32_t bytes_left = tmem_transport->available_read();
157
3
    *len = *len - bytes_left;
158
3
    return Status::OK();
159
3
}
_ZN5doris22deserialize_thrift_msgINS_19TFoldConstantParamsEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
1.56k
                              T* deserialized_msg) {
133
    // Deserialize msg bytes into c++ thrift msg using memory
134
    // transport. TMemoryBuffer is not const-safe, although we use it in
135
    // a const-safe way, so we have to explicitly cast away the const.
136
1.56k
    auto conf = std::make_shared<apache::thrift::TConfiguration>();
137
    // On Thrift 0.14.0+, need use TConfiguration to raise the max message size.
138
    // max message size is 100MB default, so make it unlimited.
139
1.56k
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
1.56k
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
1.56k
            new apache::thrift::transport::TMemoryBuffer(
142
1.56k
                    const_cast<uint8_t*>(buf), *len,
143
1.56k
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
1.56k
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
1.56k
            create_deserialize_protocol(tmem_transport, compact);
146
147
1.56k
    try {
148
1.56k
        deserialized_msg->read(tproto.get());
149
1.56k
    } catch (std::exception& e) {
150
0
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
0
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
1.56k
    uint32_t bytes_left = tmem_transport->available_read();
157
1.56k
    *len = *len - bytes_left;
158
1.56k
    return Status::OK();
159
1.56k
}
160
161
// Redirects all Thrift logging to VLOG_CRITICAL
162
void init_thrift_logging();
163
164
// Wait for a server that is running locally to start accepting
165
// connections, up to a maximum timeout
166
Status wait_for_local_server(const ThriftServer& server, int num_retries, int retry_interval_ms);
167
168
// Wait for a server to start accepting connections, up to a maximum timeout
169
Status wait_for_server(const std::string& host, int port, int num_retries, int retry_interval_ms);
170
171
// Utility method to print address as address:port
172
void t_network_address_to_string(const TNetworkAddress& address, std::string* out);
173
174
// Compares two TNetworkAddresses alphanumerically by their host:port
175
// string representation
176
bool t_network_address_comparator(const TNetworkAddress& a, const TNetworkAddress& b);
177
178
std::string to_string(const TUniqueId& id);
179
180
bool _has_inverted_index_v1_or_partial_update(TOlapTableSink sink);
181
bool _has_row_binlog(const TOlapTableSink& sink);
182
183
} // namespace doris