Skip to content

Commit bf389c9

Browse files
ti-chi-botkolafishJaySon-HuangCalvinNeo
authored
vector: A new load balance to improve the vector search performance when tiflash replica >1 (#9636) (#9651)
close #9637 In this pr: [https://github.com/tikv/client-c/pull/193](https://github.com/tikv/client-c/pull/193) add a bool paramater centralized_schedule for Client::buildBatchCopTasks When set to true: Regions are concentrated into as few BatchCopTasks as possible This PR modifies the call to this function, setting the newly added parameter to true when the request is a ANN query. Signed-off-by: Calvin Neo <calvinneo1995@gmail.com> Co-authored-by: Yu Jin <yujin.yujin@gmail.com> Co-authored-by: JaySon-Huang <tshent@qq.com> Co-authored-by: Calvin Neo <CalvinNeo@users.noreply.github.com> Co-authored-by: JaySon <tshent@qq.com>
1 parent 62fb024 commit bf389c9

File tree

6 files changed

+54
-3
lines changed

6 files changed

+54
-3
lines changed

dbms/src/Interpreters/Context.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ struct ContextShared
188188

189189
JointThreadInfoJeallocMapPtr joint_memory_allocation_map; /// Joint thread-wise alloc/dealloc map
190190

191+
std::unordered_set<uint64_t> store_id_blocklist; /// Those store id are blocked from batch cop request.
192+
191193
class SessionKeyHash
192194
{
193195
public:
@@ -2218,6 +2220,44 @@ void Context::setMockMPPServerInfo(MockMPPServerInfo & info)
22182220
mpp_server_info = info;
22192221
}
22202222

2223+
const std::unordered_set<uint64_t> * Context::getStoreIdBlockList() const
2224+
{
2225+
return &shared->store_id_blocklist;
2226+
}
2227+
2228+
// NOLINTNEXTLINE(readability-convert-member-functions-to-static)
2229+
bool Context::initializeStoreIdBlockList(const String & comma_sep_string)
2230+
{
2231+
#if SERVERLESS_PROXY == 1
2232+
std::istringstream iss(comma_sep_string);
2233+
std::string token;
2234+
2235+
while (std::getline(iss, token, ','))
2236+
{
2237+
try
2238+
{
2239+
uint64_t number = std::stoull(token);
2240+
shared->store_id_blocklist.insert(number);
2241+
}
2242+
catch (...)
2243+
{
2244+
// Keep empty
2245+
LOG_INFO(DB::Logger::get(), "StoreIdBlockList is not set, input_str={}", comma_sep_string);
2246+
shared->store_id_blocklist.clear();
2247+
return false;
2248+
}
2249+
}
2250+
2251+
if (!shared->store_id_blocklist.empty())
2252+
LOG_INFO(DB::Logger::get(), "StoreIdBlockList have been set, {}", shared->store_id_blocklist);
2253+
2254+
return true;
2255+
#else
2256+
UNUSED(comma_sep_string);
2257+
return true;
2258+
#endif
2259+
}
2260+
22212261
SessionCleaner::~SessionCleaner()
22222262
{
22232263
try
@@ -2251,4 +2291,5 @@ void SessionCleaner::run()
22512291
break;
22522292
}
22532293
}
2294+
22542295
} // namespace DB

dbms/src/Interpreters/Context.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class Context
190190
}};
191191
using DatabasePtr = std::shared_ptr<IDatabase>;
192192
using Databases = std::map<String, std::shared_ptr<IDatabase>>;
193+
193194
/// Use copy constructor or createGlobal() instead
194195
Context();
195196

@@ -560,6 +561,9 @@ class Context
560561

561562
void mockConfigLoaded() { is_config_loaded = true; }
562563

564+
bool initializeStoreIdBlockList(const String &);
565+
const std::unordered_set<uint64_t> * getStoreIdBlockList() const;
566+
563567
private:
564568
/** Check if the current client has access to the specified database.
565569
* If access is denied, throw an exception.

dbms/src/Interpreters/SettingsCommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ struct SettingString
849849
void write(WriteBuffer & buf) const { writeBinary(value, buf); }
850850

851851
String get() const { return value; }
852+
const String & getRef() const { return value; }
852853

853854
private:
854855
String value;

dbms/src/Server/Server.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,9 @@ int Server::main(const std::vector<std::string> & /*args*/)
15121512
global_context->setFormatSchemaPath(format_schema_path.path() + "/");
15131513
format_schema_path.createDirectories();
15141514

1515+
// We do not support blocking store by id in OP mode currently.
1516+
global_context->initializeStoreIdBlockList("");
1517+
15151518
LOG_INFO(log, "Loading metadata.");
15161519
loadMetadataSystem(*global_context); // Load "system" database. Its engine keeps as Ordinary.
15171520
/// After attaching system databases we can initialize system log.

dbms/src/Storages/StorageDisaggregated.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ std::vector<pingcap::coprocessor::BatchCopTask> StorageDisaggregated::buildBatch
105105
physical_table_ids.emplace_back(remote_table_range.first);
106106
ranges_for_each_physical_table.emplace_back(remote_table_range.second);
107107
}
108-
108+
bool has_ann_query = table_scan.getANNQueryInfo().query_type() != tipb::ANNQueryType::InvalidQueryType;
109109
pingcap::kv::Cluster * cluster = context.getTMTContext().getKVCluster();
110110
pingcap::kv::Backoffer bo(pingcap::kv::copBuildTaskMaxBackoff);
111111
pingcap::kv::StoreType store_type = pingcap::kv::StoreType::TiFlash;
@@ -116,9 +116,11 @@ std::vector<pingcap::coprocessor::BatchCopTask> StorageDisaggregated::buildBatch
116116
table_scan.isPartitionTableScan(),
117117
physical_table_ids,
118118
ranges_for_each_physical_table,
119+
context.getStoreIdBlockList(),
119120
store_type,
120121
label_filter,
121-
&Poco::Logger::get("pingcap/coprocessor"));
122+
&Poco::Logger::get("pingcap/coprocessor"),
123+
has_ann_query);
122124
LOG_DEBUG(log, "batch cop tasks(nums: {}) build finish for tiflash_storage node", batch_cop_tasks.size());
123125
return batch_cop_tasks;
124126
}

0 commit comments

Comments
 (0)