diff --git a/be/src/service/service_be/starrocks_be.cpp b/be/src/service/service_be/starrocks_be.cpp index 8a552e3147ddad..fe3d17a809c73e 100644 --- a/be/src/service/service_be/starrocks_be.cpp +++ b/be/src/service/service_be/starrocks_be.cpp @@ -219,9 +219,7 @@ void start_be(const std::vector& paths, bool as_cn) { brpc::FLAGS_max_body_size = config::brpc_max_body_size; // Configure keepalive. -#ifdef WITH_BRPC_KEEPALIVE brpc::FLAGS_socket_keepalive = config::brpc_socket_keepalive; -#endif brpc::FLAGS_socket_max_unwritten_bytes = config::brpc_socket_max_unwritten_bytes; auto brpc_server = std::make_unique(); diff --git a/build.sh b/build.sh index 2e25a63fad75f2..9cb16859530c0f 100755 --- a/build.sh +++ b/build.sh @@ -150,7 +150,6 @@ WITH_GCOV=OFF WITH_BENCH=OFF WITH_CLANG_TIDY=OFF WITH_STARCACHE=ON -WITH_BRPC_KEEPALIVE=OFF USE_STAROS=OFF BUILD_JAVA_EXT=ON OUTPUT_COMPILE_TIME=OFF @@ -236,7 +235,6 @@ else --with-clang-tidy) WITH_CLANG_TIDY=ON; shift ;; --without-java-ext) BUILD_JAVA_EXT=OFF; shift ;; --without-starcache) WITH_STARCACHE=OFF; shift ;; - --with-brpc-keepalive) WITH_BRPC_KEEPALIVE=ON; shift ;; --output-compile-time) OUTPUT_COMPILE_TIME=ON; shift ;; -h) HELP=1; shift ;; --help) HELP=1; shift ;; @@ -372,7 +370,6 @@ if [ ${BUILD_BE} -eq 1 ] ; then -DWITH_CLANG_TIDY=${WITH_CLANG_TIDY} \ -DWITH_COMPRESS=${WITH_COMPRESS} \ -DWITH_STARCACHE=${WITH_STARCACHE} \ - -DWITH_BRPC_KEEPALIVE=${WITH_BRPC_KEEPALIVE} \ -DUSE_STAROS=${USE_STAROS} \ -DENABLE_FAULT_INJECTION=${ENABLE_FAULT_INJECTION} \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. diff --git a/thirdparty/build-thirdparty.sh b/thirdparty/build-thirdparty.sh index 6a4717c83432bc..937a1670271c6a 100755 --- a/thirdparty/build-thirdparty.sh +++ b/thirdparty/build-thirdparty.sh @@ -55,6 +55,9 @@ cd $TP_DIR # Download thirdparties. ${TP_DIR}/download-thirdparty.sh +TP_INSTALL_DIR=/root/starrocks/thirdparty/installed/ +STARROCKS_GCC_HOME=/ + # set COMPILER if [[ ! -z ${STARROCKS_GCC_HOME} ]]; then export CC=${STARROCKS_GCC_HOME}/bin/gcc @@ -368,13 +371,8 @@ build_glog() { check_if_source_exist $GLOG_SOURCE cd $TP_SOURCE_DIR/$GLOG_SOURCE - # to generate config.guess and config.sub to support aarch64 - rm -rf config.* - autoreconf -i + $CMAKE_CMD -G "${CMAKE_GENERATOR}" -DCMAKE_INSTALL_PREFIX=$TP_INSTALL_DIR -DBUILD_SHARED_LIBS=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DDCMAKE_INSTALL_LIBDIR=lib - LDFLAGS="-L${TP_LIB_DIR}" \ - CPPFLAGS="-I${TP_INCLUDE_DIR}" \ - ./configure --prefix=$TP_INSTALL_DIR --enable-frame-pointers --disable-shared --enable-static make -j$PARALLEL make install } @@ -560,7 +558,7 @@ build_brpc() { cd $TP_SOURCE_DIR/$BRPC_SOURCE CMAKE_GENERATOR="Unix Makefiles" BUILD_SYSTEM='make' - ./config_brpc.sh --headers="$TP_INSTALL_DIR/include /usr/include" --libs="$TP_INSTALL_DIR/bin $TP_INSTALL_DIR/lib /usr/lib" --with-glog + PATH=$PATH:$TP_INSTALL_DIR/bin/ ./config_brpc.sh --headers="$TP_INSTALL_DIR/include /usr/include" --libs="$TP_INSTALL_DIR/bin $TP_INSTALL_DIR/lib /usr/lib" --with-glog --with-thrift make -j$PARALLEL cp -rf output/* ${TP_INSTALL_DIR}/ if [ -f $TP_INSTALL_DIR/lib/libbrpc.a ]; then @@ -1347,27 +1345,6 @@ export CPPFLAGS=$GLOBAL_CPPFLAGS export CXXFLAGS=$GLOBAL_CXXFLAGS export CFLAGS=$GLOBAL_CFLAGS -build_libevent -build_zlib -build_lz4 -build_lzo2 -build_bzip -build_openssl -build_boost # must before thrift -build_protobuf -build_gflags -build_gtest -build_glog -build_rapidjson -build_simdjson -build_snappy -build_gperftools -build_curl -build_re2 -build_thrift -build_leveldb -build_brpc -build_rocksdb build_kerberos # must build before arrow build_sasl diff --git a/thirdparty/download-thirdparty.sh b/thirdparty/download-thirdparty.sh index 78cbfc6d201b94..8be3094885478c 100755 --- a/thirdparty/download-thirdparty.sh +++ b/thirdparty/download-thirdparty.sh @@ -250,6 +250,10 @@ if [ ! -f $PATCHED_MARK ] && [ $GLOG_SOURCE == "glog-0.4.0" ]; then patch -p1 < $TP_PATCH_DIR/glog-0.4.0-remove-unwind-dependency.patch touch $PATCHED_MARK fi +if [ ! -f $PATCHED_MARK ] && [ $GLOG_SOURCE == "glog-0.7.1" ]; then + patch -p1 < $TP_PATCH_DIR/glog-0.7.1.patch + touch $PATCHED_MARK +fi cd - echo "Finished patching $GLOG_SOURCE" @@ -305,6 +309,10 @@ if [ ! -f $PATCHED_MARK ] && [ $BRPC_SOURCE == "brpc-1.3.0" ]; then patch -p1 < $TP_PATCH_DIR/brpc-1.3.0-2479.patch touch $PATCHED_MARK fi +if [ ! -f $PATCHED_MARK ] && [ $BRPC_SOURCE == "brpc-1.9.0" ]; then + patch < $TP_PATCH_DIR/brpc-1.9.0.patch + touch $PATCHED_MARK +fi cd - echo "Finished patching $BRPC_SOURCE" diff --git a/thirdparty/patches/brpc-1.9.0.patch b/thirdparty/patches/brpc-1.9.0.patch new file mode 100644 index 00000000000000..9558ec50035a1b --- /dev/null +++ b/thirdparty/patches/brpc-1.9.0.patch @@ -0,0 +1,13 @@ +diff --git a/config_brpc.sh b/config_brpc.sh +index ddaa6daa..2269587a 100755 +--- a/config_brpc.sh ++++ b/config_brpc.sh +@@ -341,7 +341,7 @@ if [ "$PROTOBUF_VERSION" -ge 4022000 ]; then + done + CXXFLAGS="-std=c++17" + else +- CXXFLAGS="-std=c++0x" ++ CXXFLAGS="-std=c++17" + fi + + LEVELDB_HDR=$(find_dir_of_header_or_die leveldb/db.h) \ No newline at end of file diff --git a/thirdparty/patches/glog-0.7.1.patch b/thirdparty/patches/glog-0.7.1.patch new file mode 100644 index 00000000000000..de9dfc1f8a75ba --- /dev/null +++ b/thirdparty/patches/glog-0.7.1.patch @@ -0,0 +1,334 @@ +diff --git a/src/flags.cc b/src/flags.cc +index c4c2aa4..7329c80 100644 +--- a/src/flags.cc ++++ b/src/flags.cc +@@ -137,6 +137,10 @@ GLOG_DEFINE_uint32(max_log_size, 1800, + GLOG_DEFINE_bool(stop_logging_if_full_disk, false, + "Stop attempting to log to disk if the disk is full."); + ++GLOG_DEFINE_string(log_split_method, "day", "split log by size, day, hour"); ++ ++GLOG_DEFINE_int32(log_filenum_quota, 10, "max log file num in log dir"); ++ + GLOG_DEFINE_string(log_backtrace_at, "", + "Emit a backtrace when logging at file:linenum."); + +diff --git a/src/glog/flags.h b/src/glog/flags.h +index cb542b9..31d5e6e 100644 +--- a/src/glog/flags.h ++++ b/src/glog/flags.h +@@ -182,6 +182,10 @@ DECLARE_string(logmailer); + + DECLARE_bool(symbolize_stacktrace); + ++DECLARE_int32(log_filenum_quota); ++ ++DECLARE_string(log_split_method); ++ + #pragma pop_macro("DECLARE_VARIABLE") + #pragma pop_macro("DECLARE_bool") + #pragma pop_macro("DECLARE_string") +diff --git a/src/glog/logging.h b/src/glog/logging.h +index 88d793f..8b90782 100644 +--- a/src/glog/logging.h ++++ b/src/glog/logging.h +@@ -52,6 +52,10 @@ + #include + #include + ++#ifndef GLOG_USE_GLOG_EXPORT ++#define GLOG_USE_GLOG_EXPORT ++#endif ++ + #if defined(GLOG_USE_GLOG_EXPORT) + # include "glog/export.h" + #endif +diff --git a/src/logging.cc b/src/logging.cc +index fc63995..16b2cb1 100644 +--- a/src/logging.cc ++++ b/src/logging.cc +@@ -31,6 +31,7 @@ + + #include "glog/logging.h" + ++#include + #include + #include + #include +@@ -443,6 +444,14 @@ class PrefixFormatter { + + std::unique_ptr g_prefix_formatter; + ++typedef struct filetime { ++ std::string name; ++ time_t time; ++ bool operator < (const struct filetime& o) const { ++ return o.time > time; ++ } ++}Filetime; ++ + // Encapsulates all file-system related state + class LogFileObject : public base::Logger { + public: +@@ -474,6 +483,8 @@ class LogFileObject : public base::Logger { + // acquiring lock_. + void FlushUnlocked(const std::chrono::system_clock::time_point& now); + ++ void CheckFileNumQuota(); ++ + private: + static const uint32 kRolloverAttemptFrequency = 0x20; + +@@ -496,6 +507,10 @@ class LogFileObject : public base::Logger { + // optional argument time_pid_string + // REQUIRES: lock_ is held + bool CreateLogfile(const string& time_pid_string); ++ ++ std::list file_list_; ++ bool inited_; ++ struct ::tm tm_time_; + }; + + // Encapsulate all log cleaner related states +@@ -707,7 +722,7 @@ inline void LogDestination::FlushLogFiles(int min_severity) { + // all this stuff. + std::lock_guard l{log_mutex}; + for (int i = min_severity; i < NUM_SEVERITIES; i++) { +- LogDestination* log = log_destination(static_cast(i)); ++ LogDestination* log = log_destinations_[i].get(); + if (log != nullptr) { + log->logger_->Flush(); + } +@@ -904,8 +919,12 @@ inline void LogDestination::LogToAllLogfiles( + ColoredWriteToStderr(severity, message, len); + } else { + for (int i = severity; i >= 0; --i) { +- LogDestination::MaybeLogToLogfile(static_cast(i), timestamp, +- message, len); ++ if (severity >= 1) { ++ LogDestination::MaybeLogToLogfile(static_cast(1), timestamp, message, len); ++ LogDestination::MaybeLogToLogfile(static_cast(0), timestamp, message, len); ++ } else if (severity == 0) { ++ LogDestination::MaybeLogToLogfile(static_cast(0), timestamp, message, len); ++ } else {} + } + } + } +@@ -997,7 +1016,8 @@ LogFileObject::LogFileObject(LogSeverity severity, const char* base_filename) + filename_extension_(), + severity_(severity), + rollover_attempt_(kRolloverAttemptFrequency - 1), +- start_time_(std::chrono::system_clock::now()) {} ++ start_time_(std::chrono::system_clock::now()), ++ inited_(false) {} + + LogFileObject::~LogFileObject() { + std::lock_guard l{mutex_}; +@@ -1058,14 +1078,9 @@ bool LogFileObject::CreateLogfile(const string& time_pid_string) { + } + string_filename += filename_extension_; + const char* filename = string_filename.c_str(); +- // only write to files, create if non-existant. +- int flags = O_WRONLY | O_CREAT; +- if (FLAGS_timestamp_in_logfile_name) { +- // demand that the file is unique for our timestamp (fail if it exists). +- flags = flags | O_EXCL; +- } +- FileDescriptor fd{ +- open(filename, flags, static_cast(FLAGS_logfile_mode))}; ++ int fdh = open(filename, O_WRONLY | O_CREAT /* | O_EXCL */ | O_APPEND, 0664); ++ FileDescriptor fd{fdh}; ++ + if (!fd) return false; + #ifdef HAVE_FCNTL + // Mark the file close-on-exec. We don't really care if this fails +@@ -1112,6 +1127,9 @@ bool LogFileObject::CreateLogfile(const string& time_pid_string) { + } + } + #endif ++ Filetime ft; ++ ft.name = string_filename; ++ file_list_.push_back(ft); + // We try to create a symlink called ., + // which is easier to use. (Every time we create a new logfile, + // we destroy the old symlink and create a new one, so it always +@@ -1155,6 +1173,55 @@ bool LogFileObject::CreateLogfile(const string& time_pid_string) { + return true; // Everything worked + } + ++void LogFileObject::CheckFileNumQuota() { ++ struct dirent *entry; ++ DIR *dp; ++ const vector & log_dirs = GetLoggingDirectories(); ++ if (log_dirs.size() < 1) return; ++ ++ //fprintf(stderr, "log dir: %s\n", log_dirs[0].c_str()); ++ // list file in log dir ++ ++ dp = opendir(log_dirs[0].c_str()); ++ if (dp == NULL) { ++ fprintf(stderr, "open log dir %s fail\n", log_dirs[0].c_str()); ++ return; ++ } ++ ++ file_list_.clear(); ++ while ((entry = readdir(dp)) != NULL) { ++ if (DT_DIR == entry->d_type || ++ DT_LNK == entry->d_type) { ++ continue; ++ } ++ std::string filename = std::string(entry->d_name); ++ //fprintf(stderr, "filename: %s\n", filename.c_str()); ++ if (filename.find(symlink_basename_ + '.' + LogSeverityNames[severity_]) == 0) { ++ std::string filepath = log_dirs[0] + "/" + filename; ++ struct stat fstat; ++ if (::stat(filepath.c_str(), &fstat) < 0) { ++ fprintf(stderr, "state %s fail\n", filepath.c_str()); ++ closedir(dp); ++ return; ++ } ++ //fprintf(stderr, "filepath: %s\n", filepath.c_str()); ++ Filetime file_time; ++ file_time.time = fstat.st_mtime; ++ file_time.name = filepath; ++ file_list_.push_back(file_time); ++ } ++ } ++ ++ closedir(dp); ++ file_list_.sort(); ++ ++ while (FLAGS_log_filenum_quota > 0 && file_list_.size() >= FLAGS_log_filenum_quota) { ++ // fprintf(stderr, "delete %s\n", file_list_.front().name.c_str()); ++ unlink(file_list_.front().name.c_str()); ++ file_list_.pop_front(); ++ } ++} ++ + void LogFileObject::Write( + bool force_flush, const std::chrono::system_clock::time_point& timestamp, + const char* message, size_t message_len) { +@@ -1171,16 +1238,58 @@ void LogFileObject::Write( + filename_extension_); + } + }; ++ std::time_t t = std::chrono::system_clock::to_time_t(timestamp); + + // Remove old logs + ScopedExit cleanupAtEnd{cleanupLogs}; + +- if (file_length_ >> 20U >= MaxLogSize() || PidHasChanged()) { ++ struct ::tm tm_time; ++ bool is_split = false; ++ if ("day" == FLAGS_log_split_method) { ++ localtime_r(&t, &tm_time); ++ if (tm_time.tm_year != tm_time_.tm_year ++ || tm_time.tm_mon != tm_time_.tm_mon ++ || tm_time.tm_mday != tm_time_.tm_mday) { ++ is_split = true; ++ } ++ } else if ("hour" == FLAGS_log_split_method) { ++ localtime_r(&t, &tm_time); ++ if (tm_time.tm_year != tm_time_.tm_year ++ || tm_time.tm_mon != tm_time_.tm_mon ++ || tm_time.tm_mday != tm_time_.tm_mday ++ || tm_time.tm_hour != tm_time_.tm_hour) { ++ is_split = true; ++ } ++ } else if (static_cast(file_length_ >> 20) >= MaxLogSize()) { ++ // PidHasChanged()) { ++ is_split = true; ++ } ++ ++ if (is_split) { + file_ = nullptr; + file_length_ = bytes_since_flush_ = dropped_mem_length_ = 0; + rollover_attempt_ = kRolloverAttemptFrequency - 1; + } + ++ if ((file_ == NULL) && (!inited_) && (FLAGS_log_split_method == "size")) { ++ CheckFileNumQuota(); ++ const char* filename = file_list_.back().name.c_str(); ++ int fd = open(filename, O_WRONLY | O_CREAT /* | O_EXCL */ | O_APPEND, 0664); ++ if (fd != -1) { ++#ifdef HAVE_FCNTL ++ // Mark the file close-on-exec. We don't really care if this fails ++ fcntl(fd, F_SETFD, FD_CLOEXEC); ++#endif ++ file_.reset(fopen(filename, "a+")); ++ if (file_ == NULL) { // Man, we're screwed!, try to create new log file ++ close(fd); ++ } ++ fseek(file_.get(), 0, SEEK_END); ++ file_length_ = bytes_since_flush_ = ftell(file_.get()); ++ inited_ = true; ++ } ++ } ++ + // If there's no destination file, make one before outputting + if (file_ == nullptr) { + // Try to rollover the log file every 32 log messages. The only time +@@ -1190,21 +1299,35 @@ void LogFileObject::Write( + rollover_attempt_ = 0; + + struct ::tm tm_time; +- std::time_t t = std::chrono::system_clock::to_time_t(timestamp); + +- if (FLAGS_log_utc_time) { +- gmtime_r(&t, &tm_time); ++ if (!inited_) { ++ CheckFileNumQuota(); ++ inited_ = true; + } else { +- localtime_r(&t, &tm_time); ++ while (FLAGS_log_filenum_quota > 0 && file_list_.size() >= FLAGS_log_filenum_quota) { ++ unlink(file_list_.front().name.c_str()); ++ file_list_.pop_front(); ++ } + } ++ localtime_r(&t, &tm_time); + + // The logfile's filename will have the date/time & pid in it + ostringstream time_pid_stream; + time_pid_stream.fill('0'); +- time_pid_stream << 1900 + tm_time.tm_year << setw(2) << 1 + tm_time.tm_mon +- << setw(2) << tm_time.tm_mday << '-' << setw(2) +- << tm_time.tm_hour << setw(2) << tm_time.tm_min << setw(2) +- << tm_time.tm_sec << '.' << GetMainThreadPid(); ++ time_pid_stream << 1900 + tm_time.tm_year ++ << setw(2) << 1 + tm_time.tm_mon ++ << setw(2) << tm_time.tm_mday; ++ ++ if ("hour" == FLAGS_log_split_method) { ++ time_pid_stream << setw(2) << tm_time.tm_hour; ++ } else if ("day" != FLAGS_log_split_method) { ++ time_pid_stream << '-' ++ << setw(2) << tm_time.tm_hour ++ << setw(2) << tm_time.tm_min ++ << setw(2) << tm_time.tm_sec; ++ } ++ ++ tm_time_ = tm_time; + const string& time_pid_string = time_pid_stream.str(); + + if (base_filename_selected_) { +@@ -1238,8 +1361,8 @@ void LogFileObject::Write( + // deadlock. Simply use a name like invalid-user. + if (uidname.empty()) uidname = "invalid-user"; + +- stripped_filename = stripped_filename + '.' + hostname + '.' + uidname + +- ".log." + LogSeverityNames[severity_] + '.'; ++ stripped_filename = stripped_filename + "." + LogSeverityNames[severity_] + ".log."; ++ + // We're going to (potentially) try to put logs in several different dirs + const vector& log_dirs = GetLoggingDirectories(); + +@@ -1263,7 +1386,7 @@ void LogFileObject::Write( + } + + // Write a header message into the log file +- if (FLAGS_log_file_header) { ++ if (false) { + ostringstream file_header_stream; + file_header_stream.fill('0'); + file_header_stream << "Log file created at: " << 1900 + tm_time.tm_year \ No newline at end of file diff --git a/thirdparty/vars.sh b/thirdparty/vars.sh index a5d98353ba3169..623258721579ce 100644 --- a/thirdparty/vars.sh +++ b/thirdparty/vars.sh @@ -115,10 +115,10 @@ GFLAGS_SOURCE=gflags-2.2.2 GFLAGS_MD5SUM="1a865b93bacfa963201af3f75b7bd64c" # glog -GLOG_DOWNLOAD="https://github.com/google/glog/archive/v0.4.0.tar.gz" -GLOG_NAME=glog-0.4.0.tar.gz -GLOG_SOURCE=glog-0.4.0 -GLOG_MD5SUM="0daea8785e6df922d7887755c3d100d0" +GLOG_DOWNLOAD="https://github.com/google/glog/archive/v0.7.1.tar.gz" +GLOG_NAME=glog-0.7.1.tar.gz +GLOG_SOURCE=glog-0.7.1 +GLOG_MD5SUM="128e2995cc33d794ff24f785a3060346" # gtest GTEST_DOWNLOAD="https://github.com/google/googletest/archive/release-1.10.0.tar.gz" @@ -193,10 +193,10 @@ LEVELDB_SOURCE=leveldb-1.20 LEVELDB_MD5SUM="298b5bddf12c675d6345784261302252" # brpc -BRPC_DOWNLOAD="https://github.com/apache/brpc/archive/refs/tags/1.3.0.tar.gz" -BRPC_NAME=brpc-1.3.0.tar.gz -BRPC_SOURCE=brpc-1.3.0 -BRPC_MD5SUM="9470f1a77ec153e82cd8a25dc2148e47" +BRPC_DOWNLOAD="https://github.com/apache/brpc/archive/refs/tags/1.9.0.tar.gz" +BRPC_NAME=brpc-1.9.0.tar.gz +BRPC_SOURCE=brpc-1.9.0 +BRPC_MD5SUM="a2b626d96a5b017f2a6701ffa594530c" # rocksdb ROCKSDB_DOWNLOAD="https://github.com/facebook/rocksdb/archive/refs/tags/v6.22.1.zip"