diff --git a/be/src/agent/agent_server.cpp b/be/src/agent/agent_server.cpp index 94d6dba44c..d695200620 100644 --- a/be/src/agent/agent_server.cpp +++ b/be/src/agent/agent_server.cpp @@ -36,7 +36,7 @@ using std::vector; namespace doris { AgentServer::AgentServer(ExecEnv* exec_env, const TMasterInfo& master_info) - : _exec_env(exec_env), _master_info(master_info), _topic_subscriber(new TopicSubscriber()) { + : _master_info(master_info), _topic_subscriber(new TopicSubscriber()) { for (auto& path : exec_env->store_paths()) { try { string dpp_download_path_str = path.path + "/" + DPP_PREFIX; @@ -54,12 +54,12 @@ AgentServer::AgentServer(ExecEnv* exec_env, const TMasterInfo& master_info) #ifndef BE_TEST #define CREATE_AND_START_POOL(type, pool_name) \ - pool_name.reset(new TaskWorkerPool(TaskWorkerPool::TaskWorkerType::type, _exec_env, \ + pool_name.reset(new TaskWorkerPool(TaskWorkerPool::TaskWorkerType::type, exec_env, \ master_info, TaskWorkerPool::ThreadModel::MULTI_THREADS)); \ pool_name->start(); #define CREATE_AND_START_THREAD(type, pool_name) \ - pool_name.reset(new TaskWorkerPool(TaskWorkerPool::TaskWorkerType::type, _exec_env, \ + pool_name.reset(new TaskWorkerPool(TaskWorkerPool::TaskWorkerType::type, exec_env, \ master_info, TaskWorkerPool::ThreadModel::SINGLE_THREAD)); \ pool_name->start(); #else diff --git a/be/src/agent/agent_server.h b/be/src/agent/agent_server.h index 0a248f15c1..bfb819dd97 100644 --- a/be/src/agent/agent_server.h +++ b/be/src/agent/agent_server.h @@ -50,8 +50,6 @@ public: private: DISALLOW_COPY_AND_ASSIGN(AgentServer); - // Not Owned - ExecEnv* _exec_env; // Reference to the ExecEnv::_master_info const TMasterInfo& _master_info; diff --git a/be/src/common/signal_handler.h b/be/src/common/signal_handler.h index 37762244a1..a89451e03d 100644 --- a/be/src/common/signal_handler.h +++ b/be/src/common/signal_handler.h @@ -274,7 +274,7 @@ void DumpTimeInfo() { void DumpSignalInfo(int signal_number, siginfo_t* siginfo) { // Get the signal name. const char* signal_name = NULL; - for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) { + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kFailureSignals); ++i) { if (signal_number == kFailureSignals[i].number) { signal_name = kFailureSignals[i].name; } @@ -437,7 +437,7 @@ inline void InstallFailureSignalHandler() { sig_action.sa_flags |= SA_SIGINFO; sig_action.sa_sigaction = &FailureSignalHandler; - for (size_t i = 0; i < ARRAYSIZE(kFailureSignals); ++i) { + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kFailureSignals); ++i) { CHECK_ERR(sigaction(kFailureSignals[i].number, &sig_action, NULL)); } kFailureSignalHandlerInstalled = true; diff --git a/be/src/gutil/integral_types.h b/be/src/gutil/integral_types.h index cf2ccdc8c4..744ac2e9df 100644 --- a/be/src/gutil/integral_types.h +++ b/be/src/gutil/integral_types.h @@ -81,23 +81,4 @@ typedef unsigned long uword_t; #endif // _MSC_VER -static const uint8 kuint8max = ((uint8)0xFF); -static const uint16 kuint16max = ((uint16)0xFFFF); -static const uint32 kuint32max = ((uint32)0xFFFFFFFF); -static const uint64 kuint64max = ((uint64)GG_LONGLONG(0xFFFFFFFFFFFFFFFF)); -static const int8 kint8min = ((int8)~0x7F); -static const int8 kint8max = ((int8)0x7F); -static const int16 kint16min = ((int16)~0x7FFF); -static const int16 kint16max = ((int16)0x7FFF); -static const int32 kint32min = ((int32)~0x7FFFFFFF); -static const int32 kint32max = ((int32)0x7FFFFFFF); -static const int64 kint64min = ((int64)GG_LONGLONG(~0x7FFFFFFFFFFFFFFF)); -static const int64 kint64max = ((int64)GG_LONGLONG(0x7FFFFFFFFFFFFFFF)); - -// TODO(user): remove this eventually. -// No object has kIllegalFprint as its Fingerprint. -typedef uint64 Fprint; -static const Fprint kIllegalFprint = 0; -static const Fprint kMaxFprint = GG_ULONGLONG(0xFFFFFFFFFFFFFFFF); - #endif // BASE_INTEGRAL_TYPES_H_ diff --git a/be/src/gutil/macros.h b/be/src/gutil/macros.h index 1a176f73b9..7f72db2058 100644 --- a/be/src/gutil/macros.h +++ b/be/src/gutil/macros.h @@ -11,6 +11,7 @@ #include // For size_t +#include "butil/macros.h" #include "gutil/port.h" // The swigged version of an abstract class must be concrete if any methods @@ -104,89 +105,6 @@ struct CompileAssert {}; // Prefer DISALLOW_COPY_AND_ASSIGN for new code. #define DISALLOW_EVIL_CONSTRUCTORS(TypeName) DISALLOW_COPY_AND_ASSIGN(TypeName) -// A macro to disallow all the implicit constructors, namely the -// default constructor, copy constructor and operator= functions. -// -// This should be used in the private: declarations for a class -// that wants to prevent anyone from instantiating it. This is -// especially useful for classes containing only static methods. -#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ - TypeName() = delete; \ - DISALLOW_COPY_AND_ASSIGN(TypeName) - -// The arraysize(arr) macro returns the # of elements in an array arr. -// The expression is a compile-time constant, and therefore can be -// used in defining new arrays, for example. If you use arraysize on -// a pointer by mistake, you will get a compile-time error. -// -// One caveat is that, for C++03, arraysize() doesn't accept any array of -// an anonymous type or a type defined inside a function. In these rare -// cases, you have to use the unsafe ARRAYSIZE() macro below. This is -// due to a limitation in C++03's template system. The limitation has -// been removed in C++11. - -// This template function declaration is used in defining arraysize. -// Note that the function doesn't need an implementation, as we only -// use its type. -template -char (&ArraySizeHelper(T (&array)[N]))[N]; - -// That gcc wants both of these prototypes seems mysterious. VC, for -// its part, can't decide which to use (another mystery). Matching of -// template overloads: the final frontier. -#ifndef _MSC_VER -template -char (&ArraySizeHelper(const T (&array)[N]))[N]; -#endif - -#define arraysize(array) (sizeof(ArraySizeHelper(array))) - -// ARRAYSIZE performs essentially the same calculation as arraysize, -// but can be used on anonymous types or types defined inside -// functions. It's less safe than arraysize as it accepts some -// (although not all) pointers. Therefore, you should use arraysize -// whenever possible. -// -// The expression ARRAYSIZE(a) is a compile-time constant of type -// size_t. -// -// ARRAYSIZE catches a few type errors. If you see a compiler error -// -// "warning: division by zero in ..." -// -// when using ARRAYSIZE, you are (wrongfully) giving it a pointer. -// You should only use ARRAYSIZE on statically allocated arrays. -// -// The following comments are on the implementation details, and can -// be ignored by the users. -// -// ARRAYSIZE(arr) works by inspecting sizeof(arr) (the # of bytes in -// the array) and sizeof(*(arr)) (the # of bytes in one array -// element). If the former is divisible by the latter, perhaps arr is -// indeed an array, in which case the division result is the # of -// elements in the array. Otherwise, arr cannot possibly be an array, -// and we generate a compiler error to prevent the code from -// compiling. -// -// Since the size of bool is implementation-defined, we need to cast -// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final -// result has type size_t. -// -// This macro is not perfect as it wrongfully accepts certain -// pointers, namely where the pointer size is divisible by the pointee -// size. For code that goes through a 32-bit compiler, where a pointer -// is 4 bytes, this means all pointers to a type whose size is 3 or -// greater than 4 will be (righteously) rejected. -// -// Kudos to Jorg Brown for this simple and elegant implementation. -// -// - wan 2005-11-16 -// -// Starting with Visual C++ 2005, WinNT.h includes ARRAYSIZE. -#if !defined(_MSC_VER) || (defined(_MSC_VER) && _MSC_VER < 1400) -#define ARRAYSIZE(a) ((sizeof(a) / sizeof(*(a))) / static_cast(!(sizeof(a) % sizeof(*(a))))) -#endif - // A macro to turn a symbol into a string #define AS_STRING(x) AS_STRING_INTERNAL(x) #define AS_STRING_INTERNAL(x) #x diff --git a/be/src/gutil/once.cc b/be/src/gutil/once.cc index 2c65a12a01..979bd84d56 100644 --- a/be/src/gutil/once.cc +++ b/be/src/gutil/once.cc @@ -33,7 +33,7 @@ void GoogleOnceInternalInit(Atomic32* control, void (*func)(), void (*func_with_ if (base::subtle::Acquire_CompareAndSwap(control, GOOGLE_ONCE_INTERNAL_INIT, GOOGLE_ONCE_INTERNAL_RUNNING) == GOOGLE_ONCE_INTERNAL_INIT || - base::internal::SpinLockWait(control, ARRAYSIZE(trans), trans) == + base::internal::SpinLockWait(control, ARRAYSIZE_UNSAFE(trans), trans) == GOOGLE_ONCE_INTERNAL_INIT) { if (func != nullptr) { (*func)(); diff --git a/be/src/gutil/port.h b/be/src/gutil/port.h index 738b2c1b0f..62f17d4d8f 100644 --- a/be/src/gutil/port.h +++ b/be/src/gutil/port.h @@ -285,16 +285,6 @@ inline void* memrchr(const void* bytes, int find_char, size_t len) { #define STATIC_ANALYSIS #endif // __KLOCWORK__ -// Annotate a function indicating the caller must examine the return value. -// Use like: -// int foo() WARN_UNUSED_RESULT; -// To explicitly ignore a result, see |ignore_result()| in . -#if defined(__GNUC__) -#define WARN_UNUSED_RESULT __attribute__((warn_unused_result)) -#else -#define WARN_UNUSED_RESULT -#endif - // GCC-specific features #if (defined(__GNUC__) || defined(__APPLE__)) && !defined(SWIG) @@ -464,40 +454,6 @@ inline void* memrchr(const void* bytes, int find_char, size_t len) { #define MUST_USE_RESULT #endif -// Annotate a virtual method indicating it must be overriding a virtual -// method in the parent class. -// Use like: -// virtual void foo() OVERRIDE; -#if defined(COMPILER_MSVC) -#define OVERRIDE override -#elif defined(__clang__) -#define OVERRIDE override -#elif defined(COMPILER_GCC) && __cplusplus >= 201103 && \ - (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 40700 -// GCC 4.7 supports explicit virtual overrides when C++11 support is enabled. -#define OVERRIDE override -#else -#define OVERRIDE -#endif - -// Annotate a virtual method indicating that subclasses must not override it, -// or annotate a class to indicate that it cannot be subclassed. -// Use like: -// virtual void foo() FINAL; -// class B FINAL : public A {}; -#if defined(COMPILER_MSVC) -// TODO(jered): Change this to "final" when chromium no longer uses MSVC 2010. -#define FINAL sealed -#elif defined(__clang__) -#define FINAL final -#elif defined(COMPILER_GCC) && __cplusplus >= 201103 && \ - (__GNUC__ * 10000 + __GNUC_MINOR__ * 100) >= 40700 -// GCC 4.7 supports explicit virtual overrides when C++11 support is enabled. -#define FINAL final -#else -#define FINAL -#endif - #if defined(__GNUC__) // Defined behavior on some of the uarchs: // PREFETCH_HINT_T0: @@ -623,12 +579,12 @@ inline void* aligned_malloc(size_t size, int minimum_alignment) { // http://stackoverflow.com/questions/196329/osx-lacks-memalign // mac allocs are already 16-byte aligned. if (minimum_alignment <= 16) return malloc(size); - // next, try to return page-aligned memory. perhaps overkill - #ifndef _POSIX_C_SOURCE +// next, try to return page-aligned memory. perhaps overkill +#ifndef _POSIX_C_SOURCE int page_size = getpagesize(); - #else +#else int page_size = vm_page_size; - #endif +#endif if (minimum_alignment <= page_size) return valloc(size); // give up return NULL; @@ -745,7 +701,7 @@ struct AlignType { #define ALIGNED_CHAR_ARRAY(T, Size) AlignType::result #endif // !SWIG -#else // __cpluscplus +#else // __cpluscplus #define ALIGNED_CHAR_ARRAY ALIGNED_CHAR_ARRAY_is_not_available_without_Cplusplus #endif // __cplusplus @@ -784,7 +740,7 @@ struct AlignType { #undef ERROR #include // for nextafter functionality on windows -#include // for HUGE_VAL +#include // for HUGE_VAL #ifndef HUGE_VALF #define HUGE_VALF (static_cast(HUGE_VAL)) @@ -1179,7 +1135,7 @@ inline void UnalignedCopy64(const void* src, void* dst) { #ifdef PTHREADS_REDHAT_WIN32 #include -using std::ostream; // NOLINT(build/include) +using std::ostream; // NOLINT(build/include) #include // NOLINT(build/include) // pthread_t is not a simple integer or pointer on Win32 std::ostream& operator<<(std::ostream& out, const pthread_t& thread_id); diff --git a/be/src/gutil/strings/numbers.cc b/be/src/gutil/strings/numbers.cc index 379ed00e94..e8366c32db 100644 --- a/be/src/gutil/strings/numbers.cc +++ b/be/src/gutil/strings/numbers.cc @@ -450,14 +450,14 @@ bool ParseLeadingBoolValue(const char* str, bool deflt) { } // ---------------------------------------------------------------------- -// FpToString() +// Uint64ToString() // FloatToString() // IntToString() // Convert various types to their string representation, possibly padded // with spaces, using snprintf format specifiers. // ---------------------------------------------------------------------- -string FpToString(Fprint fp) { +string Uint64ToString(uint64 fp) { char buf[17]; snprintf(buf, sizeof(buf), "%016" PRIx64, fp); return string(buf); diff --git a/be/src/gutil/strings/numbers.h b/be/src/gutil/strings/numbers.h index 52d766570c..fd53353945 100644 --- a/be/src/gutil/strings/numbers.h +++ b/be/src/gutil/strings/numbers.h @@ -31,7 +31,7 @@ using std::vector; * @{ */ // Convert a fingerprint to 16 hex digits. -string FpToString(Fprint fp); +string Uint64ToString(uint64 fp); // Formats a uint128 as a 32-digit hex string. string Uint128ToHexString(uint128 ui128); diff --git a/be/src/gutil/strtoint.cc b/be/src/gutil/strtoint.cc index d0aeff5c39..e5df02d324 100644 --- a/be/src/gutil/strtoint.cc +++ b/be/src/gutil/strtoint.cc @@ -7,7 +7,8 @@ #include "gutil/strtoint.h" #include -#include + +#include // Replacement strto[u]l functions that have identical overflow and underflow // characteristics for both ILP-32 and LP-64 platforms, including errno @@ -17,15 +18,15 @@ int32 strto32_adapter(const char* nptr, char** endptr, int base) { errno = 0; const long result = strtol(nptr, endptr, base); if (errno == ERANGE && result == LONG_MIN) { - return kint32min; + return std::numeric_limits::min(); } else if (errno == ERANGE && result == LONG_MAX) { - return kint32max; - } else if (errno == 0 && result < kint32min) { + return std::numeric_limits::max(); + } else if (errno == 0 && result < std::numeric_limits::min()) { errno = ERANGE; - return kint32min; - } else if (errno == 0 && result > kint32max) { + return std::numeric_limits::min(); + } else if (errno == 0 && result > std::numeric_limits::max()) { errno = ERANGE; - return kint32max; + return std::numeric_limits::max(); } if (errno == 0) errno = saved_errno; return static_cast(result); @@ -36,10 +37,10 @@ uint32 strtou32_adapter(const char* nptr, char** endptr, int base) { errno = 0; const unsigned long result = strtoul(nptr, endptr, base); if (errno == ERANGE && result == ULONG_MAX) { - return kuint32max; - } else if (errno == 0 && result > kuint32max) { + return std::numeric_limits::max(); + } else if (errno == 0 && result > std::numeric_limits::max()) { errno = ERANGE; - return kuint32max; + return std::numeric_limits::max(); } if (errno == 0) errno = saved_errno; return static_cast(result); diff --git a/be/src/runtime/cache/result_node.cpp b/be/src/runtime/cache/result_node.cpp index 6ed0ab016d..273b9cc5e6 100644 --- a/be/src/runtime/cache/result_node.cpp +++ b/be/src/runtime/cache/result_node.cpp @@ -123,7 +123,7 @@ PCacheStatus ResultNode::update_sql_cache(const PUpdateCacheRequest* request, PCacheStatus ResultNode::update_partition_cache(const PUpdateCacheRequest* request, bool& is_update_firstkey) { - PartitionKey first_key = kint64max; + PartitionKey first_key = std::numeric_limits::max(); if (_partition_list.size() == 0) { is_update_firstkey = true; } else { diff --git a/be/src/runtime/fragment_mgr.cpp b/be/src/runtime/fragment_mgr.cpp index 04d32572af..8b5a1c5c44 100644 --- a/be/src/runtime/fragment_mgr.cpp +++ b/be/src/runtime/fragment_mgr.cpp @@ -45,7 +45,6 @@ #include "runtime/stream_load/stream_load_pipe.h" #include "runtime/thread_context.h" #include "service/backend_options.h" -#include "service/brpc_conflict.h" #include "util/debug_util.h" #include "util/doris_metrics.h" #include "util/stopwatch.hpp" @@ -432,10 +431,7 @@ FragmentMgr::FragmentMgr(ExecEnv* exec_env) _stop_background_threads_latch(1) { _entity = DorisMetrics::instance()->metric_registry()->register_entity("FragmentMgr"); INT_UGAUGE_METRIC_REGISTER(_entity, timeout_canceled_fragment_count); - REGISTER_HOOK_METRIC(plan_fragment_count, [this]() { - // std::lock_guard lock(_lock); - return _fragment_map.size(); - }); + REGISTER_HOOK_METRIC(plan_fragment_count, [this]() { return _fragment_map.size(); }); auto s = Thread::create( "FragmentMgr", "cancel_timeout_plan_fragment", [this]() { this->cancel_worker(); }, diff --git a/be/src/runtime/memory/thread_mem_tracker_mgr.h b/be/src/runtime/memory/thread_mem_tracker_mgr.h index 03ccacdeba..6c8cae39f9 100644 --- a/be/src/runtime/memory/thread_mem_tracker_mgr.h +++ b/be/src/runtime/memory/thread_mem_tracker_mgr.h @@ -17,14 +17,13 @@ #pragma once +#include #include #include -#include +#include "gutil/macros.h" #include "runtime/memory/mem_tracker.h" #include "runtime/memory/mem_tracker_limiter.h" -// After brpc_conflict.h -#include namespace doris { diff --git a/be/src/runtime/thread_context.h b/be/src/runtime/thread_context.h index 48ff9cc389..ca09df0ecf 100644 --- a/be/src/runtime/thread_context.h +++ b/be/src/runtime/thread_context.h @@ -17,8 +17,6 @@ #pragma once -#include -// After brpc_conflict.h #include #include @@ -26,6 +24,7 @@ #include "common/logging.h" #include "gen_cpp/PaloInternalService_types.h" // for TQueryType +#include "gutil/macros.h" #include "runtime/memory/thread_mem_tracker_mgr.h" #include "runtime/threadlocal.h" diff --git a/be/src/service/brpc.h b/be/src/service/brpc.h index 863376b9c1..c4657229d4 100644 --- a/be/src/service/brpc.h +++ b/be/src/service/brpc.h @@ -20,10 +20,6 @@ // all header need by brpc is contain in this file. // include this file instead of include . -// clang-format off -#include "service/brpc_conflict.h" -// clang-format on - #include #include #include diff --git a/be/src/service/brpc_conflict.h b/be/src/service/brpc_conflict.h deleted file mode 100644 index 35ef1b815c..0000000000 --- a/be/src/service/brpc_conflict.h +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#pragma once - -// This file is used to fixed macro conflict between butil and gutil -// and this file must put the first include in source file - -#include "gutil/macros.h" -// Macros in the guti/macros.h, use butil's define -#ifdef DISALLOW_IMPLICIT_CONSTRUCTORS -#undef DISALLOW_IMPLICIT_CONSTRUCTORS -#endif - -#ifdef arraysize -#undef arraysize -#endif - -#ifdef ARRAY_SIZE -#undef ARRAY_SIZE -#endif - -#undef OVERRIDE -#undef FINAL - -// use be/src/gutil/integral_types.h override butil/basictypes.h -#include "gutil/integral_types.h" -#ifdef BASE_INTEGRAL_TYPES_H_ -#define BUTIL_BASICTYPES_H_ -#endif - -#ifdef DEBUG_MODE -#undef DEBUG_MODE -#endif diff --git a/be/src/util/threadpool.cpp b/be/src/util/threadpool.cpp index db7b55166d..881984ba38 100644 --- a/be/src/util/threadpool.cpp +++ b/be/src/util/threadpool.cpp @@ -42,7 +42,7 @@ class FunctionRunnable : public Runnable { public: explicit FunctionRunnable(std::function func) : _func(std::move(func)) {} - void run() OVERRIDE { _func(); } + void run() override { _func(); } private: std::function _func; diff --git a/be/src/vec/runtime/vdata_stream_recvr.cpp b/be/src/vec/runtime/vdata_stream_recvr.cpp index 71e2d36ab3..a649816a1b 100644 --- a/be/src/vec/runtime/vdata_stream_recvr.cpp +++ b/be/src/vec/runtime/vdata_stream_recvr.cpp @@ -173,6 +173,8 @@ void VDataStreamRecvr::SenderQueue::add_block(Block* block, bool use_move) { _data_arrival_cv.notify_one(); if (_recvr->exceeds_limit(block_size)) { + // yiguolei + // It is too tricky here, if the running thread is bthread then the tid may be wrong. std::thread::id tid = std::this_thread::get_id(); MonotonicStopWatch monotonicStopWatch; monotonicStopWatch.start(); diff --git a/be/test/util/easy_json-test.cpp b/be/test/util/easy_json-test.cpp index 60786757f0..ed81ab9d1a 100644 --- a/be/test/util/easy_json-test.cpp +++ b/be/test/util/easy_json-test.cpp @@ -38,24 +38,6 @@ TEST_F(EasyJsonTest, TestNull) { EXPECT_TRUE(ej.value().IsNull()); } -TEST_F(EasyJsonTest, TestBasic) { - EasyJson ej; - ej.SetObject(); - ej.Set("1", true); - ej.Set("2", kint32min); - ej.Set("4", kint64min); - ej.Set("6", 1.0); - ej.Set("7", "string"); - - Value& v = ej.value(); - - EXPECT_EQ(v["1"].GetBool(), true); - EXPECT_EQ(v["2"].GetInt(), kint32min); - EXPECT_EQ(v["4"].GetInt64(), kint64min); - EXPECT_EQ(v["6"].GetDouble(), 1.0); - EXPECT_EQ(string(v["7"].GetString()), "string"); -} - TEST_F(EasyJsonTest, TestNested) { EasyJson ej; ej.SetObject();