Coverage Report

Created: 2026-11-05 17:06

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
140k
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
140k
        try {
72
140k
            _mem_buffer->resetBuffer();
73
140k
            obj->write(_protocol.get());
74
140k
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
140k
        _mem_buffer->getBuffer(buffer, len);
79
140k
        return Status::OK();
80
140k
    }
_ZN5doris16ThriftSerializer9serializeIKNS_23TReportExecStatusParamsEEENS_6StatusEPT_PjPPh
Line
Count
Source
70
36.6k
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
36.6k
        try {
72
36.6k
            _mem_buffer->resetBuffer();
73
36.6k
            obj->write(_protocol.get());
74
36.6k
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
36.7k
        _mem_buffer->getBuffer(buffer, len);
79
36.7k
        return Status::OK();
80
36.6k
    }
_ZN5doris16ThriftSerializer9serializeINS_12TResultBatchEEENS_6StatusEPT_PjPPh
Line
Count
Source
70
97.9k
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
97.9k
        try {
72
97.9k
            _mem_buffer->resetBuffer();
73
97.9k
            obj->write(_protocol.get());
74
97.9k
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
97.9k
        _mem_buffer->getBuffer(buffer, len);
79
97.9k
        return Status::OK();
80
97.9k
    }
_ZN5doris16ThriftSerializer9serializeINS_26TJavaUdfExecutorCtorParamsEEENS_6StatusEPT_PjPPh
Line
Count
Source
70
5.80k
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
5.80k
        try {
72
5.80k
            _mem_buffer->resetBuffer();
73
5.80k
            obj->write(_protocol.get());
74
5.80k
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
5.81k
        _mem_buffer->getBuffer(buffer, len);
79
5.81k
        return Status::OK();
80
5.80k
    }
_ZN5doris16ThriftSerializer9serializeINS_18TIcebergCommitDataEEENS_6StatusEPT_PjPPh
Line
Count
Source
70
9
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
9
        try {
72
9
            _mem_buffer->resetBuffer();
73
9
            obj->write(_protocol.get());
74
9
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
9
        _mem_buffer->getBuffer(buffer, len);
79
9
        return Status::OK();
80
9
    }
_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
31
    Status serialize(T* obj, uint32_t* len, uint8_t** buffer) {
71
31
        try {
72
31
            _mem_buffer->resetBuffer();
73
31
            obj->write(_protocol.get());
74
31
        } catch (std::exception& e) {
75
0
            return Status::InternalError("Couldn't serialize thrift object:\n{}", e.what());
76
0
        }
77
78
31
        _mem_buffer->getBuffer(buffer, len);
79
31
        return Status::OK();
80
31
    }
81
82
    template <class T>
83
1.44k
    Status serialize(T* obj, std::string* result) {
84
1.44k
        try {
85
1.44k
            _mem_buffer->resetBuffer();
86
1.44k
            obj->write(_protocol.get());
87
1.44k
        } 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.44k
    }
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
155k
                              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
155k
    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
155k
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
155k
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
155k
            new apache::thrift::transport::TMemoryBuffer(
142
155k
                    const_cast<uint8_t*>(buf), *len,
143
155k
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
155k
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
155k
            create_deserialize_protocol(tmem_transport, compact);
146
147
155k
    try {
148
155k
        deserialized_msg->read(tproto.get());
149
155k
    } catch (std::exception& e) {
150
6
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
6
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
155k
    uint32_t bytes_left = tmem_transport->available_read();
157
155k
    *len = *len - bytes_left;
158
155k
    return Status::OK();
159
155k
}
_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
31
                              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
31
    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
31
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
31
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
31
            new apache::thrift::transport::TMemoryBuffer(
142
31
                    const_cast<uint8_t*>(buf), *len,
143
31
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
31
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
31
            create_deserialize_protocol(tmem_transport, compact);
146
147
31
    try {
148
31
        deserialized_msg->read(tproto.get());
149
31
    } 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
31
    uint32_t bytes_left = tmem_transport->available_read();
157
31
    *len = *len - bytes_left;
158
31
    return Status::OK();
159
31
}
_ZN5doris22deserialize_thrift_msgIN8tparquet12FileMetaDataEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
874
                              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
874
    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
874
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
874
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
874
            new apache::thrift::transport::TMemoryBuffer(
142
874
                    const_cast<uint8_t*>(buf), *len,
143
874
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
874
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
874
            create_deserialize_protocol(tmem_transport, compact);
146
147
874
    try {
148
874
        deserialized_msg->read(tproto.get());
149
874
    } 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
874
    uint32_t bytes_left = tmem_transport->available_read();
157
874
    *len = *len - bytes_left;
158
874
    return Status::OK();
159
874
}
_ZN5doris22deserialize_thrift_msgIN8tparquet11ColumnIndexEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
685
                              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
685
    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
685
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
685
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
685
            new apache::thrift::transport::TMemoryBuffer(
142
685
                    const_cast<uint8_t*>(buf), *len,
143
685
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
685
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
685
            create_deserialize_protocol(tmem_transport, compact);
146
147
685
    try {
148
685
        deserialized_msg->read(tproto.get());
149
685
    } 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
685
    uint32_t bytes_left = tmem_transport->available_read();
157
685
    *len = *len - bytes_left;
158
685
    return Status::OK();
159
685
}
_ZN5doris22deserialize_thrift_msgIN8tparquet11OffsetIndexEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
685
                              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
685
    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
685
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
685
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
685
            new apache::thrift::transport::TMemoryBuffer(
142
685
                    const_cast<uint8_t*>(buf), *len,
143
685
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
685
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
685
            create_deserialize_protocol(tmem_transport, compact);
146
147
685
    try {
148
685
        deserialized_msg->read(tproto.get());
149
685
    } 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
685
    uint32_t bytes_left = tmem_transport->available_read();
157
685
    *len = *len - bytes_left;
158
685
    return Status::OK();
159
685
}
_ZN5doris22deserialize_thrift_msgIN8tparquet10PageHeaderEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
4.68k
                              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.68k
    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.68k
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
4.68k
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
4.68k
            new apache::thrift::transport::TMemoryBuffer(
142
4.68k
                    const_cast<uint8_t*>(buf), *len,
143
4.68k
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
4.68k
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
4.68k
            create_deserialize_protocol(tmem_transport, compact);
146
147
4.68k
    try {
148
4.68k
        deserialized_msg->read(tproto.get());
149
4.68k
    } catch (std::exception& e) {
150
5
        return Status::InternalError<false>("Couldn't deserialize thrift msg:\n{}", e.what());
151
5
    } catch (...) {
152
        // TODO: Find the right exception for 0 bytes
153
0
        return Status::InternalError("Unknown exception");
154
0
    }
155
156
4.68k
    uint32_t bytes_left = tmem_transport->available_read();
157
4.68k
    *len = *len - bytes_left;
158
4.68k
    return Status::OK();
159
4.68k
}
_ZN5doris22deserialize_thrift_msgINS_14TQueryPlanInfoEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
6
                              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
6
    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
6
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
6
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
6
            new apache::thrift::transport::TMemoryBuffer(
142
6
                    const_cast<uint8_t*>(buf), *len,
143
6
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
6
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
6
            create_deserialize_protocol(tmem_transport, compact);
146
147
6
    try {
148
6
        deserialized_msg->read(tproto.get());
149
6
    } 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
6
    uint32_t bytes_left = tmem_transport->available_read();
157
6
    *len = *len - bytes_left;
158
6
    return Status::OK();
159
6
}
_ZN5doris22deserialize_thrift_msgINS_16TDescriptorTableEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
115
                              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
115
    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
115
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
115
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
115
            new apache::thrift::transport::TMemoryBuffer(
142
115
                    const_cast<uint8_t*>(buf), *len,
143
115
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
115
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
115
            create_deserialize_protocol(tmem_transport, compact);
146
147
115
    try {
148
115
        deserialized_msg->read(tproto.get());
149
115
    } 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
115
    uint32_t bytes_left = tmem_transport->available_read();
157
115
    *len = *len - bytes_left;
158
115
    return Status::OK();
159
115
}
_ZN5doris22deserialize_thrift_msgINS_9TExprListEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
115
                              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
115
    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
115
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
115
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
115
            new apache::thrift::transport::TMemoryBuffer(
142
115
                    const_cast<uint8_t*>(buf), *len,
143
115
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
115
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
115
            create_deserialize_protocol(tmem_transport, compact);
146
147
115
    try {
148
115
        deserialized_msg->read(tproto.get());
149
115
    } 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
115
    uint32_t bytes_left = tmem_transport->available_read();
157
115
    *len = *len - bytes_left;
158
115
    return Status::OK();
159
115
}
_ZN5doris22deserialize_thrift_msgINS_13TQueryOptionsEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
115
                              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
115
    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
115
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
115
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
115
            new apache::thrift::transport::TMemoryBuffer(
142
115
                    const_cast<uint8_t*>(buf), *len,
143
115
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
115
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
115
            create_deserialize_protocol(tmem_transport, compact);
146
147
115
    try {
148
115
        deserialized_msg->read(tproto.get());
149
115
    } 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
115
    uint32_t bytes_left = tmem_transport->available_read();
157
115
    *len = *len - bytes_left;
158
115
    return Status::OK();
159
115
}
_ZN5doris22deserialize_thrift_msgINS_9TExprNodeEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
893
                              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
893
    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
893
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
893
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
893
            new apache::thrift::transport::TMemoryBuffer(
142
893
                    const_cast<uint8_t*>(buf), *len,
143
893
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
893
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
893
            create_deserialize_protocol(tmem_transport, compact);
146
147
893
    try {
148
893
        deserialized_msg->read(tproto.get());
149
893
    } 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
893
    uint32_t bytes_left = tmem_transport->available_read();
157
893
    *len = *len - bytes_left;
158
893
    return Status::OK();
159
893
}
_ZN5doris22deserialize_thrift_msgINS_27TPipelineFragmentParamsListEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
146k
                              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
146k
    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
146k
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
146k
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
146k
            new apache::thrift::transport::TMemoryBuffer(
142
146k
                    const_cast<uint8_t*>(buf), *len,
143
146k
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
146k
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
146k
            create_deserialize_protocol(tmem_transport, compact);
146
147
146k
    try {
148
146k
        deserialized_msg->read(tproto.get());
149
146k
    } 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
146k
    uint32_t bytes_left = tmem_transport->available_read();
157
146k
    *len = *len - bytes_left;
158
146k
    return Status::OK();
159
146k
}
_ZN5doris22deserialize_thrift_msgINS_15TResultFileSinkEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
1
                              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
    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
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
1
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
1
            new apache::thrift::transport::TMemoryBuffer(
142
1
                    const_cast<uint8_t*>(buf), *len,
143
1
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
1
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
1
            create_deserialize_protocol(tmem_transport, compact);
146
147
1
    try {
148
1
        deserialized_msg->read(tproto.get());
149
1
    } 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
    uint32_t bytes_left = tmem_transport->available_read();
157
1
    *len = *len - bytes_left;
158
1
    return Status::OK();
159
1
}
_ZN5doris22deserialize_thrift_msgINS_14TFileScanRangeEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
143
                              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
143
    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
143
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
143
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
143
            new apache::thrift::transport::TMemoryBuffer(
142
143
                    const_cast<uint8_t*>(buf), *len,
143
143
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
143
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
143
            create_deserialize_protocol(tmem_transport, compact);
146
147
143
    try {
148
143
        deserialized_msg->read(tproto.get());
149
143
    } 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
143
    uint32_t bytes_left = tmem_transport->available_read();
157
143
    *len = *len - bytes_left;
158
143
    return Status::OK();
159
143
}
_ZN5doris22deserialize_thrift_msgINS_16TTableDescriptorEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
2
                              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
2
    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
2
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
2
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
2
            new apache::thrift::transport::TMemoryBuffer(
142
2
                    const_cast<uint8_t*>(buf), *len,
143
2
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
2
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
2
            create_deserialize_protocol(tmem_transport, compact);
146
147
2
    try {
148
2
        deserialized_msg->read(tproto.get());
149
2
    } 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
2
    uint32_t bytes_left = tmem_transport->available_read();
157
2
    *len = *len - bytes_left;
158
2
    return Status::OK();
159
2
}
_ZN5doris22deserialize_thrift_msgINS_19TFoldConstantParamsEEENS_6StatusEPKhPjbPT_
Line
Count
Source
132
664
                              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
664
    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
664
    conf->setMaxMessageSize(std::numeric_limits<int>::max());
140
664
    std::shared_ptr<apache::thrift::transport::TMemoryBuffer> tmem_transport(
141
664
            new apache::thrift::transport::TMemoryBuffer(
142
664
                    const_cast<uint8_t*>(buf), *len,
143
664
                    apache::thrift::transport::TMemoryBuffer::OBSERVE, conf));
144
664
    std::shared_ptr<apache::thrift::protocol::TProtocol> tproto =
145
664
            create_deserialize_protocol(tmem_transport, compact);
146
147
664
    try {
148
664
        deserialized_msg->read(tproto.get());
149
664
    } 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
664
    uint32_t bytes_left = tmem_transport->available_read();
157
664
    *len = *len - bytes_left;
158
664
    return Status::OK();
159
664
}
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_changelog(const TOlapTableSink& sink);
182
183
} // namespace doris