Skip to content

Commit

Permalink
Refine some include headers & add option ENABLE_FAILPOINTS (#2296)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang authored and LittleFall committed Apr 7, 2022
1 parent 41c4637 commit 3775b05
Show file tree
Hide file tree
Showing 21 changed files with 153 additions and 91 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,14 @@ add_subdirectory (contrib) # Should be done after option ENABLE_TESTS, cause we
option (TEST_COVERAGE "Enables flags for test coverage" OFF)
option (ENABLE_TESTS "Enables tests" ${NOT_MSVC})

# Enable failpoint injection by default if ENABLE_TESTS is turn ON.
if (ENABLE_TESTS)
set (ENABLE_FAILPOINTS_DEFAULT "ON")
else ()
set (ENABLE_FAILPOINTS_DEFAULT "OFF")
endif()
option (ENABLE_FAILPOINTS "Enables failpoints injection" ${ENABLE_FAILPOINTS_DEFAULT})

# Flags for test coverage
if (TEST_COVERAGE AND CMAKE_BUILD_TYPE STREQUAL "Debug")
include(CodeCoverage)
Expand Down
2 changes: 1 addition & 1 deletion dbms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ endif ()

find_package (Threads)

if (ENABLE_TESTS)
if (ENABLE_FAILPOINTS)
add_definitions(-DFIU_ENABLE)
endif()

Expand Down
25 changes: 12 additions & 13 deletions dbms/src/Common/Config/ConfigProcessor.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#pragma once

#include <string>
#include <unordered_set>
#include <vector>

#include <Poco/AutoPtr.h>
#include <Poco/ConsoleChannel.h>
#include <Poco/DirectoryIterator.h>
#include <Poco/File.h>
#include <Poco/Path.h>
#include <Poco/DirectoryIterator.h>
#include <Poco/ConsoleChannel.h>
#include <Poco/Util/AbstractConfiguration.h>
#include <Common/Config/cpptoml.h>

#include <common/logger_useful.h>

#include <string>
#include <unordered_set>
#include <vector>


using ConfigurationPtr = Poco::AutoPtr<Poco::Util::AbstractConfiguration>;
namespace cpptoml
{
class table;
}

using TOMLTablePtr = std::shared_ptr<cpptoml::table>;

class ConfigProcessor
Expand All @@ -24,10 +27,7 @@ class ConfigProcessor
using Substitutions = std::vector<std::pair<std::string, std::string>>;

/// Set log_to_console to true if the logging subsystem is not initialized yet.
explicit ConfigProcessor(
const std::string & path,
bool log_to_console = false,
const Substitutions & substitutions = Substitutions());
explicit ConfigProcessor(const std::string & path, bool log_to_console = false, const Substitutions & substitutions = Substitutions());

~ConfigProcessor();

Expand All @@ -51,7 +51,6 @@ class ConfigProcessor
void savePreprocessedConfig(const LoadedConfig & loaded_config);

public:

/// Is the file named as result of config preprocessing, not as original files.
static bool isPreprocessedFile(const std::string & config_path);

Expand Down
16 changes: 13 additions & 3 deletions dbms/src/Common/Config/TOMLConfiguration.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#include "TOMLConfiguration.h"
/// Suppress gcc warning: ‘*((void*)&<anonymous> +4)’ may be used uninitialized in this function
#if !__clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
#include <Common/Config/cpptoml.h>
#if !__clang__
#pragma GCC diagnostic pop
#endif

#include <sstream>

#include "Poco/Exception.h"
#include <Common/Config/TOMLConfiguration.h>
#include <Poco/Exception.h>

#include <sstream>

namespace DB
{
Expand Down
6 changes: 4 additions & 2 deletions dbms/src/Common/Config/TOMLConfiguration.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#pragma once

#include <Common/Config/cpptoml.h>

#include <istream>

#include "Poco/DOM/AutoPtr.h"
#include "Poco/Util/MapConfiguration.h"

namespace cpptoml
{
class table;
}
namespace DB
{

Expand Down
43 changes: 21 additions & 22 deletions dbms/src/Common/LRUCache.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#pragma once

#include <unordered_map>
#include <common/logger_useful.h>

#include <atomic>
#include <chrono>
#include <list>
#include <memory>
#include <chrono>
#include <mutex>
#include <atomic>

#include <common/logger_useful.h>
#include <unordered_map>


namespace DB
Expand All @@ -16,10 +16,7 @@ namespace DB
template <typename T>
struct TrivialWeightFunction
{
size_t operator()(const T &) const
{
return 1;
}
size_t operator()(const T &) const { return 1; }
};


Expand All @@ -29,7 +26,10 @@ struct TrivialWeightFunction
/// Cache starts to evict entries when their total weight exceeds max_size and when expiration time of these
/// entries is due.
/// Value weight should not change after insertion.
template <typename TKey, typename TMapped, typename HashFunction = std::hash<TKey>, typename WeightFunction = TrivialWeightFunction<TMapped>>
template <typename TKey,
typename TMapped,
typename HashFunction = std::hash<TKey>,
typename WeightFunction = TrivialWeightFunction<TMapped>>
class LRUCache
{
public:
Expand All @@ -44,7 +44,8 @@ class LRUCache

public:
LRUCache(size_t max_size_, const Delay & expiration_delay_ = Delay::zero())
: max_size(std::max(static_cast<size_t>(1), max_size_)), expiration_delay(expiration_delay_) {}
: max_size(std::max(static_cast<size_t>(1), max_size_)), expiration_delay(expiration_delay_)
{}

MappedPtr get(const Key & key)
{
Expand Down Expand Up @@ -158,15 +159,14 @@ class LRUCache
virtual ~LRUCache() {}

private:

/// Represents pending insertion attempt.
struct InsertToken
{
explicit InsertToken(LRUCache & cache_) : cache(cache_) {}

std::mutex mutex;
bool cleaned_up = false; /// Protected by the token mutex
MappedPtr value; /// Protected by the token mutex
MappedPtr value; /// Protected by the token mutex

LRUCache & cache;
size_t refcount = 0; /// Protected by the cache mutex
Expand All @@ -185,7 +185,8 @@ class LRUCache

InsertTokenHolder() = default;

void acquire(const Key * key_, const std::shared_ptr<InsertToken> & token_, [[maybe_unused]] std::lock_guard<std::mutex> & cache_lock)
void acquire(
const Key * key_, const std::shared_ptr<InsertToken> & token_, [[maybe_unused]] std::lock_guard<std::mutex> & cache_lock)
{
key = key_;
token = token_;
Expand Down Expand Up @@ -229,8 +230,8 @@ class LRUCache
{
bool expired(const Timestamp & last_timestamp, const Delay & expiration_delay) const
{
return (expiration_delay == Delay::zero()) ||
((last_timestamp > timestamp) && ((last_timestamp - timestamp) > expiration_delay));
return (expiration_delay == Delay::zero())
|| ((last_timestamp > timestamp) && ((last_timestamp - timestamp) > expiration_delay));
}

MappedPtr value;
Expand All @@ -252,8 +253,8 @@ class LRUCache
const Delay expiration_delay;

mutable std::mutex mutex;
std::atomic<size_t> hits {0};
std::atomic<size_t> misses {0};
std::atomic<size_t> hits{0};
std::atomic<size_t> misses{0};

WeightFunction weight_function;

Expand All @@ -276,9 +277,7 @@ class LRUCache

void setImpl(const Key & key, const MappedPtr & mapped, [[maybe_unused]] std::lock_guard<std::mutex> & cache_lock)
{
auto res = cells.emplace(std::piecewise_construct,
std::forward_as_tuple(key),
std::forward_as_tuple());
auto res = cells.emplace(std::piecewise_construct, std::forward_as_tuple(key), std::forward_as_tuple());

Cell & cell = res.first->second;
bool inserted = res.second;
Expand Down Expand Up @@ -348,4 +347,4 @@ class LRUCache
};


}
} // namespace DB
1 change: 0 additions & 1 deletion dbms/src/Flash/BatchCoprocessorHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <Flash/Coprocessor/InterpreterDAG.h>
#include <Storages/IStorage.h>
#include <Storages/StorageMergeTree.h>
#include <Storages/Transaction/LockException.h>
#include <Storages/Transaction/SchemaSyncer.h>
#include <Storages/Transaction/TMTContext.h>

Expand Down
3 changes: 2 additions & 1 deletion dbms/src/Flash/Coprocessor/DAGDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
#include <Storages/RegionQueryInfo.h>
#include <kvproto/tikvpb.grpc.pb.h>
#include <tipb/select.pb.h>

#pragma GCC diagnostic pop

#include <vector>

namespace DB
{

Expand Down
1 change: 1 addition & 0 deletions dbms/src/Flash/FlashService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <Core/Types.h>
#include <Flash/BatchCommandsHandler.h>
#include <Flash/BatchCoprocessorHandler.h>
#include <Flash/Coprocessor/DAGContext.h>
#include <Flash/Coprocessor/DAGUtils.h>
#include <Flash/FlashService.h>
#include <Flash/Mpp/MPPHandler.h>
Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Flash/Mpp/MPPHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <DataStreams/BlockIO.h>
#include <DataStreams/IProfilingBlockInputStream.h>
#include <DataStreams/copyData.h>
#include <Flash/Coprocessor/DAGContext.h>
#include <Flash/Coprocessor/DAGDriver.h>
#include <Interpreters/Context.h>
#include <Storages/MergeTree/BackgroundProcessingPool.h>
#include <common/logger_useful.h>
Expand Down
1 change: 1 addition & 0 deletions dbms/src/Functions/FunctionsTiDBConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <DataTypes/DataTypeUUID.h>
#include <DataTypes/DataTypesNumber.h>
#include <Flash/Coprocessor/DAGUtils.h>
#include <Flash/Coprocessor/DAGContext.h>
#include <Functions/FunctionFactory.h>
#include <Functions/FunctionHelpers.h>
#include <Functions/FunctionsConversion.h>
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Interpreters/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <Core/NamesAndTypes.h>
#include <Core/Types.h>
#include <Flash/Coprocessor/DAGContext.h>
#include <IO/CompressionSettings.h>
#include <Interpreters/ClientInfo.h>
#include <Interpreters/Settings.h>
Expand Down Expand Up @@ -97,6 +96,7 @@ using FileProviderPtr = std::shared_ptr<FileProvider>;
class RateLimiter;
using RateLimiterPtr = std::shared_ptr<RateLimiter>;
struct TiFlashRaftConfig;
class DAGContext;

namespace DM
{
Expand Down
42 changes: 42 additions & 0 deletions dbms/src/Interpreters/TimezoneInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <Interpreters/TimezoneInfo.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <tipb/select.pb.h>
#pragma GCC diagnostic pop

namespace DB
{
void TimezoneInfo::resetByDAGRequest(const tipb::DAGRequest & rqst)
{
if (rqst.has_time_zone_name() && !rqst.time_zone_name().empty())
{
// dag request use name based timezone info
is_name_based = true;
timezone_offset = 0;
timezone = &DateLUT::instance(rqst.time_zone_name());
timezone_name = timezone->getTimeZone();
is_utc_timezone = timezone_name == "UTC";
}
else if (rqst.has_time_zone_offset())
{
// dag request use offset based timezone info
is_name_based = false;
timezone_offset = rqst.time_zone_offset();
timezone = &DateLUT::instance("UTC");
timezone_name = "";
is_utc_timezone = timezone_offset == 0;
}
else
{
// dag request does not have timezone info
is_name_based = false;
timezone_offset = 0;
// set the default timezone to UTC because TiDB assumes
// the default timezone is UTC
timezone = &DateLUT::instance("UTC");
timezone_name = "";
is_utc_timezone = true;
}
}

} // namespace DB
Loading

0 comments on commit 3775b05

Please sign in to comment.