Skip to content

Commit

Permalink
Merge branch 'master' into xuanyili/getFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
wirybeaver authored Jul 5, 2022
2 parents fe9896a + a0ecce0 commit 7636c23
Show file tree
Hide file tree
Showing 60 changed files with 1,452 additions and 311 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@
[submodule "contrib/cpu_features"]
path = contrib/cpu_features
url = https://github.com/google/cpu_features
[submodule "contrib/arm-optimized-routines"]
path = contrib/arm-optimized-routines
url = https://github.com/ARM-software/optimized-routines
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ ninja tiflash
tiup playground nightly --tiflash.binpath $BUILD/dbms/src/Server/tiflash
```
3. Check $WORKSPACE/tests/_env.sh to make the port and build dir right.
4. Run your integration tests using commands like "./run-test.sh fullstack-test2/ddl" under $WORKSPACE dir
4. Run your integration tests using commands like "./run-test.sh fullstack-test2/ddl" under $WORKSPACE/tests dir
## Run MicroBenchmark Tests
To run micro benchmark tests, you need to build with -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_TESTS=ON:
```shell
cd $BUILD
cmake $WORKSPACE/tiflash -GNinja -DCMAKE_BUILD_TYPE=DEBUG -DENABLE_TESTS=ON
cmake $WORKSPACE/tiflash -GNinja -DCMAKE_BUILD_TYPE=RELEASE -DENABLE_TESTS=ON
ninja bench_dbms
```
Expand Down
4 changes: 4 additions & 0 deletions contrib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,7 @@ add_subdirectory(benchmark)

set (BUILD_TESTING OFF CACHE BOOL "Disable cpu-features testing" FORCE)
add_subdirectory(cpu_features)

if (ARCH_AARCH64 AND ARCH_LINUX)
add_subdirectory(arm-optimized-routines-cmake)
endif ()
1 change: 1 addition & 0 deletions contrib/arm-optimized-routines
Submodule arm-optimized-routines added at e373f6
45 changes: 45 additions & 0 deletions contrib/arm-optimized-routines-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2022 PingCAP, Ltd.
#
# Licensed 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.

# This library is to override performance-critical routines for aarch64 targets.
# The implementations are imported from official ARM repo.
# To reduce dispatching cost, indirect function technique is utilized. Therefore,
# this library should only be enabled with ELF targets.

# Considerations:
# - By Jun, 2022, most enterprise OSs (CentOS 7, CentOS Stream 8 and RHEL 8) still
# use relatively old glibc on ARM64, where ASIMD, MTE, DC ZVA and SVE are not
# fully utilized. However, it is becoming increasingly common to use ARM64 instances
# in cloud-native situations.
# - `optimized-routines` repo is actively maintained by ARM officials. Therefore,
# the qualities can be ensured while using it also enables us to keep sync with latest
# acceleration techniques.

set(CMAKE_C_FLAGS "")
ENABLE_LANGUAGE(C)
ENABLE_LANGUAGE(ASM)
set(TIFLASH_AOR_DIR ../arm-optimized-routines)

file(GLOB TIFLASH_AARCH64_STRING_FILES ${TIFLASH_AOR_DIR}/string/aarch64/*.S)
add_library(tiflash-aarch64-string STATIC ${TIFLASH_AARCH64_STRING_FILES} src/aor.c)
target_compile_options(tiflash-aarch64-string PRIVATE -march=armv8-a+sve)
target_include_directories(tiflash-aarch64-string PRIVATE ${TIFLASH_AOR_DIR}/string/include)

file(GLOB TIFLASH_AARCH64_MATH_FILES ${TIFLASH_AOR_DIR}/math/*.c)
add_library(tiflash-aarch64-math STATIC ${TIFLASH_AARCH64_MATH_FILES})
target_include_directories(tiflash-aarch64-math PRIVATE ${TIFLASH_AOR_DIR}/math/include)

# it is reasonable to keep these libraries optimized
target_compile_options(tiflash-aarch64-string PRIVATE -O3 -g3 -fno-omit-frame-pointer -ffunction-sections -fdata-sections)
target_compile_options(tiflash-aarch64-math PRIVATE -O3 -g3 -fno-omit-frame-pointer -ffunction-sections -fdata-sections)
115 changes: 115 additions & 0 deletions contrib/arm-optimized-routines-cmake/src/aor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2022 PingCAP, Ltd.
//
// Licensed 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.

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <stringlib.h>
#include <sys/auxv.h>

// Provide default macro definitions in case that they are not defined on current linux distro.
// For example, TiFlash compiled on older linux kernels may also be used in newer ones.
// These values should be stable for Linux: only false negative is expected when running on
// older kernels, but it is acceptable as `google/cpu_features` is also doing so.
#ifndef HWCAP2_MTE
#define HWCAP2_MTE (1 << 18)
#endif

#ifndef HWCAP_SVE
#define HWCAP_SVE (1 << 22)
#endif

#ifndef AT_HWCAP2
#define AT_HWCAP2 26
#endif

#ifndef AT_HWCAP
#define AT_HWCAP 16
#endif

/// check if MTE is supported in current environment
static inline bool mte_supported(void)
{
return (getauxval(AT_HWCAP2) & HWCAP2_MTE) != 0;
}

/// check if SVE is supported in current environment
static inline bool sve_supported(void)
{
return (getauxval(AT_HWCAP) & HWCAP_SVE) != 0;
}

#define STRINGIFY_IMPL(X) #X
#define STRINGIFY(X) STRINGIFY_IMPL(X)
/**
* \brief
* Symbol is defined as hidden visibility. Therefore, implementations here are only to override routines with TiFlash
* binary itself. This is because dependencies like `ld.so`, `libgcc_s.so`, etc will need essential routines like
* `memcpy` to finish the early loading procedure. Therefore, declare such symbols as visible indirect function will
* create cyclic dependency. It shall be good enough to override symbols within TiFlash, as most heavy computation works
* are happening in the main binary.
* \param NAME: exported symbol name
* \param SVE: preferred implementation when SVE is available
* \param MTE: preferred implementation when MTE is available
* \param ASIMD: preferred implementation for generic aarch64 targets (ASIMD is required by default for Armv8 and above)
*/
#define DISPATCH(NAME, SVE, MTE, ASIMD) \
extern typeof(ASIMD) __tiflash_##NAME __attribute__((ifunc(STRINGIFY(__tiflash_##NAME##_resolver)))); \
extern typeof(ASIMD) NAME __attribute__((visibility("hidden"), alias(STRINGIFY(__tiflash_##NAME)))); \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wunused-function\"") static typeof(ASIMD) * __tiflash_##NAME##_resolver(void) \
{ \
if (sve_supported()) \
{ \
return SVE; \
} \
if (mte_supported()) \
{ \
return MTE; \
} \
return ASIMD; \
} \
_Pragma("GCC diagnostic pop")
#undef memcpy
#undef memmove
#undef memset
#undef memchr
#undef memrchr
#undef memcmp
#undef strcpy
#undef stpcpy
#undef strcmp
#undef strchr
#undef strrchr
#undef strchrnul
#undef strlen
#undef strnlen
#undef strncmp

DISPATCH(memcpy, __memcpy_aarch64_sve, __memcpy_aarch64_simd, __memcpy_aarch64_simd)
DISPATCH(memmove, __memmove_aarch64_sve, __memmove_aarch64_simd, __memmove_aarch64_simd)
DISPATCH(memset, __memset_aarch64, __memset_aarch64, __memset_aarch64)
DISPATCH(memchr, __memchr_aarch64_sve, __memchr_aarch64_mte, __memchr_aarch64)
DISPATCH(memrchr, __memrchr_aarch64, __memrchr_aarch64, __memrchr_aarch64)
DISPATCH(memcmp, __memcmp_aarch64_sve, __memcmp_aarch64, __memcmp_aarch64)
DISPATCH(strcpy, __strcpy_aarch64_sve, __strcpy_aarch64, __strcpy_aarch64)
DISPATCH(stpcpy, __stpcpy_aarch64_sve, __stpcpy_aarch64, __stpcpy_aarch64)
DISPATCH(strcmp, __strcmp_aarch64_sve, __strcmp_aarch64, __strcmp_aarch64)
DISPATCH(strchr, __strchr_aarch64_sve, __strchr_aarch64_mte, __strchr_aarch64)
DISPATCH(strrchr, __strrchr_aarch64_sve, __strrchr_aarch64_mte, __strrchr_aarch64)
DISPATCH(strchrnul, __strchrnul_aarch64_sve, __strchrnul_aarch64_mte, __strchrnul_aarch64)
DISPATCH(strlen, __strlen_aarch64_sve, __strlen_aarch64_mte, __strlen_aarch64)
DISPATCH(strnlen, __strnlen_aarch64_sve, __strnlen_aarch64, __strnlen_aarch64)
DISPATCH(strncmp, __strncmp_aarch64_sve, __strncmp_aarch64, __strncmp_aarch64)
2 changes: 1 addition & 1 deletion contrib/client-c
2 changes: 1 addition & 1 deletion contrib/prometheus-cpp
Submodule prometheus-cpp updated 126 files
9 changes: 9 additions & 0 deletions contrib/prometheus-cpp-cmake/pull/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ if(ENABLE_COMPRESSION)
endif()

add_library(pull
${PROMETHEUS_SRC_DIR}/pull/src/basic_auth.cc
${PROMETHEUS_SRC_DIR}/pull/src/basic_auth.h
${PROMETHEUS_SRC_DIR}/pull/src/endpoint.cc
${PROMETHEUS_SRC_DIR}/pull/src/endpoint.h
${PROMETHEUS_SRC_DIR}/pull/src/exposer.cc
${PROMETHEUS_SRC_DIR}/pull/src/handler.cc
${PROMETHEUS_SRC_DIR}/pull/src/handler.h
${PROMETHEUS_SRC_DIR}/pull/src/metrics_collector.cc
${PROMETHEUS_SRC_DIR}/pull/src/metrics_collector.h

${PROMETHEUS_SRC_DIR}/pull/src/detail/base64.h

$<$<BOOL:${USE_THIRDPARTY_LIBRARIES}>:$<TARGET_OBJECTS:civetweb>>
)

Expand Down
2 changes: 2 additions & 0 deletions contrib/prometheus-cpp-cmake/push/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ if(NOT CURL_FOUND)
endif()

add_library(push
${PROMETHEUS_SRC_DIR}/push/src/curl_wrapper.cc
${PROMETHEUS_SRC_DIR}/push/src/curl_wrapper.h
${PROMETHEUS_SRC_DIR}/push/src/gateway.cc
)

Expand Down
2 changes: 1 addition & 1 deletion contrib/tiflash-proxy
Submodule tiflash-proxy updated 814 files
6 changes: 5 additions & 1 deletion contrib/tiflash-proxy-cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ file(GLOB_RECURSE _TIFLASH_PROXY_SRCS "${_TIFLASH_PROXY_SOURCE_DIR}/*.rs")
list(FILTER _TIFLASH_PROXY_SRCS EXCLUDE REGEX ${_TIFLASH_PROXY_SOURCE_DIR}/target/.*)

# use `CFLAGS=-w CXXFLAGS=-w` to inhibit warning messages.
set(TIFLASH_RUST_ENV CMAKE=${CMAKE_COMMAND} CFLAGS=-w CXXFLAGS=-w)
if (TIFLASH_LLVM_TOOLCHAIN)
set(TIFLASH_RUST_ENV CMAKE=${CMAKE_COMMAND} "CFLAGS=-w -fuse-ld=lld" "CXXFLAGS=-w -fuse-ld=lld -stdlib=libc++")
else()
set(TIFLASH_RUST_ENV CMAKE=${CMAKE_COMMAND} CFLAGS=-w CXXFLAGS=-w)
endif()

if(TIFLASH_LLVM_TOOLCHAIN AND USE_LIBCXX)
set(TIFLASH_RUST_LINKER ${CMAKE_CURRENT_BINARY_DIR}/tiflash-linker)
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/DataStreams/ParallelAggregatingBlockInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ void ParallelAggregatingBlockInputStream::Handler::onException(std::exception_pt

/// can not cancel parent inputStream or the exception might be lost
if (!parent.executed)
/// kill the processor so ExchangeReceiver will be closed
parent.processor.cancel(true);
/// use cancel instead of kill to avoid too many useless error message
parent.processor.cancel(false);
}


Expand Down
4 changes: 2 additions & 2 deletions dbms/src/DataStreams/UnionBlockInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ class UnionBlockInputStream final : public IProfilingBlockInputStream
/// and the exception is lost.
output_queue.emplace(exception);
/// can not cancel itself or the exception might be lost
/// kill the processor so ExchangeReceiver will be closed
processor.cancel(true);
/// use cancel instead of kill to avoid too many useless error message
processor.cancel(false);
}

struct Handler
Expand Down
13 changes: 11 additions & 2 deletions dbms/src/Debug/MockSchemaGetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,25 @@
#include <Debug/MockTiDB.h>
#include <TiDB/Schema/SchemaGetter.h>

#include <optional>

namespace DB
{

struct MockSchemaGetter
{
TiDB::DBInfoPtr getDatabase(DatabaseID db_id) { return MockTiDB::instance().getDBInfoByID(db_id); }

Int64 getVersion() { return MockTiDB::instance().getVersion(); }

SchemaDiff getSchemaDiff(Int64 version) { return MockTiDB::instance().getSchemaDiff(version); }
std::optional<SchemaDiff> getSchemaDiff(Int64 version)
{
return MockTiDB::instance().getSchemaDiff(version);
}

bool checkSchemaDiffExists(Int64 version)
{
return MockTiDB::instance().checkSchemaDiffExists(version);
}

TiDB::TableInfoPtr getTableInfo(DatabaseID, TableID table_id) { return MockTiDB::instance().getTableInfoByID(table_id); }

Expand Down
7 changes: 6 additions & 1 deletion dbms/src/Debug/MockTiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,9 +668,14 @@ std::pair<bool, DatabaseID> MockTiDB::getDBIDByName(const String & database_name
return std::make_pair(false, -1);
}

SchemaDiff MockTiDB::getSchemaDiff(Int64 version_)
std::optional<SchemaDiff> MockTiDB::getSchemaDiff(Int64 version_)
{
return version_diff[version_];
}

bool MockTiDB::checkSchemaDiffExists(Int64 version)
{
return version_diff.find(version) != version_diff.end();
}

} // namespace DB
4 changes: 3 additions & 1 deletion dbms/src/Debug/MockTiDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ class MockTiDB : public ext::Singleton<MockTiDB>

std::pair<bool, DatabaseID> getDBIDByName(const String & database_name);

SchemaDiff getSchemaDiff(Int64 version);
bool checkSchemaDiffExists(Int64 version);

std::optional<SchemaDiff> getSchemaDiff(Int64 version);

std::unordered_map<String, DatabaseID> getDatabases() { return databases; }

Expand Down
1 change: 0 additions & 1 deletion dbms/src/Debug/astToExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,6 @@ ExecutorPtr compileProject(ExecutorPtr input, size_t & executor_index, ASTPtr se
}
}
}

auto project = std::make_shared<mock::Project>(executor_index, output_schema, std::move(exprs));
project->children.push_back(input);
return project;
Expand Down
6 changes: 5 additions & 1 deletion dbms/src/Flash/Coprocessor/DAGContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,18 @@ class DAGContext
std::vector<tipb::FieldType> output_field_types;
std::vector<Int32> output_offsets;

/// Hold the order of list based executors.
/// It is used to ensure that the order of Execution summary of list based executors is the same as the order of list based executors.
std::vector<String> list_based_executors_order;

private:
void initExecutorIdToJoinIdMap();
void initOutputInfo();

private:
/// Hold io for correcting the destruction order.
BlockIO io;
/// profile_streams_map is a map that maps from executor_id to profile BlockInputStreams
/// profile_streams_map is a map that maps from executor_id to profile BlockInputStreams.
std::unordered_map<String, BlockInputStreams> profile_streams_map;
/// executor_id_to_join_id_map is a map that maps executor id to all the join executor id of itself and all its children.
std::unordered_map<String, std::vector<String>> executor_id_to_join_id_map;
Expand Down
23 changes: 23 additions & 0 deletions dbms/src/Flash/Coprocessor/DAGQuerySource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@

namespace DB
{
namespace
{
void fillOrderForListBasedExecutors(DAGContext & dag_context, const DAGQueryBlock & query_block)
{
assert(query_block.source);
auto & list_based_executors_order = dag_context.list_based_executors_order;
list_based_executors_order.push_back(query_block.source_name);
if (query_block.selection)
list_based_executors_order.push_back(query_block.selection_name);
if (query_block.aggregation)
list_based_executors_order.push_back(query_block.aggregation_name);
if (query_block.having)
list_based_executors_order.push_back(query_block.having_name);
if (query_block.limit_or_topn)
list_based_executors_order.push_back(query_block.limit_or_topn_name);
if (query_block.exchange_sender)
dag_context.list_based_executors_order.push_back(query_block.exchange_sender_name);
}
} // namespace

DAGQuerySource::DAGQuerySource(Context & context_)
: context(context_)
{
Expand All @@ -32,6 +52,9 @@ DAGQuerySource::DAGQuerySource(Context & context_)
else
{
root_query_block = std::make_shared<DAGQueryBlock>(1, dag_request.executors());
auto & dag_context = getDAGContext();
if (!dag_context.return_executor_id)
fillOrderForListBasedExecutors(dag_context, *root_query_block);
}
}

Expand Down
Loading

0 comments on commit 7636c23

Please sign in to comment.