From 64fe87bdb10168d8e4fb55c565519377eb0e4ee8 Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Mon, 2 Jun 2025 19:50:00 +0000 Subject: [PATCH 1/7] Add aux mirror --- .../gp_aux_catalog--1.0--1.1.sql | 8 +++ gpcontrib/gp_aux_catalog/gp_aux_catalog.c | 50 ++++++++++++++++++- src/backend/utils/gp/segadmin.c | 13 ++++- src/include/catalog/gp_segment_config.h | 1 + src/include/utils/builtins.h | 4 ++ 5 files changed, 73 insertions(+), 3 deletions(-) diff --git a/gpcontrib/gp_aux_catalog/gp_aux_catalog--1.0--1.1.sql b/gpcontrib/gp_aux_catalog/gp_aux_catalog--1.0--1.1.sql index 552edc953ec..ae69ca21f6b 100644 --- a/gpcontrib/gp_aux_catalog/gp_aux_catalog--1.0--1.1.sql +++ b/gpcontrib/gp_aux_catalog/gp_aux_catalog--1.0--1.1.sql @@ -23,3 +23,11 @@ SELECT gpdb_binary_upgrade_catalog_1_0_to_1_1_m(); DROP FUNCTION gpdb_binary_upgrade_catalog_1_0_to_1_1_seg(); DROP FUNCTION gpdb_binary_upgrade_catalog_1_0_to_1_1_m(); + +CREATE OR REPLACE FUNCTION +gp_add_segment_aux_mirror(int2, text, text, int4, text) +RETURNS int2 +AS 'MODULE_PATHNAME' +VOLATILE +EXECUTE ON MASTER +LANGUAGE C STRICT; diff --git a/gpcontrib/gp_aux_catalog/gp_aux_catalog.c b/gpcontrib/gp_aux_catalog/gp_aux_catalog.c index b67a312e189..e8bcda83d7b 100644 --- a/gpcontrib/gp_aux_catalog/gp_aux_catalog.c +++ b/gpcontrib/gp_aux_catalog/gp_aux_catalog.c @@ -3,6 +3,7 @@ #include "catalog/indexing.h" #include "utils/builtins.h" +<<<<<<< HEAD #include "utils/fmgroids.h" #include "access/heapam.h" #include "catalog/pg_proc.h" @@ -16,6 +17,11 @@ #include "catalog/pg_amop.h" #include "access/htup_details.h" #include "../backend/commands/analyzefuncs.c" +======= + +#include "cdb/cdbutil.h" + +>>>>>>> c97cd21a41 (Add aux mirror) PG_MODULE_MAGIC; void _PG_init(void); @@ -43,6 +49,7 @@ pg_event_trigger_table_rewrite_reason(PG_FUNCTION_ARGS) return pg_event_trigger_table_rewrite_reason_internal(fcinfo); } +<<<<<<< HEAD static void gpdb_binary_upgrade_insert_pro_tup( Relation rel, @@ -167,4 +174,45 @@ gp_acquire_sample_rows_vac(PG_FUNCTION_ARGS) bool inherited = PG_GETARG_BOOL(2); int32 vacopts = PG_GETARG_INT32(3); return gp_acquire_sample_rows_int(fcinfo,relOid,targrows,inherited,vacopts); -} \ No newline at end of file +} + +Datum +gp_add_segment_aux_mirror(PG_FUNCTION_ARGS) +{ + GpSegConfigEntry new; + + if (PG_ARGISNULL(0)) + elog(ERROR, "contentid cannot be NULL"); + new.segindex = PG_GETARG_INT16(0); + + if (PG_ARGISNULL(1)) + elog(ERROR, "hostname cannot be NULL"); + new.hostname = TextDatumGetCString(PG_GETARG_DATUM(1)); + + if (PG_ARGISNULL(2)) + elog(ERROR, "address cannot be NULL"); + new.address = TextDatumGetCString(PG_GETARG_DATUM(2)); + + if (PG_ARGISNULL(3)) + elog(ERROR, "port cannot be NULL"); + new.port = PG_GETARG_INT32(3); + + if (PG_ARGISNULL(4)) + elog(ERROR, "datadir cannot be NULL"); + new.datadir = TextDatumGetCString(PG_GETARG_DATUM(4)); + +/* XXX: todo - check + mirroring_sanity_check(MASTER_ONLY | SUPERUSER, "gp_add_segment_aux_mirror"); +*/ + + + new.dbid = get_availableDbId(); + new.mode = GP_SEGMENT_CONFIGURATION_MODE_NOTINSYNC; + new.status = GP_SEGMENT_CONFIGURATION_STATUS_DOWN; + new.role = GP_SEGMENT_CONFIGURATION_ROLE_AUX_MIRROR; + new.preferred_role = GP_SEGMENT_CONFIGURATION_ROLE_AUX_MIRROR; + + add_segment(&new); + + PG_RETURN_INT16(new.dbid); +} diff --git a/src/backend/utils/gp/segadmin.c b/src/backend/utils/gp/segadmin.c index 4cd7c4aaad7..40f993cbafc 100644 --- a/src/backend/utils/gp/segadmin.c +++ b/src/backend/utils/gp/segadmin.c @@ -52,6 +52,15 @@ content_get_mirror_dbid(int16 contentid) * preferred, role */ ); } +/* Convenience routine to look up the mirror for a given segment index */ +static int16 +content_get_query_aux_mirror_dbid(int16 contentid) +{ + return contentid_get_dbid(contentid, GP_SEGMENT_CONFIGURATION_ROLE_AUX_MIRROR, false /* false == current, not + * preferred, role */ ); +} + + /* Tell the caller whether a mirror exists at a given segment index */ static bool segment_has_mirror(int16 contentid) @@ -110,7 +119,7 @@ get_maxdbid() * gp_segment_configuration to prevent races but no one should be calling * this code concurrently if we've done our job right. */ -static int16 +int16 get_availableDbId() { /* @@ -320,7 +329,7 @@ remove_segment_config(int16 dbid) heap_close(rel, NoLock); } -static void +void add_segment(GpSegConfigEntry *new_segment_information) { int16 primary_dbid = new_segment_information->dbid; diff --git a/src/include/catalog/gp_segment_config.h b/src/include/catalog/gp_segment_config.h index 41a1eacee0f..fb9c6320f2b 100644 --- a/src/include/catalog/gp_segment_config.h +++ b/src/include/catalog/gp_segment_config.h @@ -28,6 +28,7 @@ #define GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY 'p' #define GP_SEGMENT_CONFIGURATION_ROLE_MIRROR 'm' +#define GP_SEGMENT_CONFIGURATION_ROLE_AUX_MIRROR 'q' #define GP_SEGMENT_CONFIGURATION_STATUS_UP 'u' #define GP_SEGMENT_CONFIGURATION_STATUS_DOWN 'd' diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h index d3ca797cca7..5982d021e5e 100644 --- a/src/include/utils/builtins.h +++ b/src/include/utils/builtins.h @@ -17,6 +17,7 @@ #define BUILTINS_H #include "fmgr.h" +#include "cdb/cdbutil.h" #include "nodes/parsenodes.h" /* @@ -1352,6 +1353,9 @@ extern Datum gp_add_master_standby(PG_FUNCTION_ARGS); extern Datum gp_remove_master_standby(PG_FUNCTION_ARGS); extern bool gp_activate_standby(void); +extern void add_segment(GpSegConfigEntry *new_segment_information); +extern int16 get_availableDbId(); + extern Datum gp_add_segment_primary(PG_FUNCTION_ARGS); extern Datum gp_add_segment_mirror(PG_FUNCTION_ARGS); extern Datum gp_remove_segment_mirror(PG_FUNCTION_ARGS); From 60b710152ddf331ddabaf7c5c6e7db64648d2f5a Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Mon, 17 Mar 2025 11:01:24 +0000 Subject: [PATCH 2/7] Dispatch read-only query on read-only targets --- gpAux/gpdemo/demo_cluster.sh | 2 + gpcontrib/gpdebug/Makefile | 12 +++ gpcontrib/gpdebug/gpdebug--1.0.sql | 2 + gpcontrib/gpdebug/gpdebug.c | 27 ++++++ gpcontrib/gpdebug/gpdebug.control | 5 ++ src/backend/access/transam/twophase.c | 2 +- src/backend/access/transam/xact.c | 4 +- src/backend/access/transam/xlog.c | 2 +- src/backend/cdb/cdbutil.c | 122 +++++++++++++++++++++----- src/backend/storage/lmgr/lock.c | 5 +- src/backend/utils/misc/guc_gp.c | 8 +- src/include/cdb/cdbutil.h | 1 + src/include/utils/unsync_guc_name.h | 1 + 13 files changed, 165 insertions(+), 28 deletions(-) create mode 100644 gpcontrib/gpdebug/Makefile create mode 100644 gpcontrib/gpdebug/gpdebug--1.0.sql create mode 100644 gpcontrib/gpdebug/gpdebug.c create mode 100644 gpcontrib/gpdebug/gpdebug.control diff --git a/gpAux/gpdemo/demo_cluster.sh b/gpAux/gpdemo/demo_cluster.sh index 73a85ade494..f1a266cfdbb 100755 --- a/gpAux/gpdemo/demo_cluster.sh +++ b/gpAux/gpdemo/demo_cluster.sh @@ -347,6 +347,8 @@ if [ "${ENABLE_COPY}" == "true" ]; then ycmdb.yc_allow_copy_to_program=on ycmdb.yc_allow_copy_from_file=on ycmdb.yc_allow_copy_to_file=on + wal_level=hot_standby + hot_standby=on EOF fi diff --git a/gpcontrib/gpdebug/Makefile b/gpcontrib/gpdebug/Makefile new file mode 100644 index 00000000000..730c487b6cf --- /dev/null +++ b/gpcontrib/gpdebug/Makefile @@ -0,0 +1,12 @@ +# gpcontrib/gpdebug/Makefile + +MODULE_big = gpdebug +OBJS = gpdebug.o $(WIN32RES) + +EXTENSION = gpdebug +DATA = gpdebug--1.0.sql +PGFILEDESC = "gpdebug - An debug logging for PostgreSQL" + +PG_CONFIG = pg_config +PGXS := $(shell $(PG_CONFIG) --pgxs) +include $(PGXS) diff --git a/gpcontrib/gpdebug/gpdebug--1.0.sql b/gpcontrib/gpdebug/gpdebug--1.0.sql new file mode 100644 index 00000000000..0a12fa1a07e --- /dev/null +++ b/gpcontrib/gpdebug/gpdebug--1.0.sql @@ -0,0 +1,2 @@ +CREATE OR REPLACE FUNCTION cleanupAllGangs() RETURNS BOOL +AS 'MODULE_PATHNAME','cleanupAllGangs' LANGUAGE C; diff --git a/gpcontrib/gpdebug/gpdebug.c b/gpcontrib/gpdebug/gpdebug.c new file mode 100644 index 00000000000..6708d2b9748 --- /dev/null +++ b/gpcontrib/gpdebug/gpdebug.c @@ -0,0 +1,27 @@ + + +/*------------------------------------------------------------------------------ + * gpdebug.c + * + * Copyright (c) 2014-2021, PostgreSQL Global Development Group + *------------------------------------------------------------------------------ + */ +#include "postgres.h" + + +#include "cdb/cdbvars.h" +#include "cdb/cdbgang.h" + +PG_MODULE_MAGIC; + +void _PG_init(void); + +PG_FUNCTION_INFO_V1(cleanupAllGangs); +Datum +cleanupAllGangs(PG_FUNCTION_ARGS) +{ + if (Gp_role != GP_ROLE_DISPATCH) + elog(ERROR, "cleanupAllGangs can only be executed on master"); + DisconnectAndDestroyAllGangs(false); + PG_RETURN_BOOL(true); +} \ No newline at end of file diff --git a/gpcontrib/gpdebug/gpdebug.control b/gpcontrib/gpdebug/gpdebug.control new file mode 100644 index 00000000000..3b53eeddd8c --- /dev/null +++ b/gpcontrib/gpdebug/gpdebug.control @@ -0,0 +1,5 @@ +# gpdebug extension +comment = 'provides debug functionality' +default_version = '1.0' +module_pathname = '$libdir/gpdebug' +relocatable = true diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index a0be6df4e2b..30272ae3ec1 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1879,7 +1879,7 @@ GetOldestPreparedTransaction() void StandbyRecoverPreparedTransactions(bool overwriteOK) { - elog(ERROR, "Hot Standby not supported"); + // elog(ERROR, "Hot Standby not supported"); } /* diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index d963e3f76d0..30b15288abe 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -2329,8 +2329,8 @@ StartTransaction(void) * hot standby is enabled. This mode is not supported in * Greenplum yet. */ - AssertImply(DistributedTransactionContext != DTX_CONTEXT_LOCAL_ONLY, - !s->startedInRecovery); + // AssertImply(DistributedTransactionContext != DTX_CONTEXT_LOCAL_ONLY, + // !s->startedInRecovery); /* * MPP Modification * diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index d212d6aaad3..096accc4183 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7200,7 +7200,7 @@ StartupXLOG(void) oldestActiveXID = PrescanPreparedTransactions(&xids, &nxids); else oldestActiveXID = checkPoint.oldestActiveXid; - Assert(TransactionIdIsValid(oldestActiveXID)); + // Assert(TransactionIdIsValid(oldestActiveXID)); /* Tell procarray about the range of xids it has to deal with */ ProcArrayInitRecovery(ShmemVariableCache->nextXid); diff --git a/src/backend/cdb/cdbutil.c b/src/backend/cdb/cdbutil.c index 0127f6d20d3..f39784bcd75 100644 --- a/src/backend/cdb/cdbutil.c +++ b/src/backend/cdb/cdbutil.c @@ -82,6 +82,7 @@ #endif bool gp_count_host_segments_using_address = false; +bool gp_dispatch_on_mirrors = false; MemoryContext CdbComponentsContext = NULL; static CdbComponentDatabases *cdb_component_dbs = NULL; @@ -92,6 +93,7 @@ static CdbComponentDatabases *getCdbComponentInfo(void); static void cleanupComponentIdleQEs(CdbComponentDatabaseInfo *cdi, bool includeWriter); static int CdbComponentDatabaseInfoCompare(const void *p1, const void *p2); +static int CdbComponentDatabaseInfoComparem(const void *p1, const void *p2); static GpSegConfigEntry * readGpSegConfigFromCatalog(int *total_dbs); static GpSegConfigEntry * readGpSegConfigFromFTSFiles(int *total_dbs); @@ -439,10 +441,20 @@ getCdbComponentInfo(void) pRow->numIdleQEs = 0; pRow->numActiveQEs = 0; - if (config->role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY || - (gp_count_host_segments_using_address && - (config->hostip == NULL || strlen(config->hostip) == 0))) - continue; + if (gp_dispatch_on_mirrors) + { + if (config->role != GP_SEGMENT_CONFIGURATION_ROLE_MIRROR || + (gp_count_host_segments_using_address && + (config->hostip == NULL || strlen(config->hostip) == 0))) + continue; + } + else + { + if (config->role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY || + (gp_count_host_segments_using_address && + (config->hostip == NULL || strlen(config->hostip) == 0))) + continue; + } hsEntry = (HostSegsEntry *) hash_search(hostSegsHash, gp_count_host_segments_using_address ? config->hostip : config->hostname, @@ -474,14 +486,26 @@ getCdbComponentInfo(void) /* * Now sort the data by segindex, isprimary desc */ - qsort(component_databases->segment_db_info, - component_databases->total_segment_dbs, sizeof(CdbComponentDatabaseInfo), - CdbComponentDatabaseInfoCompare); + if (gp_dispatch_on_mirrors) + { + qsort(component_databases->segment_db_info, + component_databases->total_segment_dbs, sizeof(CdbComponentDatabaseInfo), + CdbComponentDatabaseInfoComparem); - qsort(component_databases->entry_db_info, - component_databases->total_entry_dbs, sizeof(CdbComponentDatabaseInfo), - CdbComponentDatabaseInfoCompare); + qsort(component_databases->entry_db_info, + component_databases->total_entry_dbs, sizeof(CdbComponentDatabaseInfo), + CdbComponentDatabaseInfoComparem); + } + else + { + qsort(component_databases->segment_db_info, + component_databases->total_segment_dbs, sizeof(CdbComponentDatabaseInfo), + CdbComponentDatabaseInfoCompare); + qsort(component_databases->entry_db_info, + component_databases->total_entry_dbs, sizeof(CdbComponentDatabaseInfo), + CdbComponentDatabaseInfoCompare); + } /* * Now count the number of distinct segindexes. Since it's sorted, this is * easy. @@ -558,10 +582,20 @@ getCdbComponentInfo(void) { cdbInfo = &component_databases->segment_db_info[i]; - if (cdbInfo->config->role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY || - (gp_count_host_segments_using_address && - (cdbInfo->config->hostip == NULL || strlen(cdbInfo->config->hostip) == 0))) - continue; + if (gp_dispatch_on_mirrors) + { + if (cdbInfo->config->role != GP_SEGMENT_CONFIGURATION_ROLE_MIRROR || + (gp_count_host_segments_using_address && + (cdbInfo->config->hostip == NULL || strlen(cdbInfo->config->hostip) == 0))) + continue; + } + else + { + if (cdbInfo->config->role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY || + (gp_count_host_segments_using_address && + (cdbInfo->config->hostip == NULL || strlen(cdbInfo->config->hostip) == 0))) + continue; + } hsEntry = (HostSegsEntry *) hash_search(hostSegsHash, gp_count_host_segments_using_address ? cdbInfo->config->hostip : cdbInfo->config->hostname, @@ -575,10 +609,20 @@ getCdbComponentInfo(void) { cdbInfo = &component_databases->entry_db_info[i]; - if (cdbInfo->config->role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY || - (gp_count_host_segments_using_address && - (cdbInfo->config->hostip == NULL || strlen(cdbInfo->config->hostip) == 0))) - continue; + if (gp_dispatch_on_mirrors) + { + if (cdbInfo->config->role != GP_SEGMENT_CONFIGURATION_ROLE_MIRROR || + (gp_count_host_segments_using_address && + (cdbInfo->config->hostip == NULL || strlen(cdbInfo->config->hostip) == 0))) + continue; + } + else + { + if (cdbInfo->config->role != GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY || + (gp_count_host_segments_using_address && + (cdbInfo->config->hostip == NULL || strlen(cdbInfo->config->hostip) == 0))) + continue; + } hsEntry = (HostSegsEntry *) hash_search(hostSegsHash, gp_count_host_segments_using_address ? cdbInfo->config->hostip : cdbInfo->config->hostname, @@ -847,7 +891,9 @@ cdbcomponent_allocateIdleQE(int contentId, SegmentType segmentType) * 1. for entrydb, it's never be writer. * 2. for first QE, it must be a writer. */ + /*XXX: what if gp_dispatch_on_mirrors?*/ isWriter = contentId == -1 ? false: (cdbinfo->numIdleQEs == 0 && cdbinfo->numActiveQEs == 0); + segdbDesc = cdbconn_createSegmentDescriptor(cdbinfo, nextQEIdentifer(cdbinfo->cdbs), isWriter); } @@ -1041,11 +1087,20 @@ cdbcomponent_getComponentInfo(int contentId) Assert(cdbs->total_segment_dbs == cdbs->total_segments * 2); cdbInfo = &cdbs->segment_db_info[2 * contentId]; - if (!SEGMENT_IS_ACTIVE_PRIMARY(cdbInfo)) + if (gp_dispatch_on_mirrors) { - cdbInfo = &cdbs->segment_db_info[2 * contentId + 1]; + if (!SEGMENT_IS_ACTIVE_MIRROR(cdbInfo)) + { + cdbInfo = &cdbs->segment_db_info[2 * contentId + 1]; + } + } + else + { + if (!SEGMENT_IS_ACTIVE_PRIMARY(cdbInfo)) + { + cdbInfo = &cdbs->segment_db_info[2 * contentId + 1]; + } } - return cdbInfo; } @@ -1228,6 +1283,31 @@ CdbComponentDatabaseInfoCompare(const void *p1, const void *p2) return cmp; } +static int +CdbComponentDatabaseInfoComparem(const void *p1, const void *p2) +{ + const CdbComponentDatabaseInfo *obj1 = (CdbComponentDatabaseInfo *) p1; + const CdbComponentDatabaseInfo *obj2 = (CdbComponentDatabaseInfo *) p2; + + int cmp = obj1->config->segindex - obj2->config->segindex; + + if (cmp == 0) + { + int obj2cmp = 0; + int obj1cmp = 0; + + if (SEGMENT_IS_ACTIVE_MIRROR(obj2)) + obj2cmp = 1; + + if (SEGMENT_IS_ACTIVE_MIRROR(obj1)) + obj1cmp = 1; + + cmp = obj2cmp - obj1cmp; + } + + return cmp; +} + /* * Maintain a cache of names. * diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index 8fa73b6236f..a523fa7cf64 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -36,6 +36,7 @@ #include "access/twophase.h" #include "access/twophase_rmgr.h" #include "cdb/cdbvars.h" +#include "cdb/cdbutil.h" #include "miscadmin.h" #include "pg_trace.h" #include "pgstat.h" @@ -837,7 +838,7 @@ LockAcquireExtended(const LOCKTAG *locktag, if (lockmethodid == DEFAULT_LOCKMETHOD && locktag->locktag_type != LOCKTAG_TRANSACTION) { - if (Gp_role == GP_ROLE_EXECUTE && !Gp_is_writer) + if (Gp_role == GP_ROLE_EXECUTE && !Gp_is_writer && !gp_dispatch_on_mirrors) { if (lockHolderProcPtr == NULL || lockHolderProcPtr == MyProc) { @@ -857,7 +858,7 @@ LockAcquireExtended(const LOCKTAG *locktag, lockHolderProcPtr = proc; } else - ereport(FATAL, + ereport(WARNING, (errcode(ERRCODE_GP_INTERCONNECTION_ERROR), errmsg(WRITER_IS_MISSING_MSG), errdetail("lock [%u,%u] %s %d. " diff --git a/src/backend/utils/misc/guc_gp.c b/src/backend/utils/misc/guc_gp.c index d7f9f6b1379..893f29788dc 100644 --- a/src/backend/utils/misc/guc_gp.c +++ b/src/backend/utils/misc/guc_gp.c @@ -3197,7 +3197,13 @@ struct config_bool ConfigureNamesBool_gp[] = &gp_use_fastanalyze, false, NULL, NULL }, - + { + {"gp_dispatch_on_mirrors", PGC_USERSET, RESOURCES, + }, + &gp_dispatch_on_mirrors, + false, NULL, NULL + }, + { {"stats_queue_level", PGC_SUSET, STATS_COLLECTOR, gettext_noop("Collects resource queue-level statistics on database activity."), diff --git a/src/include/cdb/cdbutil.h b/src/include/cdb/cdbutil.h index 17570586fdb..236a2b6c5ef 100644 --- a/src/include/cdb/cdbutil.h +++ b/src/include/cdb/cdbutil.h @@ -206,6 +206,7 @@ extern int16 contentid_get_dbid(int16 contentid, char role, bool getPreferredRol extern int numsegmentsFromQD; extern bool gp_count_host_segments_using_address; +extern bool gp_dispatch_on_mirrors; /* * Returns the number of segments diff --git a/src/include/utils/unsync_guc_name.h b/src/include/utils/unsync_guc_name.h index 45adb3a496f..5ecc02ad167 100644 --- a/src/include/utils/unsync_guc_name.h +++ b/src/include/utils/unsync_guc_name.h @@ -160,6 +160,7 @@ "gp_dispatch_keepalives_idle", "gp_dispatch_keepalives_interval", "gp_dispatch_keepalives_count", + "gp_dispatch_on_mirrors", "gp_distinct_grouping_sets_threshold", "gp_dtx_recovery_interval", "gp_dtx_recovery_prepared_period", From 6c09b1a5e5d48de9f792d56df738b58653c4d2a9 Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Tue, 3 Jun 2025 13:07:17 +0000 Subject: [PATCH 3/7] tmp --- src/backend/cdb/cdbutil.c | 91 +++++++++++++++------------------------ src/include/cdb/cdbutil.h | 2 + 2 files changed, 37 insertions(+), 56 deletions(-) diff --git a/src/backend/cdb/cdbutil.c b/src/backend/cdb/cdbutil.c index f39784bcd75..2f300402272 100644 --- a/src/backend/cdb/cdbutil.c +++ b/src/backend/cdb/cdbutil.c @@ -93,7 +93,6 @@ static CdbComponentDatabases *getCdbComponentInfo(void); static void cleanupComponentIdleQEs(CdbComponentDatabaseInfo *cdi, bool includeWriter); static int CdbComponentDatabaseInfoCompare(const void *p1, const void *p2); -static int CdbComponentDatabaseInfoComparem(const void *p1, const void *p2); static GpSegConfigEntry * readGpSegConfigFromCatalog(int *total_dbs); static GpSegConfigEntry * readGpSegConfigFromFTSFiles(int *total_dbs); @@ -382,7 +381,7 @@ getCdbComponentInfo(void) (CdbComponentDatabaseInfo *) palloc0(sizeof(CdbComponentDatabaseInfo) * total_dbs); component_databases->entry_db_info = - (CdbComponentDatabaseInfo *) palloc0(sizeof(CdbComponentDatabaseInfo) * 2); + (CdbComponentDatabaseInfo *) palloc0(sizeof(CdbComponentDatabaseInfo) * 3); for (i = 0; i < total_dbs; i++) { @@ -486,26 +485,14 @@ getCdbComponentInfo(void) /* * Now sort the data by segindex, isprimary desc */ - if (gp_dispatch_on_mirrors) - { - qsort(component_databases->segment_db_info, - component_databases->total_segment_dbs, sizeof(CdbComponentDatabaseInfo), - CdbComponentDatabaseInfoComparem); - qsort(component_databases->entry_db_info, - component_databases->total_entry_dbs, sizeof(CdbComponentDatabaseInfo), - CdbComponentDatabaseInfoComparem); - } - else - { - qsort(component_databases->segment_db_info, - component_databases->total_segment_dbs, sizeof(CdbComponentDatabaseInfo), - CdbComponentDatabaseInfoCompare); + qsort(component_databases->segment_db_info, + component_databases->total_segment_dbs, sizeof(CdbComponentDatabaseInfo), + CdbComponentDatabaseInfoCompare); - qsort(component_databases->entry_db_info, - component_databases->total_entry_dbs, sizeof(CdbComponentDatabaseInfo), - CdbComponentDatabaseInfoCompare); - } + qsort(component_databases->entry_db_info, + component_databases->total_entry_dbs, sizeof(CdbComponentDatabaseInfo), + CdbComponentDatabaseInfoCompare); /* * Now count the number of distinct segindexes. Since it's sorted, this is * easy. @@ -1084,14 +1071,17 @@ cdbcomponent_getComponentInfo(int contentId) /* with mirror, segment_db_info is sorted by content id */ if (cdbs->total_segment_dbs != cdbs->total_segments) { - Assert(cdbs->total_segment_dbs == cdbs->total_segments * 2); + Assert(cdbs->total_segment_dbs >= cdbs->total_segments * 2); cdbInfo = &cdbs->segment_db_info[2 * contentId]; if (gp_dispatch_on_mirrors) { - if (!SEGMENT_IS_ACTIVE_MIRROR(cdbInfo)) - { - cdbInfo = &cdbs->segment_db_info[2 * contentId + 1]; + for (int i = 0; i < cdbs->total_segment_dbs; ++ i) { + if (SEGMENT_IS_AUX_MIRROR(&cdbs->segment_db_info[i]) + && cdbs->segment_db_info[i].config->segindex == contentId) + { + cdbInfo = &cdbs->segment_db_info[i]; + } } } else @@ -1264,45 +1254,34 @@ CdbComponentDatabaseInfoCompare(const void *p1, const void *p2) const CdbComponentDatabaseInfo *obj1 = (CdbComponentDatabaseInfo *) p1; const CdbComponentDatabaseInfo *obj2 = (CdbComponentDatabaseInfo *) p2; - int cmp = obj1->config->segindex - obj2->config->segindex; + int cmp; - if (cmp == 0) + if (SEGMENT_IS_AUX_MIRROR(obj1) && SEGMENT_IS_AUX_MIRROR(obj2)) { - int obj2cmp = 0; - int obj1cmp = 0; - - if (SEGMENT_IS_ACTIVE_PRIMARY(obj2)) - obj2cmp = 1; - - if (SEGMENT_IS_ACTIVE_PRIMARY(obj1)) - obj1cmp = 1; - - cmp = obj2cmp - obj1cmp; + cmp = obj1->config->segindex - obj2->config->segindex; + } + else if (SEGMENT_IS_AUX_MIRROR(obj1)) + { + cmp = 1; } - - return cmp; -} - -static int -CdbComponentDatabaseInfoComparem(const void *p1, const void *p2) -{ - const CdbComponentDatabaseInfo *obj1 = (CdbComponentDatabaseInfo *) p1; - const CdbComponentDatabaseInfo *obj2 = (CdbComponentDatabaseInfo *) p2; - - int cmp = obj1->config->segindex - obj2->config->segindex; - - if (cmp == 0) + else if (SEGMENT_IS_AUX_MIRROR(obj2)) { - int obj2cmp = 0; - int obj1cmp = 0; + cmp = -1; + } else { + cmp = obj1->config->segindex - obj2->config->segindex; - if (SEGMENT_IS_ACTIVE_MIRROR(obj2)) - obj2cmp = 1; + if (cmp == 0) + { + int obj2cmp = 0; + int obj1cmp = 0; + if (SEGMENT_IS_ACTIVE_PRIMARY(obj2)) + obj2cmp = 1; - if (SEGMENT_IS_ACTIVE_MIRROR(obj1)) - obj1cmp = 1; + if (SEGMENT_IS_ACTIVE_PRIMARY(obj1)) + obj1cmp = 1; - cmp = obj2cmp - obj1cmp; + cmp = obj2cmp - obj1cmp; + } } return cmp; diff --git a/src/include/cdb/cdbutil.h b/src/include/cdb/cdbutil.h index 236a2b6c5ef..56e214eb117 100644 --- a/src/include/cdb/cdbutil.h +++ b/src/include/cdb/cdbutil.h @@ -75,6 +75,8 @@ struct CdbComponentDatabaseInfo #define SEGMENT_IS_ACTIVE_MIRROR(p) \ ((p)->config->role == GP_SEGMENT_CONFIGURATION_ROLE_MIRROR ? true : false) +#define SEGMENT_IS_AUX_MIRROR(p) \ + ((p)->config->role == GP_SEGMENT_CONFIGURATION_ROLE_AUX_MIRROR ? true : false) #define SEGMENT_IS_ACTIVE_PRIMARY(p) \ ((p)->config->role == GP_SEGMENT_CONFIGURATION_ROLE_PRIMARY ? true : false) From 96f8a2c7d3d4d39f9a9da42dbada3fddf5e7229a Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Tue, 3 Jun 2025 14:19:28 +0000 Subject: [PATCH 4/7] zz --- src/backend/cdb/cdbutil.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/backend/cdb/cdbutil.c b/src/backend/cdb/cdbutil.c index 2f300402272..2ae28f36ee3 100644 --- a/src/backend/cdb/cdbutil.c +++ b/src/backend/cdb/cdbutil.c @@ -442,7 +442,7 @@ getCdbComponentInfo(void) if (gp_dispatch_on_mirrors) { - if (config->role != GP_SEGMENT_CONFIGURATION_ROLE_MIRROR || + if (config->role != GP_SEGMENT_CONFIGURATION_ROLE_AUX_MIRROR|| (gp_count_host_segments_using_address && (config->hostip == NULL || strlen(config->hostip) == 0))) continue; @@ -494,11 +494,14 @@ getCdbComponentInfo(void) component_databases->total_entry_dbs, sizeof(CdbComponentDatabaseInfo), CdbComponentDatabaseInfoCompare); /* - * Now count the number of distinct segindexes. Since it's sorted, this is - * easy. + * Now count the number of distinct segindexes. Since it's sorted up until aux mirrors, + * this is easy. */ for (i = 0; i < component_databases->total_segment_dbs; i++) { + if (component_databases->segment_db_info[i].config->role == GP_SEGMENT_CONFIGURATION_ROLE_AUX_MIRROR) { + break; + } if (i == 0 || (component_databases->segment_db_info[i].config->segindex != component_databases->segment_db_info[i - 1].config->segindex)) { @@ -571,7 +574,7 @@ getCdbComponentInfo(void) if (gp_dispatch_on_mirrors) { - if (cdbInfo->config->role != GP_SEGMENT_CONFIGURATION_ROLE_MIRROR || + if (cdbInfo->config->role != GP_SEGMENT_CONFIGURATION_ROLE_AUX_MIRROR || (gp_count_host_segments_using_address && (cdbInfo->config->hostip == NULL || strlen(cdbInfo->config->hostip) == 0))) continue; @@ -598,7 +601,7 @@ getCdbComponentInfo(void) if (gp_dispatch_on_mirrors) { - if (cdbInfo->config->role != GP_SEGMENT_CONFIGURATION_ROLE_MIRROR || + if (cdbInfo->config->role != GP_SEGMENT_CONFIGURATION_ROLE_AUX_MIRROR || (gp_count_host_segments_using_address && (cdbInfo->config->hostip == NULL || strlen(cdbInfo->config->hostip) == 0))) continue; From 43ba72f5e0560926c699c88929a2bf3c5006094f Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Sun, 22 Jun 2025 08:38:55 +0000 Subject: [PATCH 5/7] f --- src/backend/access/transam/twophase.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 30272ae3ec1..809bcad9bef 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -1282,7 +1282,7 @@ StandbyTransactionIdIsPrepared(TransactionId xid) * files, so we cannot use ReadTwoPhaseFile() here. Fortunately, this * isn't needed until we try to use Hot Standby. */ - elog(ERROR, "Hot Standby not supported"); + //elog(ERROR, "Hot Standby not supported"); #if 0 char *buf; TwoPhaseFileHeader *hdr; From 824be0d35bdbc4bc82e255bd685fe34714e1f962 Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Mon, 23 Jun 2025 07:17:53 +0000 Subject: [PATCH 6/7] add space --- src/backend/access/transam/distributedlog.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/access/transam/distributedlog.c b/src/backend/access/transam/distributedlog.c index 460c732bf80..26c302f873a 100644 --- a/src/backend/access/transam/distributedlog.c +++ b/src/backend/access/transam/distributedlog.c @@ -163,6 +163,7 @@ DistributedLog_InitOldestXmin(void) pg_atomic_write_u32((pg_atomic_uint32 *)&DistributedLogShared->oldestXmin, oldestXmin); } + /* * Advance the "oldest xmin" among distributed snapshots. * From 43f400852dfd92eb31174d8e6de15e20ac0d516f Mon Sep 17 00:00:00 2001 From: reshke kirill Date: Mon, 23 Jun 2025 10:05:52 +0000 Subject: [PATCH 7/7] Init DistributedLog vars --- src/backend/access/transam/xlog.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 096accc4183..6cc945c12e5 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7205,6 +7205,15 @@ StartupXLOG(void) /* Tell procarray about the range of xids it has to deal with */ ProcArrayInitRecovery(ShmemVariableCache->nextXid); + /* also initialize latestCompletedXid, to nextXid - 1 */ + LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE); + ShmemVariableCache->latestCompletedXid = ShmemVariableCache->nextXid; + TransactionIdRetreat(ShmemVariableCache->latestCompletedXid); + elog(LOG, "latest completed transaction id is %u and next transaction id is %u", + ShmemVariableCache->latestCompletedXid, + ShmemVariableCache->nextXid); + LWLockRelease(ProcArrayLock); + /* * Startup commit log and subtrans only. MultiXact has already * been started up and other SLRUs are not maintained during