参考文献: 次世代高速オープンソースRDB Tsurugi (神林飛志 et al. 著)
前提:
Tsurugi インストール済
Java11 インストール済
Belayer インストール済
-- 1. テストデータ作成
tgctl start
tgctl status
git clone https://github.com/project-tsurugi/phone-bill-benchmark.git
cd phone-bill-benchmark/src/
./gradlew distTar
ls build/distributions/
cd build/distributions/
tar xf phone-bill.tar.gz
cd phone-bill
./bin/create_table.sh conf/batch-only
./bin/create_test_data.sh conf/batch-only
-- 2. アクセストークン取得
export TSURUGI_TOKEN_EXPIRATION=50h
export TSURUGI_AUTH_AT_EXPIRATION_MIN=3000
cd $TSURUGI_HOME
./bin/authentication-server stop
./bin/authentication-server start
cd $HOME/belayer/tsurugi-webapp-1.0.1
./bin/start_server.sh > ~/logs/belayer.log 2>&1 &
curl -s -d uid=tsurugi -d pw=password localhost:8000/api/auth | jq
export AT=$(curl -s -d uid=tsurugi -d pw=password localhost:8000/api/auth | jq -r '.accessToken')
echo $AT
-- 3. バックアップ/リストア
-- 3.1 データ確認
tgsql --connection tcp://localhost:12345
select count(*) from history;
select count(*) from contracts;
\exit
-- 3.2 バックアップ
curl -s -H "Content-Type: application/json" -H "Authorization: Bearer $AT" -X POST -d '{ "dirPath": "bkup"}' localhost:8000/api/backup | jq
{
"jobId": "HJDT3ciC",
"uid": "tsurugi",
"type": "backup"
}
curl -s -H "Content-Type: application/json" -H "Authorization: Bearer $AT" localhost:8000/api/br/status/backup/HJDT3ciC | jq
curl -s -H "Content-Type: application/json" -H "Authorization: Bearer $AT" localhost:8000/api/dirlist/bkup | jq
cd $BELAYER_STORAGE_ROOT
ls -lR
-- 3.3 DB初期化
cd $TSURUGI_HOME
./bin/tgctl shutdown
rm -rf var/data/log/
./bin/tgctl start
-- 3.4 データ確認
tgsql --connection tcp://localhost:12345
select count(*) from history;
select count(*) from contracts;
\exit
-- 3.5 リストア
tgctl shutdown
curl -s -H "Content-Type: application/json" -H "Authorization: Bearer $AT" -X POST -d '{ "zipFilePath": "bkup/backup-HJDT3ciC.zip"}' localhost:8000/api/restore | jq
{
"jobId": "k6hNmpGN",
"uid": "tsurugi",
"type": "restore"
}
curl -s -H "Content-Type: application/json" -H "Authorization: Bearer $AT" localhost:8000/api/br/status/restore/k6hNmpGN | jq
-- 3.6 データ確認
tgctl start
tgsql --connection tcp://localhost:12345
select count(*) from history;
select count(*) from contracts;
\exit
-- 4. ダンプ/ロード
--4.1 ダンプ
curl -s -H "Content-Type: application/json" -H "Authorization: Bearer $AT" -X POST -d '{ "dirPath": "dump_dir"}' localhost:8000/api/dump/history | jq
{
"jobId": "UT9cDX1t",
"uid": "tsurugi",
"type": "dump",
"files": null,
"status": null,
"errorMessage": null
}
curl -s -H "Content-Type: application/json" -H "Authorization: Bearer $AT" localhost:8000/api/dumpload/status/dump/UT9cDX1t | jq
curl -s -H "Content-Type: application/json" -H "Authorization: Bearer $AT" localhost:8000/api/dirlist/dump_dir | jq
cd $BELAYER_STORAGE_ROOT
ls -lR
-- 4.2 データ削除
tgsql --connection tcp://localhost:12345
begin long transaction write preserve history;
delete from history;
commit;
select count(*) from history;
\exit
--4.3 ロード
curl -v -H "Content-Type: application/json" -H "Authorization: Bearer $AT" -X POST \
-d '{ "files": ["dump_dir/UT9cDX1t/d1700231942_0_0.parquet"], "mappings": null, "format": "parquet" ,"transactional": false}' \
localhost:8000/api/load/history | jq
{
"jobId": "CmTDZ0aU",
"uid": "tsurugi",
"type": "load",
"files": null,
"status": null,
"errorMessage": null
}
curl -v -H "Content-Type: application/json" -H "Authorization: Bearer $AT" localhost:8000/api/dumpload/status/load/CmTDZ0aU | jq
★ "status": "FAILED" エラー原因不明
→ 2023/12/09 Belayer 1.1.0 を使用して再実行したところ、エラーは発生しなかった
-- 4.4 データ確認
tgsql --connection tcp://localhost:12345
select count(*) from history;
\exit