Skip to content

Commit

Permalink
[refactor] Check status precise_code instead of construct OLAPInterna…
Browse files Browse the repository at this point in the history
…lError (#9514)

* check status precise_code instead of construct OLAPInternalError
* move is_io_error to Status
  • Loading branch information
platoneko authored May 12, 2022
1 parent d26f5d2 commit 4cd579b
Show file tree
Hide file tree
Showing 25 changed files with 80 additions and 84 deletions.
4 changes: 2 additions & 2 deletions be/src/agent/task_worker_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ void TaskWorkerPool::_alter_tablet(const TAgentTaskRequest& agent_task_req, int6
EngineAlterTabletTask engine_task(agent_task_req.alter_tablet_req_v2);
Status sc_status = _env->storage_engine()->execute_task(&engine_task);
if (!sc_status.ok()) {
if (sc_status == Status::OLAPInternalError(OLAP_ERR_DATA_QUALITY_ERR)) {
if (sc_status.precise_code() == OLAP_ERR_DATA_QUALITY_ERR) {
error_msgs.push_back("The data quality does not satisfy, please check your data. ");
}
status = Status::DataQualityError("The data quality does not satisfy");
Expand Down Expand Up @@ -1734,7 +1734,7 @@ void TaskWorkerPool::_storage_medium_migrate_v2(const TAgentTaskRequest& agent_t
EngineStorageMigrationTaskV2 engine_task(agent_task_req.storage_migration_req_v2);
Status sc_status = _env->storage_engine()->execute_task(&engine_task);
if (!sc_status.ok()) {
if (sc_status == Status::OLAPInternalError(OLAP_ERR_DATA_QUALITY_ERR)) {
if (sc_status.precise_code() == OLAP_ERR_DATA_QUALITY_ERR) {
error_msgs.push_back("The data quality does not satisfy, please check your data. ");
}
status = Status::DataQualityError("The data quality does not satisfy");
Expand Down
9 changes: 8 additions & 1 deletion be/src/common/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,14 @@ class Status {
bool is_end_of_file() const { return code() == TStatusCode::END_OF_FILE; }
bool is_not_found() const { return code() == TStatusCode::NOT_FOUND; }
bool is_already_exist() const { return code() == TStatusCode::ALREADY_EXIST; }
bool is_io_error() const { return code() == TStatusCode::IO_ERROR; }
bool is_io_error() const {
auto p_code = precise_code();
return code() == TStatusCode::IO_ERROR ||
((OLAP_ERR_IO_ERROR == p_code || OLAP_ERR_READ_UNENOUGH == p_code) &&
errno == EIO) ||
OLAP_ERR_CHECKSUM_ERROR == p_code || OLAP_ERR_FILE_DATA_ERROR == p_code ||
OLAP_ERR_TEST_FILE_ERROR == p_code || OLAP_ERR_ROWBLOCK_READ_INFO_ERROR == p_code;
}

/// @return @c true iff the status indicates Uninitialized.
bool is_uninitialized() const { return code() == TStatusCode::UNINITIALIZED; }
Expand Down
4 changes: 2 additions & 2 deletions be/src/http/action/compaction_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Status CompactionAction::_execute_compaction_callback(TabletSharedPtr tablet,
BaseCompaction base_compaction(tablet);
res = base_compaction.compact();
if (!res) {
if (res == Status::OLAPInternalError(OLAP_ERR_BE_NO_SUITABLE_VERSION)) {
if (res.precise_code() == OLAP_ERR_BE_NO_SUITABLE_VERSION) {
// Ignore this error code.
VLOG_NOTICE << "failed to init base compaction due to no suitable version, tablet="
<< tablet->full_name();
Expand All @@ -223,7 +223,7 @@ Status CompactionAction::_execute_compaction_callback(TabletSharedPtr tablet,
CumulativeCompaction cumulative_compaction(tablet);
res = cumulative_compaction.compact();
if (!res) {
if (res == Status::OLAPInternalError(OLAP_ERR_CUMULATIVE_NO_SUITABLE_VERSION)) {
if (res.precise_code() == OLAP_ERR_CUMULATIVE_NO_SUITABLE_VERSION) {
// Ignore this error code.
VLOG_NOTICE << "failed to init cumulative compaction due to no suitable version,"
<< "tablet=" << tablet->full_name();
Expand Down
4 changes: 2 additions & 2 deletions be/src/olap/collect_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ inline Status CollectIterator::Level1Iterator::_merge_next(const RowCursor** row
if (LIKELY(res.ok())) {
_heap->push(_cur_child);
_cur_child = _heap->top();
} else if (res == Status::OLAPInternalError(OLAP_ERR_DATA_EOF)) {
} else if (res.precise_code() == OLAP_ERR_DATA_EOF) {
// current child has been read, to read next
delete _cur_child;
if (!_heap->empty()) {
Expand Down Expand Up @@ -412,7 +412,7 @@ inline Status CollectIterator::Level1Iterator::_normal_next(const RowCursor** ro
auto res = _cur_child->next(row, delete_flag);
if (LIKELY(res.ok())) {
return Status::OK();
} else if (res == Status::OLAPInternalError(OLAP_ERR_DATA_EOF)) {
} else if (res.precise_code() == OLAP_ERR_DATA_EOF) {
// current child has been read, to read next
delete _cur_child;
_children.pop_front();
Expand Down
9 changes: 4 additions & 5 deletions be/src/olap/data_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void DataDir::health_check() {
if (!res) {
LOG(WARNING) << "store read/write test file occur IO Error. path="
<< _path_desc.filepath;
if (is_io_error(res)) {
if (res.is_io_error()) {
_is_used = false;
}
}
Expand Down Expand Up @@ -406,9 +406,8 @@ Status DataDir::load() {
const std::string& value) -> bool {
Status status = _tablet_manager->load_tablet_from_meta(this, tablet_id, schema_hash, value,
false, false, false, false);
if (!status.ok() &&
status != Status::OLAPInternalError(OLAP_ERR_TABLE_ALREADY_DELETED_ERROR) &&
status != Status::OLAPInternalError(OLAP_ERR_ENGINE_INSERT_OLD_TABLET)) {
if (!status.ok() && status.precise_code() != OLAP_ERR_TABLE_ALREADY_DELETED_ERROR &&
status.precise_code() != OLAP_ERR_ENGINE_INSERT_OLD_TABLET) {
// load_tablet_from_meta() may return Status::OLAPInternalError(OLAP_ERR_TABLE_ALREADY_DELETED_ERROR)
// which means the tablet status is DELETED
// This may happen when the tablet was just deleted before the BE restarted,
Expand Down Expand Up @@ -501,7 +500,7 @@ Status DataDir::load() {
rowset_meta->tablet_uid() == tablet->tablet_uid()) {
Status publish_status = tablet->add_rowset(rowset, false);
if (!publish_status &&
publish_status != Status::OLAPInternalError(OLAP_ERR_PUSH_VERSION_ALREADY_EXIST)) {
publish_status.precise_code() != OLAP_ERR_PUSH_VERSION_ALREADY_EXIST) {
LOG(WARNING) << "add visible rowset to tablet failed rowset_id:"
<< rowset->rowset_id() << " tablet id: " << rowset_meta->tablet_id()
<< " txn id:" << rowset_meta->txn_id()
Expand Down
2 changes: 1 addition & 1 deletion be/src/olap/file_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Status ReadOnlyFileStream::seek(PositionProvider* position) {
res = _assure_data();
if (OLAP_LIKELY(res.ok())) {
// assure data will be successful in most case
} else if (res == Status::OLAPInternalError(OLAP_ERR_COLUMN_STREAM_EOF)) {
} else if (res.precise_code() == OLAP_ERR_COLUMN_STREAM_EOF) {
VLOG_TRACE << "file stream eof.";
return res;
} else {
Expand Down
2 changes: 1 addition & 1 deletion be/src/olap/memtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ Status MemTable::_do_flush(int64_t& duration_ns) {
SCOPED_RAW_TIMER(&duration_ns);
if (_skip_list) {
Status st = _rowset_writer->flush_single_memtable(this, &_flush_size);
if (st == Status::OLAPInternalError(OLAP_ERR_FUNC_NOT_IMPLEMENTED)) {
if (st.precise_code() == OLAP_ERR_FUNC_NOT_IMPLEMENTED) {
// For alpha rowset, we do not implement "flush_single_memtable".
// Flush the memtable like the old way.
Table::Iterator it(_skip_list.get());
Expand Down
2 changes: 1 addition & 1 deletion be/src/olap/push_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Status PushHandler::_do_streaming_ingestion(TabletSharedPtr tablet, const TPushR
request.partition_id, tablet_var.tablet, request.transaction_id, load_id,
tablet_var.rowset_to_add, false);
if (commit_status != Status::OK() &&
commit_status != Status::OLAPInternalError(OLAP_ERR_PUSH_TRANSACTION_ALREADY_EXIST)) {
commit_status.precise_code() != OLAP_ERR_PUSH_TRANSACTION_ALREADY_EXIST) {
res = commit_status;
}
}
Expand Down
24 changes: 12 additions & 12 deletions be/src/olap/rowset/column_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Status ColumnData::get_next_block(RowBlock** row_block) {
_is_normal_read = true;
auto res = _get_block(false);
if (!res.ok()) {
if (res != Status::OLAPInternalError(OLAP_ERR_DATA_EOF)) {
if (res.precise_code() != OLAP_ERR_DATA_EOF) {
LOG(WARNING) << "Get next block failed.";
}
*row_block = nullptr;
Expand Down Expand Up @@ -165,7 +165,7 @@ Status ColumnData::_find_position_by_short_key(const RowCursor& key, bool find_l
RowBlockPosition tmp_pos;
auto res = _segment_group->find_short_key(key, &_short_key_cursor, find_last_key, &tmp_pos);
if (!res.ok()) {
if (res == Status::OLAPInternalError(OLAP_ERR_INDEX_EOF)) {
if (res.precise_code() == OLAP_ERR_INDEX_EOF) {
res = Status::OLAPInternalError(OLAP_ERR_DATA_EOF);
} else {
LOG(WARNING) << "find row block failed. res = " << res;
Expand All @@ -185,7 +185,7 @@ Status ColumnData::_find_position_by_full_key(const RowCursor& key, bool find_la
RowBlockPosition tmp_pos;
auto res = _segment_group->find_short_key(key, &_short_key_cursor, false, &tmp_pos);
if (!res.ok()) {
if (res == Status::OLAPInternalError(OLAP_ERR_INDEX_EOF)) {
if (res.precise_code() == OLAP_ERR_INDEX_EOF) {
res = Status::OLAPInternalError(OLAP_ERR_DATA_EOF);
} else {
LOG(WARNING) << "find row block failed. res = " << res;
Expand All @@ -202,7 +202,7 @@ Status ColumnData::_find_position_by_full_key(const RowCursor& key, bool find_la
RowBlockPosition end_position;
res = _segment_group->find_short_key(key, &_short_key_cursor, true, &end_position);
if (!res.ok()) {
if (res == Status::OLAPInternalError(OLAP_ERR_INDEX_EOF)) {
if (res.precise_code() == OLAP_ERR_INDEX_EOF) {
res = Status::OLAPInternalError(OLAP_ERR_DATA_EOF);
} else {
LOG(WARNING) << "find row block failed. res = " << res;
Expand Down Expand Up @@ -282,7 +282,7 @@ Status ColumnData::_seek_to_row(const RowCursor& key, bool find_last_key, bool i
res = _find_position_by_short_key(key, find_last_key, &position);
}
if (!res.ok()) {
if (res != Status::OLAPInternalError(OLAP_ERR_DATA_EOF)) {
if (res.precise_code() != OLAP_ERR_DATA_EOF) {
LOG(WARNING) << "Fail to find the key.[res=" << res << " key=" << key.to_string()
<< " find_last_key=" << find_last_key << "]";
}
Expand All @@ -299,7 +299,7 @@ Status ColumnData::_seek_to_row(const RowCursor& key, bool find_last_key, bool i
}
res = _get_block(without_filter);
if (!res.ok()) {
if (res != Status::OLAPInternalError(OLAP_ERR_DATA_EOF)) {
if (res.precise_code() != OLAP_ERR_DATA_EOF) {
LOG(WARNING) << "Fail to find the key.[res=" << res << " key=" << key.to_string()
<< " find_last_key=" << find_last_key << "]";
}
Expand Down Expand Up @@ -359,19 +359,19 @@ Status ColumnData::prepare_block_read(const RowCursor* start_key, bool find_star
_end_block = _current_block;
_end_row_index = _read_block->pos();
_end_key_is_set = true;
} else if (res != Status::OLAPInternalError(OLAP_ERR_DATA_EOF)) {
} else if (res.precise_code() != OLAP_ERR_DATA_EOF) {
LOG(WARNING) << "Find end key failed.key=" << end_key->to_string();
return res;
}
// res == Status::OLAPInternalError(OLAP_ERR_DATA_EOF) means there is no end key, then we read to
// res.precise_code() == OLAP_ERR_DATA_EOF means there is no end key, then we read to
// the end of this ColumnData
}
set_eof(false);
if (start_key != nullptr) {
auto res = _seek_to_row(*start_key, !find_start_key, false);
if (res.ok()) {
*first_block = _read_block.get();
} else if (res == Status::OLAPInternalError(OLAP_ERR_DATA_EOF)) {
} else if (res.precise_code() == OLAP_ERR_DATA_EOF) {
_eof = true;
*first_block = nullptr;
return res;
Expand Down Expand Up @@ -450,7 +450,7 @@ Status ColumnData::get_first_row_block(RowBlock** row_block) {
RowBlockPosition block_pos;
Status res = segment_group()->find_first_row_block(&block_pos);
if (!res.ok()) {
if (res == Status::OLAPInternalError(OLAP_ERR_INDEX_EOF)) {
if (res.precise_code() == OLAP_ERR_INDEX_EOF) {
*row_block = nullptr;
_eof = true;
return res;
Expand All @@ -461,7 +461,7 @@ Status ColumnData::get_first_row_block(RowBlock** row_block) {

res = _seek_to_block(block_pos, false);
if (!res.ok()) {
if (res != Status::OLAPInternalError(OLAP_ERR_DATA_EOF)) {
if (res.precise_code() != OLAP_ERR_DATA_EOF) {
LOG(WARNING) << "seek to block fail. res = " << res;
}
*row_block = nullptr;
Expand All @@ -470,7 +470,7 @@ Status ColumnData::get_first_row_block(RowBlock** row_block) {

res = _get_block(false);
if (!res.ok()) {
if (res != Status::OLAPInternalError(OLAP_ERR_DATA_EOF)) {
if (res.precise_code() != OLAP_ERR_DATA_EOF) {
LOG(WARNING) << "fail to load data to row block. res=" << res
<< ", version=" << version().first << "-" << version().second;
}
Expand Down
22 changes: 11 additions & 11 deletions be/src/olap/rowset/column_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Status StringColumnDirectReader::seek(PositionProvider* position) {

// All strings in segment may be empty, so the data stream is EOF and
// and length stream is not EOF.
if (res.ok() || Status::OLAPInternalError(OLAP_ERR_COLUMN_STREAM_EOF) == res) {
if (res.ok() || OLAP_ERR_COLUMN_STREAM_EOF == res.precise_code()) {
res = _length_reader->seek(position);
}

Expand Down Expand Up @@ -383,7 +383,7 @@ Status StringColumnDictionaryReader::next(char* buffer, uint32_t* length) {
Status res = _data_reader->next(&value);
// 错误或是EOF
if (!res.ok()) {
if (Status::OLAPInternalError(OLAP_ERR_DATA_EOF) == res) {
if (OLAP_ERR_DATA_EOF == res.precise_code()) {
_eof = true;
}

Expand Down Expand Up @@ -799,7 +799,7 @@ Status TinyColumnReader::seek(PositionProvider* positions) {
return res;
}
res = _data_reader->seek(positions);
if (!res.ok() && Status::OLAPInternalError(OLAP_ERR_COLUMN_STREAM_EOF) != res) {
if (!res.ok() && OLAP_ERR_COLUMN_STREAM_EOF != res.precise_code()) {
LOG(WARNING) << "fail to seek tinyint stream. res = " << res;
return res;
}
Expand All @@ -817,7 +817,7 @@ Status TinyColumnReader::next_vector(ColumnVector* column_vector, uint32_t size,
MemPool* mem_pool) {
Status res = ColumnReader::next_vector(column_vector, size, mem_pool);
if (!res.ok()) {
if (Status::OLAPInternalError(OLAP_ERR_DATA_EOF) == res) {
if (OLAP_ERR_DATA_EOF == res.precise_code()) {
_eof = true;
}
return res;
Expand All @@ -844,7 +844,7 @@ Status TinyColumnReader::next_vector(ColumnVector* column_vector, uint32_t size,
}
_stats->bytes_read += size;

if (Status::OLAPInternalError(OLAP_ERR_DATA_EOF) == res) {
if (OLAP_ERR_DATA_EOF == res.precise_code()) {
_eof = true;
}

Expand Down Expand Up @@ -929,13 +929,13 @@ Status DecimalColumnReader::seek(PositionProvider* positions) {
return res;
}
res = _int_reader->seek(positions);
if (!res.ok() && Status::OLAPInternalError(OLAP_ERR_COLUMN_STREAM_EOF) != res) {
if (!res.ok() && OLAP_ERR_COLUMN_STREAM_EOF != res.precise_code()) {
LOG(WARNING) << "fail to seek int stream of decimal. res = " << res;
return res;
}

res = _frac_reader->seek(positions);
if (!res.ok() && Status::OLAPInternalError(OLAP_ERR_COLUMN_STREAM_EOF) != res) {
if (!res.ok() && OLAP_ERR_COLUMN_STREAM_EOF != res.precise_code()) {
LOG(WARNING) << "fail to seek frac stream of decimal. res = " << res;
return res;
}
Expand Down Expand Up @@ -966,7 +966,7 @@ Status DecimalColumnReader::next_vector(ColumnVector* column_vector, uint32_t si
MemPool* mem_pool) {
Status res = ColumnReader::next_vector(column_vector, size, mem_pool);
if (!res.ok()) {
if (Status::OLAPInternalError(OLAP_ERR_DATA_EOF) == res) {
if (OLAP_ERR_DATA_EOF == res.precise_code()) {
_eof = true;
}
return res;
Expand Down Expand Up @@ -1093,13 +1093,13 @@ Status LargeIntColumnReader::seek(PositionProvider* positions) {
}

res = _high_reader->seek(positions);
if (!res.ok() && Status::OLAPInternalError(OLAP_ERR_COLUMN_STREAM_EOF) != res) {
if (!res.ok() && OLAP_ERR_COLUMN_STREAM_EOF != res.precise_code()) {
LOG(WARNING) << "fail to seek high int stream of largeint. res = " << res;
return res;
}

res = _low_reader->seek(positions);
if (!res.ok() && Status::OLAPInternalError(OLAP_ERR_COLUMN_STREAM_EOF) != res) {
if (!res.ok() && OLAP_ERR_COLUMN_STREAM_EOF != res.precise_code()) {
LOG(WARNING) << "fail to seek low int stream of largeint. res = " << res;
return res;
}
Expand Down Expand Up @@ -1128,7 +1128,7 @@ Status LargeIntColumnReader::next_vector(ColumnVector* column_vector, uint32_t s
MemPool* mem_pool) {
Status res = ColumnReader::next_vector(column_vector, size, mem_pool);
if (!res.ok()) {
if (Status::OLAPInternalError(OLAP_ERR_DATA_EOF) == res) {
if (OLAP_ERR_DATA_EOF == res.precise_code()) {
_eof = true;
}
return res;
Expand Down
Loading

0 comments on commit 4cd579b

Please sign in to comment.