Skip to content

Commit

Permalink
support mix_mode in dt_workload (#5011)
Browse files Browse the repository at this point in the history
ref #3594
  • Loading branch information
lidezhu authored Jun 1, 2022
1 parent a0ed1a6 commit 800715c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dbms/src/Storages/DeltaMerge/tools/workload/DTWorkload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void DTWorkload::verifyHandle(uint64_t r)
}
for (size_t i = 0; i < handle_col->size(); i++)
{
// Handle must be int64 or uint64. Currently, TableGenterator would ensure this limit.
// Handle must be int64 or uint64. Currently, TableGenerator would ensure this limit.
uint64_t h = handle_col->getInt(i);
uint64_t store_ts = ts_col->getInt(i);

Expand Down
29 changes: 21 additions & 8 deletions dbms/src/Storages/DeltaMerge/tools/workload/MainEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,26 @@ void run(WorkloadOptions & opts)
// Table Schema
auto table_gen = TableGenerator::create(opts);
auto table_info = table_gen->get(opts.table_id, opts.table_name);
// In this for loop, destory DeltaMergeStore gracefully and recreate it.
for (uint64_t i = 0; i < opts.verify_round; i++)
// In this for loop, destroy DeltaMergeStore gracefully and recreate it.
auto run_test = [&]() {
for (uint64_t i = 0; i < opts.verify_round; i++)
{
DTWorkload workload(opts, handle_table, table_info);
workload.run(i);
stats.push_back(workload.getStat());
LOG_FMT_INFO(log, "No.{} Workload {} {}", i, opts.write_key_distribution, stats.back().toStrings());
}
};
run_test();

if (opts.ps_run_mode == DB::PageStorageRunMode::MIX_MODE)
{
DTWorkload workload(opts, handle_table, table_info);
workload.run(i);
stats.push_back(workload.getStat());
LOG_FMT_INFO(log, "No.{} Workload {} {}", i, opts.write_key_distribution, stats.back().toStrings());
// clear statistic in DB::PageStorageRunMode::ONLY_V2
stats.clear();
auto & global_context = TiFlashTestEnv::getGlobalContext();
global_context.setPageStorageRunMode(DB::PageStorageRunMode::MIX_MODE);
global_context.initializeGlobalStoragePoolIfNeed(global_context.getPathPool());
run_test();
}
}
catch (...)
Expand Down Expand Up @@ -254,8 +267,9 @@ int DTWorkload::mainEntry(int argc, char ** argv)
// or the logging in global context won't be output to
// the log file
init(opts);
TiFlashTestEnv::initializeGlobalContext(opts.work_dirs, opts.enable_ps_v3);

// For mixed mode, we need to run the test in ONLY_V2 mode first.
TiFlashTestEnv::initializeGlobalContext(opts.work_dirs, opts.ps_run_mode == PageStorageRunMode::ONLY_V3 ? PageStorageRunMode::ONLY_V3 : PageStorageRunMode::ONLY_V2);
if (opts.testing_type == "daily_perf")
{
dailyPerformanceTest(opts);
Expand All @@ -277,7 +291,6 @@ int DTWorkload::mainEntry(int argc, char ** argv)
runAndRandomKill(opts);
}
}

TiFlashTestEnv::shutdown();
return 0;
}
20 changes: 16 additions & 4 deletions dbms/src/Storages/DeltaMerge/tools/workload/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::string WorkloadOptions::toString(std::string seperator) const
fmt::format("read_stream_count {}{}", read_stream_count, seperator) + //
fmt::format("testing_type {}{}", testing_type, seperator) + //
fmt::format("log_write_request {}{}", log_write_request, seperator) + //
fmt::format("enable_ps_v3 {}{}", enable_ps_v3, seperator) + //
fmt::format("ps_run_mode {}{}", ps_run_mode, seperator) + //
fmt::format("bg_thread_count {}{}", bg_thread_count, seperator) + //
fmt::format("table_id {}{}", table_id, seperator) + //
fmt::format("table_name {}{}", table_name, seperator);
Expand Down Expand Up @@ -88,7 +88,7 @@ std::pair<bool, std::string> WorkloadOptions::parseOptions(int argc, char * argv
//
("log_write_request", value<bool>()->default_value(false), "") //
//
("enable_ps_v3", value<bool>()->default_value(true), "") //
("ps_run_mode", value<uint64_t>()->default_value(2, "possible value: 1(only_v2), 2(only_v3), 3(mix_mode), and note that in mix_mode, the test will run twice, first round in only_v2 mode and second round in mix_mode")) //
//
("bg_thread_count", value<uint64_t>()->default_value(4), "") //
//
Expand Down Expand Up @@ -155,8 +155,20 @@ std::pair<bool, std::string> WorkloadOptions::parseOptions(int argc, char * argv

testing_type = vm["testing_type"].as<std::string>();
log_write_request = vm["log_write_request"].as<bool>();

enable_ps_v3 = vm["enable_ps_v3"].as<bool>();
switch (vm["ps_run_mode"].as<uint64_t>())
{
case static_cast<uint64_t>(PageStorageRunMode::ONLY_V2):
ps_run_mode = PageStorageRunMode::ONLY_V2;
break;
case static_cast<uint64_t>(PageStorageRunMode::ONLY_V3):
ps_run_mode = PageStorageRunMode::ONLY_V3;
break;
case static_cast<uint64_t>(PageStorageRunMode::MIX_MODE):
ps_run_mode = PageStorageRunMode::MIX_MODE;
break;
default:
return {false, fmt::format("unknown ps_run_mode {}.", vm["ps_run_mode"].as<uint64_t>())};
}

bg_thread_count = vm["bg_thread_count"].as<uint64_t>();

Expand Down
4 changes: 3 additions & 1 deletion dbms/src/Storages/DeltaMerge/tools/workload/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#pragma once

#include <Storages/Page/PageStorage.h>

#include <string>
#include <vector>

Expand Down Expand Up @@ -53,7 +55,7 @@ struct WorkloadOptions

bool log_write_request;

bool enable_ps_v3;
PageStorageRunMode ps_run_mode;

uint64_t bg_thread_count;

Expand Down
4 changes: 2 additions & 2 deletions dbms/src/TestUtils/TiFlashTestEnv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace DB::tests
{
std::unique_ptr<Context> TiFlashTestEnv::global_context = nullptr;

void TiFlashTestEnv::initializeGlobalContext(Strings testdata_path, bool enable_ps_v3)
void TiFlashTestEnv::initializeGlobalContext(Strings testdata_path, PageStorageRunMode ps_run_mode)
{
// set itself as global context
global_context = std::make_unique<DB::Context>(DB::Context::createGlobal());
Expand Down Expand Up @@ -68,7 +68,7 @@ void TiFlashTestEnv::initializeGlobalContext(Strings testdata_path, bool enable_
global_context->getPathCapacity(),
global_context->getFileProvider());

global_context->setPageStorageRunMode(enable_ps_v3 ? PageStorageRunMode::ONLY_V3 : PageStorageRunMode::ONLY_V2);
global_context->setPageStorageRunMode(ps_run_mode);
global_context->initializeGlobalStoragePoolIfNeed(global_context->getPathPool());
LOG_FMT_INFO(Logger::get("TiFlashTestEnv"), "Storage mode : {}", static_cast<UInt8>(global_context->getPageStorageRunMode()));

Expand Down
3 changes: 2 additions & 1 deletion dbms/src/TestUtils/TiFlashTestEnv.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <Poco/File.h>
#include <Poco/Path.h>
#include <Poco/SortedDirectoryIterator.h>
#include <Storages/Page/PageStorage.h>
#include <TestUtils/TiFlashTestException.h>
#include <fmt/core.h>

Expand Down Expand Up @@ -88,7 +89,7 @@ class TiFlashTestEnv

static Context getContext(const DB::Settings & settings = DB::Settings(), Strings testdata_path = {});

static void initializeGlobalContext(Strings testdata_path = {}, bool enable_ps_v3 = true);
static void initializeGlobalContext(Strings testdata_path = {}, PageStorageRunMode ps_run_mode = PageStorageRunMode::ONLY_V3);
static Context & getGlobalContext() { return *global_context; }
static void shutdown();

Expand Down

0 comments on commit 800715c

Please sign in to comment.