From 4c66176ed8ee6049e43e0b6eea5544b4d5f68a3c Mon Sep 17 00:00:00 2001 From: douxin Date: Tue, 7 Jan 2025 19:34:14 +0800 Subject: [PATCH 1/2] [feature] adding guc param enable_mot_server to diable mot engine and remove rdtscp --- CMakeLists.txt | 5 +- cmake/src/build_options.cmake | 5 + cmake/src/config-in/pg_config.h.in | 4 + configure | 37 ++++ src/Makefile.global.in | 5 + src/bin/gs_guc/cluster_guc.conf | 1 + src/common/backend/utils/init/globals.cpp | 3 +- src/common/backend/utils/misc/guc.cpp | 13 ++ .../process/postmaster/postmaster.cpp | 4 +- .../mot/core/infra/synchronization/cycles.h | 14 +- .../system/checkpoint/checkpoint_ctrlfile.cpp | 2 +- .../system/checkpoint/checkpoint_manager.cpp | 8 +- .../system/checkpoint/checkpoint_utils.cpp | 82 +++++++- .../core/system/checkpoint/checkpoint_utils.h | 3 +- .../storage/mot/fdw_adapter/mot_fdw.cpp | 22 ++- .../storage/mot/fdw_adapter/mot_fdw_xlog.cpp | 4 + .../storage/mot/fdw_adapter/mot_internal.cpp | 3 + .../knl/knl_guc/knl_instance_attr_common.h | 1 + src/include/storage/mot/mot_fdw.h | 3 + src/test/regress/expected/mot/disable_mot.out | 178 ++++++++++++++++++ .../make_fastcheck_single_mot_postgresql.conf | 1 + src/test/regress/parallel_schedule0A | 5 +- src/test/regress/sql/mot/disable_mot.sql | 134 +++++++++++++ 23 files changed, 523 insertions(+), 14 deletions(-) create mode 100644 src/test/regress/expected/mot/disable_mot.out create mode 100644 src/test/regress/sql/mot/disable_mot.sql diff --git a/CMakeLists.txt b/CMakeLists.txt index ef522d6023..5a74237e5c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,9 @@ endif() if("${ENABLE_MOT}" STREQUAL "") set(ENABLE_MOT "OFF") endif() +if("${ENABLE_X86_RDTSCP}" STREQUAL "") + set(ENABLE_X86_RDTSCP "OFF") +endif() if("${ENABLE_HTAP}" STREQUAL "") set(ENABLE_HTAP "ON") endif() @@ -116,7 +119,7 @@ install(DIRECTORY ${CMAKE_BINARY_DIR}/pg_plugin DESTINATION lib/postgresql) install(DIRECTORY ${CMAKE_BINARY_DIR}/libsimsearch DESTINATION lib) if(EXISTS ${CMAKE_SOURCE_DIR}/contrib/dolphin) - install(CODE "execute_process(COMMAND bash cmake.sh ${BUILD_TUPLE} ${ENABLE_LITE_MODE} ${ENABLE_MOT} ${ENABLE_HTAP} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/contrib/dolphin)") + install(CODE "execute_process(COMMAND bash cmake.sh ${BUILD_TUPLE} ${ENABLE_LITE_MODE} ${ENABLE_MOT} ${ENABLE_X86_RDTSCP} ${ENABLE_HTAP} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/contrib/dolphin)") install(FILES ${CMAKE_SOURCE_DIR}/contrib/dolphin/dolphin.control DESTINATION share/postgresql/extension/ ) diff --git a/cmake/src/build_options.cmake b/cmake/src/build_options.cmake index 30b5836221..27056f4f27 100755 --- a/cmake/src/build_options.cmake +++ b/cmake/src/build_options.cmake @@ -59,6 +59,7 @@ option(ENABLE_LITE_MODE "enable lite in single_node mode,the old is --enable-lit option(ENABLE_FINANCE_MODE "enable finance in single_node mode,the old is --enable-finance-mode" OFF) option(ENABLE_DEBUG "enable privategauss,the old is --enable-pribategauss" OFF) option(ENABLE_MOT "enable mot in single_node mode,the old is --enable-mot" OFF) +option(ENABLE_X86_RDTSCP "enable rdtscp instruction for x86 architecture in single_node mode,the old is --enable-x86-rdtscp" OFF) option(ENABLE_NUMA "enable numa,the old is --enable-numa" ON) option(ENABLE_LSE "enable lse,the old is --enable-lse" ON) option(ENABLE_MYSQL_FDW "enable export or import data with mysql,the old is --enable-mysql-fdw" OFF) @@ -234,6 +235,10 @@ if(${USE_SPQ}) set(GAUSSDB_CONFIGURE "${GAUSSDB_CONFIGURE} -DUSE_SPQ") endif() +if(${ENABLE_X86_RDTSCP}) + set(GAUSSDB_CONFIGURE "${GAUSSDB_CONFIGURE} -DENABLE_X86_RDTSCP") +endif() + if(${ENABLE_HTAP}) set(GAUSSDB_CONFIGURE "${GAUSSDB_CONFIGURE} -DENABLE_HTAP") endif() diff --git a/cmake/src/config-in/pg_config.h.in b/cmake/src/config-in/pg_config.h.in index cc35853edf..a2afbefb8b 100755 --- a/cmake/src/config-in/pg_config.h.in +++ b/cmake/src/config-in/pg_config.h.in @@ -931,6 +931,10 @@ * --enable-mot */ #cmakedefine ENABLE_MOT +/* Define to 1 if you want to use rdtscp instruction for x86 architecture + * --enable-x86-rdtscp */ +#cmakedefine ENABLE_X86_RDTSCP + /* Define to 1 if you want to use mysql fdw * * --enable-mysql-fdw */ #cmakedefine ENABLE_MYSQL_FDW diff --git a/configure b/configure index d7ba9b8e65..02d3c947a9 100755 --- a/configure +++ b/configure @@ -758,6 +758,7 @@ enable_lite_mode enable_relocation enable_finance_mode enable_mot +enable_x86_rdtscp enable_htap enable_bbox enable_memory_check @@ -848,6 +849,7 @@ enable_lite_mode enable_relocation enable_finance_mode enable_mot +enable_x86_rdtscp enable_htap enable_bbox enable_memory_check @@ -1563,6 +1565,7 @@ Optional Features: --disable-spinlocks do not use spinlocks --enable-debug build with debugging symbols (-g) --enable-htap enable htap feture + --enable-x86-rdtscp enable rdtscp instruction for x86 architecture --enable-qunit enable query driven unit test framework(QUnit) --enable-profiling build with profiling enabled --enable-coverage build with coverage testing instrumentation @@ -3320,6 +3323,40 @@ _ACEOF fi +# Check whether --enable-x86-rdtscp was given. +if test "${enable_x86_rdtscp+set}" = set; then + enableval=$enable_x86_rdtscp; + case $enableval in + yes) + +cat >>confdefs.h <<\_ACEOF +#define ENABLE_X86_RDTSCP 1 +_ACEOF + + ;; + no) + : + ;; + *) + { { $as_echo "$as_me:$LINENO: error: no argument expected for --enable-x86-rdtscp option" >&5 +$as_echo "$as_me: error: no argument expected for --enable-x86-rdtscp option" >&2;} + { (exit 1); exit 1; }; } + ;; + esac + +else + enable_x86_rdtscp=no + +fi + +if test "$enable_x86_rdtscp" = yes; then + +cat >>confdefs.h <<\_ACEOF +#define ENABLE_X86_RDTSCP 1 +_ACEOF + +fi + # Check whether --enable-bbox was given. if test "${enable_bbox+set}" = set; then enableval=$enable_bbox; diff --git a/src/Makefile.global.in b/src/Makefile.global.in index be525376a7..6030f4e950 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -177,6 +177,7 @@ enable_lite_mode = @enable_lite_mode@ enable_relocation = @enable_relocation@ enable_finance_mode = @enable_finance_mode@ enable_mot = @enable_mot@ +enable_x86_rdtscp = @enable_x86_rdtscp@ enable_bbox = @enable_bbox@ enable_llvm = @enable_llvm@ enable_mysql_fdw = @enable_mysql_fdw@ @@ -763,6 +764,10 @@ ifeq ($(enable_mot), yes) override CPPFLAGS := $(CPPFLAGS) -I$(MASSTREE_INCLUDE_PATH) endif +ifeq ($(enable_x86_rdtscp), yes) + override CPPFLAGS := $(CPPFLAGS) -DENABLE_X86_RDTSCP +endif + ifeq ($(enable_htap), yes) override CPPFLAGS := $(CPPFLAGS) -DENABLE_HTAP endif diff --git a/src/bin/gs_guc/cluster_guc.conf b/src/bin/gs_guc/cluster_guc.conf index 03d9361219..47db8ee804 100755 --- a/src/bin/gs_guc/cluster_guc.conf +++ b/src/bin/gs_guc/cluster_guc.conf @@ -836,6 +836,7 @@ ss_txnstatus_cache_size|int|0,524288|NULL|NULL| subscription_conflict_resolution|enum|error,apply_remote,keep_local|NULL|NULL| time_record_level|int|0,10|NULL|NULL| enable_record_nettime|bool|0,0|NULL|NULL| +enable_mot_server|bool|0,0|NULL|NULL| ss_disaster_mode|enum|single,stream,dorado|NULL|NULL| enable_uwal|bool|0,0|NULL|NULL| uwal_config|string|0,0|NULL|GUC to control paxos cluster| diff --git a/src/common/backend/utils/init/globals.cpp b/src/common/backend/utils/init/globals.cpp index fd8eeb2193..691c2571da 100644 --- a/src/common/backend/utils/init/globals.cpp +++ b/src/common/backend/utils/init/globals.cpp @@ -77,12 +77,13 @@ bool will_shutdown = false; * ********************************************/ -const uint32 GRAND_VERSION_NUM = 93038; +const uint32 GRAND_VERSION_NUM = 93039; /******************************************** * 2.VERSION NUM FOR EACH FEATURE * Please write indescending order. ********************************************/ +const uint32 DISABLE_MOT_ENGINE = 93039; const uint32 ANALYZE_PARTITION_VERSION_NUMBER = 93037; const uint32 NLS_LOWER_VERSION_NUMBER = 93036; const uint32 SUPPORT_D_FORMAT_DATABASE = 93035; diff --git a/src/common/backend/utils/misc/guc.cpp b/src/common/backend/utils/misc/guc.cpp index 40a3100e19..5f89ad0ebe 100755 --- a/src/common/backend/utils/misc/guc.cpp +++ b/src/common/backend/utils/misc/guc.cpp @@ -2154,6 +2154,19 @@ static void InitConfigureNamesBool() NULL, NULL }, + {{"enable_mot_server", + PGC_POSTMASTER, + NODE_SINGLENODE, + DEVELOPER_OPTIONS, + gettext_noop("Enable mot server"), + NULL + }, + &g_instance.attr.attr_common.enable_mot_server, + false, + NULL, + NULL, + NULL + }, {{"foreign_key_checks", PGC_USERSET, NODE_ALL, diff --git a/src/gausskernel/process/postmaster/postmaster.cpp b/src/gausskernel/process/postmaster/postmaster.cpp index 46f4cffb15..92c62ef305 100644 --- a/src/gausskernel/process/postmaster/postmaster.cpp +++ b/src/gausskernel/process/postmaster/postmaster.cpp @@ -3053,7 +3053,9 @@ int PostmasterMain(int argc, char* argv[]) #ifdef ENABLE_MOT /* Initialize the MOT engine */ - InitMOT(); + if (g_instance.attr.attr_common.enable_mot_server) { + InitMOT(); + } #endif /* diff --git a/src/gausskernel/storage/mot/core/infra/synchronization/cycles.h b/src/gausskernel/storage/mot/core/infra/synchronization/cycles.h index 89213af135..6f5e669097 100644 --- a/src/gausskernel/storage/mot/core/infra/synchronization/cycles.h +++ b/src/gausskernel/storage/mot/core/infra/synchronization/cycles.h @@ -67,9 +67,21 @@ public: */ static __inline __attribute__((always_inline)) uint64_t Rdtscp() { + // time statistics: + // rdtsc--10ns + // rtdscp--16ns + // cpuid + rdtsc--981ns + // cpuid--974ns #if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) uint32_t low, high; - __asm__ __volatile__("rdtscp" : "=a"(low), "=d"(high) : : "%rcx"); + #ifdef ENABLE_X86_RDTSCP + __asm__ __volatile__("rdtscp" : "=a"(low), "=d"(high) : : "%rcx"); + #else + __asm__ __volatile__("cpuid\n\t" + "rdtsc\n\t" + : "=a"(low), "=d"(high) + ); + #endif return (((uint64_t)high << 32) | low); #elif defined(__aarch64__) unsigned long cval = 0; diff --git a/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_ctrlfile.cpp b/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_ctrlfile.cpp index 76e5794fc3..e186be39d6 100644 --- a/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_ctrlfile.cpp +++ b/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_ctrlfile.cpp @@ -64,7 +64,7 @@ bool CheckpointControlFile::Init() } do { - if (GetGlobalConfiguration().m_checkpointDir.length() >= CheckpointUtils::MAX_PATH) { + if (GetGlobalConfiguration().m_checkpointDir.length() >= CheckpointUtils::CHECKPOINT_MAX_PATH) { MOT_REPORT_ERROR(MOT_ERROR_INVALID_CFG, "Checkpoint", "Invalid checkpoint_dir configuration, length exceeds max path length"); diff --git a/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_manager.cpp b/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_manager.cpp index 18b39c1b9c..27f4d1ba20 100644 --- a/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_manager.cpp +++ b/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_manager.cpp @@ -660,7 +660,7 @@ void CheckpointManager::RemoveOldCheckpoints(uint64_t curCheckcpointId) void CheckpointManager::RemoveCheckpointDir(uint64_t checkpointId) { errno_t erc; - char buf[CheckpointUtils::MAX_PATH]; + char buf[CheckpointUtils::CHECKPOINT_MAX_PATH]; std::string oldCheckpointDir; if (!CheckpointUtils::SetWorkingDir(oldCheckpointDir, checkpointId)) { MOT_LOG_ERROR("removeCheckpointDir: failed to set working directory"); @@ -677,11 +677,11 @@ void CheckpointManager::RemoveCheckpointDir(uint64_t checkpointId) } struct stat statbuf = {0}; - erc = memset_s(buf, CheckpointUtils::MAX_PATH, 0, CheckpointUtils::MAX_PATH); + erc = memset_s(buf, CheckpointUtils::CHECKPOINT_MAX_PATH, 0, CheckpointUtils::CHECKPOINT_MAX_PATH); securec_check(erc, "\0", "\0"); erc = snprintf_s(buf, - CheckpointUtils::MAX_PATH, - CheckpointUtils::MAX_PATH - 1, + CheckpointUtils::CHECKPOINT_MAX_PATH, + CheckpointUtils::CHECKPOINT_MAX_PATH - 1, "%s/%s", oldCheckpointDir.c_str(), p->d_name); diff --git a/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_utils.cpp b/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_utils.cpp index a1f17fe35f..6b8307f43e 100644 --- a/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_utils.cpp +++ b/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_utils.cpp @@ -124,10 +124,10 @@ bool SeekFile(int fd, off64_t offset) bool GetWorkingDir(std::string& dir) { dir.clear(); - char cwd[MAX_PATH] = {0}; + char cwd[CHECKPOINT_MAX_PATH] = {0}; size_t checkpointDirLength = GetGlobalConfiguration().m_checkpointDir.length(); if (checkpointDirLength > 0) { - errno_t erc = strncpy_s(cwd, MAX_PATH, GetGlobalConfiguration().m_checkpointDir.c_str(), checkpointDirLength); + errno_t erc = strncpy_s(cwd, CHECKPOINT_MAX_PATH, GetGlobalConfiguration().m_checkpointDir.c_str(), checkpointDirLength); securec_check(erc, "\0", "\0"); } else if (!getcwd(cwd, sizeof(cwd))) { MOT_REPORT_SYSTEM_ERROR(getcwd, "N/A", "Failed to get current working directory"); @@ -207,5 +207,83 @@ void Hexdump(const char* msg, char* b, uint32_t buflen) (void)fprintf(stderr, "%s\n", line); } } + +bool CheckMotTable() +{ + MOT_LOG_INFO("start check if there are mot tables"); + + uint64_t m_checkpointId; + if (CheckpointControlFile::GetCtrlFile() == nullptr) { + MOT_LOG_WARN("CheckpointUtils: no ctrl file"); + return false; + } + + if (CheckpointControlFile::GetCtrlFile()->GetMetaVersion() > MetadataProtoVersion::METADATA_VER_CURR) { + MOT_LOG_WARN("CheckpointRecovery: metadata version %u is greater than current %u", + CheckpointControlFile::GetCtrlFile()->GetMetaVersion(), + MetadataProtoVersion::METADATA_VER_CURR); + return false; + } + + if (CheckpointControlFile::GetCtrlFile()->GetId() == CheckpointControlFile::INVALID_ID) { + m_checkpointId = CheckpointControlFile::INVALID_ID; // no mot control was found. + MOT_LOG_WARN("CheckpointUtils: invalid ctrl file id"); + return false; + } else { + m_checkpointId = CheckpointControlFile::GetCtrlFile()->GetId(); + } + + std::string m_workingDir; + if (!CheckpointUtils::SetWorkingDir(m_workingDir, m_checkpointId)) { + MOT_LOG_WARN("CheckpointUtils: failed to obtain checkpoint's working dir"); + return false; + } + + std::string mapFile; + CheckpointUtils::MakeMapFilename(mapFile, m_workingDir, m_checkpointId); + int fd = -1; + if (!CheckpointUtils::OpenFileRead(mapFile, fd)) { + MOT_LOG_WARN("CheckpointUtils: Failed to open map file '%s'", mapFile.c_str()); + return false; + } + + CheckpointUtils::MapFileHeader mapFileHeader; + if (CheckpointUtils::ReadFile(fd, (char*)&mapFileHeader, sizeof(CheckpointUtils::MapFileHeader)) != + sizeof(CheckpointUtils::MapFileHeader)) { + MOT_LOG_WARN("CheckpointUtils: Failed to read map file '%s' header", mapFile.c_str()); + (void)CheckpointUtils::CloseFile(fd); + return false; + } + + if (mapFileHeader.m_magic != CheckpointUtils::HEADER_MAGIC) { + MOT_LOG_WARN("CheckpointUtils: Failed to verify map file'%s'", mapFile.c_str()); + (void)CheckpointUtils::CloseFile(fd); + return false; + } + + CheckpointManager::MapFileEntry entry; + int count = 0; + for (uint64_t i = 0; i < mapFileHeader.m_numEntries; i++) { + if (CheckpointUtils::ReadFile(fd, (char*)&entry, sizeof(CheckpointManager::MapFileEntry)) != + sizeof(CheckpointManager::MapFileEntry)) { + MOT_LOG_WARN("CheckpointUtils: Failed to read map file '%s' entry: %lu", + mapFile.c_str(), + i); + (void)CheckpointUtils::CloseFile(fd); + return false; + } + if (entry.m_maxSegId >= 0) { + MOT_LOG_ERROR("CheckpointUtils: find mot tables when enable_mot_server = off"); + return true; + } + } + + if (CheckpointUtils::CloseFile(fd)) { + MOT_LOG_WARN("CheckpointUtils: Failed to close map file"); + return false; + } + + return false; +} } // namespace CheckpointUtils } // namespace MOT diff --git a/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_utils.h b/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_utils.h index 6e7cd38ac6..97adb96253 100644 --- a/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_utils.h +++ b/src/gausskernel/storage/mot/core/system/checkpoint/checkpoint_utils.h @@ -61,7 +61,7 @@ const char* const IPD_FILE_SUFFIX = ".ptd"; const char* const END_FILE_SUFFIX = ".end"; // Max path length -const size_t MAX_PATH = 1024; +const size_t CHECKPOINT_MAX_PATH = 1024; /** * @brief A wrapper function that checks if a file exists @@ -70,6 +70,7 @@ const size_t MAX_PATH = 1024; */ bool IsFileExists(const std::string& fileName); +bool CheckMotTable(); /** * @brief A wrapper function that checks if a dir exists * @param fileName The directory name to check diff --git a/src/gausskernel/storage/mot/fdw_adapter/mot_fdw.cpp b/src/gausskernel/storage/mot/fdw_adapter/mot_fdw.cpp index 5bdf0a0c5e..f926271317 100644 --- a/src/gausskernel/storage/mot/fdw_adapter/mot_fdw.cpp +++ b/src/gausskernel/storage/mot/fdw_adapter/mot_fdw.cpp @@ -77,6 +77,7 @@ #include "table.h" #include "txn.h" #include "checkpoint_manager.h" +#include "checkpoint_utils.h" #include #include "redo_log_handler_type.h" #include "ext_config_loader.h" @@ -171,6 +172,14 @@ static void InitMOTHandler(); void MOTRecover() { + if (!g_instance.attr.attr_common.enable_mot_server) { + bool hasMotTable = MOT::CheckpointUtils::CheckMotTable(); + if (hasMotTable) { + ereport(FATAL, (errmsg("find exist mot tables when enable_mot_server = off, " + "please set enable_mot_server = on to start"))); + } + } + if (!MOTAdaptor::m_initialized) { // This is the case when StartupXLOG is called during bootstrap. return; @@ -246,6 +255,17 @@ void InitMOT() (void)JitExec::JitInitialize(); } +/** + * Check if mot server is enable + */ +void MOTCheckIsEnable() +{ + if (!g_instance.attr.attr_common.enable_mot_server) { + ereport(ERROR, (errmsg("MOT engine is not initialized"), + errhint("Set enable_mot_server = on to initialize mot engine"))); + } +} + /* * Shutdown the engine. */ @@ -295,7 +315,7 @@ Datum mot_fdw_handler(PG_FUNCTION_ARGS) fdwroutine->GetForeignSessionMemSize = MOTGetForeignSessionMemSize; fdwroutine->NotifyForeignConfigChange = MOTNotifyForeignConfigChange; - if (!u_sess->mot_cxt.callbacks_set) { + if (!u_sess->mot_cxt.callbacks_set && g_instance.attr.attr_common.enable_mot_server) { RegisterXactCallback(MOTXactCallback, NULL); RegisterSubXactCallback(MOTSubxactCallback, NULL); u_sess->mot_cxt.callbacks_set = true; diff --git a/src/gausskernel/storage/mot/fdw_adapter/mot_fdw_xlog.cpp b/src/gausskernel/storage/mot/fdw_adapter/mot_fdw_xlog.cpp index 1bdc248ae8..f2d9967674 100644 --- a/src/gausskernel/storage/mot/fdw_adapter/mot_fdw_xlog.cpp +++ b/src/gausskernel/storage/mot/fdw_adapter/mot_fdw_xlog.cpp @@ -69,6 +69,10 @@ void MOTRedo(XLogReaderState* record) if (!IsValidEntry(recordType)) { elog(ERROR, "MOTRedo: invalid op code %" PRIu8, recordType); } + if (!g_instance.attr.attr_common.enable_mot_server) { + ereport(FATAL, (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("Could not redo MOT tables when enable_mot_server = off."))); + } if (MOT::GetRecoveryManager()->IsErrorSet() || !MOT::GetRecoveryManager()->ApplyRedoLog(lsn, data, len)) { // we treat errors fatally. ereport(FATAL, (errcode(ERRCODE_INTERNAL_ERROR), errmsg("MOT recovery failed."))); diff --git a/src/gausskernel/storage/mot/fdw_adapter/mot_internal.cpp b/src/gausskernel/storage/mot/fdw_adapter/mot_internal.cpp index 28005612a2..da7cc81d07 100644 --- a/src/gausskernel/storage/mot/fdw_adapter/mot_internal.cpp +++ b/src/gausskernel/storage/mot/fdw_adapter/mot_internal.cpp @@ -43,6 +43,7 @@ #include "utils/date.h" #include "mot_internal.h" +#include "storage/mot/mot_fdw.h" #include "mot_fdw_helpers.h" #include "row.h" #include "log_statistics.h" @@ -79,6 +80,7 @@ static inline bool EnsureSafeThreadAccessInline(bool throwError = true) if (MOTCurrThreadId == INVALID_THREAD_ID) { MOT_LOG_DEBUG("Initializing safe thread access for current thread"); if (MOT::AllocThreadId() == INVALID_THREAD_ID) { + MOTCheckIsEnable(); MOT_LOG_ERROR("Failed to allocate thread identifier"); if (throwError) { ereport(ERROR, (errmodule(MOD_MOT), errmsg("Failed to allocate thread identifier"))); @@ -274,6 +276,7 @@ MOT::TxnManager* MOTAdaptor::InitTxnManager( bool attachCleanFunc = (MOTCurrThreadId == INVALID_THREAD_ID ? true : !g_instance.attr.attr_common.enable_thread_pool); + MOTCheckIsEnable(); // First time we handle this connection if (m_engine == nullptr) { elog(ERROR, "initTxnManager: MOT engine is not initialized"); diff --git a/src/include/knl/knl_guc/knl_instance_attr_common.h b/src/include/knl/knl_guc/knl_instance_attr_common.h index 35f1e93701..991eebd5c3 100644 --- a/src/include/knl/knl_guc/knl_instance_attr_common.h +++ b/src/include/knl/knl_guc/knl_instance_attr_common.h @@ -106,6 +106,7 @@ typedef struct knl_instance_attr_common { bool light_comm; bool enable_expr_fusion; bool enable_default_index_deduplication; + bool enable_mot_server; } knl_instance_attr_common; #endif /* SRC_INCLUDE_KNL_KNL_INSTANCE_ATTR_COMMON_H_ */ diff --git a/src/include/storage/mot/mot_fdw.h b/src/include/storage/mot/mot_fdw.h index 446d864ae4..ddd7a78b86 100644 --- a/src/include/storage/mot/mot_fdw.h +++ b/src/include/storage/mot/mot_fdw.h @@ -32,6 +32,9 @@ /** @brief Initializes MOT engine. */ extern void InitMOT(); +/** @brief Check if mot server is enable. */ +extern void MOTCheckIsEnable(); + /** @brief Shutdown the MOT engine. */ extern void TermMOT(); diff --git a/src/test/regress/expected/mot/disable_mot.out b/src/test/regress/expected/mot/disable_mot.out new file mode 100644 index 0000000000..1dd39a8cbc --- /dev/null +++ b/src/test/regress/expected/mot/disable_mot.out @@ -0,0 +1,178 @@ +show enable_mot_server; + enable_mot_server +------------------- + off +(1 row) + +set enable_mot_server = on; +ERROR: parameter "enable_mot_server" cannot be changed without restarting the server +set enable_mot_server = off; +ERROR: parameter "enable_mot_server" cannot be changed without restarting the server +drop user if exists test_mot; +create user test_mot password 'Test@123'; +grant all privileges to test_mot; +set session authorization test_mot password 'Test@123'; +drop schema if exists disable_mot_test cascade; +NOTICE: schema "disable_mot_test" does not exist, skipping +create schema disable_mot_test; +set current_schema to disable_mot_test; +\dt + List of relations + Schema | Name | Type | Owner | Storage +--------+------+------+-------+--------- +(0 rows) + +create foreign table test(x int) server mot_server; +ERROR: MOT engine is not initialized +HINT: Set enable_mot_server = on to initialize mot engine +create foreign table test1(id int); +ERROR: MOT engine is not initialized +HINT: Set enable_mot_server = on to initialize mot engine +drop foreign table test; +ERROR: foreign table "test" does not exist +drop foreign table test1; +ERROR: foreign table "test1" does not exist +\dt + List of relations + Schema | Name | Type | Owner | Storage +--------+------+------+-------+--------- +(0 rows) + +create table test1(id int); +create view test_view as select * from test1; +insert into test1 values(1),(2),(3); +select * from test1; + id +---- + 1 + 2 + 3 +(3 rows) + +select * from test_view; + id +---- + 1 + 2 + 3 +(3 rows) + +begin; +insert into test1 values(4),(5),(6); +select * from test1; + id +---- + 1 + 2 + 3 + 4 + 5 + 6 +(6 rows) + +select * from test_view; + id +---- + 1 + 2 + 3 + 4 + 5 + 6 +(6 rows) + +commit; +select * from test1; + id +---- + 1 + 2 + 3 + 4 + 5 + 6 +(6 rows) + +select * from test_view; + id +---- + 1 + 2 + 3 + 4 + 5 + 6 +(6 rows) + +begin; +insert into test1 values(7),(8),(9); +select * from test1; + id +---- + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +(9 rows) + +select * from test_view; + id +---- + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 +(9 rows) + +rollback; +select * from test1; + id +---- + 1 + 2 + 3 + 4 + 5 + 6 +(6 rows) + +select * from test_view; + id +---- + 1 + 2 + 3 + 4 + 5 + 6 +(6 rows) + +\dt + List of relations + Schema | Name | Type | Owner | Storage +----------+-------+-------+----------+---------------------------------- + test_mot | test1 | table | test_mot | {orientation=row,compression=no} +(1 row) + +select name, setting, category, short_desc, extra_desc, context, vartype, boot_val, reset_val from pg_settings where name = 'enable_mot_server'; + name | setting | category | short_desc | extra_desc | context | vartype | boot_val | reset_val +-------------------+---------+-------------------+-------------------+------------+------------+---------+----------+----------- + enable_mot_server | off | Developer Options | Enable mot server | | postmaster | bool | off | off +(1 row) + +drop table test1; +drop view test_view; +drop schema disable_mot_test cascade; +drop schema test_mot_cascade; +\c postgres +drop user test_mot; diff --git a/src/test/regress/make_fastcheck_single_mot_postgresql.conf b/src/test/regress/make_fastcheck_single_mot_postgresql.conf index 6211f2546a..353e29ad8a 100644 --- a/src/test/regress/make_fastcheck_single_mot_postgresql.conf +++ b/src/test/regress/make_fastcheck_single_mot_postgresql.conf @@ -29,3 +29,4 @@ enable_incremental_checkpoint = false enable_double_write = off password_encryption_type = 1 enable_global_syscache = on +enable_mot_server=on diff --git a/src/test/regress/parallel_schedule0A b/src/test/regress/parallel_schedule0A index 66c25f3ace..1ab172ccdd 100644 --- a/src/test/regress/parallel_schedule0A +++ b/src/test/regress/parallel_schedule0A @@ -484,7 +484,7 @@ test: holdable_cursor cursor_expression cursor_expression_dump test: test_float test_numeric_with_neg_scale test_float_dump # test for tid range scan -test: tidrangescan +# test: tidrangescan test: alter_table_000 alter_table_002 alter_table_003 alter_table_modify #test: alter_table_001 alter_table_modify_ustore @@ -516,3 +516,6 @@ test: gs_dump_2hash # test backup tool audit log test: backup_tool_audit test: extra_float_digits + +# test disable mot +# test: mot/disable_mot \ No newline at end of file diff --git a/src/test/regress/sql/mot/disable_mot.sql b/src/test/regress/sql/mot/disable_mot.sql new file mode 100644 index 0000000000..1fed7419f4 --- /dev/null +++ b/src/test/regress/sql/mot/disable_mot.sql @@ -0,0 +1,134 @@ +--guc param +show enable_mot_server; +set enable_mot_server = on; +set enable_mot_server = off; +select name, setting, category, short_desc, extra_desc, context, vartype, boot_val, reset_val from pg_settings where name = 'enable_mot_server'; +-- pre-operation, create user and schema +drop user if exists test_mot; +create user test_mot password 'Test@123'; +GRANT USAGE ON FOREIGN SERVER mot_server TO test_mot; +grant all privileges to test_mot; +set session authorization test_mot password 'Test@123'; +create database disable_mot; +\c disable_mot; +drop schema if exists disable_mot_test cascade; +create schema disable_mot_test; +set current_schema to disable_mot_test; +\dt +-- create server +create server my_server foreign data wrapper log_fdw; +drop server my_server; +create server my_server1 foreign data wrapper mot_fdw; +drop server my_server1; +-- create object +create table test_table(id int); +create foreign table test(id int) server mot_server; +insert into test values(1),(2),(3); +update test set id = 5 where id = 3; +select * from test; +delete from test; +prepare pre1 as select * from test; +prepare pre2 as insert into test values(1); +prepare pre3 as delete from test; +prepare pre4 as update test set id = 6; +prepare pre5 as insert into test values($1); +execute pre1; +execute pre2; +execute pre1; +execute pre3; +execute pre1; +insert into test values(1),(2),(3); +execute pre1; +execute pre4; +execute pre1; +execute pre5(8); +execute pre1; +create view test_view as select * from test; +select * from test_view; +insert into test values(1),(2),(3); +select * from test; +explain select * from test; +vacuum test; +analyze test; +analyse test; +truncate table test; +alter foreign table test rename to test_mot_table; +create foreign table test1(id int); +create foreign table test2(id int primary key); +create foreign table bmsql_oorder ( + o_w_id integer not null, + o_d_id integer not null, + o_id integer not null, + o_c_id integer not null, + o_carrier_id integer, + o_ol_cnt integer, + o_all_local integer, + o_entry_d timestamp, + primary key (o_w_id, o_d_id, o_id) +); +create index bmsql_oorder_index1 on bmsql_oorder(o_w_id, o_d_id, o_c_id, o_id); +drop view test_view; +drop foreign table test; +drop foreign table test1; +drop foreign table test2; +drop foreign table bmsql_oorder; +\dt +create table test1(id int); +create view test_view1 as select * from test1; +insert into test1 values(1),(2),(3); +select * from test1; +select * from test_view1; +begin; +insert into test1 values(4),(5),(6); +select * from test1; +select * from test_view1; +commit; +select * from test1; +select * from test_view1; +begin; +insert into test1 values(7),(8),(9); +select * from test1; +select * from test_view1; +rollback; +select * from test1; +select * from test_view1; +\dt +CREATE foreign TABLE grade +( + number INTEGER, + name CHAR(20), + class CHAR(20), + grade INTEGER +); +-- procedure +CREATE PROCEDURE insert_data1(param1 INT = 0, param2 CHAR(20), param3 CHAR(20), param4 INT = 0) +IS + BEGIN + INSERT INTO grade VALUES(param1, param2, param3, param4); +END; +/ +CALL insert_data1(param1:=210101, param2:='Alan', param3:='21.01', param4:=92); +select * from grade; +DROP PROCEDURE insert_data1; +drop foreign table grade; +-- system tables +select extname from pg_extension where extname = 'mot_fdw'; +select * from pg_foreign_table; +select * from pg_foreign_server; +select * from pg_foreign_data_wrapper; +-- system functions +select * from mot_global_memory_detail(); +select * from mot_jit_detail(); +select * from mot_jit_profile(); +select * from mot_local_memory_detail(); +select * from mot_session_memory_detail(); +-- post-operation, clean +drop table test_table; +drop table test1; +drop view test_view1; +drop schema disable_mot_test cascade; +\c postgres +revoke USAGE ON FOREIGN SERVER mot_server from test_mot; +drop schema test_mot cascade; +drop database disable_mot; +drop user test_mot; -- Gitee From 7e79432cd5b409d23025bf9d25bc433c7e5cc1e4 Mon Sep 17 00:00:00 2001 From: douxin Date: Thu, 20 Feb 2025 00:38:35 +0800 Subject: [PATCH 2/2] fix core --- .../mot/core/infra/synchronization/cycles.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/gausskernel/storage/mot/core/infra/synchronization/cycles.h b/src/gausskernel/storage/mot/core/infra/synchronization/cycles.h index 6f5e669097..c10fe88a0b 100644 --- a/src/gausskernel/storage/mot/core/infra/synchronization/cycles.h +++ b/src/gausskernel/storage/mot/core/infra/synchronization/cycles.h @@ -74,14 +74,15 @@ public: // cpuid--974ns #if defined(__GNUC__) && (defined(__x86_64__) || defined(__i386__)) uint32_t low, high; - #ifdef ENABLE_X86_RDTSCP - __asm__ __volatile__("rdtscp" : "=a"(low), "=d"(high) : : "%rcx"); - #else - __asm__ __volatile__("cpuid\n\t" - "rdtsc\n\t" - : "=a"(low), "=d"(high) - ); - #endif + __asm__ __volatile__("rdtscp" : "=a"(low), "=d"(high) : : "%rcx"); + // #ifdef ENABLE_X86_RDTSCP + // __asm__ __volatile__("rdtscp" : "=a"(low), "=d"(high) : : "%rcx"); + // #else + // __asm__ __volatile__("cpuid\n\t" + // "rdtsc\n\t" + // : "=a"(low), "=d"(high) + // ); + // #endif return (((uint64_t)high << 32) | low); #elif defined(__aarch64__) unsigned long cval = 0; -- Gitee