Giter Club home page Giter Club logo

jogasaki's Introduction

Jogasaki SQL job scheduler

Requirements

  • CMake >= 3.16
  • C++ Compiler >= C++17
  • mpdecimal 2.5.1 (see Manual install steps for mpdecimal section below to install on Ubuntu 20.04)
  • and see Dockerfile section
# retrieve third party modules
git submodule update --init --recursive

Dockerfile

FROM ubuntu:22.04

RUN apt update -y && apt install -y git build-essential cmake ninja-build libboost-filesystem-dev libboost-system-dev libboost-container-dev libboost-thread-dev libboost-stacktrace-dev libgoogle-glog-dev libgflags-dev doxygen libtbb-dev libnuma-dev protobuf-compiler protobuf-c-compiler libprotobuf-dev libmsgpack-dev uuid-dev libicu-dev pkg-config flex bison libmpdec-dev libparquet-dev=14.0.1-1 libparquet-glib-dev=14.0.1-1 libarrow-dev=14.0.1-1 libarrow-glib-dev=14.0.1-1

(see "Additional file installation for Apache Parquet" below if installing libparquet-dev, libparquet-glib-dev fails)

Note

Apache Arrow/Parquet packages with major version 14 are required. Different versions such as 13 or 15 cause cmake build failure.

optional packages:

Install modules

tsurugidb modules

This requires below tsurugidb modules to be installed.

Additional file installation for Apache Arrow/Parquet

Jogasaki requires Apache Arrow and Parquet package versioned as 14.0.1-1 (Official release stays to this version for stability. Jogasaki may be built and run with later versions, but it's for development/testing purpose only, not for production.)

Installing Apache Arrow/Paquet packages libarrow-dev, libarrow-glib-dev, libparquet-dev, libparquet-glib-dev requires additional files installation. If installing these packages from apt install command fails, issue below commands to install required files.

sudo apt install -y -V lsb-release
wget https://apache.jfrog.io/artifactory/arrow/$(lsb_release --id --short | tr 'A-Z' 'a-z')/apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb
sudo apt install -y -V ./apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb
sudo apt update
sudo apt install -y -V libparquet-dev=14.0.1-1 libparquet-glib-dev=14.0.1-1 libarrow-dev=14.0.1-1 libarrow-glib-dev=14.0.1-1 gir1.2-parquet-1.0=14.0.1-1 gir1.2-arrow-1.0=14.0.1-1 libarrow-acero-dev=14.0.1-1

(You can see here for full instruction. )

Manual install steps for mpdecimal

Ubuntu 22.04 users can safely skip this section since apt install libmpdec-dev installs new version enough for Jogasaki. On Ubuntu 20.04, the apt command installs slightly old mpdecimal package (2.4) while jogasaki requires newer version(2.5 or later.) Follow these steps in order to install mpdecmal in the custom location.

  1. Download mpdecimal-2.5.1.tar.gz listed here.
  2. Untar the archive and move into the extracted directory.
$ cd mpdecimal-2.5.1
  1. run configure specifying --prefix option with installation target directory.
./configure --prefix=<install directory>
  1. build and install
make
make install

How to build

mkdir -p build
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
cmake --build .

available options:

  • -DCMAKE_INSTALL_PREFIX=<installation directory> - change install location
  • -DCMAKE_PREFIX_PATH=<installation directory> - indicate prerequisite installation directory
  • -DCMAKE_IGNORE_PATH="/usr/local/include;/usr/local/lib/" - specify the libraries search paths to ignore. This is convenient if the environment has conflicting version installed on system default search paths. (e.g. gflags in /usr/local)
  • -DBUILD_SHARED_LIBS=OFF - create static libraries instead of shared libraries
  • -DBUILD_TESTS=OFF - don't build test programs
  • -DBUILD_DOCUMENTS=OFF - don't build documents by doxygen
  • -DINSTALL_EXAMPLES=ON - install example applications
  • -DFORCE_INSTALL_RPATH=ON - automatically configure INSTALL_RPATH for non-default library paths
  • -DSHARKSFIN_IMPLEMENTATION=<implementation name> - switch sharksfin implementation. Available options are memory and shirakami (default: memory)
  • -DPERFORMANCE_TOOLS=ON - enable performance tooling to measure engine performance
  • -DINSTALL_API_ONLY=ON - configure build directory just to install public header files. Use when other components require jogasaki public headers.
  • -DENABLE_ALTIMETER=ON - turn on altimeter logging.
  • for debugging only
    • -DENABLE_SANITIZER=OFF - disable sanitizers (requires -DCMAKE_BUILD_TYPE=Debug)
    • -DENABLE_UB_SANITIZER=ON - enable undefined behavior sanitizer (requires -DENABLE_SANITIZER=ON)
    • -DENABLE_COVERAGE=ON - enable code coverage analysis (requires -DCMAKE_BUILD_TYPE=Debug)
    • -DTRACY_ENABLE=ON - enable tracy profiler for multi-thread debugging. See section below.
    • -DLIKWID_ENABLE=ON - enable LIKWID for performance metrics. See section below.

install

cmake --build . --target install

run tests

ctest -V

generate documents

cmake --build . --target doxygen

Customize logging setting

You can customize logging in the same way as sharksfin. See sharksfin README.md for more details.

GLOG_minloglevel=0 ./group-cli --minimum

Multi-thread debugging/profiling with Tracy

You can use Tracy Profiler to graphically display the threads operations and improve printf debug by printing messages on the tooltips on the Tracy profiler UI. By setting cmake build option -DTRACY_ENABLE=ON, TracyClient.cpp file is added to the build and tracing macros are enabled.

(2021-11 TracyClient.cpp is included in tateyama only in order to avoid start up conflict, so set -DTRACY_ENABLE=ON both on tateyama and jogasaki if you profile jogasaki)

Prerequirement:

  1. ensure tracy code is located under third_party/tracy directory.
git submodule update --init third_party/tracy
  1. include common.h at the top of files that requires tracing.
#include <jogasaki/common.h>
  1. Put trace_scope at the beginning of the scope to trace, or use other tracing functions defined in common.h.

Recompile time saving with ccache

You can save re-compile time using ccache, which caches the compiled output and reuse on recompilation if no change is detected. This works well with jogasaki build as jogasaki build has dependencies to many components and translation units are getting bigger.

  1. Install ccache
apt install ccache
  1. add -DCMAKE_CXX_COMPILER_LAUNCHER=ccache to cmake build option.

First time build does not change as it requires building and caching all artifacts into cache directory, e.g. ~/.ccache. When you recompile, you will see it finishes very fast. Checking ccache -s shows the cache hit ratio and size of the cached files.

Profiling with LIKWID

You can use LIKWID to retrieve the performance metrics via hardware counters. By setting cmake build option -DLIKWID_ENABLE=ON, jogasaki is linked to the LIKWID library and its marker API macros are enabled.

Prerequirement:

  1. Install LIKWID in your environment. Typically, this can be done by clone the LIKWID repository, update the config.mk, run make and make install. You can install to users local directory, but you need sudo to run make install in order to set SUID for some binary files.

  2. include common.h at the top of files that requires profiling. This allow you to call LIKWID marker APIs such as LIKWID_MARKER_START

#include <jogasaki/common.h>
  1. Make sure LIKWID initialize/deinitialize macros LIKWID_MARKER_INIT/LIKWID_MARKER_CLOSE are called at some point where the code does initialize/deinitialize.
  2. Put LIKWID_MARKER_START/LIKWID_MARKER_STOP macros to specify the scope to profile.

Running jogasaki with likwid-perfctr command will show you the performance counters incremented by the code betweenLIKWID_MARKER_START and LIKWID_MARKER_STOP. See LIKWID documentation for details

License

Apache License, Version 2.0

jogasaki's People

Contributors

kuron99 avatar t-horikawa avatar kookubo avatar thawk105 avatar akirakw avatar ban-nobuhiro avatar ashigeru avatar

Stargazers

Yoshiaki Nishimura avatar Yusuke Saito avatar Riki Otaki avatar

Watchers

 avatar Kambayashi avatar AOE Takashi avatar  avatar  avatar  avatar

jogasaki's Issues

メンテナンスモードでは jogasaki を起動しない、あるいは最小限の機能に絞るようにする

メンテナンスモードでは SQL サービスが提供する機能は極めて限定的なので、
メンテナンスモードでは jogasaki を起動しない、あるいは最小限の機能に絞るようにする。

背景

oltp restore backup コマンドでリストアをする際に、
tateyama-bootstrap / tateyama は、メンテナンスモードでサーバを起動してから limestone の datastore::restore() を呼んでいるが、
メンテナンスモードでのデータベース開始時に jogasaki が shirakami を起動しており、これが問題になることがある。

  • shirakami の初期化時の処理が limestone の restore の事前要求条件 (datastore::ready() 前) を満たさなくしてしまう。
  • 組み込みテーブル作成により shirakami から log_channel 経由でログが書かれるが、 restore 中であり、(restore側が異常検出して)エラーとなる。

議論: https://nautilus-rd.slack.com/archives/GB4QT920L/p1674559329737239
参考: https://github.com/project-tsurugi/tateyama/blob/master/docs/tateyama-arch-ja.md
参考: https://github.com/project-tsurugi/limestone/blob/master/docs/datastore-if.md

Transaction優先度指定のためのAPI追加

Transaction開始時にpriorityを設定して、TX間の優先順位をつけて実行する仕組みを実装する

参考:

セカンダリインデックスのあるテーブルに対するINSERT OR REPLACE文

セカンダリインデックスのあるテーブルに対してINSERT OR REPLACEを実行した場合はプライマリに対する更新(upsert)に加えて、セカンダリインデックスのエントリの(再)作成が必要になるが、現状ではセカンダリインデックスの更新が正しく行われず、セカンダリインデックスのあるテーブルに対するINSERT OR REPLACE文は正しく動作しない。

KVSに最大文字列長を超える文字列が来たときのエラーコードが正しくない

https://github.com/project-tsurugi/jogasaki/blob/master/src/jogasaki/api/kvsservice/serializer.cpp#L60-L62
で判定して、err_resource_limit_reachedを返している。
これはセッション数など、OSリソースが足りなくなった場合のエラーであり、文字列長制限エラーとしては不適切。

SQLクライアントではVALUE_TOO_LONG_EXCEPTIONが返るらしい。
これと同じでなくてもかまわない。
現在、KVSのエラーコードには文字列長制限エラーにふさわしい値がなさそうなので、追加すべき。
https://github.com/project-tsurugi/jogasaki/blob/master/include/jogasaki/api/kvsservice/status.h

Intel Inspectorのデータ競合の警告

#196, #209 の調査で、ltxWithoutTimeout()テストを走らせたとき、Intel Inspectorがdata raceを指摘したところがあります。
jogasaki/utils/backoff_timer.hのreset()とoperator()()で、current_wait_ns_の設定・参照に絡むところにdata raceがあるという指摘でした。
opeartor()()の★付き3行と、初期化のreset()とのread/write・write/write競合が出ておりました。

    bool operator()() {
★      if(current_wait_ns_ == 0 || initial_wait_ns_ == 0) return true;
        auto now = Clock::now();
★      if(std::chrono::duration_cast<std::chrono::nanoseconds>(now - begin_).count() > static_cast<std::int64_t>(current_wait_ns_)) {
★          current_wait_ns_ = std::min(current_wait_ns_*2, max_wait_ns_);

利用ソースは tsurugi-0.202302080820-snapshot のすべてデフォルト設定ビルド(RelWithDebugInfo)です。

NUL(0x00)を含む文字列データにおいてインデックスのデータ順序が想定と異なるケースがある

下記slack channelで議論されたもの。終端文字列と列データの連結によって順序が崩れることがある。
https://nautilus-rd.slack.com/archives/GB4QT920L/p1669687088327249

影響範囲

  • NUL(0x00)を含む文字列をchar/varchar列のデータで使用し、かつ
  • その列がprimary/secondary インデックスのいずれかのキーとして使用され
  • そのキー定義が複数列からなり、その列に後続する列が存在するとき
  • ORDER BY等の順序取得において正しい順序が得られない可能性がある

Sequenceメタデータ保存用ストレージの整備

jogasakiは主キーが存在しない表に対して内部的にシーケンスを作成し、主キーの代わりに使用する。
現状ではシーケンスのメタデータ情報は最小限必要な内容をsystem_sequencesという名前のStorageに保存しているが、この保存方法に下記のような問題がある。

  • 現状で必要なマッピングしか保存していないため、ユーザー定義のシーケンスに対応できない
  • key/valueの構造を直接ハードコードしているためメタデータの拡張に対して柔軟性がない

Protocol bufferメッセージ等によってシーケンスのメタデータを定義し、十分な情報をvalueとして保存する必要がある。

RTXのトランザクションでERR_INVALID_STATE: SQL--0007が発生

電話料金バッチのUTでERR_INVALID_STATE: SQL--0007 というエラーが起きる。

  • 同じテストを動かしてエラーが起きるときと起きないときがあります。再現条件は不明です。
  • リリースビルドのDockerイメージを使用しているときに発生します。デバッグビルドのDockerイメージでは発生しません。
  • サーバ側のログとクライアント側のスタックトレースを添付します。

再現方法

  • phone-bill-benchmarkのブランチwip/iceaxe-supportの最新コミット(9b813b4)チェックアウト
  • UTケース PhoneBillTest#testConfigVariationForIceaxe を実行

starcktrace.txt
serverlog.txt

make_signed_coefficient_full(takatori::decimal::triple value) の結果が不正になるケースがある

std::tuple<std::uint64_t, std::uint64_t, std::size_t> make_signed_coefficient_full(takatori::decimal::triple value);

に対するテスト(https://github.com/project-tsurugi/jogasaki/blob/9cc5fa7507e6eaf89e2ee7b58ed9261a66e9d668/test/jogasaki/utils/decimal_utils_test.cpp#L94)
の亜種として、

TEST_F(decimal_utils_test, negative_max_represented_by_9_bytes_variation) {
    auto [hi, lo, sz] = utils::make_signed_coefficient_full({-1, 0, 0x8000000000000001UL, 0});
    EXPECT_EQ(0xFFFFFFFFFFFFFFFFUL, hi);
    EXPECT_EQ(0x7FFFFFFFFFFFFFFFUL, lo);
    EXPECT_EQ(9, sz);
}

を追加すると、szが9ではなく8となるため、このテストはfailする(szは9となるのが正しいはず)。

delayedタスクキューのsizeを確認できるようにする

jogasakiが使用しているタスクスケジューラーのワーカー配下にdelayedタスクキューがあるが、tbb::concurrent_queueを使用していて、スレッドセーフにsizeやempty-nessの確認ができないことを改善したい。

現状
jogasakiが使用しているタスクスケジューラーのワーカーはlocal, sticky, delayedの3つのタスクキューを保持する

  • sticky: あるトランザクションに関連づいたタスクを特定のワーカーからのみ実行することでシリアル実行するためのキュー
  • delayed: waitや条件付きタスクのように頻繁な起動が必要ないタスクのためのキュー
  • local: 上記以外の通常のタスクのためのキュー
    スケジューラーへタスクのスケジュールが要求されると、スケジューラーはこのワーカーと配下のタスクキューから適当なものを選択し、キューへタスクをpushする。(これがマルチスレッドから実行され得るためキューは並列アクセス可能なデータ構造(tbb::concurrent_queue)となっている。

ワーカースレッドは下記のように動作し、delayedタスクキューのチェック頻度を少なくしている。

  1. stickyまたはlocalをチェックし、タスクがあれば実行する
  2. 1を一定回数繰り返す
  3. 2の繰り返しが一定回数を超えたらdelayedタスクキューを処理する。delayedタスクキューにタスクがあればpopし、stickyまたはlocalへpushする。
  4. 1へ戻る

課題
delayedタスクキューがtbb::concurrent_queueであるため、delayedタスクキューに要素が存在するかというチェックが簡単にできない。ワーカーがサスペンド可能か、という状況を確認するために、delayedタスクキューに要素があるかどうかをチェックする必要がある。
popしてpushすることで存在を確認可能だが、タスクのリオーダーが発生するため避けたい。

解決案
delayedタスクキューをstd::dequeを使用する、複数スレッドから直接delayedタスクキューへの投入を避け、一旦sticky又はlocalへ投入し、タスク初回の実行で実行条件が満たされなかったことを検知した後にdelayedタスクキューへ移動させる。
これによって、delayedタスクキューへアクセスするのはワーカースレッドのみとできる。

SQLエラー発生時のTXアボートを一貫して行うようにする

SQL実行エンジンのAPIにSQLテキストとトランザクションを渡してSQLの実行を指示するものがある。
現状ではコンパイルエラーが起きた際にトランザクションはアボートされずに再利用が可能になっているが、APIの規約としてはエラー時にトランザクションは復帰させられない(ことがほとんどである。コンパイラエラーが例外的)ので、このケースも一貫してアボートさせることが望ましい。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.