66
77#include " db/catalog/meta_types.hpp"
88
9+ #include " config/config.hpp"
10+
911namespace vectordb {
12+
13+ extern Config globalConfig;
14+
1015namespace engine {
1116
1217TableMVP::TableMVP (meta::TableSchema &table_schema,
@@ -65,7 +70,7 @@ TableMVP::TableMVP(meta::TableSchema &table_schema,
6570 auto distFunc = GetDistFunc (fType , mType );
6671
6772 auto pool = std::make_shared<execution::ExecutorPool>();
68- for (int executorIdx = 0 ; executorIdx < NumExecutorPerField;
73+ for (int executorIdx = 0 ; executorIdx < globalConfig. NumExecutorPerField ;
6974 executorIdx++) {
7075 pool->release (std::make_shared<execution::VecSearchExecutor>(
7176 table_schema_.fields_ [i].vector_dimension_ ,
@@ -75,10 +80,10 @@ TableMVP::TableMVP(meta::TableSchema &table_schema,
7580 columnData,
7681 distFunc,
7782 &table_schema_.fields_ [i].vector_dimension_ ,
78- IntraQueryThreads,
79- MasterQueueSize,
80- LocalQueueSize,
81- GlobalSyncInterval));
83+ globalConfig. IntraQueryThreads ,
84+ globalConfig. MasterQueueSize ,
85+ globalConfig. LocalQueueSize ,
86+ globalConfig. GlobalSyncInterval ));
8287 }
8388 executor_pool_.push_back (pool);
8489 }
@@ -87,7 +92,8 @@ TableMVP::TableMVP(meta::TableSchema &table_schema,
8792
8893Status TableMVP::Rebuild (const std::string &db_catalog_path) {
8994 // Limit how many threads rebuild takes.
90- omp_set_num_threads (RebuildThreads);
95+ omp_set_num_threads (globalConfig.RebuildThreads );
96+ std::cout << " Rebuild table segment with threads: " << globalConfig.RebuildThreads << std::endl;
9197
9298 // Get the current record number.
9399 int64_t record_number = table_segment_->record_number_ ;
@@ -112,7 +118,7 @@ Status TableMVP::Rebuild(const std::string &db_catalog_path) {
112118 fType == meta::FieldType::SPARSE_VECTOR_FLOAT ||
113119 fType == meta::FieldType::SPARSE_VECTOR_DOUBLE) {
114120 if (ann_graph_segment_[index]->record_number_ == record_number ||
115- record_number < MinimalGraphSize) {
121+ record_number < globalConfig. MinimalGraphSize ) {
116122 // No need to rebuild the ann graph.
117123 std::cout << " Skip rebuild ANN graph for attribute: "
118124 << table_schema_.fields_ [i].name_ << std::endl;
@@ -171,7 +177,7 @@ Status TableMVP::Rebuild(const std::string &db_catalog_path) {
171177 auto pool = std::make_shared<execution::ExecutorPool>();
172178 auto distFunc = GetDistFunc (fType , mType );
173179
174- for (int executorIdx = 0 ; executorIdx < NumExecutorPerField;
180+ for (int executorIdx = 0 ; executorIdx < globalConfig. NumExecutorPerField ;
175181 executorIdx++) {
176182 pool->release (std::make_shared<execution::VecSearchExecutor>(
177183 table_schema_.fields_ [i].vector_dimension_ ,
@@ -182,10 +188,10 @@ Status TableMVP::Rebuild(const std::string &db_catalog_path) {
182188 columnData,
183189 distFunc,
184190 &table_schema_.fields_ [i].vector_dimension_ ,
185- IntraQueryThreads,
186- MasterQueueSize,
187- LocalQueueSize,
188- GlobalSyncInterval));
191+ globalConfig. IntraQueryThreads ,
192+ globalConfig. MasterQueueSize ,
193+ globalConfig. LocalQueueSize ,
194+ globalConfig. GlobalSyncInterval ));
189195 }
190196 std::unique_lock<std::mutex> lock (executor_pool_mutex_);
191197 executor_pool_.set (index, pool);
@@ -199,6 +205,68 @@ Status TableMVP::Rebuild(const std::string &db_catalog_path) {
199205 return Status::OK ();
200206}
201207
208+ Status TableMVP::SwapExecutors () {
209+ // Get the current record number.
210+ int64_t record_number = table_segment_->record_number_ ;
211+
212+ int64_t index = 0 ;
213+ for (int i = 0 ; i < table_schema_.fields_ .size (); ++i) {
214+ auto fType = table_schema_.fields_ [i].field_type_ ;
215+ auto mType = table_schema_.fields_ [i].metric_type_ ;
216+
217+ if (fType == meta::FieldType::VECTOR_FLOAT ||
218+ fType == meta::FieldType::VECTOR_DOUBLE ||
219+ fType == meta::FieldType::SPARSE_VECTOR_FLOAT ||
220+ fType == meta::FieldType::SPARSE_VECTOR_DOUBLE) {
221+
222+ VectorColumnData columnData;
223+ if (fType == meta::FieldType::VECTOR_FLOAT || fType == meta::FieldType::VECTOR_DOUBLE) {
224+ columnData = table_segment_
225+ ->vector_tables_ [table_segment_->field_name_mem_offset_map_
226+ [table_schema_.fields_ [i].name_ ]];
227+ } else {
228+ // sparse vector
229+ columnData = &table_segment_
230+ ->var_len_attr_table_ [table_segment_->field_name_mem_offset_map_
231+ [table_schema_.fields_ [i].name_ ]];
232+ }
233+
234+ // Rebuild the ann graph.
235+ std::cout << " Swap executors for attribute: "
236+ << table_schema_.fields_ [i].name_ << std::endl;
237+
238+ // Replace the executors.
239+ auto pool = std::make_shared<execution::ExecutorPool>();
240+ auto distFunc = GetDistFunc (fType , mType );
241+
242+ for (int executorIdx = 0 ; executorIdx < globalConfig.NumExecutorPerField ;
243+ executorIdx++) {
244+ pool->release (std::make_shared<execution::VecSearchExecutor>(
245+ table_schema_.fields_ [i].vector_dimension_ ,
246+ ann_graph_segment_[index]->navigation_point_ ,
247+ ann_graph_segment_[index],
248+ ann_graph_segment_[index]->offset_table_ ,
249+ ann_graph_segment_[index]->neighbor_list_ ,
250+ columnData,
251+ distFunc,
252+ &table_schema_.fields_ [i].vector_dimension_ ,
253+ globalConfig.IntraQueryThreads ,
254+ globalConfig.MasterQueueSize ,
255+ globalConfig.LocalQueueSize ,
256+ globalConfig.GlobalSyncInterval ));
257+ }
258+ std::unique_lock<std::mutex> lock (executor_pool_mutex_);
259+ executor_pool_.set (index, pool);
260+ lock.unlock ();
261+
262+ ++index;
263+ }
264+ }
265+
266+ std::cout << " Swap executors done." << std::endl;
267+ return Status::OK ();
268+ }
269+
202270Status TableMVP::Insert (vectordb::Json &record, std::unordered_map<std::string, std::string> &headers, bool upsert) {
203271 int64_t wal_id =
204272 wal_->WriteEntry (upsert ? LogEntryType::UPSERT : LogEntryType::INSERT, record.DumpToString ());
0 commit comments