@@ -282,7 +282,7 @@ void ObPluginVectorIndexLoadScheduler::mark_tenant_need_check()
282282 LOG_DEBUG (" finsh mark tenant need check" , KR (ret), K (local_tenant_task_.need_check_ ));
283283}
284284
285- int ObPluginVectorIndexLoadScheduler::check_is_vector_index_table (const ObTableSchema &table_schema,
285+ int ObPluginVectorIndexLoadScheduler::check_is_vector_index_table (const ObSimpleTableSchemaV2 &table_schema,
286286 bool &is_vector_index_table,
287287 bool &is_shared_index_table)
288288{
@@ -394,7 +394,7 @@ int ObPluginVectorIndexLoadScheduler::acquire_adapter_in_maintenance(
394394
395395int ObPluginVectorIndexLoadScheduler::set_shared_table_info_in_maintenance (
396396 const int64_t table_id,
397- const ObTableSchema *table_schema,
397+ const ObSimpleTableSchemaV2 *table_schema,
398398 ObVecIdxSharedTableInfoMap &shared_table_info_map)
399399{
400400 int ret = OB_SUCCESS ;
@@ -451,15 +451,22 @@ int ObPluginVectorIndexLoadScheduler::set_shared_table_info_in_maintenance(
451451 return ret;
452452}
453453
454+ int ObPluginVectorIndexLoadScheduler::check_has_vector_index (bool &has_ivf_index, ObIArray<uint64_t > &vec_table_id_array)
455+ {
456+ int ret = OB_SUCCESS ;
457+ if (OB_FAIL (ObPluginVectorIndexUtils::get_tenant_vector_index_ids (tenant_id_, has_ivf_index, vec_table_id_array))) {
458+ LOG_WARN (" fail to get tenant table ids" , KR (ret), K_ (tenant_id));
459+ }
460+ return ret;
461+ }
454462
455463// scan all vector tablet in current tenant/LS
456- int ObPluginVectorIndexLoadScheduler::execute_adapter_maintenance ()
464+ int ObPluginVectorIndexLoadScheduler::execute_adapter_maintenance (ObIArray< uint64_t > &vec_table_id_array )
457465{
458466 int ret = OB_SUCCESS ;
459467 ObTimeGuard guard (" ObPluginVectorIndexLoadScheduler::check_and_generate_tablet_tasks" ,
460468 VEC_INDEX_LOAD_TIME_NORMAL_THRESHOLD );
461469 const schema::ObTableSchema *table_schema = nullptr ;
462- ObSEArray<uint64_t , DEFAULT_TABLE_ARRAY_SIZE > table_id_array;
463470
464471 ObVecIdxSharedTableInfoMap shared_table_info_map;
465472 ObMemAttr memattr (tenant_id_, " VecIdxInfo" );
@@ -472,20 +479,18 @@ int ObPluginVectorIndexLoadScheduler::execute_adapter_maintenance()
472479
473480 if (current_memory_config_ != 0 ) { // has memory for new adapter
474481
475- if (OB_FAIL (ObTTLUtil::get_tenant_table_ids (tenant_id_, table_id_array))) {
476- LOG_WARN (" fail to get tenant table ids" , KR (ret), K_ (tenant_id));
477- } else if (!table_id_array.empty ()
478- && OB_FAIL (shared_table_info_map.create (DEFAULT_TABLE_ARRAY_SIZE , memattr, memattr))) {
482+ if (!vec_table_id_array.empty ()
483+ && OB_FAIL (shared_table_info_map.create (DEFAULT_TABLE_ARRAY_SIZE , memattr, memattr))) {
479484 LOG_WARN (" fail to create param map" , KR (ret));
480485 }
481486
482487 int64_t start_idx = 0 ;
483488 int64_t end_idx = 0 ;
484489
485- while (OB_SUCC (ret) && start_idx < table_id_array .count ()) {
490+ while (OB_SUCC (ret) && start_idx < vec_table_id_array .count ()) {
486491 ObSchemaGetterGuard schema_guard;
487492 start_idx = end_idx;
488- end_idx = MIN (table_id_array .count (), start_idx + TBALE_GENERATE_BATCH_SIZE );
493+ end_idx = MIN (vec_table_id_array .count (), start_idx + TBALE_GENERATE_BATCH_SIZE );
489494
490495 bool is_vector_index = false ;
491496 bool is_shared_index = false ;
@@ -494,11 +499,11 @@ int ObPluginVectorIndexLoadScheduler::execute_adapter_maintenance()
494499 }
495500
496501 for (int64_t idx = start_idx; OB_SUCC (ret) && idx < end_idx; ++idx) {
497- const int64_t table_id = table_id_array .at (idx);
498- const ObTableSchema *table_schema = nullptr ;
502+ const int64_t table_id = vec_table_id_array .at (idx);
503+ const ObSimpleTableSchemaV2 *table_schema = nullptr ;
499504 if (is_sys_table (table_id)) {
500505 // do nothing
501- } else if (OB_FAIL (schema_guard.get_table_schema (tenant_id_, table_id, table_schema))) {
506+ } else if (OB_FAIL (schema_guard.get_simple_table_schema (tenant_id_, table_id, table_schema))) {
502507 LOG_WARN (" failed to get simple schema" , KR (ret), K (table_id));
503508 } else if (OB_ISNULL (table_schema)) {
504509 ret = OB_TABLE_NOT_EXIST ;
@@ -507,10 +512,17 @@ int ObPluginVectorIndexLoadScheduler::execute_adapter_maintenance()
507512 // do nothing
508513 } else if (OB_FAIL (check_is_vector_index_table (*table_schema, is_vector_index, is_shared_index))) {
509514 LOG_WARN (" fail to check is vector index" , KR (ret));
510- } else if (is_vector_index
511- && OB_FAIL (acquire_adapter_in_maintenance (table_id, table_schema, shared_table_info_map))) {
512- // for one vector_index table
513- LOG_WARN (" fail to create adapter in maintenance" , KR (ret), K (table_id));
515+ } else if (is_vector_index) {
516+ const ObTableSchema *tmp_table_schema = nullptr ;
517+ if (OB_FAIL (schema_guard.get_table_schema (tenant_id_, table_id, tmp_table_schema))) {
518+ LOG_WARN (" failed to get simple schema" , KR (ret), K (table_id));
519+ } else if (OB_ISNULL (tmp_table_schema)) {
520+ ret = OB_TABLE_NOT_EXIST ;
521+ LOG_WARN (" table schema is null" , KR (ret), K (table_id), K_ (tenant_id));
522+ } else if (OB_FAIL (acquire_adapter_in_maintenance (table_id, tmp_table_schema, shared_table_info_map))) {
523+ // for one vector_index table
524+ LOG_WARN (" fail to create adapter in maintenance" , KR (ret), K (table_id));
525+ }
514526 } else if (is_shared_index
515527 && OB_FAIL (set_shared_table_info_in_maintenance (table_id,
516528 table_schema,
@@ -564,7 +576,7 @@ int read_tenant_task_status(uint64_t tenant_id,
564576 return ret;
565577}
566578
567- int ObPluginVectorIndexLoadScheduler::check_and_load_task_executors ()
579+ int ObPluginVectorIndexLoadScheduler::check_and_load_task_executors (bool &has_ivf_index )
568580{
569581 int ret = OB_SUCCESS ;
570582 uint64_t task_trace_base_num = 0 ;
@@ -584,7 +596,7 @@ int ObPluginVectorIndexLoadScheduler::check_and_load_task_executors()
584596 if (OB_FAIL (ivf_task_exec_.check_schema_version_changed (schema_changed))) {
585597 // only when schema changed, load ivf task
586598 LOG_WARN (" fail to check schema version changed" , K (ret));
587- } else if (!schema_changed) {
599+ } else if (!schema_changed || !has_ivf_index ) {
588600 // schema not changed, only do cleanup if needed, skip thread pool check and task loading
589601 if (OB_FAIL (ivf_task_exec_.clear_old_task_ctx_if_need ())) {
590602 LOG_WARN (" fail to clear old ivf task ctx" , K (ret));
@@ -606,7 +618,7 @@ int ObPluginVectorIndexLoadScheduler::check_and_load_task_executors()
606618// read from sys table with tenant id, special table id & special tablet id, not implemented
607619// 2. check if need mem load task
608620// from log replay, or long time not processed
609- int ObPluginVectorIndexLoadScheduler::reload_tenant_task ()
621+ int ObPluginVectorIndexLoadScheduler::reload_tenant_task (bool &has_ivf_index )
610622{
611623 int ret = OB_SUCCESS ;
612624 ObVectorIndexTenantStatus tenant_task;
@@ -647,7 +659,7 @@ int ObPluginVectorIndexLoadScheduler::reload_tenant_task()
647659 // vector index async task
648660 int tmp_ret = OB_SUCCESS ;
649661 if (is_stopped () || !is_leader_) { // skip
650- } else if (OB_TMP_FAIL (check_and_load_task_executors ())) {
662+ } else if (OB_TMP_FAIL (check_and_load_task_executors (has_ivf_index ))) {
651663 LOG_WARN (" fail to check and load task executors" , K (tmp_ret));
652664 }
653665
@@ -938,7 +950,7 @@ int ObPluginVectorIndexLoadScheduler::check_ls_task_state(ObPluginVectorIndexMgr
938950 return ret;
939951}
940952
941- int ObPluginVectorIndexLoadScheduler::check_and_execute_adapter_maintenance_task (ObPluginVectorIndexMgr *&mgr)
953+ int ObPluginVectorIndexLoadScheduler::check_and_execute_adapter_maintenance_task (ObPluginVectorIndexMgr *&mgr, ObIArray< uint64_t > &vec_table_id_array )
942954{
943955 int ret = OB_SUCCESS ;
944956 bool need_check = false ;
@@ -950,7 +962,7 @@ int ObPluginVectorIndexLoadScheduler::check_and_execute_adapter_maintenance_task
950962 } else if (OB_NOT_NULL (mgr) && OB_FAIL (check_index_adpter_exist (mgr))) {
951963 LOG_WARN (" fail to check exist paritial index adapter" , KR (ret));
952964 } else if (local_tenant_task_.need_check_ ) {
953- if (OB_FAIL (execute_adapter_maintenance ())) {
965+ if (OB_FAIL (execute_adapter_maintenance (vec_table_id_array ))) {
954966 LOG_WARN (" fail to generate tablet tasks" , K_ (tenant_id));
955967 }
956968 int tmp_ret = OB_SUCCESS ;
@@ -1143,7 +1155,7 @@ int ObPluginVectorIndexLoadScheduler::start_task_executors()
11431155 return ret;
11441156}
11451157
1146- int ObPluginVectorIndexLoadScheduler::check_and_execute_tasks ()
1158+ int ObPluginVectorIndexLoadScheduler::check_and_execute_tasks (ObIArray< uint64_t > &vec_table_id_array )
11471159{
11481160 int ret = OB_SUCCESS ;
11491161 ObTimeGuard guard (" ObPluginVectorIndexLoadScheduler::check_and_handle_event" ,
@@ -1164,7 +1176,7 @@ int ObPluginVectorIndexLoadScheduler::check_and_execute_tasks()
11641176 } else {
11651177 // Notice: index_ls_mgr maybe null
11661178 // create / remove adapter, check need update & write mem sync log
1167- if (can_schedule (ObVectorTaskScheduleType::ADAPTER_MAINTENANCE ) && OB_FAIL (check_and_execute_adapter_maintenance_task (index_ls_mgr))) { // Tips: do merge
1179+ if (can_schedule (ObVectorTaskScheduleType::ADAPTER_MAINTENANCE ) && OB_FAIL (check_and_execute_adapter_maintenance_task (index_ls_mgr, vec_table_id_array ))) { // Tips: do merge
11681180 LOG_WARN (" fail to check and execute adapter maintenance task" ,
11691181 KR (ret), K (tenant_id_), K (ls_->get_ls_id ()));
11701182 }
@@ -1230,11 +1242,15 @@ void ObPluginVectorIndexLoadScheduler::run_task()
12301242 }
12311243 } else if (check_can_do_work ()){
12321244 check_can_schedule ();
1245+ bool has_ivf_index = false ;
1246+ ObSEArray<uint64_t , DEFAULT_TABLE_ARRAY_SIZE > vec_table_id_array;
12331247 if (OB_FAIL (check_tenant_memory ())) {
12341248 LOG_WARN (" check vector index resource failed" , KR (ret));
1235- } else if (OB_FAIL (reload_tenant_task ())) {
1249+ } else if (OB_FAIL (check_has_vector_index (has_ivf_index, vec_table_id_array))) {
1250+ LOG_WARN (" check vector index schema failed" , KR (ret));
1251+ } else if (OB_FAIL (reload_tenant_task (has_ivf_index))) {
12361252 LOG_WARN (" fail to reload tenant task" , KR (ret));
1237- } else if (OB_FAIL (check_and_execute_tasks ())) {
1253+ } else if (OB_FAIL (check_and_execute_tasks (vec_table_id_array ))) {
12381254 LOG_WARN (" fail to scan and handle all tenant event" , KR (ret));
12391255 }
12401256 schedule_finish ();
0 commit comments