Coverage Report

Created: 2024-11-21 14:00

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