Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
lidezhu committed Jun 27, 2022
2 parents 15a5f9f + 73e708c commit 912728d
Show file tree
Hide file tree
Showing 562 changed files with 21,779 additions and 10,602 deletions.
7 changes: 7 additions & 0 deletions .clang-tidy
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ Checks: '-*,
modernize-redundant-void-arg,
modernize-replace-auto-ptr,
modernize-replace-random-shuffle,
modernize-use-auto,
modernize-use-bool-literals,
modernize-use-nullptr,
modernize-use-using,
modernize-use-override,
modernize-use-equals-default,
modernize-use-equals-delete,
Expand Down Expand Up @@ -160,6 +162,11 @@ Checks: '-*,
clang-analyzer-unix.cstring.NullArg,
boost-use-to-string,
cppcoreguidelines-pro-type-cstyle-cast,
cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-no-malloc,
cppcoreguidelines-virtual-class-destructor,
'
WarningsAsErrors: '*'

Expand Down
33 changes: 30 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ endif ()
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

option (USE_CCACHE "Set to OFF to disable ccache" ON)
if (USE_CCACHE)
set(NOT_USE_CCACHE 0)
else()
set(NOT_USE_CCACHE 1)
endif()

option(ENABLE_PCH "Enable `Precompiled header`" OFF)

include (cmake/find_ccache.cmake)

if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "None")
Expand Down Expand Up @@ -102,6 +110,28 @@ if (COMPILER_CLANG)
# Clang doesn't have int128 predefined macros, workaround by manually defining them
# Reference: https://stackoverflow.com/questions/41198673/uint128-t-not-working-with-clang-and-libstdc
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__GLIBCXX_BITSIZE_INT_N_0=128 -D__GLIBCXX_TYPE_INT_N_0=__int128")

option(ENABLE_TIME_TRACES "Enable clang feature time traces" OFF)
if (ENABLE_TIME_TRACES)
set (CLANG_TIME_TRACES_FLAGS "-ftime-trace")
message (STATUS "Using clang time traces flag `${CLANG_TIME_TRACES_FLAGS}`. Generates JSON file based on output filename. Results can be analyzed with chrome://tracing or https://www.speedscope.app for flamegraph visualization.")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CLANG_TIME_TRACES_FLAGS}")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLANG_TIME_TRACES_FLAGS}")
endif ()

# https://clang.llvm.org/docs/ThinLTO.html
# Applies to clang only.
option(ENABLE_THINLTO "Clang-specific link time optimization" OFF)

if (ENABLE_THINLTO AND NOT ENABLE_TESTS)
# Link time optimization
set (THINLTO_JOBS "0" CACHE STRING "ThinLTO compilation parallelism")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto=thin -fvisibility=hidden -fvisibility-inlines-hidden -fsplit-lto-unit")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=thin -fvisibility=hidden -fvisibility-inlines-hidden -fwhole-program-vtables -fsplit-lto-unit")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto=thin -flto-jobs=${THINLTO_JOBS} -fvisibility=hidden -fvisibility-inlines-hidden -fwhole-program-vtables -fsplit-lto-unit")
elseif (ENABLE_THINLTO)
message (WARNING "Cannot enable ThinLTO")
endif ()
endif ()

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Expand Down Expand Up @@ -402,9 +432,6 @@ else (ENABLE_FAILPOINTS)
message (STATUS "Failpoints are disabled")
endif (ENABLE_FAILPOINTS)

# Enable PageStorage V3 test.
option (ENABLE_V3_PAGESTORAGE "Enables V3 PageStorage" ON)

# Flags for test coverage
option (TEST_COVERAGE "Enables flags for test coverage" OFF)
option (TEST_COVERAGE_XML "Output XML report for test coverage" OFF)
Expand Down
76 changes: 59 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
# TiFlash

![tiflash-architecture](tiflash-architecture.png)

[TiFlash](https://docs.pingcap.com/tidb/stable/tiflash-overview) is a columnar storage component of [TiDB](https://docs.pingcap.com/tidb/stable). It mainly plays the role of Analytical Processing (AP) in the Hybrid Transactional/Analytical Processing (HTAP) architecture of TiDB.
[TiFlash](https://docs.pingcap.com/tidb/stable/tiflash-overview) is a columnar storage component of [TiDB](https://docs.pingcap.com/tidb/stable) and [TiDB Cloud](https://en.pingcap.com/tidb-cloud/), the fully-managed service of TiDB. It mainly plays the role of Analytical Processing (AP) in the Hybrid Transactional/Analytical Processing (HTAP) architecture of TiDB.

TiFlash stores data in columnar format and synchronizes data updates in real-time from [TiKV](https://github.com/tikv/tikv) by Raft logs with sub-second latency. Reads in TiFlash are guaranteed transactionally consistent with Snapshot Isolation level. TiFlash utilizes Massively Parallel Processing (MPP) computing architecture to accelerate the analytical workloads.

TiFlash repository is based on [ClickHouse](https://github.com/ClickHouse/ClickHouse). We appreciate the excellent work of ClickHouse team.
TiFlash repository is based on [ClickHouse](https://github.com/ClickHouse/ClickHouse). We appreciate the excellent work of the ClickHouse team.

## Quick Start

### Start with TiDB Cloud

Quickly explore TiFlash with [a free trial of TiDB Cloud](https://tidbcloud.com/free-trial).

See [TiDB Cloud Quick Start Guide](https://docs.pingcap.com/tidbcloud/tidb-cloud-quickstart).

### Start with TiDB

See [Quick Start with HTAP](https://docs.pingcap.com/tidb/stable/quick-start-with-htap) and [Use TiFlash](https://docs.pingcap.com/tidb/stable/use-tiflash).

## Build TiFlash

TiFlash supports building on the following hardware architectures:
* x86-64/amd64
* aarch64

- x86-64/amd64
- aarch64

And the following operating systems:
* Linux
* MacOS

- Linux
- MacOS

### 1. Checkout Source Code

Assume `$WORKSPACE` to be the directory under which the TiFlash repo is placed.

```shell
cd $WORKSPACE
git clone --recursive https://github.com/pingcap/tiflash.git
git clone https://github.com/pingcap/tiflash.git --recursive -j 20
```

### 2. Prepare Prerequisites
Expand All @@ -44,19 +59,20 @@ The following packages are needed for all platforms:
- Ninja or GNU Make

The following are platform-specific prerequisites. Click to expand details:

<details>
<summary><b>Linux specific prerequisites</b></summary>

TiFlash can be built using either LLVM or GCC toolchain on Linux. LLVM toolchain is our official one for releasing.
> But for GCC, only GCC 7.x is supported as far, and is not planned to be a long term support. So it may get broken some day, silently.
TiFlash can be built using either LLVM or GCC toolchain on Linux. LLVM toolchain is our official one for releasing.

> But for GCC, only GCC 7.x is supported as far, and is not planned to be a long term support. So it may get broken some day, silently.
- LLVM 13.0.0+

TiFlash compiles using full LLVM toolchain (`clang/compiler-rt/libc++/libc++abi`) by default. You can use a system-wise toolchain if `clang/compiler-rt/libc++/libc++abi` can be installed in your environment.

Click sections below to see detailed instructions:


<details>
<summary><b>Set up LLVM via package managers in Debian/Ubuntu</b></summary>

Expand Down Expand Up @@ -123,6 +139,8 @@ cmake $WORKSPACE/tiflash
make tiflash -j
```

> **NOTE**: Option `-j` (defaults to your system CPU core count, otherwise you can optionally specify a number) is used to control the build parallelism. Higher parallelism consumes more memory. If you encounter compiler OOM or hang, try to lower the parallelism by specifying a reasonable number, e.g., half of your system CPU core count or even smaller, after `-j`, depending on the available memory in your system.
After building, you can get TiFlash binary under `$BUILD/dbms/src/Server/tiflash`.

### Build Options
Expand Down Expand Up @@ -195,11 +213,12 @@ To run unit tests, you need to build with `-DCMAKE_BUILD_TYPE=DEBUG`:
```shell
cd $BUILD
cmake $WORKSPACE/tiflash -GNinja -DCMAKE_BUILD_TYPE=DEBUG
ninja gtests_dbms
ninja gtests_dbms # Most TiFlash unit tests
ninja gtests_libdaemon # Settings related tests
ninja gtests_libcommon
ninja gtests_libdaemon
```
And the unit-test executables are at `$BUILD/dbms/gtests_dbms`, `$BUILD/libs/libcommon/src/tests/gtests_libcommon` and `$BUILD/libs/libdaemon/src/tests/gtests_libdaemon`.

And the unit-test executables are at `$BUILD/dbms/gtests_dbms`, `$BUILD/libs/libdaemon/src/tests/gtests_libdaemon` and `$BUILD/libs/libcommon/src/tests/gtests_libcommon`.

## Run Sanitizer Tests

Expand All @@ -211,19 +230,42 @@ To generate unit test executables with sanitizer enabled:
cd $BUILD
cmake $WORKSPACE/tiflash -GNinja -DENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=ASan # or TSan
ninja gtests_dbms
ninja gtests_libcommon
ninja gtests_libdaemon
ninja gtests_libcommon
```

There are known false positives reported from leak sanitizer (which is included in address sanitizer). To suppress these errors, set the following environment variables before running the executables:

```
```shell
LSAN_OPTIONS=suppressions=$WORKSPACE/tiflash/test/sanitize/asan.suppression
```

## Run Integration Tests

TBD.
1. Build your own tiflash binary in $BUILD with `-DCMAKE_BUILD_TYPE=DEBUG`.
```
cd $BUILD
cmake $WORKSPACE/tiflash -GNinja -DCMAKE_BUILD_TYPE=DEBUG
ninja tiflash
```
2. Run tidb cluster locally using tiup playgroud or other tools.
```
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

## 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
ninja bench_dbms
```

And the microbenchmark-test executables are at `$BUILD/dbms/bench_dbms`, you can run it with `./bench_dbms` or `./bench_dbms --benchmark_filter=xxx` . More usage please check with `./bench_dbms --help`.

## Generate LLVM Coverage Report

Expand Down
14 changes: 14 additions & 0 deletions cmake/find_ccache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ if (USE_CCACHE AND CCACHE_FOUND AND NOT CMAKE_CXX_COMPILER_LAUNCHER MATCHES "cca
message ("${CCACHE_CONFIG}")
set_property (GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_FOUND})
set_property (GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE_FOUND})

if (ENABLE_PCH)
execute_process (COMMAND ${CCACHE_FOUND} --get-config sloppiness OUTPUT_VARIABLE _CCACHE_SLOPPINESS OUTPUT_STRIP_TRAILING_WHITESPACE)
string (FIND "${_CCACHE_SLOPPINESS}" "pch_defines" _CCACHE_SLOPPINESS_RES)
if (NOT _CCACHE_SLOPPINESS_RES STREQUAL "-1")
string (FIND "${_CCACHE_SLOPPINESS}" "time_macros" _CCACHE_SLOPPINESS_RES)
endif ()

if (_CCACHE_SLOPPINESS_RES STREQUAL "-1")
message(WARNING "`Precompiled header` won't be cached by ccache, sloppiness = `${CCACHE_SLOPPINESS}`,please execute `ccache -o sloppiness=pch_defines,time_macros`")
set (ENABLE_PCH FALSE CACHE BOOL "" FORCE)
endif ()
endif ()

else ()
message (STATUS "Not using ccache ${CCACHE_FOUND}, USE_CCACHE=${USE_CCACHE}")
endif ()
2 changes: 1 addition & 1 deletion contrib/client-c
2 changes: 1 addition & 1 deletion contrib/kvproto
Submodule kvproto updated 47 files
+2 −0 .github/workflows/cpp-test.yaml
+2 −0 .github/workflows/golang-test.yaml
+2 −0 .github/workflows/rust-test.yaml
+5 −10 Cargo.toml
+2 −2 go.mod
+29 −7 go.sum
+5,778 −3,182 pkg/brpb/brpb.pb.go
+1,201 −925 pkg/cdcpb/cdcpb.pb.go
+1,125 −801 pkg/configpb/configpb.pb.go
+664 −481 pkg/coprocessor/coprocessor.pb.go
+289 −228 pkg/deadlock/deadlock.pb.go
+1,684 −859 pkg/debugpb/debugpb.pb.go
+393 −298 pkg/diagnosticspb/diagnosticspb.pb.go
+6 −4 pkg/disk_usage/disk_usage.pb.go
+615 −530 pkg/encryptionpb/encryptionpb.pb.go
+597 −493 pkg/enginepb/enginepb.pb.go
+665 −490 pkg/eraftpb/eraftpb.pb.go
+1,009 −545 pkg/errorpb/errorpb.pb.go
+3,572 −0 pkg/gcpb/gcpb.pb.go
+970 −665 pkg/import_kvpb/import_kvpb.pb.go
+5,421 −3,272 pkg/import_sstpb/import_sstpb.pb.go
+15,330 −11,479 pkg/kvrpcpb/kvrpcpb.pb.go
+750 −464 pkg/metapb/metapb.pb.go
+515 −376 pkg/mpp/mpp.pb.go
+8,832 −4,871 pkg/pdpb/pdpb.pb.go
+2,645 −1,749 pkg/raft_cmdpb/raft_cmdpb.pb.go
+829 −613 pkg/raft_serverpb/raft_serverpb.pb.go
+544 −166 pkg/replication_modepb/replication_modepb.pb.go
+259 −249 pkg/resource_usage_agent/resource_usage_agent.pb.go
+2,129 −2,187 pkg/tikvpb/tikvpb.pb.go
+423 −373 pkg/tracepb/tracepb.pb.go
+115 −0 proto/brpb.proto
+14 −0 proto/cdcpb.proto
+4 −0 proto/coprocessor.proto
+11 −0 proto/debugpb.proto
+7 −0 proto/errorpb.proto
+117 −0 proto/gcpb.proto
+93 −1 proto/import_sstpb.proto
+53 −2 proto/kvrpcpb.proto
+14 −1 proto/metapb.proto
+71 −5 proto/pdpb.proto
+13 −2 proto/replication_modepb.proto
+6 −0 proto/tikvpb.proto
+2 −2 scripts/check.sh
+4 −3 scripts/common.sh
+6 −5 scripts/generate_go.sh
+1 −1 tools.json
2 changes: 1 addition & 1 deletion contrib/tiflash-proxy
Submodule tiflash-proxy updated 36 files
+40 −33 Cargo.lock
+1 −4 Cargo.toml
+27 −0 Makefile
+20 −7 build.sh
+6 −1 cargo-build.sh
+3 −0 components/error_code/src/raftstore.rs
+2 −2 components/pd_client/src/client.rs
+2 −0 components/pd_client/src/util.rs
+1 −0 components/raftstore/Cargo.toml
+9 −0 components/raftstore/src/errors.rs
+3 −2 components/raftstore/src/store/config.rs
+1 −1 components/raftstore/src/store/fsm/apply.rs
+693 −206 components/raftstore/src/store/fsm/peer.rs
+85 −61 components/raftstore/src/store/fsm/store.rs
+1 −2 components/raftstore/src/store/mod.rs
+32 −13 components/raftstore/src/store/msg.rs
+341 −7 components/raftstore/src/store/peer.rs
+5 −0 components/raftstore/src/store/peer_storage.rs
+0 −14 components/raftstore/src/store/util.rs
+2 −1 components/raftstore/src/store/worker/mod.rs
+89 −142 components/raftstore/src/store/worker/pd.rs
+1 −0 components/raftstore/src/store/worker/raftlog_gc.rs
+1 −1 components/server/src/lib.rs
+36 −51 components/test_raftstore/src/cluster.rs
+30 −28 components/test_raftstore/src/pd.rs
+65 −52 components/tikv_util/src/sys/cgroup.rs
+3 −4 components/tikv_util/src/sys/mod.rs
+10 −0 debug.sh
+107 −1 metrics/grafana/tikv_details.json
+11 −0 release.sh
+13 −2 src/server/service/kv.rs
+2 −20 src/server/status_server/profile.rs
+408 −36 tests/failpoints/cases/test_unsafe_recovery.rs
+1 −1 tests/integrations/raftstore/mod.rs
+0 −86 tests/integrations/raftstore/test_unsafe_recover.rs
+1,070 −0 tests/integrations/raftstore/test_unsafe_recovery.rs
47 changes: 41 additions & 6 deletions dbms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ add_headers_and_sources(dbms src/Storages/Page/V2/mvcc)
add_headers_and_sources(dbms src/Storages/Page/V2/VersionSet)
add_headers_and_sources(dbms src/Storages/Page/V2/gc)
add_headers_and_sources(dbms src/WindowFunctions)
if (ENABLE_V3_PAGESTORAGE)
add_headers_and_sources(dbms src/Storages/Page/V3)
add_headers_and_sources(dbms src/Storages/Page/V3/LogFile)
add_headers_and_sources(dbms src/Storages/Page/V3/WAL)
add_headers_and_sources(dbms src/Storages/Page/V3/spacemap)
endif()
add_headers_and_sources(dbms src/TiDB/Schema)
add_headers_and_sources(dbms src/Storages/Page/V3)
add_headers_and_sources(dbms src/Storages/Page/V3/LogFile)
add_headers_and_sources(dbms src/Storages/Page/V3/WAL)
add_headers_and_sources(dbms src/Storages/Page/V3/spacemap)
add_headers_and_sources(dbms src/Storages/Page/)
add_headers_and_sources(dbms src/TiDB)
add_headers_and_sources(dbms src/Client)
Expand Down Expand Up @@ -258,6 +257,16 @@ target_include_directories (clickhouse_common_io BEFORE PRIVATE ${COMMON_INCLUDE
# https://cmake.org/pipermail/cmake/2016-May/063400.html
target_link_libraries (clickhouse_common_io PUBLIC ${TIFLASH_XXHASH_LIBRARY})

function(add_target_pch context target)
if (ENABLE_PCH)
message(STATUS "Add PCH `${context}` for target `${target}`")
target_precompile_headers(${target} PRIVATE ${context})
endif ()
if(${ARGC} GREATER 2)
add_target_pch(${context} ${ARGN})
endif()
endfunction()

if (ENABLE_TESTS)
include (${TiFlash_SOURCE_DIR}/cmake/find_gtest.cmake)

Expand Down Expand Up @@ -296,6 +305,8 @@ if (ENABLE_TESTS)
target_compile_options(gtests_dbms PRIVATE -Wno-unknown-pragmas -Wno-deprecated-copy)
add_check(gtests_dbms)

add_target_pch("pch-dbms.h" gtests_dbms)

grep_bench_sources(${TiFlash_SOURCE_DIR}/dbms dbms_bench_sources)
add_executable(bench_dbms EXCLUDE_FROM_ALL
${dbms_bench_sources}
Expand All @@ -305,11 +316,15 @@ if (ENABLE_TESTS)
${TiFlash_SOURCE_DIR}/dbms/src/AggregateFunctions/AggregateFunctionSum.cpp
)
target_include_directories(bench_dbms BEFORE PRIVATE ${SPARCEHASH_INCLUDE_DIR} ${benchmark_SOURCE_DIR}/include)
target_compile_definitions(bench_dbms PUBLIC DBMS_PUBLIC_GTEST)

target_link_libraries(bench_dbms gtest dbms test_util_bench_main benchmark clickhouse_functions)
if (ENABLE_TIFLASH_DTWORKLOAD)
target_link_libraries(bench_dbms dt-workload-lib)
endif ()
if (ENABLE_TIFLASH_PAGEWORKLOAD)
target_link_libraries(bench_dbms page-workload-lib)
endif ()

add_check(bench_dbms)
endif ()
Expand Down Expand Up @@ -341,3 +356,23 @@ if (TEST_COVERAGE AND CMAKE_BUILD_TYPE STREQUAL "Debug")
)
endif ()
endif ()

# dbms
add_target_pch("pch-dbms.h" dbms flash_service)
add_target_pch("pch-common.h" clickhouse_common_io clickhouse_functions clickhouse_aggregate_functions)
add_target_pch("pch-common.h" clickhouse_parsers clickhouse_storages_system dt-workload-lib clickhouse-server-lib)

# common
add_target_pch("pch-kvpb.h" kv_client)

add_target_pch("pch-stl.h" ${Boost_SYSTEM_LIBRARY} cctz ${RE2_LIBRARY} ${RE2_ST_LIBRARY})

# grpc
add_target_pch("$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/pch-stl.h>" grpc grpc++)

# pb
add_target_pch("pch-stl.h" libprotobuf kvproto tipb libprotoc)

# poco
add_target_pch("pch-stl.h" Net Crypto Util Data NetSSL)
add_target_pch("$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/pch-stl.h>" XML Foundation JSON)
20 changes: 6 additions & 14 deletions dbms/src/Parsers/ParserCheckQuery.h → dbms/pch-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@

#pragma once

#include <Parsers/ParserQueryWithOutput.h>
#include <Common/Exception.h>
#include <Common/FmtUtils.h>
#include <Common/StackTrace.h>
#include <common/StringRef.h>
#include <common/types.h>

namespace DB
{
/** Query of form
* CHECK [TABLE] [database.]table
*/
class ParserCheckQuery : public IParserBase
{
protected:
const char * getName() const { return "ALTER query"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected);
};

}
#include "pch-stl.h"
18 changes: 18 additions & 0 deletions dbms/pch-dbms.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.

#pragma once

#include "pch-common.h"
#include "pch-kvpb.h"
Loading

0 comments on commit 912728d

Please sign in to comment.