From 7715f3baac947aec51f57211e69fb76be91c663e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=BE=BE=E6=A0=87?= <848833284@qq.com> Date: Thu, 6 Jun 2024 12:53:00 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=A7=86=E5=9B=BE=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=8D=87=E7=BA=A7=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/catalog/builtin_funcs.ini | 2 +- src/common/backend/utils/init/globals.cpp | 2 +- .../storage/access/common/reloptions.cpp | 20 ++++++++++++++++++ .../storage/access/ustore/knl_uundorecord.cpp | 3 ++- .../access/ustore/undo/knl_uundoapi.cpp | 21 +++++++++++++++++++ src/gausskernel/storage/lmgr/lwlock.cpp | 1 + src/include/access/tableam.h | 2 +- src/include/access/ustore/undo/knl_uundoapi.h | 1 + .../rollback-post_catalog_maindb_92_935.sql | 7 +++++++ .../rollback-post_catalog_otherdb_92_935.sql | 7 +++++++ .../upgrade-post_catalog_maindb_92_935.sql | 16 ++++++++++++++ .../upgrade-post_catalog_otherdb_92_935.sql | 16 ++++++++++++++ 12 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback-post_catalog_maindb_92_935.sql create mode 100644 src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback-post_catalog_otherdb_92_935.sql create mode 100644 src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade-post_catalog_maindb_92_935.sql create mode 100644 src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade-post_catalog_otherdb_92_935.sql diff --git a/src/common/backend/catalog/builtin_funcs.ini b/src/common/backend/catalog/builtin_funcs.ini index cb68399b3..0a6a555e4 100644 --- a/src/common/backend/catalog/builtin_funcs.ini +++ b/src/common/backend/catalog/builtin_funcs.ini @@ -3947,7 +3947,7 @@ ), AddFuncGroup( "gs_stat_undo", 1, - AddBuiltinFunc(_0(4434), _1("gs_stat_undo"), _2(0), _3(false), _4(true), _5(gs_stat_undo), _6(2249), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(1), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(0), _21(10, 23, 25, 23, 23, 28, 28, 20, 20, 23, 23), _22(10, 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(10, "curr_used_zone_count", "top_used_zones", "curr_used_undo_size", "undo_threshold", "global_recycle_xid", "oldest_xmin", "total_undo_chain_len", "max_undo_chain_len", "create_undo_file_count", "discard_undo_file_count"), _24(NULL), _25("gs_stat_undo"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(NULL), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)) + AddBuiltinFunc(_0(4434), _1("gs_stat_undo"), _2(0), _3(false), _4(true), _5(gs_stat_undo), _6(2249), _7(PG_CATALOG_NAMESPACE), _8(BOOTSTRAP_SUPERUSERID), _9(INTERNALlanguageId), _10(1), _11(1), _12(0), _13(0), _14(false), _15(false), _16(false), _17(false), _18('s'), _19(0), _20(0), _21(10, 23, 25, 23, 23, 28, 28, 20, 20, 23, 23), _22(10, 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'), _23(10, "curr_used_zone_count", "top_used_zones", "curr_used_undo_size", "undo_threshold", "global_recycle_xid", "oldest_xmin", "total_undo_chain_len", "max_undo_chain_len", "create_undo_file_count", "discard_undo_file_count"), _24(NULL), _25("gs_stat_undo"), _26(NULL), _27(NULL), _28(NULL), _29(0), _30(false), _31(false), _32(false), _33(NULL), _34('f'), _35(NULL), _36(0), _37(false), _38(NULL), _39(NULL), _40(0)) ), AddFuncGroup( "gs_undo_translot", 1, diff --git a/src/common/backend/utils/init/globals.cpp b/src/common/backend/utils/init/globals.cpp index fd64ddbea..2304425c6 100644 --- a/src/common/backend/utils/init/globals.cpp +++ b/src/common/backend/utils/init/globals.cpp @@ -75,7 +75,7 @@ bool will_shutdown = false; * NEXT | 92899 | ? | ? * ********************************************/ -const uint32 GRAND_VERSION_NUM = 92934; +const uint32 GRAND_VERSION_NUM = 92935; /******************************************** * 2.VERSION NUM FOR EACH FEATURE diff --git a/src/gausskernel/storage/access/common/reloptions.cpp b/src/gausskernel/storage/access/common/reloptions.cpp index 69578eb4c..98cc0dc3d 100644 --- a/src/gausskernel/storage/access/common/reloptions.cpp +++ b/src/gausskernel/storage/access/common/reloptions.cpp @@ -904,6 +904,7 @@ Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, * doesn't enforce it.) */ const char *storageType = NULL; + const char *toastStorageType = NULL; bool toastStorageTypeSet = false; foreach (cell, defList) { DefElem *def = (DefElem *)lfirst(cell); @@ -954,6 +955,9 @@ Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, continue; } else if (pg_strcasecmp(def->defnamespace, namspace) != 0) { continue; + } else { + toastStorageType = ((def->arg != NULL) ? defGetString(def) : NULL); + continue; } toastStorageTypeSet = true; /* toast table set the storage type itself */ } else if (def->defnamespace == NULL) @@ -981,6 +985,22 @@ Datum transformRelOptions(Datum oldOptions, List *defList, const char *namspace, } } + if (namspace != NULL && pg_strcasecmp(namspace, "toast") == 0 && toastStorageType != NULL) { + const char *actualStorageType = NULL; + if (storageType == NULL) { + actualStorageType = u_sess->attr.attr_sql.enable_default_ustore_table ? "ustore" : "astore"; + } else { + actualStorageType = storageType; + } + + if (pg_strcasecmp(actualStorageType, "astore") == 0 || pg_strcasecmp(actualStorageType, "ustore") == 0) { + if (pg_strcasecmp(actualStorageType, toastStorageType) != 0) { + ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("toast cannot be set for %s with storage_type=%s", actualStorageType, toastStorageType))); + } + } + } + /* we did not specify a storage type for toast, so use the same storage type as its parent */ if (namspace != NULL && pg_strcasecmp(namspace, "toast") == 0 && !toastStorageTypeSet) { if (storageType != NULL) { diff --git a/src/gausskernel/storage/access/ustore/knl_uundorecord.cpp b/src/gausskernel/storage/access/ustore/knl_uundorecord.cpp index 6be81451e..e822693e2 100644 --- a/src/gausskernel/storage/access/ustore/knl_uundorecord.cpp +++ b/src/gausskernel/storage/access/ustore/knl_uundorecord.cpp @@ -364,7 +364,8 @@ void UndoRecord::Load(bool keepBuffer) Page page = BufferGetPage(buffer); BufferDesc *bufDesc = GetBufferDescriptor(buffer - 1); if (bufDesc->tag.blockNum != blk || bufDesc->tag.rnode.dbNode != UNDO_DB_OID || - bufDesc->tag.rnode.relNode != (Oid)zoneId) { + bufDesc->tag.rnode.relNode != (Oid)zoneId || + (!PageIsNew(page) && PageGetPageLayoutVersion(page) != PG_COMM_PAGE_LAYOUT_VERSION)) { ereport(PANIC, (errmsg(UNDOFORMAT("undo buffer desc invalid, bufdesc: dbid=%u, relid=%u, blockno=%u. " "expect: dbid=%u, zoneid=%u, blockno=%u."), diff --git a/src/gausskernel/storage/access/ustore/undo/knl_uundoapi.cpp b/src/gausskernel/storage/access/ustore/undo/knl_uundoapi.cpp index 550e5c179..2247b3beb 100644 --- a/src/gausskernel/storage/access/ustore/undo/knl_uundoapi.cpp +++ b/src/gausskernel/storage/access/ustore/undo/knl_uundoapi.cpp @@ -785,4 +785,25 @@ void ReleaseSlotBuffer() PG_END_TRY(); } } + +void initUndoZoneLock() +{ + if (g_instance.undo_cxt.uZones != NULL) { + int persistZoneCount = PERSIST_ZONE_COUNT; + for (int persist = (int)UNDO_PERMANENT; persist <= (int)UNDO_TEMP; persist++) { + CHECK_FOR_INTERRUPTS(); + for (auto idx = 0; idx < persistZoneCount; idx++) { + CHECK_FOR_INTERRUPTS(); + int zoneId = (int)(idx + persist * PERSIST_ZONE_COUNT); + UndoZone *uzone = (UndoZone *)g_instance.undo_cxt.uZones[zoneId]; + if (uzone == NULL) { + break; + } + uzone->InitLock(); + uzone->GetUndoSpace()->LockInit(); + uzone->GetSlotSpace()->LockInit(); + } + } + } +} } // namespace undo diff --git a/src/gausskernel/storage/lmgr/lwlock.cpp b/src/gausskernel/storage/lmgr/lwlock.cpp index 007f934ac..14722b4ad 100644 --- a/src/gausskernel/storage/lmgr/lwlock.cpp +++ b/src/gausskernel/storage/lmgr/lwlock.cpp @@ -681,6 +681,7 @@ static void InitializeLWLocks(int numLocks) for (id = NumFixedLWLocks; id < numLocks; id++, lock++) { LWLockInitialize(&lock->lock, LWTRANCHE_UNKNOWN); } + undo::initUndoZoneLock(); } const char *GetBuiltInTrancheName(int trancheId) diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h index 560596c7e..bbc052fb2 100644 --- a/src/include/access/tableam.h +++ b/src/include/access/tableam.h @@ -906,7 +906,7 @@ static inline void tableam_tuple_abort_speculative(Relation relation, Tuple tupl static inline bool tableam_tuple_check_compress(Relation relation, Tuple tuple) { - relation->rd_tam_ops->tuple_check_compress(tuple); + return relation->rd_tam_ops->tuple_check_compress(tuple); } /* ----------------------------------------------------------------------- diff --git a/src/include/access/ustore/undo/knl_uundoapi.h b/src/include/access/ustore/undo/knl_uundoapi.h index 9559c26d2..de7e8b438 100644 --- a/src/include/access/ustore/undo/knl_uundoapi.h +++ b/src/include/access/ustore/undo/knl_uundoapi.h @@ -65,6 +65,7 @@ void ReleaseSlotBuffer(); void InitUndoCountThreshold(); void RebuildUndoZoneBitmap(); UndoRecPtr GetPrevUrp(UndoRecPtr currUrp); +void initUndoZoneLock(); } // namespace undo extern void GetUndoFileDirectory(char *path, int len, UndoPersistence upersistence); diff --git a/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback-post_catalog_maindb_92_935.sql b/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback-post_catalog_maindb_92_935.sql new file mode 100644 index 000000000..159ef88a4 --- /dev/null +++ b/src/include/catalog/upgrade_sql/rollback_catalog_maindb/rollback-post_catalog_maindb_92_935.sql @@ -0,0 +1,7 @@ +/*------ add sys fuction gs_stat_undo ------*/ +DROP FUNCTION IF EXISTS pg_catalog.gs_stat_undo(); +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 4434; +CREATE FUNCTION pg_catalog.gs_stat_undo(OUT curr_used_zone_count int4, OUT top_used_zones text, OUT curr_used_undo_size int4, +OUT undo_threshold int4, OUT oldest_xid_in_undo oid, OUT oldest_xmin oid, OUT total_undo_chain_len oid, OUT max_undo_chain_len oid, +OUT create_undo_file_count int4, OUT discard_undo_file_count int4) +RETURNS record LANGUAGE INTERNAL as 'gs_stat_undo'; \ No newline at end of file diff --git a/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback-post_catalog_otherdb_92_935.sql b/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback-post_catalog_otherdb_92_935.sql new file mode 100644 index 000000000..159ef88a4 --- /dev/null +++ b/src/include/catalog/upgrade_sql/rollback_catalog_otherdb/rollback-post_catalog_otherdb_92_935.sql @@ -0,0 +1,7 @@ +/*------ add sys fuction gs_stat_undo ------*/ +DROP FUNCTION IF EXISTS pg_catalog.gs_stat_undo(); +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 4434; +CREATE FUNCTION pg_catalog.gs_stat_undo(OUT curr_used_zone_count int4, OUT top_used_zones text, OUT curr_used_undo_size int4, +OUT undo_threshold int4, OUT oldest_xid_in_undo oid, OUT oldest_xmin oid, OUT total_undo_chain_len oid, OUT max_undo_chain_len oid, +OUT create_undo_file_count int4, OUT discard_undo_file_count int4) +RETURNS record LANGUAGE INTERNAL as 'gs_stat_undo'; \ No newline at end of file diff --git a/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade-post_catalog_maindb_92_935.sql b/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade-post_catalog_maindb_92_935.sql new file mode 100644 index 000000000..08fa0111b --- /dev/null +++ b/src/include/catalog/upgrade_sql/upgrade_catalog_maindb/upgrade-post_catalog_maindb_92_935.sql @@ -0,0 +1,16 @@ +/*------ add sys fuction gs_stat_undo ------*/ +DROP FUNCTION IF EXISTS pg_catalog.gs_stat_undo(); +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 4434; +CREATE FUNCTION pg_catalog.gs_stat_undo( + OUT curr_used_zone_count int4, + OUT top_used_zones text, + OUT curr_used_undo_size int4, + OUT undo_threshold int4, + OUT global_recycle_xid xid, + OUT oldest_xmin xid, + OUT total_undo_chain_len int8, + OUT max_undo_chain_len int8, + OUT create_undo_file_count int4, + OUT discard_undo_file_count int4) +RETURNS SETOF record +LANGUAGE INTERNAL STABLE NOT SHIPPABLE ROWS 1 as 'gs_stat_undo'; \ No newline at end of file diff --git a/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade-post_catalog_otherdb_92_935.sql b/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade-post_catalog_otherdb_92_935.sql new file mode 100644 index 000000000..08fa0111b --- /dev/null +++ b/src/include/catalog/upgrade_sql/upgrade_catalog_otherdb/upgrade-post_catalog_otherdb_92_935.sql @@ -0,0 +1,16 @@ +/*------ add sys fuction gs_stat_undo ------*/ +DROP FUNCTION IF EXISTS pg_catalog.gs_stat_undo(); +SET LOCAL inplace_upgrade_next_system_object_oids = IUO_PROC, 4434; +CREATE FUNCTION pg_catalog.gs_stat_undo( + OUT curr_used_zone_count int4, + OUT top_used_zones text, + OUT curr_used_undo_size int4, + OUT undo_threshold int4, + OUT global_recycle_xid xid, + OUT oldest_xmin xid, + OUT total_undo_chain_len int8, + OUT max_undo_chain_len int8, + OUT create_undo_file_count int4, + OUT discard_undo_file_count int4) +RETURNS SETOF record +LANGUAGE INTERNAL STABLE NOT SHIPPABLE ROWS 1 as 'gs_stat_undo'; \ No newline at end of file