diff --git a/src/rootserver/ob_ddl_service.cpp b/src/rootserver/ob_ddl_service.cpp index f5e294c08c..958c18ac82 100755 --- a/src/rootserver/ob_ddl_service.cpp +++ b/src/rootserver/ob_ddl_service.cpp @@ -2412,6 +2412,7 @@ int ObDDLService::create_tables_in_trans(const bool if_not_exist, int64_t refreshed_schema_version = 0; ObDDLTaskRecord task_record; ddl_task_id = 0; + ObMViewInfo mview_info; if (OB_FAIL(get_tenant_schema_guard_with_version_in_inner_table(tenant_id, schema_guard))) { LOG_WARN("fail to get schema guard with version in inner table", K(ret), K(tenant_id)); } else if (OB_FAIL(schema_guard.get_schema_version(tenant_id, refreshed_schema_version))) { @@ -2563,7 +2564,8 @@ int ObDDLService::create_tables_in_trans(const bool if_not_exist, db_schema->get_database_name_str(), table_schema.get_table_name_str(), table_schema.get_view_schema().get_mv_refresh_info(), - table_schema.get_schema_version()))) { + table_schema.get_schema_version(), + mview_info))) { LOG_WARN("fail to start mview refresh job", KR(ret)); } } @@ -2618,6 +2620,7 @@ int ObDDLService::create_tables_in_trans(const bool if_not_exist, dep_infos, allocator, tenant_data_version, + mview_info, task_record))) { LOG_WARN("failed to start mview complete refresh task", KR(ret)); } else { @@ -2673,6 +2676,7 @@ int ObDDLService::start_mview_complete_refresh_task( const ObIArray *dep_infos, common::ObIAllocator &allocator, const uint64_t tenant_data_version, + const ObMViewInfo &mview_info, ObDDLTaskRecord &task_record) { int ret = OB_SUCCESS; @@ -2692,6 +2696,8 @@ int ObDDLService::start_mview_complete_refresh_task( if (OB_UNLIKELY(nullptr == dep_infos || nullptr == mv_refresh_info)) { ret = OB_INVALID_ARGUMENT; LOG_WARN("dep_infos is nullptr", KR(ret) , KP(dep_infos), KP(mv_refresh_info)); + } else if (OB_FAIL(arg.last_refresh_scn_.convert_for_inner_table_field(mview_info.get_last_refresh_scn()))) { + LOG_WARN("fail to covert for inner table field", KR(ret), K(mview_info)); } else if (OB_FAIL(share::ObBackupUtils::get_tenant_sys_time_zone_wrap(tenant_id, time_zone, arg.tz_info_wrap_))) { diff --git a/src/rootserver/ob_ddl_service.h b/src/rootserver/ob_ddl_service.h index d3d5a13a7c..d8efd4cb82 100644 --- a/src/rootserver/ob_ddl_service.h +++ b/src/rootserver/ob_ddl_service.h @@ -72,6 +72,7 @@ class ObTableSchema; class ObMultiVersionSchemaService; class ObNeedPriv; class ObSchemaMgr; +class ObMViewInfo; } } @@ -2698,6 +2699,7 @@ private: const ObIArray *dep_infos, common::ObIAllocator &allocator, const uint64_t tenant_data_version, + const share::schema::ObMViewInfo &mview_info, ObDDLTaskRecord &task_record); bool need_modify_dep_obj_status(const obrpc::ObAlterTableArg &alter_table_arg) const; diff --git a/src/storage/mview/ob_mview_sched_job_utils.cpp b/src/storage/mview/ob_mview_sched_job_utils.cpp index 73beab52db..72cf376b36 100644 --- a/src/storage/mview/ob_mview_sched_job_utils.cpp +++ b/src/storage/mview/ob_mview_sched_job_utils.cpp @@ -29,6 +29,7 @@ #include "sql/parser/ob_parser_utils.h" #include "sql/resolver/ob_schema_checker.h" #include "sql/resolver/expr/ob_raw_expr_util.h" +#include "storage/tx/ob_ts_mgr.h" namespace oceanbase { @@ -175,11 +176,14 @@ int ObMViewSchedJobUtils::add_mview_info_and_refresh_job(ObISQLClient &sql_clien const ObString &db_name, const ObString &table_name, const ObMVRefreshInfo *refresh_info, - const int64_t schema_version) + const int64_t schema_version, + ObMViewInfo &mview_info) { int ret = OB_SUCCESS; ObString refresh_job; ObArenaAllocator allocator("CreateMVTmp"); + SCN curr_ts; + mview_info.reset(); if (refresh_info == nullptr) { ret = OB_INVALID_ARGUMENT; LOG_WARN("refresh_info is null", KR(ret)); @@ -222,15 +226,25 @@ int ObMViewSchedJobUtils::add_mview_info_and_refresh_job(ObISQLClient &sql_clien } } } + if (OB_SUCC(ret)) { + if (OB_FAIL(OB_TS_MGR.get_ts_sync(tenant_id, + GCONF.rpc_timeout, + curr_ts))) { + LOG_WARN("fail to get gts sync", K(ret), K(tenant_id)); + } else if (OB_UNLIKELY(!curr_ts.is_valid())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected curr_scn", KR(ret), K(tenant_id), K(curr_ts)); + } + } if (OB_SUCC(ret)) { - ObMViewInfo mview_info; mview_info.set_tenant_id(tenant_id); mview_info.set_mview_id(mview_id); mview_info.set_build_mode(ObMViewBuildMode::IMMEDIATE); mview_info.set_refresh_mode(refresh_info->refresh_mode_); mview_info.set_refresh_method(refresh_info->refresh_method_); mview_info.set_refresh_job(refresh_job); + mview_info.set_last_refresh_scn(curr_ts.get_val_for_inner_table_field()); mview_info.set_schema_version(schema_version); if (refresh_info->start_time_.is_timestamp()) { mview_info.set_refresh_start(refresh_info->start_time_.get_timestamp()); diff --git a/src/storage/mview/ob_mview_sched_job_utils.h b/src/storage/mview/ob_mview_sched_job_utils.h index 11d9859dc9..0d3e17858c 100644 --- a/src/storage/mview/ob_mview_sched_job_utils.h +++ b/src/storage/mview/ob_mview_sched_job_utils.h @@ -24,6 +24,7 @@ namespace schema class ObMVRefreshInfo; class ObSchemaGetterGuard; class ObUserInfo; +class ObMViewInfo; } } namespace common @@ -76,7 +77,8 @@ public: const common::ObString &db_name, const common::ObString &table_name, const share::schema::ObMVRefreshInfo *refresh_info, - const int64_t schema_version); + const int64_t schema_version, + share::schema::ObMViewInfo &mview_info); static int disable_mview_refresh_job(common::ObISQLClient &sql_client, const uint64_t tenant_id,