Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-handle SSTFiles to DTFiles when applying snapshots #1439

Merged
merged 43 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2315810
Move mock snapshot functions into one file
JaySon-Huang Mar 26, 2021
67921c8
Predecode convert SSTFiles to DTFiles for snapshot
JaySon-Huang Feb 20, 2021
074c03b
Ingest files into StorageDeltaMerge
JaySon-Huang Feb 5, 2021
795bf9e
Cleanup some small comments left by #1517
JaySon-Huang Mar 18, 2021
53c7b87
Fix for applying snapshot with incomplete cfs
JaySon-Huang Apr 1, 2021
1c65514
Optimize for ingest SST
JaySon-Huang Apr 2, 2021
e071ea4
Fix bug for recovering tombstoned table
JaySon-Huang Apr 8, 2021
b20e14b
Refactor to bound the primary key into block
JaySon-Huang Apr 13, 2021
34e962f
Check whether the blocks decoded from SSTFiles are sorted by pk,ver
JaySon-Huang Apr 13, 2021
a62ac8d
Recreate DTFile if REGION_DATA_SCHEMA_UPDATED & fix ingestSST by DTFile
JaySon-Huang Apr 14, 2021
a26bcfd
Make mock mpp test runable for different service port
JaySon-Huang Apr 14, 2021
053c6f6
Enable GC for ingested DTFiles
JaySon-Huang Apr 15, 2021
30b4aeb
Refine the metrics of ingestSST
JaySon-Huang Apr 15, 2021
fe40487
Refine some comments
JaySon-Huang Apr 16, 2021
550f5ab
init SubFileStat for DTFile in DMFilePackFilter
JaySon-Huang Apr 19, 2021
023e2d8
Remove debugging logs
JaySon-Huang Apr 19, 2021
d501bab
Cleanup useless code
JaySon-Huang Apr 21, 2021
109d613
Do DMFile::initializeSubFileStatIfNeeded inside DMFile::readMeta
JaySon-Huang Apr 21, 2021
5fb7a4a
Fix metrics for ingest file
JaySon-Huang Apr 22, 2021
8ce750a
Fix warnings under MacOS
JaySon-Huang Apr 22, 2021
4ccd89f
Rebase latest master
JaySon-Huang Apr 23, 2021
2539c06
Fix after rebased
JaySon-Huang Apr 23, 2021
18ded2d
Use operate per minute instead of per second for DeleteRange,Ingest,S…
JaySon-Huang Apr 25, 2021
e756fda
small fix
JaySon-Huang Apr 26, 2021
de60e65
Fix function name
JaySon-Huang Apr 26, 2021
64846dc
Fix duplicated function
JaySon-Huang Apr 26, 2021
83fa503
Fix DTFileOutputStream::write && Fix read more key-values into memory…
JaySon-Huang Apr 26, 2021
1992558
Merge remote-tracking branch 'upstream/master' into optimize-handle-sst
JaySon-Huang Apr 27, 2021
23aa653
Fix compile error
JaySon-Huang Apr 27, 2021
dd46c95
Fix compile error & fix bug in StableValueSpace::calculateStableProperty
JaySon-Huang Apr 27, 2021
1e2b95e
Set min to 0 for heatmap Panels
JaySon-Huang Apr 28, 2021
bfc0d41
Refactor SST I/O streams
JaySon-Huang Apr 29, 2021
d862576
Refactor BoundedSSTFilesToBlockInputStream
JaySon-Huang Apr 29, 2021
0f3be33
Merge branch 'master' into optimize-handle-sst
JaySon-Huang Apr 29, 2021
43d7bda
Remove some useless duplicated fields
JaySon-Huang Apr 29, 2021
0dcd2dd
Cleanup useless code
JaySon-Huang Apr 29, 2021
0f6ba3f
Add a unittest for ingest
JaySon-Huang Apr 29, 2021
e08de31
Fix bug for decoding schema && schema align
JaySon-Huang Apr 29, 2021
65795d1
Add more test case for ingest file with an older schema
JaySon-Huang Apr 29, 2021
5e5d31a
Persist block property for ingested DTFiles
JaySon-Huang Apr 29, 2021
258a985
Remove useless code
JaySon-Huang Apr 30, 2021
a9049d5
Merge branch 'master' into optimize-handle-sst
JaySon-Huang Apr 30, 2021
1c3eaac
Cleanup code
JaySon-Huang Apr 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dbms/src/Common/ErrorCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ namespace ErrorCodes
extern const int PAGE_SIZE_NOT_MATCH = 9006;
extern const int ILLFORMED_PAGE_NAME = 9007;
extern const int ILLFORMAT_RAFT_ROW = 9008;
extern const int REGION_DATA_SCHEMA_UPDATED = 9009;

extern const int LOCK_EXCEPTION = 10000;
extern const int VERSION_ERROR = 10001;
Expand Down
4 changes: 3 additions & 1 deletion dbms/src/Common/FailPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ std::unordered_map<String, std::shared_ptr<FailPointChannel>> FailPointHelper::f
M(exception_before_mpp_register_tunnel_for_root_mpp_task) \
M(exception_before_mpp_root_task_run) \
M(exception_during_mpp_root_task_run) \
M(exception_during_write_to_storage)
M(exception_during_write_to_storage) \
M(force_set_sst_to_dtfile_block_size) \
M(force_set_sst_decode_rand)

#define APPLY_FOR_FAILPOINTS_WITH_CHANNEL(M) \
M(pause_after_learner_read) \
Expand Down
4 changes: 3 additions & 1 deletion dbms/src/Common/TiFlashMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace DB
M(tiflash_storage_write_amplification, "The data write amplification in storage engine", Gauge) \
M(tiflash_storage_read_tasks_count, "Total number of storage engine read tasks", Counter) \
M(tiflash_storage_command_count, "Total number of storage's command, such as delete range / shutdown /startup", Counter, \
F(type_delete_range, {"type", "delete_range"})) \
F(type_delete_range, {"type", "delete_range"}), F(type_ingest, {"type", "ingest"})) \
M(tiflash_storage_subtask_count, "Total number of storage's sub task", Counter, F(type_delta_merge, {"type", "delta_merge"}), \
F(type_delta_merge_fg, {"type", "delta_merge_fg"}), F(type_delta_merge_bg_gc, {"type", "delta_merge_bg_gc"}), \
F(type_delta_compact, {"type", "delta_compact"}), F(type_delta_flush, {"type", "delta_flush"}), \
Expand All @@ -101,11 +101,13 @@ namespace DB
F(type_place_index_update, {{"type", "place_index_update"}}, ExpBuckets{0.0005, 2, 20})) \
M(tiflash_storage_throughput_bytes, "Calculate the throughput of tasks of storage in bytes", Gauge, /**/ \
F(type_write, {"type", "write"}), /**/ \
F(type_ingest, {"type", "ingest"}), /**/ \
F(type_delta_merge, {"type", "delta_merge"}), /**/ \
F(type_split, {"type", "split"}), /**/ \
F(type_merge, {"type", "merge"})) /**/ \
M(tiflash_storage_throughput_rows, "Calculate the throughput of tasks of storage in rows", Gauge, /**/ \
F(type_write, {"type", "write"}), /**/ \
F(type_ingest, {"type", "ingest"}), /**/ \
F(type_delta_merge, {"type", "delta_merge"}), /**/ \
F(type_split, {"type", "split"}), /**/ \
F(type_merge, {"type", "merge"})) /**/ \
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/DataStreams/IBlockInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class IBlockInputStream : private boost::noncopyable

protected:
BlockInputStreams children;
std::shared_mutex children_mutex;
mutable std::shared_mutex children_mutex;

private:
TableStructureReadLocks table_locks;
Expand Down
6 changes: 4 additions & 2 deletions dbms/src/Debug/DBGInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ DBGInvoker::DBGInvoker()

regSchemalessFunc("region_snapshot", MockRaftCommand::dbgFuncRegionSnapshot);
regSchemalessFunc("region_snapshot_data", MockRaftCommand::dbgFuncRegionSnapshotWithData);
regSchemalessFunc("region_snapshot_pre_handle_block", MockRaftCommand::dbgFuncRegionSnapshotPreHandleBlock);
regSchemalessFunc("region_snapshot_apply_block", MockRaftCommand::dbgFuncRegionSnapshotApplyBlock);
regSchemalessFunc("region_snapshot_pre_handle_block", /**/ MockRaftCommand::dbgFuncRegionSnapshotPreHandleBlock);
regSchemalessFunc("region_snapshot_apply_block", /* */ MockRaftCommand::dbgFuncRegionSnapshotApplyBlock);
regSchemalessFunc("region_snapshot_pre_handle_file", /* */ MockRaftCommand::dbgFuncRegionSnapshotPreHandleDTFiles);
regSchemalessFunc("region_snapshot_apply_file", /* */ MockRaftCommand::dbgFuncRegionSnapshotApplyDTFiles);
regSchemalessFunc("region_ingest_sst", MockRaftCommand::dbgFuncIngestSST);

regSchemalessFunc("init_fail_point", DbgFailPointFunc::dbgInitFailPoint);
Expand Down
7 changes: 6 additions & 1 deletion dbms/src/Debug/dbgFuncCoprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ static const String MPP_QUERY = "mpp_query";
static const String USE_BROADCAST_JOIN = "use_broadcast_join";
static const String MPP_PARTITION_NUM = "mpp_partition_num";
static const String MPP_TIMEOUT = "mpp_timeout";
static const String LOCAL_HOST = "127.0.0.1:3930";
static String LOCAL_HOST = "127.0.0.1:3930";

namespace Debug
{
void setServiceAddr(const std::string & addr) { LOCAL_HOST = addr; }
} // namespace Debug

struct DAGProperties
{
Expand Down
5 changes: 5 additions & 0 deletions dbms/src/Debug/dbgFuncCoprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ BlockInputStreamPtr dbgFuncTiDBQuery(Context & context, const ASTs & args);
// ./storages-client.sh "DBGInvoke mock_dag(query, region_id[, start_ts])"
BlockInputStreamPtr dbgFuncMockTiDBQuery(Context & context, const ASTs & args);

namespace Debug
{
void setServiceAddr(const std::string & addr);
}

} // namespace DB
10 changes: 10 additions & 0 deletions dbms/src/Debug/dbgFuncMockRaftCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ struct MockRaftCommand
// Usage:
// ./storages-client.sh "DBGInvoke region_snapshot_apply_block(region_id)"
static void dbgFuncRegionSnapshotApplyBlock(Context & context, const ASTs & args, DBGInvoker::Printer output);

// Simulate a region pre-handle snapshot data to DTFiles
// Usage:
// ./storage-client.sh "DBGInvoke region_snapshot_pre_handle_file(database_name, table_name, region_id, start, end, schema_string, pk_name[, test-fields=1, cfs="write,default"])"
static void dbgFuncRegionSnapshotPreHandleDTFiles(Context & context, const ASTs & args, DBGInvoker::Printer output);

// Apply snapshot for a region. (apply a pre-handle snapshot)
// Usage:
// ./storages-client.sh "DBGInvoke region_snapshot_apply_file(region_id)"
static void dbgFuncRegionSnapshotApplyDTFiles(Context & context, const ASTs & args, DBGInvoker::Printer output);
};

} // namespace DB
127 changes: 123 additions & 4 deletions dbms/src/Debug/dbgFuncMockRaftSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ namespace DB

namespace FailPoints
{
extern const char force_set_prehandle_dtfile_block_size[];
}
extern const char force_set_sst_to_dtfile_block_size[];
extern const char force_set_sst_decode_rand[];
} // namespace FailPoints

namespace ErrorCodes
{
Expand Down Expand Up @@ -143,7 +144,7 @@ void MockRaftCommand::dbgFuncRegionSnapshotWithData(Context & context, const AST

// Mock to apply a snapshot with data in `region`
auto & tmt = context.getTMTContext();
context.getTMTContext().getKVStore()->checkAndApplySnapshot(region, tmt);
context.getTMTContext().getKVStore()->checkAndApplySnapshot<RegionPtrWithBlock>(region, tmt);
std::stringstream ss;
ss << "put region #" << region_id << ", range" << range_string << " to table #" << table_id << " with " << cnt << " records";
output(ss.str());
Expand Down Expand Up @@ -402,6 +403,7 @@ void MockRaftCommand::dbgFuncIngestSST(Context & context, const ASTs & args, DBG
auto & kvstore = tmt.getKVStore();
auto region = kvstore->getRegion(region_id);

FailPointHelper::enableFailPoint(FailPoints::force_set_sst_decode_rand);
// Register some mock SST reading methods so that we can decode data in `MockSSTReader::MockSSTData`
RegionMockTest mock_test(kvstore, region);

Expand Down Expand Up @@ -517,12 +519,129 @@ void MockRaftCommand::dbgFuncRegionSnapshotApplyBlock(Context & context, const A
RegionID region_id = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args.front()).value);
auto [region, block_cache] = GLOBAL_REGION_MAP.popRegionCache("__snap_" + std::to_string(region_id));
auto & tmt = context.getTMTContext();
context.getTMTContext().getKVStore()->checkAndApplySnapshot({region, std::move(block_cache)}, tmt);
context.getTMTContext().getKVStore()->checkAndApplySnapshot<RegionPtrWithBlock>({region, std::move(block_cache)}, tmt);

std::stringstream ss;
ss << "success apply " << region->id() << " with block cache";
output(ss.str());
}


/// Mock to pre-decode snapshot to DTFile(s) then apply

// Simulate a region pre-handle snapshot data to DTFiles
// ./storage-client.sh "DBGInvoke region_snapshot_pre_handle_file(database_name, table_name, region_id, start, end, schema_string, pk_name[, test-fields=1, cfs="write,default"])"
void MockRaftCommand::dbgFuncRegionSnapshotPreHandleDTFiles(Context & context, const ASTs & args, DBGInvoker::Printer output)
{
if (args.size() < 7 || args.size() > 9)
throw Exception("Args not matched, should be: database_name, table_name, region_id, start, end, schema_string, pk_name"
" [, test-fields, cfs=\"write,default\"]",
ErrorCodes::BAD_ARGUMENTS);

const String & database_name = typeid_cast<const ASTIdentifier &>(*args[0]).name;
const String & table_name = typeid_cast<const ASTIdentifier &>(*args[1]).name;
RegionID region_id = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[2]).value);
RegionID start_handle = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[3]).value);
RegionID end_handle = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[4]).value);

const String schema_str = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[5]).value);
String handle_pk_name = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[6]).value);

UInt64 test_fields = 1;
if (args.size() > 7)
test_fields = (UInt64)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args[7]).value);
std::unordered_set<ColumnFamilyType> cfs;
{
String cfs_str = "write,default";
if (args.size() > 8)
cfs_str = safeGet<String>(typeid_cast<const ASTLiteral &>(*args[8]).value);
if (cfs_str.find("write") != std::string::npos)
cfs.insert(ColumnFamilyType::Write);
if (cfs_str.find("default") != std::string::npos)
cfs.insert(ColumnFamilyType::Default);
}

// Parse a TableInfo from `schema_str` to generate data with this schema
TiDB::TableInfoPtr mocked_table_info;
{
ASTPtr columns_ast;
ParserColumnDeclarationList schema_parser;
Tokens tokens(schema_str.data(), schema_str.data() + schema_str.length());
TokenIterator pos(tokens);
Expected expected;
if (!schema_parser.parse(pos, columns_ast, expected))
throw Exception("Invalid TiDB table schema", ErrorCodes::LOGICAL_ERROR);
ColumnsDescription columns
= InterpreterCreateQuery::getColumnsDescription(typeid_cast<const ASTExpressionList &>(*columns_ast), context);
mocked_table_info = MockTiDB::parseColumns(table_name, columns, handle_pk_name, "dt");
}

MockTiDB::TablePtr table = MockTiDB::instance().getTableByName(database_name, table_name);
const auto & table_info = RegionBench::getTableInfo(context, database_name, table_name);
if (table_info.is_common_handle)
throw Exception("Mocking pre handle SST files to DTFiles to a common handle table is not supported", ErrorCodes::LOGICAL_ERROR);

// Mock SST data for handle [start, end)
const auto region_name = "__snap_snap_" + std::to_string(region_id);
GenMockSSTData(*mocked_table_info, table->id(), region_name, start_handle, end_handle, test_fields, cfs);

auto & tmt = context.getTMTContext();
auto & kvstore = tmt.getKVStore();
auto old_region = kvstore->getRegion(region_id);

// We may call this function mutiple time to mock some situation, try to reuse the region in `GLOBAL_REGION_MAP`
// so that we can collect uncommitted data.
UInt64 index = MockTiKV::instance().getRaftIndex(region_id) + 1;
RegionPtr new_region = RegionBench::createRegion(table->id(), region_id, start_handle, end_handle, index);

// Register some mock SST reading methods so that we can decode data in `MockSSTReader::MockSSTData`
RegionMockTest mock_test(kvstore, new_region);

std::vector<SSTView> sst_views;
{
if (cfs.count(ColumnFamilyType::Write) > 0)
sst_views.push_back(SSTView{
ColumnFamilyType::Write,
BaseBuffView{region_name.data(), region_name.length()},
});
if (cfs.count(ColumnFamilyType::Default) > 0)
sst_views.push_back(SSTView{
ColumnFamilyType::Default,
BaseBuffView{region_name.data(), region_name.length()},
});
}

// set block size so that we can test for schema-sync while decoding dt files
FailPointHelper::enableFailPoint(FailPoints::force_set_sst_to_dtfile_block_size);

auto ingest_ids = kvstore->preHandleSnapshotToFiles(
new_region, SSTViewVec{sst_views.data(), sst_views.size()}, index, MockTiKV::instance().getRaftTerm(region_id), tmt);
GLOBAL_REGION_MAP.insertRegionSnap(region_name, {new_region, ingest_ids});

{
std::stringstream ss;
ss << "Generate " << ingest_ids.size() << " files for [region_id=" << region_id << "]";
output(ss.str());
}
}

// Apply snapshot for a region. (apply a pre-handle snapshot)
// ./storages-client.sh "DBGInvoke region_snapshot_apply_file(region_id)"
void MockRaftCommand::dbgFuncRegionSnapshotApplyDTFiles(Context & context, const ASTs & args, DBGInvoker::Printer output)
{
if (args.size() != 1)
throw Exception("Args not matched, should be: region-id", ErrorCodes::BAD_ARGUMENTS);

RegionID region_id = (RegionID)safeGet<UInt64>(typeid_cast<const ASTLiteral &>(*args.front()).value);
const auto region_name = "__snap_snap_" + std::to_string(region_id);
auto [new_region, ingest_ids] = GLOBAL_REGION_MAP.popRegionSnap(region_name);
auto & tmt = context.getTMTContext();
context.getTMTContext().getKVStore()->checkAndApplySnapshot<RegionPtrWithSnapshotFiles>(
RegionPtrWithSnapshotFiles{new_region, std::move(ingest_ids)}, tmt);

std::stringstream ss;
ss << "success apply region " << new_region->id() << " with dt files";
output(ss.str());
}

} // namespace DB
2 changes: 1 addition & 1 deletion dbms/src/Debug/dbgFuncMockTiDBTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ struct MockTiDBTable

// Inject mocked TiDB table.
// Usage:
// ./storages-client.sh "DBGInvoke mock_tidb_table(database_name, table_name, 'col1 type1, col2 type2, ...' [, handle_pk_name, engine-type(tmt|dt)])"

// ./storages-client.sh "DBGInvoke mock_tidb_table(database_name, table_name, 'col1 type1, col2 type2, ...' [, handle_pk_name, engine-type(tmt|dt)])"
// engine: [tmt, dt], tmt by default
static void dbgFuncMockTiDBTable(Context & context, const ASTs & args, DBGInvoker::Printer output);

Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Debug/dbgFuncRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void dbgFuncPutRegion(Context & context, const ASTs & args, DBGInvoker::Printer

TMTContext & tmt = context.getTMTContext();
RegionPtr region = RegionBench::createRegion(table_info, region_id, start_keys, end_keys);
tmt.getKVStore()->onSnapshot(region, nullptr, 0, tmt);
tmt.getKVStore()->onSnapshot<RegionPtrWithBlock>(region, nullptr, 0, tmt);

std::stringstream ss;
ss << "put region #" << region_id << ", range" << RecordKVFormat::DecodedTiKVKeyRangeToDebugString(region->getRange()->rawKeys())
Expand All @@ -74,7 +74,7 @@ void dbgFuncPutRegion(Context & context, const ASTs & args, DBGInvoker::Printer

TMTContext & tmt = context.getTMTContext();
RegionPtr region = RegionBench::createRegion(table_id, region_id, start, end);
tmt.getKVStore()->onSnapshot(region, nullptr, 0, tmt);
tmt.getKVStore()->onSnapshot<RegionPtrWithBlock>(region, nullptr, 0, tmt);

std::stringstream ss;
ss << "put region #" << region_id << ", range[" << start << ", " << end << ")"
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Debug/dbgTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ void concurrentBatchInsert(const TiDB::TableInfo & table_info, Int64 concurrent_

Regions regions = createRegions(table_info.id, concurrent_num, key_num_each_region, handle_begin, curr_max_region_id + 1);
for (const RegionPtr & region : regions)
tmt.getKVStore()->onSnapshot(region, nullptr, 0, tmt);
tmt.getKVStore()->onSnapshot<RegionPtrWithBlock>(region, nullptr, 0, tmt);

std::list<std::thread> threads;
for (Int64 i = 0; i < concurrent_num; i++, handle_begin += key_num_each_region)
Expand Down
39 changes: 38 additions & 1 deletion dbms/src/Server/RaftConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ TiFlashRaftConfig TiFlashRaftConfig::parseSettings(Poco::Util::LayeredConfigurat
else
res.engine = DEFAULT_ENGINE;
}
LOG_DEBUG(log, "Default storage engine: " << static_cast<Int64>(res.engine));

/// "tmt" engine ONLY support disable_bg_flush = false.
/// "dt" engine ONLY support disable_bg_flush = true.
Expand Down Expand Up @@ -97,6 +96,44 @@ TiFlashRaftConfig TiFlashRaftConfig::parseSettings(Poco::Util::LayeredConfigurat
res.enable_compatible_mode = config.getBool("raft.enable_compatible_mode");
}

if (config.has("raft.snapshot.method"))
{
String snapshot_method = config.getString("raft.snapshot.method");
std::transform(snapshot_method.begin(), snapshot_method.end(), snapshot_method.begin(), [](char ch) { return std::tolower(ch); });
if (snapshot_method == "block")
{
res.snapshot_apply_method = TiDB::SnapshotApplyMethod::Block;
}
else if (snapshot_method == "file1")
{
res.snapshot_apply_method = TiDB::SnapshotApplyMethod::DTFile_Directory;
}
else if (snapshot_method == "file2")
{
res.snapshot_apply_method = TiDB::SnapshotApplyMethod::DTFile_Single;
}
}
switch (res.snapshot_apply_method)
{
case TiDB::SnapshotApplyMethod::DTFile_Directory:
case TiDB::SnapshotApplyMethod::DTFile_Single:
if (res.engine != TiDB::StorageEngine::DT)
{
throw Exception(
"Illegal arguments: can not use DTFile to store snapshot data when the storage engine is not DeltaTree, [engine="
+ DB::toString(static_cast<Int32>(res.engine))
+ "] [snapshot method=" + applyMethodToString(res.snapshot_apply_method) + "]",
ErrorCodes::INVALID_CONFIG_PARAMETER);
}
break;
default:
break;
}

LOG_INFO(log,
"Default storage engine [type=" << static_cast<Int64>(res.engine)
<< "] [snapshot.method=" << applyMethodToString(res.snapshot_apply_method) << "]");

return res;
}

Expand Down
2 changes: 2 additions & 0 deletions dbms/src/Server/RaftConfigParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ struct TiFlashRaftConfig
static constexpr TiDB::StorageEngine DEFAULT_ENGINE = TiDB::StorageEngine::DT;
bool disable_bg_flush = false;
TiDB::StorageEngine engine = DEFAULT_ENGINE;
TiDB::SnapshotApplyMethod snapshot_apply_method = TiDB::SnapshotApplyMethod::DTFile_Directory;

public:
TiFlashRaftConfig() = default;

static TiFlashRaftConfig parseSettings(Poco::Util::LayeredConfiguration & config, Poco::Logger * log);

};

} // namespace DB
Loading