Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement](Log) Reduce usage of log fatal(PART I) #42344

Merged
merged 35 commits into from
Dec 19, 2024

Conversation

linrrzqqq
Copy link
Contributor

@linrrzqqq linrrzqqq commented Oct 23, 2024

Proposed changes

Issue Number: close #40835

use throw Exception to replace them which not in if constexpr, and change part of INTERNAL_ERROR in this pr(file aggregate_function_reader_first_last.h and aggregate_function_window.h) to FatalError.
for those in if constexpr else{...}, use static_assert about template argument which used in that judgement to advance them to compile time

but there seems to be some bugs with the template parameter instantiation in the files comparison_predicate.h, set_probe_sink_operator.cpp, set_sink_operator.cpp, in_list_predicate.h and set_source_operator.cpp that I haven't modified yet.

@doris-robot
Copy link

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR

Since 2024-03-18, the Document has been moved to doris-website.
See Doris Document.

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@@ -651,7 +651,7 @@ struct ConvertImplNumberToJsonb {
} else if constexpr (std::is_same_v<ColumnFloat64, ColumnType>) {
writer.writeDouble(data[i]);
} else {
LOG(FATAL) << "unsupported type ";
throw Exception(Status::NotSupported("unsupported type "));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for if constexpr, you can use static_assert rather than throw

@@ -40,21 +41,22 @@ Elf::Elf(const std::string& path) {
std::error_code ec;
elf_size = std::filesystem::file_size(_file, ec);
if (ec) {
LOG(FATAL) << fmt::format("failed to get file size {}: ({}), {}", _file.native(),
ec.value(), ec.message());
throw Exception(Status::IOError("failed to get file size {}: ({}), {}", _file.native(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a new error type. we can call it FatalError. and for all Exception changed from LOG(FATAL), use it as the error code

Copy link
Contributor

sh-checker report

To get the full details, please check in the job output.

shellcheck errors

'shellcheck ' returned error 1 finding the following syntactical issues:

----------

In build.sh line 297:
    local submodule_path=$1
    ^---------------------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 298:
    local submodule_name=$2
    ^---------------------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 299:
    local archive_url=$3
    ^------------------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 301:
    set +e
    ^----^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 302:
    cd "${DORIS_HOME}"
    ^----------------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 303:
    echo "Update ${submodule_name} submodule ..."
    ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 304:
    git submodule update --init --recursive "${submodule_path}"
    ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 305:
    exit_code=$?
    ^----------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 306:
    if [[ "${exit_code}" -eq 0 ]]; then
    ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
       ^------------------------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 307:
        cd "${submodule_path}"
        ^--------------------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 308:
        submodule_commit_id=$(git rev-parse HEAD)
        ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
                              ^----------------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 309:
        cd -
        ^--^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 310:
        expect_submodule_commit_id=$(git ls-tree HEAD "${submodule_path}" | awk '{print $3}')
        ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
                                     ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 311:
        echo "Current commit ID of ${submodule_name} submodule: ${submodule_commit_id}, expected is ${expect_submodule_commit_id}"
        ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 313:
    set -e
    ^----^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 314:
    if [[ "${exit_code}" -ne 0 ]]; then
    ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
       ^------------------------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 315:
        set +e
        ^----^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 317:
        submodule_commit=$(git ls-tree HEAD "${submodule_path}" | awk '{print $3}')
        ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
                           ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 318:
        exit_code=$?
        ^----------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 319:
        if [[ "${exit_code}" = "0" ]]; then
        ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
           ^------------------------^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 320:
            commit_specific_url=$(echo "${archive_url}" | sed "s/refs\/heads/${submodule_commit}/")
            ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).
                                  ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 322:
            commit_specific_url="${archive_url}"
            ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 324:
        set -e
        ^----^ SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 325:
        echo "Update ${submodule_name} submodule failed, start to download and extract ${commit_specific_url}"
        ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 327:
        mkdir -p "${DORIS_HOME}/${submodule_path}"
        ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).


In build.sh line 328:
        curl -L "${commit_specific_url}" | tar -xz -C "${DORIS_HOME}/${submodule_path}" --strip-components=1
        ^-- SC2317 (info): Command appears to be unreachable. Check usage (or ignore if invoked indirectly).

For more information:
  https://www.shellcheck.net/wiki/SC2317 -- Command appears to be unreachable...
----------

You can address the above issues in one of three ways:
1. Manually correct the issue in the offending shell script;
2. Disable specific issues by adding the comment:
  # shellcheck disable=NNNN
above the line that contains the issue, where NNNN is the error code;
3. Add '-e NNNN' to the SHELLCHECK_OPTS setting in your .yml action file.



shfmt errors
'shfmt ' found no issues.

build.sh Outdated
@@ -551,8 +551,8 @@ FE_MODULES="$(

# Clean and build Backend
if [[ "${BUILD_BE}" -eq 1 ]]; then
update_submodule "be/src/apache-orc" "apache-orc" "https://github.com/apache/doris-thirdparty/archive/refs/heads/orc.tar.gz"
update_submodule "be/src/clucene" "clucene" "https://github.com/apache/doris-thirdparty/archive/refs/heads/clucene.tar.gz"
# update_submodule "be/src/apache-orc" "apache-orc" "https://github.com/apache/doris-thirdparty/archive/ads/clucene.tarefs/heads/orc.tar.gz"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't commit this

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@@ -10,15 +10,18 @@
#include <ctype.h>
#include <errno.h>
#include <float.h> // for DBL_DIG and FLT_DIG
#include <math.h> // for HUGE_VAL
#include <inttypes.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: inclusion of deprecated C++ header 'inttypes.h'; consider using 'cinttypes' instead [modernize-deprecated-headers]

Suggested change
#include <inttypes.h>
#include <cinttypes>

@@ -10,15 +10,18 @@
#include <ctype.h>
#include <errno.h>
#include <float.h> // for DBL_DIG and FLT_DIG
#include <math.h> // for HUGE_VAL
#include <inttypes.h>
#include <math.h> // for HUGE_VAL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: inclusion of deprecated C++ header 'math.h'; consider using 'cmath' instead [modernize-deprecated-headers]

Suggested change
#include <math.h> // for HUGE_VAL
#include <cmath> // for HUGE_VAL

@@ -524,7 +526,7 @@ class ComparisonPredicateBase : public ColumnPredicate {
_base_loop_bit<is_nullable, is_and>(sel, size, flags, null_map, data_array,
dict_code);
} else {
LOG(FATAL) << "column_dictionary must use StringRef predicate.";
static_assert(!std::is_same_v<T, StringRef>, "column_dictionary must use StringRef predicate.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we wrote if constexpr (std::is_same_v<T, StringRef>) upon
so here going into else means T is not same with StringRef. we want a failure here. so I think we should assert std::is_same_v<T, StringRef>, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I made a mistake here, and I have done fixing three similar errors in this file right away

@@ -780,7 +780,7 @@ typedef int ssize_t;
using std::ostream;
inline ostream& operator<<(ostream& os, const unsigned __int64& num) {
// Fake operator; doesn't actually do anything.
LOG(FATAL) << "64-bit ostream operator << not supported in VC++ 6";
throw Exception(Statsu::FatalError("64-bit ostream operator << not supported in VC++ 6"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a typo?

@@ -899,8 +902,7 @@ int Base64UnescapeInternal(const char* src, int szsrc, char* dest, int szdest,
// of data bytes that must remain in the input to avoid aborting the
// loop.
#define GET_INPUT(label, remain) \
label: \
--szsrc; \
label : --szsrc; \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont re-format it if you didn't change

@@ -29,7 +29,8 @@ Exception::Exception(int code, const std::string_view& msg) {
_err_msg->_stack = get_stack_trace();
}
if (config::exit_on_exception) {
LOG(FATAL) << "[ExitOnException] error code: " << code << ", message: " << msg;
throw Exception(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont change this. we want always exit on exception here.

Copy link
Contributor

@zclllyybb zclllyybb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should leave dwarf.cpp, elf.cpp and gutil/port.h as they are. dont patch this change on those filles.

@linrrzqqq linrrzqqq marked this pull request as ready for review November 28, 2024 16:30
@linrrzqqq linrrzqqq changed the title [Enhancement](Log) Reduce usage of log fatal [Enhancement](Log) Reduce usage of log fatal(PART I) Nov 29, 2024
@@ -489,7 +491,7 @@ const char* strstr_delimited(const char* haystack, const char* needle, char deli
++haystack;
}
}
LOG(FATAL) << "Unreachable statement";
throw doris::Exception(doris::Status::FatalError("Unreachable statement"));
return nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

@@ -431,8 +431,8 @@ class InListPredicateBase : public ColumnPredicate {
}
}
} else {
LOG(FATAL) << "column_dictionary must use StringRef predicate.";
__builtin_unreachable();
throw Exception(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use static_assert. or just not modify this in this PR

@@ -300,7 +300,7 @@ class KeyCoderTraits<FieldType::OLAP_FIELD_TYPE_CHAR> {
}

static Status decode_ascending(Slice* encoded_key, size_t index_size, uint8_t* cell_ptr) {
LOG(FATAL) << "decode_ascending is not implemented";
throw Exception(Status::FatalError("decode_ascending is not implemented"));
return Status::OK();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the returns

@linrrzqqq
Copy link
Contributor Author

run buildall

@linrrzqqq
Copy link
Contributor Author

run buildall

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@linrrzqqq
Copy link
Contributor Author

run buildall

@linrrzqqq
Copy link
Contributor Author

run buildall

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@linrrzqqq
Copy link
Contributor Author

run buildall

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@linrrzqqq
Copy link
Contributor Author

run buildall

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@doris-robot
Copy link

TeamCity be ut coverage result:
Function Coverage: 38.87% (10129/26061)
Line Coverage: 29.78% (85138/285905)
Region Coverage: 28.88% (43419/150344)
Branch Coverage: 25.40% (22124/87104)
Coverage Report: http://coverage.selectdb-in.cc/coverage/ac1d12e062d3d12ecf38fb94920d748485f03083_ac1d12e062d3d12ecf38fb94920d748485f03083/report/index.html

@linrrzqqq
Copy link
Contributor Author

run p0

1 similar comment
@linrrzqqq
Copy link
Contributor Author

run p0

Copy link
Contributor

@zclllyybb zclllyybb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

PR approved by anyone and no changes requested.

Copy link
Contributor

@xinyiZzz xinyiZzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Dec 19, 2024
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@BiteTheDDDDt BiteTheDDDDt merged commit 55c26e0 into apache:master Dec 19, 2024
28 of 30 checks passed
wangbo added a commit to wangbo/incubator-doris that referenced this pull request Dec 19, 2024
@linrrzqqq linrrzqqq deleted the log_fatal branch January 18, 2025 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by one committer. reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement](good first issue) Reduce usage of log fatal
7 participants