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

Remove useless code #5004

Merged
merged 14 commits into from
May 31, 2022
1 change: 0 additions & 1 deletion dbms/src/Debug/DBGInvoker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ DBGInvoker::DBGInvoker()

regSchemalessFunc("put_region", dbgFuncPutRegion);

regSchemalessFunc("try_flush", dbgFuncTryFlush);
regSchemalessFunc("try_flush_region", dbgFuncTryFlushRegion);

regSchemalessFunc("dump_all_region", dbgFuncDumpAllRegion);
Expand Down
8 changes: 0 additions & 8 deletions dbms/src/Debug/dbgFuncRegion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ void dbgFuncPutRegion(Context & context, const ASTs & args, DBGInvoker::Printer
}
}

void dbgFuncTryFlush(Context & context, const ASTs &, DBGInvoker::Printer output)
{
TMTContext & tmt = context.getTMTContext();
tmt.getRegionTable().tryFlushRegions();

output("region_table try flush regions");
}

void dbgFuncTryFlushRegion(Context & context, const ASTs & args, DBGInvoker::Printer output)
{
if (args.size() != 1)
Expand Down
5 changes: 0 additions & 5 deletions dbms/src/Debug/dbgFuncRegion.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ void dbgFuncDumpAllRegion(Context & context, const ASTs & args, DBGInvoker::Prin
// ./storage-client.sh "DBGInvoke dump_all_mock_region(table_id)"
void dbgFuncDumpAllMockRegion(Context & context, const ASTs & args, DBGInvoker::Printer output);

// Try flush regions
// Usage:
// ./storage-client.sh "DBGInvoke try_flush([force_flush])"
void dbgFuncTryFlush(Context & context, const ASTs & args, DBGInvoker::Printer output);

// Try flush regions
// Usage:
// ./storage-client.sh "DBGInvoke try_flush_region(database_name, table_name, region_id)"
Expand Down
6 changes: 1 addition & 5 deletions dbms/src/Server/RaftConfigParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ TiFlashRaftConfig TiFlashRaftConfig::parseSettings(Poco::Util::LayeredConfigurat
{
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")
if (snapshot_method == "file1")
{
res.snapshot_apply_method = TiDB::SnapshotApplyMethod::DTFile_Directory;
}
Expand Down
92 changes: 4 additions & 88 deletions dbms/src/Storages/Transaction/ApplySnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,75 +261,6 @@ void KVStore::onSnapshot(const RegionPtrWrap & new_region_wrap, RegionPtr old_re

extern RegionPtrWithBlock::CachePtr GenRegionPreDecodeBlockData(const RegionPtr &, Context &);

/// `preHandleSnapshotToBlock` read data from SSTFiles and predoced the data as a block
RegionPreDecodeBlockDataPtr KVStore::preHandleSnapshotToBlock(
RegionPtr new_region,
const SSTViewVec snaps,
uint64_t /*index*/,
uint64_t /*term*/,
TMTContext & tmt)
{
RegionPreDecodeBlockDataPtr cache{nullptr};
{
decltype(bg_gc_region_data)::value_type tmp;
std::lock_guard lock(bg_gc_region_data_mutex);
if (!bg_gc_region_data.empty())
{
tmp.swap(bg_gc_region_data.back());
bg_gc_region_data.pop_back();
}
}

Stopwatch watch;
auto & ctx = tmt.getContext();
SCOPE_EXIT({ GET_METRIC(tiflash_raft_command_duration_seconds, type_apply_snapshot_predecode).Observe(watch.elapsedSeconds()); });

{
LOG_FMT_INFO(log, "Pre-handle snapshot {} with {} TiKV sst files", new_region->toString(false), snaps.len);
// Iterator over all SST files and insert key-values into `new_region`
for (UInt64 i = 0; i < snaps.len; ++i)
{
const auto & snapshot = snaps.views[i];
auto sst_reader = SSTReader{proxy_helper, snapshot};

uint64_t kv_size = 0;
while (sst_reader.remained())
{
auto key = sst_reader.key();
auto value = sst_reader.value();
new_region->insert(snaps.views[i].type, TiKVKey(key.data, key.len), TiKVValue(value.data, value.len));
++kv_size;
sst_reader.next();
}

LOG_FMT_INFO(log,
"Decode {} got [cf: {}, kv size: {}]",
std::string_view(snapshot.path.data, snapshot.path.len),
CFToName(snapshot.type),
kv_size);
// Note that number of keys in different cf will be aggregated into one metrics
GET_METRIC(tiflash_raft_process_keys, type_apply_snapshot).Increment(kv_size);
}
{
LOG_FMT_INFO(log, "Start to pre-decode {} into block", new_region->toString());
auto block_cache = GenRegionPreDecodeBlockData(new_region, ctx);
if (block_cache)
{
std::stringstream ss;
block_cache->toString(ss);
LOG_FMT_INFO(log, "Got pre-decode block cache {}", ss.str());
}
else
LOG_FMT_INFO(log, "Got empty pre-decode block cache");

cache = std::move(block_cache);
}
LOG_FMT_INFO(log, "Pre-handle snapshot {} cost {}ms", new_region->toString(false), watch.elapsedMilliseconds());
}

return cache;
}

std::vector<UInt64> KVStore::preHandleSnapshotToFiles(
RegionPtr new_region,
const SSTViewVec snaps,
Expand Down Expand Up @@ -473,8 +404,8 @@ void KVStore::handlePreApplySnapshot(const RegionPtrWrap & new_region, TMTContex
LOG_FMT_INFO(log, "{} apply snapshot success", new_region->toString(false));
}

template void KVStore::handlePreApplySnapshot<RegionPtrWithBlock>(const RegionPtrWithBlock &, TMTContext &);
JaySon-Huang marked this conversation as resolved.
Show resolved Hide resolved
template void KVStore::handlePreApplySnapshot<RegionPtrWithSnapshotFiles>(const RegionPtrWithSnapshotFiles &, TMTContext &);

template void KVStore::checkAndApplySnapshot<RegionPtrWithBlock>(const RegionPtrWithBlock &, TMTContext &);
template void KVStore::checkAndApplySnapshot<RegionPtrWithSnapshotFiles>(const RegionPtrWithSnapshotFiles &, TMTContext &);
template void KVStore::onSnapshot<RegionPtrWithBlock>(const RegionPtrWithBlock &, RegionPtr, UInt64, TMTContext &);
Expand Down Expand Up @@ -521,10 +452,7 @@ void KVStore::handleApplySnapshot(
TMTContext & tmt)
{
auto new_region = genRegionPtr(std::move(region), peer_id, index, term);
if (snapshot_apply_method == TiDB::SnapshotApplyMethod::Block)
handlePreApplySnapshot(RegionPtrWithBlock{new_region, preHandleSnapshotToBlock(new_region, snaps, index, term, tmt)}, tmt);
else
handlePreApplySnapshot(RegionPtrWithSnapshotFiles{new_region, preHandleSnapshotToFiles(new_region, snaps, index, term, tmt)}, tmt);
handlePreApplySnapshot(RegionPtrWithSnapshotFiles{new_region, preHandleSnapshotToFiles(new_region, snaps, index, term, tmt)}, tmt);
}

EngineStoreApplyRes KVStore::handleIngestSST(UInt64 region_id, const SSTViewVec snaps, UInt64 index, UInt64 term, TMTContext & tmt)
Expand All @@ -543,15 +471,12 @@ EngineStoreApplyRes KVStore::handleIngestSST(UInt64 region_id, const SSTViewVec

fiu_do_on(FailPoints::force_set_sst_decode_rand, {
static int num_call = 0;
switch (num_call++ % 3)
switch (num_call++ % 2)
{
case 0:
snapshot_apply_method = TiDB::SnapshotApplyMethod::Block;
break;
case 1:
snapshot_apply_method = TiDB::SnapshotApplyMethod::DTFile_Directory;
break;
case 2:
case 1:
snapshot_apply_method = TiDB::SnapshotApplyMethod::DTFile_Single;
break;
default:
Expand All @@ -576,15 +501,6 @@ EngineStoreApplyRes KVStore::handleIngestSST(UInt64 region_id, const SSTViewVec
}
};

if (snapshot_apply_method == TiDB::SnapshotApplyMethod::Block)
{
// try to flush remain data in memory.
func_try_flush();
region->handleIngestSSTInMemory(snaps, index, term);
// after `handleIngestSSTInMemory`, all data are stored in `region`, try to flush committed data into storage
func_try_flush();
}
else
{
// try to flush remain data in memory.
func_try_flush();
Expand Down
7 changes: 1 addition & 6 deletions dbms/src/Storages/Transaction/KVStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,7 @@ class KVStore final : private boost::noncopyable
EngineStoreApplyRes handleWriteRaftCmd(const WriteCmdsView & cmds, UInt64 region_id, UInt64 index, UInt64 term, TMTContext & tmt);

void handleApplySnapshot(metapb::Region && region, uint64_t peer_id, const SSTViewVec, uint64_t index, uint64_t term, TMTContext & tmt);
RegionPreDecodeBlockDataPtr preHandleSnapshotToBlock(
RegionPtr new_region,
const SSTViewVec,
uint64_t index,
uint64_t term,
TMTContext & tmt);

std::vector<UInt64> /* */ preHandleSnapshotToFiles(
RegionPtr new_region,
const SSTViewVec,
Expand Down
54 changes: 0 additions & 54 deletions dbms/src/Storages/Transaction/PartitionStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,60 +353,6 @@ void RegionTable::writeBlockByRegion(
data_list_to_remove = std::move(*data_list_read);
}

RegionTable::ReadBlockByRegionRes RegionTable::readBlockByRegion(const TiDB::TableInfo & table_info,
const ColumnsDescription & columns [[maybe_unused]],
const Names & column_names_to_read,
const RegionPtr & region,
RegionVersion region_version,
RegionVersion conf_version,
bool resolve_locks,
Timestamp start_ts,
const std::unordered_set<UInt64> * bypass_lock_ts,
RegionScanFilterPtr scan_filter)
{
if (!region)
throw Exception(std::string(__PRETTY_FUNCTION__) + ": region is null", ErrorCodes::LOGICAL_ERROR);

// Tiny optimization for queries that need only handle, tso, delmark.
bool need_value = column_names_to_read.size() != 3;
auto region_data_lock = resolveLocksAndReadRegionData(
table_info.id,
region,
start_ts,
bypass_lock_ts,
region_version,
conf_version,
resolve_locks,
need_value);

return std::visit(variant_op::overloaded{
[&](RegionDataReadInfoList & data_list_read) -> ReadBlockByRegionRes {
/// Read region data as block.
Block block;
// FIXME: remove this deprecated function
assert(0);
{
auto reader = RegionBlockReader(nullptr);
bool ok = reader.setStartTs(start_ts)
.setFilter(scan_filter)
.read(block, data_list_read, /*force_decode*/ true);
if (!ok)
// TODO: Enrich exception message.
throw Exception("Read region " + std::to_string(region->id()) + " of table "
+ std::to_string(table_info.id) + " failed",
ErrorCodes::LOGICAL_ERROR);
}
return block;
},
[&](LockInfoPtr & lock_value) -> ReadBlockByRegionRes {
assert(lock_value);
throw LockException(region->id(), std::move(lock_value));
},
[](RegionException::RegionReadStatus & s) -> ReadBlockByRegionRes { return s; },
},
region_data_lock);
}

RegionTable::ResolveLocksAndWriteRegionRes RegionTable::resolveLocksAndWriteRegion(TMTContext & tmt,
const TiDB::TableID table_id,
const RegionPtr & region,
Expand Down
39 changes: 2 additions & 37 deletions dbms/src/Storages/Transaction/ProxyFFI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,6 @@ RawRustPtrWrap::RawRustPtrWrap(RawRustPtrWrap && src)
src.ptr = nullptr;
}

struct PreHandledSnapshotWithBlock
{
~PreHandledSnapshotWithBlock() { CurrentMetrics::sub(CurrentMetrics::RaftNumSnapshotsPendingApply); }
PreHandledSnapshotWithBlock(const RegionPtr & region_, RegionPtrWithBlock::CachePtr && cache_)
: region(region_)
, cache(std::move(cache_))
{
CurrentMetrics::add(CurrentMetrics::RaftNumSnapshotsPendingApply);
}
RegionPtr region;
RegionPtrWithBlock::CachePtr cache;
};

struct PreHandledSnapshotWithFiles
{
~PreHandledSnapshotWithFiles() { CurrentMetrics::sub(CurrentMetrics::RaftNumSnapshotsPendingApply); }
Expand Down Expand Up @@ -362,13 +349,6 @@ RawCppPtr PreHandleSnapshot(

switch (kvstore->applyMethod())
{
case TiDB::SnapshotApplyMethod::Block:
{
// Pre-decode as a block
auto new_region_block_cache = kvstore->preHandleSnapshotToBlock(new_region, snaps, index, term, tmt);
auto * res = new PreHandledSnapshotWithBlock{new_region, std::move(new_region_block_cache)};
return GenRawCppPtr(res, RawCppPtrTypeImpl::PreHandledSnapshotWithBlock);
}
case TiDB::SnapshotApplyMethod::DTFile_Directory:
case TiDB::SnapshotApplyMethod::DTFile_Single:
{
Expand All @@ -391,18 +371,12 @@ RawCppPtr PreHandleSnapshot(
template <typename PreHandledSnapshot>
void ApplyPreHandledSnapshot(EngineStoreServerWrap * server, PreHandledSnapshot * snap)
{
static_assert(
std::is_same_v<PreHandledSnapshot, PreHandledSnapshotWithBlock> || std::is_same_v<PreHandledSnapshot, PreHandledSnapshotWithFiles>,
"Unknown pre-handled snapshot type");
static_assert(std::is_same_v<PreHandledSnapshot, PreHandledSnapshotWithFiles>, "Unknown pre-handled snapshot type");

try
{
auto & kvstore = server->tmt->getKVStore();
if constexpr (std::is_same_v<PreHandledSnapshot, PreHandledSnapshotWithBlock>)
{
kvstore->handlePreApplySnapshot(RegionPtrWithBlock{snap->region, std::move(snap->cache)}, *server->tmt);
}
else if constexpr (std::is_same_v<PreHandledSnapshot, PreHandledSnapshotWithFiles>)
if constexpr (std::is_same_v<PreHandledSnapshot, PreHandledSnapshotWithFiles>)
{
kvstore->handlePreApplySnapshot(RegionPtrWithSnapshotFiles{snap->region, std::move(snap->ingest_ids)}, *server->tmt);
}
Expand All @@ -418,12 +392,6 @@ void ApplyPreHandledSnapshot(EngineStoreServerWrap * server, RawVoidPtr res, Raw
{
switch (static_cast<RawCppPtrTypeImpl>(type))
{
case RawCppPtrTypeImpl::PreHandledSnapshotWithBlock:
{
auto * snap = reinterpret_cast<PreHandledSnapshotWithBlock *>(res);
ApplyPreHandledSnapshot(server, snap);
break;
}
case RawCppPtrTypeImpl::PreHandledSnapshotWithFiles:
{
auto * snap = reinterpret_cast<PreHandledSnapshotWithFiles *>(res);
Expand All @@ -445,9 +413,6 @@ void GcRawCppPtr(RawVoidPtr ptr, RawCppPtrType type)
case RawCppPtrTypeImpl::String:
delete reinterpret_cast<RawCppStringPtr>(ptr);
break;
case RawCppPtrTypeImpl::PreHandledSnapshotWithBlock:
delete reinterpret_cast<PreHandledSnapshotWithBlock *>(ptr);
break;
case RawCppPtrTypeImpl::PreHandledSnapshotWithFiles:
delete reinterpret_cast<PreHandledSnapshotWithFiles *>(ptr);
break;
Expand Down
1 change: 0 additions & 1 deletion dbms/src/Storages/Transaction/ProxyFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ enum class RawCppPtrTypeImpl : RawCppPtrType
{
None = 0,
String,
PreHandledSnapshotWithBlock,
PreHandledSnapshotWithFiles,
WakerNotifier,
};
Expand Down
41 changes: 0 additions & 41 deletions dbms/src/Storages/Transaction/Region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,47 +720,6 @@ EngineStoreApplyRes Region::handleWriteRaftCmd(const WriteCmdsView & cmds, UInt6
return EngineStoreApplyRes::None;
}

void Region::handleIngestSSTInMemory(const SSTViewVec snaps, UInt64 index, UInt64 term)
{
if (index <= appliedIndex())
return;

{
std::unique_lock<std::shared_mutex> lock(mutex);

for (UInt64 i = 0; i < snaps.len; ++i)
{
const auto & snapshot = snaps.views[i];
auto sst_reader = SSTReader{proxy_helper, snapshot};

LOG_FMT_INFO(log,
"{} begin to ingest sst of cf {} at [term: {}, index: {}]",
this->toString(false),
CFToName(snapshot.type),
term,
index);

uint64_t kv_size = 0;
while (sst_reader.remained())
{
auto key = sst_reader.key();
auto value = sst_reader.value();
doInsert(snaps.views[i].type, TiKVKey(key.data, key.len), TiKVValue(value.data, value.len));
++kv_size;
sst_reader.next();
}

LOG_FMT_INFO(log,
"{} finish to ingest sst of kv count {}",
this->toString(false),
kv_size);
GET_METRIC(tiflash_raft_process_keys, type_ingest_sst).Increment(kv_size);
}
meta.setApplied(index, term);
}
meta.notifyAll();
}

void Region::finishIngestSSTByDTFile(RegionPtr && rhs, UInt64 index, UInt64 term)
{
if (index <= appliedIndex())
Expand Down
1 change: 0 additions & 1 deletion dbms/src/Storages/Transaction/Region.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class Region : public std::enable_shared_from_this<Region>

TableID getMappedTableID() const;
EngineStoreApplyRes handleWriteRaftCmd(const WriteCmdsView & cmds, UInt64 index, UInt64 term, TMTContext & tmt);
void handleIngestSSTInMemory(const SSTViewVec snaps, UInt64 index, UInt64 term);
void finishIngestSSTByDTFile(RegionPtr && rhs, UInt64 index, UInt64 term);

UInt64 getSnapshotEventFlag() const { return snapshot_event_flag; }
Expand Down
Loading