Coverage Report

Created: 2024-11-22 12:06

/root/doris/be/src/common/status.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file. See the AUTHORS file for names of contributors.
4
5
#pragma once
6
7
#include <fmt/format.h>
8
#include <gen_cpp/Status_types.h> // for TStatus
9
#include <gen_cpp/types.pb.h>
10
#include <glog/logging.h>
11
12
#include <cstdint>
13
#include <iostream>
14
#include <memory>
15
#include <string>
16
#include <string_view>
17
#include <utility>
18
19
#include "common/compiler_util.h" // IWYU pragma: keep
20
#ifdef ENABLE_STACKTRACE
21
#include "util/stack_util.h"
22
#endif
23
24
#include "common/expected.h"
25
26
namespace doris {
27
28
class PStatus;
29
30
namespace ErrorCode {
31
32
// E thrift_error_name, print_stacktrace
33
#define APPLY_FOR_THRIFT_ERROR_CODES(TStatusError)        \
34
    TStatusError(PUBLISH_TIMEOUT, false);                 \
35
    TStatusError(MEM_ALLOC_FAILED, true);                 \
36
    TStatusError(BUFFER_ALLOCATION_FAILED, true);         \
37
    TStatusError(INVALID_ARGUMENT, false);                \
38
    TStatusError(INVALID_JSON_PATH, false);               \
39
    TStatusError(MINIMUM_RESERVATION_UNAVAILABLE, true);  \
40
    TStatusError(CORRUPTION, true);                       \
41
    TStatusError(IO_ERROR, true);                         \
42
    TStatusError(NOT_FOUND, true);                        \
43
    TStatusError(ALREADY_EXIST, true);                    \
44
    TStatusError(NOT_IMPLEMENTED_ERROR, true);            \
45
    TStatusError(END_OF_FILE, false);                     \
46
    TStatusError(INTERNAL_ERROR, true);                   \
47
    TStatusError(RUNTIME_ERROR, true);                    \
48
    TStatusError(CANCELLED, false);                       \
49
    TStatusError(ANALYSIS_ERROR, false);                  \
50
    TStatusError(MEM_LIMIT_EXCEEDED, false);              \
51
    TStatusError(THRIFT_RPC_ERROR, true);                 \
52
    TStatusError(TIMEOUT, true);                          \
53
    TStatusError(TOO_MANY_TASKS, true);                   \
54
    TStatusError(UNINITIALIZED, false);                   \
55
    TStatusError(INCOMPLETE, false);                      \
56
    TStatusError(OLAP_ERR_VERSION_ALREADY_MERGED, false); \
57
    TStatusError(ABORTED, true);                          \
58
    TStatusError(DATA_QUALITY_ERROR, false);              \
59
    TStatusError(LABEL_ALREADY_EXISTS, true);             \
60
    TStatusError(NOT_AUTHORIZED, true);                   \
61
    TStatusError(BINLOG_DISABLE, false);                  \
62
    TStatusError(BINLOG_TOO_OLD_COMMIT_SEQ, false);       \
63
    TStatusError(BINLOG_TOO_NEW_COMMIT_SEQ, false);       \
64
    TStatusError(BINLOG_NOT_FOUND_DB, false);             \
65
    TStatusError(BINLOG_NOT_FOUND_TABLE, false);          \
66
    TStatusError(NETWORK_ERROR, false);                   \
67
    TStatusError(ILLEGAL_STATE, false);                   \
68
    TStatusError(SNAPSHOT_NOT_EXIST, true);               \
69
    TStatusError(HTTP_ERROR, true);                       \
70
    TStatusError(TABLET_MISSING, true);                   \
71
    TStatusError(NOT_MASTER, true);                       \
72
    TStatusError(OBTAIN_LOCK_FAILED, false);              \
73
    TStatusError(SNAPSHOT_EXPIRED, false);                \
74
    TStatusError(DELETE_BITMAP_LOCK_ERROR, false);
75
// E error_name, error_code, print_stacktrace
76
#define APPLY_FOR_OLAP_ERROR_CODES(E)                        \
77
    E(OK, 0, false);                                         \
78
    E(CALL_SEQUENCE_ERROR, -202, true);                      \
79
    E(BUFFER_OVERFLOW, -204, true);                          \
80
    E(CONFIG_ERROR, -205, true);                             \
81
    E(INIT_FAILED, -206, true);                              \
82
    E(INVALID_SCHEMA, -207, true);                           \
83
    E(CHECKSUM_ERROR, -208, true);                           \
84
    E(SIGNATURE_ERROR, -209, true);                          \
85
    E(CATCH_EXCEPTION, -210, true);                          \
86
    E(PARSE_PROTOBUF_ERROR, -211, true);                     \
87
    E(SERIALIZE_PROTOBUF_ERROR, -212, true);                 \
88
    E(WRITE_PROTOBUF_ERROR, -213, true);                     \
89
    E(VERSION_NOT_EXIST, -214, false);                       \
90
    E(TABLE_NOT_FOUND, -215, true);                          \
91
    E(TRY_LOCK_FAILED, -216, false);                         \
92
    E(EXCEEDED_LIMIT, -217, false);                          \
93
    E(OUT_OF_BOUND, -218, false);                            \
94
    E(INVALID_ROOT_PATH, -222, true);                        \
95
    E(NO_AVAILABLE_ROOT_PATH, -223, true);                   \
96
    E(CHECK_LINES_ERROR, -224, true);                        \
97
    E(INVALID_CLUSTER_INFO, -225, true);                     \
98
    E(TRANSACTION_NOT_EXIST, -226, false);                   \
99
    E(DISK_FAILURE, -227, true);                             \
100
    E(TRANSACTION_ALREADY_COMMITTED, -228, false);           \
101
    E(TRANSACTION_ALREADY_VISIBLE, -229, false);             \
102
    E(VERSION_ALREADY_MERGED, -230, true);                   \
103
    E(LZO_DISABLED, -231, true);                             \
104
    E(DISK_REACH_CAPACITY_LIMIT, -232, true);                \
105
    E(TOO_MANY_TRANSACTIONS, -233, false);                   \
106
    E(INVALID_SNAPSHOT_VERSION, -234, true);                 \
107
    E(TOO_MANY_VERSION, -235, false);                        \
108
    E(NOT_INITIALIZED, -236, true);                          \
109
    E(ALREADY_CANCELLED, -237, false);                       \
110
    E(TOO_MANY_SEGMENTS, -238, false);                       \
111
    E(ALREADY_CLOSED, -239, false);                          \
112
    E(SERVICE_UNAVAILABLE, -240, true);                      \
113
    E(NEED_SEND_AGAIN, -241, false);                         \
114
    E(OS_ERROR, -242, true);                                 \
115
    E(DIR_NOT_EXIST, -243, true);                            \
116
    E(FILE_NOT_EXIST, -244, true);                           \
117
    E(CREATE_FILE_ERROR, -245, true);                        \
118
    E(STL_ERROR, -246, true);                                \
119
    E(MUTEX_ERROR, -247, true);                              \
120
    E(PTHREAD_ERROR, -248, true);                            \
121
    E(UB_FUNC_ERROR, -250, true);                            \
122
    E(COMPRESS_ERROR, -251, true);                           \
123
    E(DECOMPRESS_ERROR, -252, true);                         \
124
    E(FILE_ALREADY_EXIST, -253, true);                       \
125
    E(BAD_CAST, -254, true);                                 \
126
    E(ARITHMETIC_OVERFLOW_ERRROR, -255, false);              \
127
    E(PERMISSION_DENIED, -256, false);                       \
128
    E(CE_CMD_PARAMS_ERROR, -300, true);                      \
129
    E(CE_BUFFER_TOO_SMALL, -301, true);                      \
130
    E(CE_CMD_NOT_VALID, -302, true);                         \
131
    E(CE_LOAD_TABLE_ERROR, -303, true);                      \
132
    E(CE_NOT_FINISHED, -304, true);                          \
133
    E(CE_TABLET_ID_EXIST, -305, true);                       \
134
    E(TABLE_VERSION_DUPLICATE_ERROR, -400, true);            \
135
    E(TABLE_VERSION_INDEX_MISMATCH_ERROR, -401, true);       \
136
    E(TABLE_INDEX_VALIDATE_ERROR, -402, true);               \
137
    E(TABLE_INDEX_FIND_ERROR, -403, true);                   \
138
    E(TABLE_CREATE_FROM_HEADER_ERROR, -404, true);           \
139
    E(TABLE_CREATE_META_ERROR, -405, true);                  \
140
    E(TABLE_ALREADY_DELETED_ERROR, -406, false);             \
141
    E(ENGINE_INSERT_EXISTS_TABLE, -500, true);               \
142
    E(ENGINE_DROP_NOEXISTS_TABLE, -501, true);               \
143
    E(ENGINE_LOAD_INDEX_TABLE_ERROR, -502, true);            \
144
    E(TABLE_INSERT_DUPLICATION_ERROR, -503, true);           \
145
    E(DELETE_VERSION_ERROR, -504, true);                     \
146
    E(GC_SCAN_PATH_ERROR, -505, true);                       \
147
    E(ENGINE_INSERT_OLD_TABLET, -506, true);                 \
148
    E(FETCH_OTHER_ERROR, -600, true);                        \
149
    E(FETCH_TABLE_NOT_EXIST, -601, true);                    \
150
    E(FETCH_VERSION_ERROR, -602, true);                      \
151
    E(FETCH_SCHEMA_ERROR, -603, true);                       \
152
    E(FETCH_COMPRESSION_ERROR, -604, true);                  \
153
    E(FETCH_CONTEXT_NOT_EXIST, -605, true);                  \
154
    E(FETCH_GET_READER_PARAMS_ERR, -606, true);              \
155
    E(FETCH_SAVE_SESSION_ERR, -607, true);                   \
156
    E(FETCH_MEMORY_EXCEEDED, -608, true);                    \
157
    E(READER_IS_UNINITIALIZED, -700, true);                  \
158
    E(READER_GET_ITERATOR_ERROR, -701, true);                \
159
    E(CAPTURE_ROWSET_READER_ERROR, -702, true);              \
160
    E(READER_READING_ERROR, -703, true);                     \
161
    E(READER_INITIALIZE_ERROR, -704, true);                  \
162
    E(BE_VERSION_NOT_MATCH, -800, true);                     \
163
    E(BE_REPLACE_VERSIONS_ERROR, -801, true);                \
164
    E(BE_MERGE_ERROR, -802, true);                           \
165
    E(CAPTURE_ROWSET_ERROR, -804, true);                     \
166
    E(BE_SAVE_HEADER_ERROR, -805, true);                     \
167
    E(BE_INIT_OLAP_DATA, -806, true);                        \
168
    E(BE_TRY_OBTAIN_VERSION_LOCKS, -807, true);              \
169
    E(BE_NO_SUITABLE_VERSION, -808, false);                  \
170
    E(BE_INVALID_NEED_MERGED_VERSIONS, -810, true);          \
171
    E(BE_ERROR_DELETE_ACTION, -811, true);                   \
172
    E(BE_SEGMENTS_OVERLAPPING, -812, true);                  \
173
    E(PUSH_INIT_ERROR, -900, true);                          \
174
    E(PUSH_VERSION_INCORRECT, -902, true);                   \
175
    E(PUSH_SCHEMA_MISMATCH, -903, true);                     \
176
    E(PUSH_CHECKSUM_ERROR, -904, true);                      \
177
    E(PUSH_ACQUIRE_DATASOURCE_ERROR, -905, true);            \
178
    E(PUSH_CREAT_CUMULATIVE_ERROR, -906, true);              \
179
    E(PUSH_BUILD_DELTA_ERROR, -907, true);                   \
180
    E(PUSH_VERSION_ALREADY_EXIST, -908, false);              \
181
    E(PUSH_TABLE_NOT_EXIST, -909, true);                     \
182
    E(PUSH_INPUT_DATA_ERROR, -910, true);                    \
183
    E(PUSH_TRANSACTION_ALREADY_EXIST, -911, false);          \
184
    E(PUSH_BATCH_PROCESS_REMOVED, -912, true);               \
185
    E(PUSH_COMMIT_ROWSET, -913, true);                       \
186
    E(PUSH_ROWSET_NOT_FOUND, -914, true);                    \
187
    E(INDEX_LOAD_ERROR, -1000, true);                        \
188
    E(INDEX_CHECKSUM_ERROR, -1002, true);                    \
189
    E(INDEX_DELTA_PRUNING, -1003, true);                     \
190
    E(DATA_ROW_BLOCK_ERROR, -1100, true);                    \
191
    E(DATA_FILE_TYPE_ERROR, -1101, true);                    \
192
    E(WRITER_INDEX_WRITE_ERROR, -1200, true);                \
193
    E(WRITER_DATA_WRITE_ERROR, -1201, true);                 \
194
    E(WRITER_ROW_BLOCK_ERROR, -1202, true);                  \
195
    E(WRITER_SEGMENT_NOT_FINALIZED, -1203, true);            \
196
    E(ROWBLOCK_DECOMPRESS_ERROR, -1300, true);               \
197
    E(ROWBLOCK_FIND_ROW_EXCEPTION, -1301, true);             \
198
    E(HEADER_ADD_VERSION, -1400, true);                      \
199
    E(HEADER_DELETE_VERSION, -1401, true);                   \
200
    E(HEADER_ADD_PENDING_DELTA, -1402, true);                \
201
    E(HEADER_ADD_INCREMENTAL_VERSION, -1403, true);          \
202
    E(HEADER_INVALID_FLAG, -1404, true);                     \
203
    E(HEADER_LOAD_INVALID_KEY, -1408, true);                 \
204
    E(HEADER_LOAD_JSON_HEADER, -1410, true);                 \
205
    E(HEADER_INIT_FAILED, -1411, true);                      \
206
    E(HEADER_PB_PARSE_FAILED, -1412, true);                  \
207
    E(HEADER_HAS_PENDING_DATA, -1413, true);                 \
208
    E(SCHEMA_SCHEMA_INVALID, -1500, true);                   \
209
    E(SCHEMA_SCHEMA_FIELD_INVALID, -1501, true);             \
210
    E(ALTER_MULTI_TABLE_ERR, -1600, true);                   \
211
    E(ALTER_DELTA_DOES_NOT_EXISTS, -1601, true);             \
212
    E(ALTER_STATUS_ERR, -1602, true);                        \
213
    E(PREVIOUS_SCHEMA_CHANGE_NOT_FINISHED, -1603, true);     \
214
    E(SCHEMA_CHANGE_INFO_INVALID, -1604, true);              \
215
    E(QUERY_SPLIT_KEY_ERR, -1605, true);                     \
216
    E(DATA_QUALITY_ERR, -1606, false);                       \
217
    E(COLUMN_DATA_LOAD_BLOCK, -1700, true);                  \
218
    E(COLUMN_DATA_RECORD_INDEX, -1701, true);                \
219
    E(COLUMN_DATA_MAKE_FILE_HEADER, -1702, true);            \
220
    E(COLUMN_DATA_READ_VAR_INT, -1703, true);                \
221
    E(COLUMN_DATA_PATCH_LIST_NUM, -1704, true);              \
222
    E(COLUMN_READ_STREAM, -1706, true);                      \
223
    E(COLUMN_STREAM_NOT_EXIST, -1716, true);                 \
224
    E(COLUMN_VALUE_NULL, -1717, true);                       \
225
    E(COLUMN_SEEK_ERROR, -1719, true);                       \
226
    E(COLUMN_NO_MATCH_OFFSETS_SIZE, -1720, true);            \
227
    E(COLUMN_NO_MATCH_FILTER_SIZE, -1721, true);             \
228
    E(DELETE_INVALID_CONDITION, -1900, true);                \
229
    E(DELETE_UPDATE_HEADER_FAILED, -1901, true);             \
230
    E(DELETE_SAVE_HEADER_FAILED, -1902, true);               \
231
    E(DELETE_INVALID_PARAMETERS, -1903, true);               \
232
    E(DELETE_INVALID_VERSION, -1904, true);                  \
233
    E(CUMULATIVE_NO_SUITABLE_VERSION, -2000, false);         \
234
    E(CUMULATIVE_REPEAT_INIT, -2001, true);                  \
235
    E(CUMULATIVE_INVALID_PARAMETERS, -2002, true);           \
236
    E(CUMULATIVE_FAILED_ACQUIRE_DATA_SOURCE, -2003, true);   \
237
    E(CUMULATIVE_INVALID_NEED_MERGED_VERSIONS, -2004, true); \
238
    E(CUMULATIVE_ERROR_DELETE_ACTION, -2005, true);          \
239
    E(CUMULATIVE_MISS_VERSION, -2006, true);                 \
240
    E(FULL_NO_SUITABLE_VERSION, -2008, false);               \
241
    E(FULL_MISS_VERSION, -2009, true);                       \
242
    E(META_INVALID_ARGUMENT, -3000, true);                   \
243
    E(META_OPEN_DB_ERROR, -3001, true);                      \
244
    E(META_KEY_NOT_FOUND, -3002, false);                     \
245
    E(META_GET_ERROR, -3003, true);                          \
246
    E(META_PUT_ERROR, -3004, true);                          \
247
    E(META_ITERATOR_ERROR, -3005, true);                     \
248
    E(META_DELETE_ERROR, -3006, true);                       \
249
    E(META_ALREADY_EXIST, -3007, true);                      \
250
    E(ROWSET_WRITER_INIT, -3100, true);                      \
251
    E(ROWSET_SAVE_FAILED, -3101, true);                      \
252
    E(ROWSET_GENERATE_ID_FAILED, -3102, true);               \
253
    E(ROWSET_DELETE_FILE_FAILED, -3103, true);               \
254
    E(ROWSET_BUILDER_INIT, -3104, true);                     \
255
    E(ROWSET_TYPE_NOT_FOUND, -3105, true);                   \
256
    E(ROWSET_ALREADY_EXIST, -3106, true);                    \
257
    E(ROWSET_CREATE_READER, -3107, true);                    \
258
    E(ROWSET_INVALID, -3108, true);                          \
259
    E(ROWSET_READER_INIT, -3110, true);                      \
260
    E(ROWSET_INVALID_STATE_TRANSITION, -3112, true);         \
261
    E(STRING_OVERFLOW_IN_VEC_ENGINE, -3113, true);           \
262
    E(ROWSET_ADD_MIGRATION_V2, -3114, true);                 \
263
    E(PUBLISH_VERSION_NOT_CONTINUOUS, -3115, false);         \
264
    E(ROWSET_RENAME_FILE_FAILED, -3116, false);              \
265
    E(SEGCOMPACTION_INIT_READER, -3117, false);              \
266
    E(SEGCOMPACTION_INIT_WRITER, -3118, false);              \
267
    E(SEGCOMPACTION_FAILED, -3119, false);                   \
268
    E(PIP_WAIT_FOR_RF, -3120, false);                        \
269
    E(PIP_WAIT_FOR_SC, -3121, false);                        \
270
    E(ROWSET_ADD_TO_BINLOG_FAILED, -3122, true);             \
271
    E(ROWSET_BINLOG_NOT_ONLY_ONE_VERSION, -3123, true);      \
272
    E(INVERTED_INDEX_INVALID_PARAMETERS, -6000, false);      \
273
    E(INVERTED_INDEX_NOT_SUPPORTED, -6001, false);           \
274
    E(INVERTED_INDEX_CLUCENE_ERROR, -6002, false);           \
275
    E(INVERTED_INDEX_FILE_NOT_FOUND, -6003, false);          \
276
    E(INVERTED_INDEX_BYPASS, -6004, false);                  \
277
    E(INVERTED_INDEX_NO_TERMS, -6005, false);                \
278
    E(INVERTED_INDEX_RENAME_FILE_FAILED, -6006, true);       \
279
    E(INVERTED_INDEX_EVALUATE_SKIPPED, -6007, false);        \
280
    E(INVERTED_INDEX_BUILD_WAITTING, -6008, false);          \
281
    E(INVERTED_INDEX_NOT_IMPLEMENTED, -6009, false);         \
282
    E(INVERTED_INDEX_COMPACTION_ERROR, -6010, false);        \
283
    E(INVERTED_INDEX_ANALYZER_ERROR, -6011, false);          \
284
    E(KEY_NOT_FOUND, -7000, false);                          \
285
    E(KEY_ALREADY_EXISTS, -7001, false);                     \
286
    E(ENTRY_NOT_FOUND, -7002, false);                        \
287
    E(CGROUP_ERROR, -7411, false);
288
289
// Define constexpr int error_code_name = error_code_value
290
#define M(NAME, ERRORCODE, ENABLESTACKTRACE) constexpr int NAME = ERRORCODE;
291
APPLY_FOR_OLAP_ERROR_CODES(M)
292
#undef M
293
294
#define MM(name, ENABLESTACKTRACE) constexpr int name = TStatusCode::name;
295
APPLY_FOR_THRIFT_ERROR_CODES(MM)
296
#undef MM
297
298
constexpr int MAX_ERROR_CODE_DEFINE_NUM = 65536;
299
struct ErrorCodeState {
300
    int16_t error_code = 0;
301
    bool stacktrace = true;
302
    std::string description;
303
    size_t count = 0; // Used for count the number of error happens
304
    std::mutex mutex; // lock guard for count state
305
};
306
extern ErrorCodeState error_states[MAX_ERROR_CODE_DEFINE_NUM];
307
308
class ErrorCodeInitializer {
309
public:
310
    ErrorCodeInitializer(int temp) : signal_value(temp) {
311
        for (auto& error_state : error_states) {
312
            error_state.error_code = 0;
313
        }
314
#define M(NAME, ENABLESTACKTRACE)                                  \
315
    error_states[TStatusCode::NAME].stacktrace = ENABLESTACKTRACE; \
316
    error_states[TStatusCode::NAME].description = #NAME;           \
317
    error_states[TStatusCode::NAME].error_code = TStatusCode::NAME;
318
        APPLY_FOR_THRIFT_ERROR_CODES(M)
319
#undef M
320
// In status.h, if error code > 0, then it means it will be used in TStatusCode and will
321
// also be used in FE.
322
// Other error codes that with error code < 0, will only be used in BE.
323
// We use abs(error code) as the index in error_states, so that these two kinds of error
324
// codes MUST not have overlap.
325
// Add an assert here to make sure the code in TStatusCode and other error code are not
326
// overlapped.
327
#define M(NAME, ERRORCODE, ENABLESTACKTRACE)                    \
328
    assert(error_states[abs(ERRORCODE)].error_code == 0);       \
329
    error_states[abs(ERRORCODE)].stacktrace = ENABLESTACKTRACE; \
330
    error_states[abs(ERRORCODE)].error_code = ERRORCODE;
331
        APPLY_FOR_OLAP_ERROR_CODES(M)
332
#undef M
333
    }
334
335
1
    void check_init() const {
336
        //the signal value is 0, it means the global error states not inited, it's logical error
337
        // DO NOT use dcheck here, because dcheck depend on glog, and glog maybe not inited at this time.
338
1
        if (signal_value == 0) {
339
0
            exit(-1);
340
0
        }
341
1
    }
342
343
private:
344
    int signal_value = 0;
345
};
346
347
extern ErrorCodeInitializer error_code_init;
348
} // namespace ErrorCode
349
350
class [[nodiscard]] Status {
351
public:
352
35.0M
    Status() : _code(ErrorCode::OK), _err_msg(nullptr) {}
353
354
    // used to convert Exception to Status
355
0
    Status(int code, std::string msg, std::string stack) : _code(code) {
356
0
        _err_msg = std::make_unique<ErrMsg>();
357
0
        _err_msg->_msg = msg;
358
0
#ifdef ENABLE_STACKTRACE
359
0
        _err_msg->_stack = stack;
360
0
#endif
361
0
    }
362
363
    // copy c'tor makes copy of error detail so Status can be returned by value
364
205k
    Status(const Status& rhs) { *this = rhs; }
365
366
    // move c'tor
367
19.9k
    Status(Status&& rhs) noexcept = default;
368
369
    // same as copy c'tor
370
205k
    Status& operator=(const Status& rhs) {
371
205k
        _code = rhs._code;
372
205k
        if (rhs._err_msg) {
373
148
            _err_msg = std::make_unique<ErrMsg>(*rhs._err_msg);
374
148
        }
375
205k
        return *this;
376
205k
    }
377
378
    // move assign
379
2.82M
    Status& operator=(Status&& rhs) noexcept {
380
2.82M
        _code = rhs._code;
381
2.82M
        if (rhs._err_msg) {
382
874
            _err_msg = std::move(rhs._err_msg);
383
874
        }
384
2.82M
        return *this;
385
2.82M
    }
386
387
    template <bool stacktrace = true>
388
    Status static create(const TStatus& status) {
389
        return Error<stacktrace>(
390
                status.status_code,
391
                "TStatus: " + (status.error_msgs.empty() ? "" : status.error_msgs[0]));
392
    }
393
394
    template <bool stacktrace = true>
395
    Status static create(const PStatus& pstatus) {
396
        return Error<stacktrace>(
397
                pstatus.status_code(),
398
                "PStatus: " + (pstatus.error_msgs_size() == 0 ? "" : pstatus.error_msgs(0)));
399
    }
400
401
    template <int code, bool stacktrace = true, typename... Args>
402
5.75k
    Status static Error(std::string_view msg, Args&&... args) {
403
5.75k
        Status status;
404
5.75k
        status._code = code;
405
5.75k
        status._err_msg = std::make_unique<ErrMsg>();
406
5.75k
        if constexpr (sizeof...(args) == 0) {
407
3
            status._err_msg->_msg = msg;
408
3
        } else {
409
3
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
410
3
        }
411
#ifdef ENABLE_STACKTRACE
412
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
413
            // Delete the first one frame pointers, which are inside the status.h
414
            status._err_msg->_stack = get_stack_trace(1);
415
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
416
        }
417
#endif
418
5.75k
        return status;
419
5.75k
    }
Unexecuted instantiation: _ZN5doris6Status5ErrorILi5ELb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
_ZN5doris6Status5ErrorILi33ELb0EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Line
Count
Source
402
10
    Status static Error(std::string_view msg, Args&&... args) {
403
10
        Status status;
404
10
        status._code = code;
405
10
        status._err_msg = std::make_unique<ErrMsg>();
406
10
        if constexpr (sizeof...(args) == 0) {
407
10
            status._err_msg->_msg = msg;
408
10
        } else {
409
10
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
410
10
        }
411
#ifdef ENABLE_STACKTRACE
412
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
413
            // Delete the first one frame pointers, which are inside the status.h
414
            status._err_msg->_stack = get_stack_trace(1);
415
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
416
        }
417
#endif
418
10
        return status;
419
10
    }
Unexecuted instantiation: _ZN5doris6Status5ErrorILi4ELb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
_ZN5doris6Status5ErrorILi32ELb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Line
Count
Source
402
1
    Status static Error(std::string_view msg, Args&&... args) {
403
1
        Status status;
404
1
        status._code = code;
405
1
        status._err_msg = std::make_unique<ErrMsg>();
406
1
        if constexpr (sizeof...(args) == 0) {
407
1
            status._err_msg->_msg = msg;
408
1
        } else {
409
1
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
410
1
        }
411
#ifdef ENABLE_STACKTRACE
412
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
413
            // Delete the first one frame pointers, which are inside the status.h
414
            status._err_msg->_stack = get_stack_trace(1);
415
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
416
        }
417
#endif
418
1
        return status;
419
1
    }
_ZN5doris6Status5ErrorILi33ELb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Line
Count
Source
402
30
    Status static Error(std::string_view msg, Args&&... args) {
403
30
        Status status;
404
30
        status._code = code;
405
30
        status._err_msg = std::make_unique<ErrMsg>();
406
30
        if constexpr (sizeof...(args) == 0) {
407
30
            status._err_msg->_msg = msg;
408
30
        } else {
409
30
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
410
30
        }
411
#ifdef ENABLE_STACKTRACE
412
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
413
            // Delete the first one frame pointers, which are inside the status.h
414
            status._err_msg->_stack = get_stack_trace(1);
415
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
416
        }
417
#endif
418
30
        return status;
419
30
    }
Unexecuted instantiation: _ZN5doris6Status5ErrorILi3ELb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi33ELb1EJRmRKtEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi33ELb0EJRNS_10segment_v214HashStrategyPBEEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
_ZN5doris6Status5ErrorILi6ELb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Line
Count
Source
402
42
    Status static Error(std::string_view msg, Args&&... args) {
403
42
        Status status;
404
42
        status._code = code;
405
42
        status._err_msg = std::make_unique<ErrMsg>();
406
42
        if constexpr (sizeof...(args) == 0) {
407
42
            status._err_msg->_msg = msg;
408
42
        } else {
409
42
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
410
42
        }
411
#ifdef ENABLE_STACKTRACE
412
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
413
            // Delete the first one frame pointers, which are inside the status.h
414
            status._err_msg->_stack = get_stack_trace(1);
415
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
416
        }
417
#endif
418
42
        return status;
419
42
    }
Unexecuted instantiation: _ZN5doris6Status5ErrorILin6009ELb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi6ELb1EJR8CURLcodeEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi33ELb0EJNS_13PredicateTypeEEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
_ZN5doris6Status5ErrorILin3002ELb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Line
Count
Source
402
38
    Status static Error(std::string_view msg, Args&&... args) {
403
38
        Status status;
404
38
        status._code = code;
405
38
        status._err_msg = std::make_unique<ErrMsg>();
406
38
        if constexpr (sizeof...(args) == 0) {
407
38
            status._err_msg->_msg = msg;
408
38
        } else {
409
38
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
410
38
        }
411
#ifdef ENABLE_STACKTRACE
412
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
413
            // Delete the first one frame pointers, which are inside the status.h
414
            status._err_msg->_stack = get_stack_trace(1);
415
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
416
        }
417
#endif
418
38
        return status;
419
38
    }
_ZN5doris6Status5ErrorILi33ELb1EJRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEES0_St17basic_string_viewIcS5_EDpOT1_
Line
Count
Source
402
2
    Status static Error(std::string_view msg, Args&&... args) {
403
2
        Status status;
404
2
        status._code = code;
405
2
        status._err_msg = std::make_unique<ErrMsg>();
406
2
        if constexpr (sizeof...(args) == 0) {
407
2
            status._err_msg->_msg = msg;
408
2
        } else {
409
2
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
410
2
        }
411
#ifdef ENABLE_STACKTRACE
412
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
413
            // Delete the first one frame pointers, which are inside the status.h
414
            status._err_msg->_stack = get_stack_trace(1);
415
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
416
        }
417
#endif
418
2
        return status;
419
2
    }
_ZN5doris6Status5ErrorILi30ELb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Line
Count
Source
402
253
    Status static Error(std::string_view msg, Args&&... args) {
403
253
        Status status;
404
253
        status._code = code;
405
253
        status._err_msg = std::make_unique<ErrMsg>();
406
253
        if constexpr (sizeof...(args) == 0) {
407
253
            status._err_msg->_msg = msg;
408
253
        } else {
409
253
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
410
253
        }
411
#ifdef ENABLE_STACKTRACE
412
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
413
            // Delete the first one frame pointers, which are inside the status.h
414
            status._err_msg->_stack = get_stack_trace(1);
415
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
416
        }
417
#endif
418
253
        return status;
419
253
    }
Unexecuted instantiation: _ZN5doris6Status5ErrorILin6010ELb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi6ELb1EJiiEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi6ELb1EJRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_EEES0_St17basic_string_viewIcS5_EDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi6ELb1EJiiiiEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
_ZN5doris6Status5ErrorILi6ELb1EJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_S7_S7_EEES0_St17basic_string_viewIcS5_EDpOT1_
Line
Count
Source
402
1
    Status static Error(std::string_view msg, Args&&... args) {
403
1
        Status status;
404
1
        status._code = code;
405
1
        status._err_msg = std::make_unique<ErrMsg>();
406
1
        if constexpr (sizeof...(args) == 0) {
407
1
            status._err_msg->_msg = msg;
408
1
        } else {
409
1
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
410
1
        }
411
#ifdef ENABLE_STACKTRACE
412
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
413
            // Delete the first one frame pointers, which are inside the status.h
414
            status._err_msg->_stack = get_stack_trace(1);
415
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
416
        }
417
#endif
418
1
        return status;
419
1
    }
Unexecuted instantiation: _ZN5doris6Status5ErrorILi12ELb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi6ELb1EJRKNS_13TSerdeDialect4typeEEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi6ELb1EJRmNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEmEEES0_St17basic_string_viewIcS6_EDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi32ELb1EJRmS2_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_EEES0_St17basic_string_viewIcS6_EDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi32ELb1EJRjRmEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi6ELb0EJPKcEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
_ZN5doris6Status5ErrorILi30ELb0EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Line
Count
Source
402
5.36k
    Status static Error(std::string_view msg, Args&&... args) {
403
5.36k
        Status status;
404
5.36k
        status._code = code;
405
5.36k
        status._err_msg = std::make_unique<ErrMsg>();
406
5.36k
        if constexpr (sizeof...(args) == 0) {
407
5.36k
            status._err_msg->_msg = msg;
408
5.36k
        } else {
409
5.36k
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
410
5.36k
        }
411
#ifdef ENABLE_STACKTRACE
412
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
413
            // Delete the first one frame pointers, which are inside the status.h
414
            status._err_msg->_stack = get_stack_trace(1);
415
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
416
        }
417
#endif
418
5.36k
        return status;
419
5.36k
    }
_ZN5doris6Status5ErrorILi1ELb0EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Line
Count
Source
402
11
    Status static Error(std::string_view msg, Args&&... args) {
403
11
        Status status;
404
11
        status._code = code;
405
11
        status._err_msg = std::make_unique<ErrMsg>();
406
11
        if constexpr (sizeof...(args) == 0) {
407
11
            status._err_msg->_msg = msg;
408
11
        } else {
409
11
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
410
11
        }
411
#ifdef ENABLE_STACKTRACE
412
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
413
            // Delete the first one frame pointers, which are inside the status.h
414
            status._err_msg->_stack = get_stack_trace(1);
415
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
416
        }
417
#endif
418
11
        return status;
419
11
    }
Unexecuted instantiation: _ZN5doris6Status5ErrorILi33ELb0EJRKPKcRiEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT1_
Unexecuted instantiation: _ZN5doris6Status5ErrorILi33ELb0EJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKPKcEEES0_St17basic_string_viewIcS5_EDpOT1_
420
421
    template <bool stacktrace = true, typename... Args>
422
14
    Status static Error(int code, std::string_view msg, Args&&... args) {
423
14
        Status status;
424
14
        status._code = code;
425
14
        status._err_msg = std::make_unique<ErrMsg>();
426
14
        if constexpr (sizeof...(args) == 0) {
427
14
            status._err_msg->_msg = msg;
428
14
        } else {
429
14
            status._err_msg->_msg = fmt::format(msg, std::forward<Args>(args)...);
430
14
        }
431
#ifdef ENABLE_STACKTRACE
432
        if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) {
433
            status._err_msg->_stack = get_stack_trace(1);
434
            LOG(WARNING) << "meet error status: " << status; // may print too many stacks.
435
        }
436
#endif
437
14
        return status;
438
14
    }
439
440
34.7M
    static Status OK() { return {}; }
441
442
// default have stacktrace. could disable manually.
443
#define ERROR_CTOR(name, code)                                                       \
444
    template <bool stacktrace = true, typename... Args>                              \
445
43
    static Status name(std::string_view msg, Args&&... args) {                       \
446
43
        return Error<ErrorCode::code, stacktrace>(msg, std::forward<Args>(args)...); \
447
43
    }
Unexecuted instantiation: _ZN5doris6Status19MemoryLimitExceededILb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Unexecuted instantiation: _ZN5doris6Status12RuntimeErrorILb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
_ZN5doris6Status10CorruptionILb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Line
Count
Source
445
1
    static Status name(std::string_view msg, Args&&... args) {                       \
446
1
        return Error<ErrorCode::code, stacktrace>(msg, std::forward<Args>(args)...); \
447
1
    }
Unexecuted instantiation: _ZN5doris6Status12NotSupportedILb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
_ZN5doris6Status13InternalErrorILb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Line
Count
Source
445
42
    static Status name(std::string_view msg, Args&&... args) {                       \
446
42
        return Error<ErrorCode::code, stacktrace>(msg, std::forward<Args>(args)...); \
447
42
    }
Unexecuted instantiation: _ZN5doris6Status13InternalErrorILb1EJR8CURLcodeEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Unexecuted instantiation: _ZN5doris6Status13InternalErrorILb1EJiiEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Unexecuted instantiation: _ZN5doris6Status13InternalErrorILb1EJRNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_EEES0_St17basic_string_viewIcS5_EDpOT0_
Unexecuted instantiation: _ZN5doris6Status13InternalErrorILb1EJiiiiEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Unexecuted instantiation: _ZN5doris6Status17BufferAllocFailedILb1EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Unexecuted instantiation: _ZN5doris6Status13InternalErrorILb1EJRKNS_13TSerdeDialect4typeEEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Unexecuted instantiation: _ZN5doris6Status13InternalErrorILb1EJRmNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEmEEES0_St17basic_string_viewIcS6_EDpOT0_
Unexecuted instantiation: _ZN5doris6Status10CorruptionILb1EJRmS2_RKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_EEES0_St17basic_string_viewIcS6_EDpOT0_
Unexecuted instantiation: _ZN5doris6Status10CorruptionILb1EJRjRmEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Unexecuted instantiation: _ZN5doris6Status13InternalErrorILb0EJPKcEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
448
449
// default have no stacktrace. could enable manually.
450
#define ERROR_CTOR_NOSTACK(name, code)                                               \
451
    template <bool stacktrace = false, typename... Args>                             \
452
5.38k
    static Status name(std::string_view msg, Args&&... args) {                       \
453
5.38k
        return Error<ErrorCode::code, stacktrace>(msg, std::forward<Args>(args)...); \
454
5.38k
    }
_ZN5doris6Status15InvalidArgumentILb0EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Line
Count
Source
452
10
    static Status name(std::string_view msg, Args&&... args) {                       \
453
10
        return Error<ErrorCode::code, stacktrace>(msg, std::forward<Args>(args)...); \
454
10
    }
Unexecuted instantiation: _ZN5doris6Status15InvalidArgumentILb0EJRNS_10segment_v214HashStrategyPBEEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Unexecuted instantiation: _ZN5doris6Status15InvalidArgumentILb0EJNS_13PredicateTypeEEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
_ZN5doris6Status9EndOfFileILb0EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Line
Count
Source
452
5.36k
    static Status name(std::string_view msg, Args&&... args) {                       \
453
5.36k
        return Error<ErrorCode::code, stacktrace>(msg, std::forward<Args>(args)...); \
454
5.36k
    }
_ZN5doris6Status9CancelledILb0EJEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Line
Count
Source
452
11
    static Status name(std::string_view msg, Args&&... args) {                       \
453
11
        return Error<ErrorCode::code, stacktrace>(msg, std::forward<Args>(args)...); \
454
11
    }
Unexecuted instantiation: _ZN5doris6Status15InvalidArgumentILb0EJRKPKcRiEEES0_St17basic_string_viewIcSt11char_traitsIcEEDpOT0_
Unexecuted instantiation: _ZN5doris6Status15InvalidArgumentILb0EJNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKPKcEEES0_St17basic_string_viewIcS5_EDpOT0_
455
456
    ERROR_CTOR(PublishTimeout, PUBLISH_TIMEOUT)
457
    ERROR_CTOR(MemoryAllocFailed, MEM_ALLOC_FAILED)
458
    ERROR_CTOR(BufferAllocFailed, BUFFER_ALLOCATION_FAILED)
459
    ERROR_CTOR_NOSTACK(InvalidArgument, INVALID_ARGUMENT)
460
    ERROR_CTOR_NOSTACK(InvalidJsonPath, INVALID_JSON_PATH)
461
    ERROR_CTOR(MinimumReservationUnavailable, MINIMUM_RESERVATION_UNAVAILABLE)
462
    ERROR_CTOR(Corruption, CORRUPTION)
463
    ERROR_CTOR(IOError, IO_ERROR)
464
    ERROR_CTOR(NotFound, NOT_FOUND)
465
    ERROR_CTOR_NOSTACK(AlreadyExist, ALREADY_EXIST)
466
    ERROR_CTOR(NotSupported, NOT_IMPLEMENTED_ERROR)
467
    ERROR_CTOR_NOSTACK(EndOfFile, END_OF_FILE)
468
    ERROR_CTOR(InternalError, INTERNAL_ERROR)
469
    ERROR_CTOR_NOSTACK(WaitForRf, PIP_WAIT_FOR_RF)
470
    ERROR_CTOR_NOSTACK(WaitForScannerContext, PIP_WAIT_FOR_SC)
471
    ERROR_CTOR(RuntimeError, RUNTIME_ERROR)
472
    ERROR_CTOR_NOSTACK(Cancelled, CANCELLED)
473
    ERROR_CTOR(MemoryLimitExceeded, MEM_LIMIT_EXCEEDED)
474
    ERROR_CTOR(RpcError, THRIFT_RPC_ERROR)
475
    ERROR_CTOR_NOSTACK(TimedOut, TIMEOUT)
476
    ERROR_CTOR_NOSTACK(TooManyTasks, TOO_MANY_TASKS)
477
    ERROR_CTOR(Uninitialized, UNINITIALIZED)
478
    ERROR_CTOR(Aborted, ABORTED)
479
    ERROR_CTOR_NOSTACK(DataQualityError, DATA_QUALITY_ERROR)
480
    ERROR_CTOR_NOSTACK(NotAuthorized, NOT_AUTHORIZED)
481
    ERROR_CTOR(HttpError, HTTP_ERROR)
482
    ERROR_CTOR_NOSTACK(NeedSendAgain, NEED_SEND_AGAIN)
483
    ERROR_CTOR(CgroupError, CGROUP_ERROR)
484
    ERROR_CTOR_NOSTACK(ObtainLockFailed, OBTAIN_LOCK_FAILED)
485
#undef ERROR_CTOR
486
487
    template <int code>
488
785k
    bool is() const {
489
785k
        return code == _code;
490
785k
    }
_ZNK5doris6Status2isILi30EEEbv
Line
Count
Source
488
776k
    bool is() const {
489
776k
        return code == _code;
490
776k
    }
_ZNK5doris6Status2isILin7002EEEbv
Line
Count
Source
488
6.02k
    bool is() const {
489
6.02k
        return code == _code;
490
6.02k
    }
_ZNK5doris6Status2isILin6003EEEbv
Line
Count
Source
488
20
    bool is() const {
489
20
        return code == _code;
490
20
    }
_ZNK5doris6Status2isILi33EEEbv
Line
Count
Source
488
1
    bool is() const {
489
1
        return code == _code;
490
1
    }
_ZNK5doris6Status2isILi39EEEbv
Line
Count
Source
488
1
    bool is() const {
489
1
        return code == _code;
490
1
    }
_ZNK5doris6Status2isILin240EEEbv
Line
Count
Source
488
2.56k
    bool is() const {
489
2.56k
        return code == _code;
490
2.56k
    }
491
492
0
    void set_code(int code) { _code = code; }
493
494
35.1M
    bool ok() const { return _code == ErrorCode::OK; }
495
496
    // Convert into TStatus.
497
    void to_thrift(TStatus* status) const;
498
    TStatus to_thrift() const;
499
    void to_protobuf(PStatus* status) const;
500
501
    std::string to_string() const;
502
    std::string to_string_no_stack() const;
503
504
    /// @return A json representation of this status.
505
    std::string to_json() const;
506
507
203
    int code() const { return _code; }
508
509
    /// Clone this status and add the specified prefix to the message.
510
    ///
511
    /// If this status is OK, then an OK status will be returned.
512
    ///
513
    /// @param [in] msg
514
    ///   The message to prepend.
515
    /// @return A ref to Status object
516
    Status& prepend(std::string_view msg);
517
518
    /// Add the specified suffix to the message.
519
    ///
520
    /// If this status is OK, then an OK status will be returned.
521
    ///
522
    /// @param [in] msg
523
    ///   The message to append.
524
    /// @return A ref to Status object
525
    Status& append(std::string_view msg);
526
527
    // if(!status) or if (status) will use this operator
528
218k
    operator bool() const { return this->ok(); }
529
530
    // Used like if ASSERT_EQ(res, Status::OK())
531
    // if the state is ok, then both code and precise code is not initialized properly, so that should check ok state
532
    // ignore error messages during comparison
533
4.22k
    bool operator==(const Status& st) const { return _code == st._code; }
534
535
    // Used like if ASSERT_NE(res, Status::OK())
536
805
    bool operator!=(const Status& st) const { return _code != st._code; }
537
538
    friend std::ostream& operator<<(std::ostream& ostr, const Status& status);
539
540
432
    std::string msg() const { return _err_msg ? _err_msg->_msg : ""; }
541
542
private:
543
    int _code;
544
    struct ErrMsg {
545
        std::string _msg;
546
#ifdef ENABLE_STACKTRACE
547
        std::string _stack;
548
#endif
549
    };
550
    std::unique_ptr<ErrMsg> _err_msg;
551
552
312
    std::string code_as_string() const {
553
312
        return (int)_code >= 0 ? doris::to_string(static_cast<TStatusCode::type>(_code))
554
312
                               : fmt::format("E{}", (int16_t)_code);
555
312
    }
556
};
557
558
// There are many thread using status to indicate the cancel state, one thread may update it and
559
// the other thread will read it. Status is not thread safe, for example, if one thread is update it
560
// and another thread is call to_string method, it may core, because the _err_msg is an unique ptr and
561
// it is deconstructed during copy method.
562
// And also we could not use lock, because we need get status frequently to check if it is cancelled.
563
// The defaule value is ok.
564
class AtomicStatus {
565
public:
566
    AtomicStatus() : error_st_(Status::OK()) {}
567
568
82
    bool ok() const { return error_code_.load(std::memory_order_acquire) == 0; }
569
570
    bool update(const Status& new_status) {
571
        // If new status is normal, or the old status is abnormal, then not need update
572
        if (new_status.ok() || error_code_.load(std::memory_order_acquire) != 0) {
573
            return false;
574
        }
575
        std::lock_guard l(mutex_);
576
        if (error_code_.load(std::memory_order_acquire) != 0) {
577
            return false;
578
        }
579
        error_st_ = new_status;
580
        error_code_.store(new_status.code(), std::memory_order_release);
581
        return true;
582
    }
583
584
    // will copy a new status object to avoid concurrency
585
    // This stauts could only be called when ok==false
586
65
    Status status() const {
587
65
        std::lock_guard l(mutex_);
588
65
        return error_st_;
589
65
    }
590
591
    AtomicStatus(const AtomicStatus&) = delete;
592
    void operator=(const AtomicStatus&) = delete;
593
594
private:
595
    std::atomic_int16_t error_code_ = 0;
596
    Status error_st_;
597
    mutable std::mutex mutex_;
598
};
599
600
168
inline std::ostream& operator<<(std::ostream& ostr, const Status& status) {
601
168
    ostr << '[' << status.code_as_string() << ']';
602
168
    ostr << status.msg();
603
#ifdef ENABLE_STACKTRACE
604
    if (status._err_msg && !status._err_msg->_stack.empty()) {
605
        ostr << '\n' << status._err_msg->_stack;
606
    }
607
#endif
608
168
    return ostr;
609
168
}
610
611
75
inline std::string Status::to_string() const {
612
75
    std::stringstream ss;
613
75
    ss << *this;
614
75
    return ss.str();
615
75
}
616
617
inline std::string Status::to_string_no_stack() const {
618
    return fmt::format("[{}]{}", code_as_string(), msg());
619
}
620
621
// some generally useful macros
622
#define RETURN_IF_ERROR(stmt)           \
623
1.38k
    do {                                \
624
1.38k
        Status _status_ = (stmt);       \
625
1.38k
        if (UNLIKELY(!_status_.ok())) { \
626
1
            return _status_;            \
627
1
        }                               \
628
1.38k
    } while (false)
629
630
#define PROPAGATE_FALSE(stmt)                     \
631
    do {                                          \
632
        if (UNLIKELY(!static_cast<bool>(stmt))) { \
633
            return false;                         \
634
        }                                         \
635
    } while (false)
636
637
#define THROW_IF_ERROR(stmt)            \
638
    do {                                \
639
        Status _status_ = (stmt);       \
640
        if (UNLIKELY(!_status_.ok())) { \
641
            throw Exception(_status_);  \
642
        }                               \
643
    } while (false)
644
645
#define RETURN_ERROR_IF_NON_VEC \
646
    return Status::NotSupported("Non-vectorized engine is not supported since Doris 2.0.");
647
648
#define RETURN_IF_STATUS_ERROR(status, stmt) \
649
    do {                                     \
650
        status = (stmt);                     \
651
        if (UNLIKELY(!status.ok())) {        \
652
            return;                          \
653
        }                                    \
654
    } while (false)
655
656
#define EXIT_IF_ERROR(stmt)             \
657
    do {                                \
658
        Status _status_ = (stmt);       \
659
        if (UNLIKELY(!_status_.ok())) { \
660
            LOG(ERROR) << _status_;     \
661
            exit(1);                    \
662
        }                               \
663
    } while (false)
664
665
#define RETURN_FALSE_IF_ERROR(stmt)   \
666
    do {                              \
667
        Status status = (stmt);       \
668
        if (UNLIKELY(!status.ok())) { \
669
            return false;             \
670
        }                             \
671
    } while (false)
672
673
/// @brief Emit a warning if @c to_call returns a bad status.
674
#define WARN_IF_ERROR(to_call, warning_prefix)              \
675
18
    do {                                                    \
676
18
        Status _s = (to_call);                              \
677
18
        if (UNLIKELY(!_s.ok())) {                           \
678
0
            LOG(WARNING) << (warning_prefix) << ": " << _s; \
679
0
        }                                                   \
680
18
    } while (false);
681
682
#define RETURN_NOT_OK_STATUS_WITH_WARN(stmt, warning_prefix)       \
683
    do {                                                           \
684
        Status _s = (stmt);                                        \
685
        if (UNLIKELY(!_s.ok())) {                                  \
686
            LOG(WARNING) << (warning_prefix) << ", error: " << _s; \
687
            return _s;                                             \
688
        }                                                          \
689
    } while (false);
690
691
template <typename T>
692
using Result = expected<T, Status>;
693
694
using ResultError = unexpected<Status>;
695
696
#define RETURN_IF_ERROR_RESULT(stmt)                \
697
    do {                                            \
698
        Status _status_ = (stmt);                   \
699
        if (UNLIKELY(!_status_.ok())) {             \
700
            return unexpected(std::move(_status_)); \
701
        }                                           \
702
    } while (false)
703
704
#define DORIS_TRY(stmt)                          \
705
    ({                                           \
706
        auto&& res = (stmt);                     \
707
        using T = std::decay_t<decltype(res)>;   \
708
        if (!res.has_value()) [[unlikely]] {     \
709
            return std::forward<T>(res).error(); \
710
        }                                        \
711
        std::forward<T>(res).value();            \
712
    });
713
714
} // namespace doris
715
716
// specify formatter for Status
717
template <>
718
struct fmt::formatter<doris::Status> {
719
    template <typename ParseContext>
720
7
    constexpr auto parse(ParseContext& ctx) {
721
7
        return ctx.begin();
722
7
    }
723
724
    template <typename FormatContext>
725
7
    auto format(doris::Status const& status, FormatContext& ctx) {
726
7
        return fmt::format_to(ctx.out(), "{}", status.to_string());
727
7
    }
728
};