Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gpAux/gpdemo/demo_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions gpcontrib/gpdebug/Makefile
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions gpcontrib/gpdebug/gpdebug--1.0.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE OR REPLACE FUNCTION cleanupAllGangs() RETURNS BOOL
AS 'MODULE_PATHNAME','cleanupAllGangs' LANGUAGE C;
27 changes: 27 additions & 0 deletions gpcontrib/gpdebug/gpdebug.c
Original file line number Diff line number Diff line change
@@ -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);
}
5 changes: 5 additions & 0 deletions gpcontrib/gpdebug/gpdebug.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# gpdebug extension
comment = 'provides debug functionality'
default_version = '1.0'
module_pathname = '$libdir/gpdebug'
relocatable = true
2 changes: 1 addition & 1 deletion src/backend/access/transam/twophase.c
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ GetOldestPreparedTransaction()
void
StandbyRecoverPreparedTransactions(bool overwriteOK)
{
elog(ERROR, "Hot Standby not supported");
// elog(ERROR, "Hot Standby not supported");
}

/*
Expand Down
4 changes: 2 additions & 2 deletions src/backend/access/transam/xact.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion src/backend/access/transam/xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
122 changes: 101 additions & 21 deletions src/backend/cdb/cdbutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.
*
Expand Down
5 changes: 3 additions & 2 deletions src/backend/storage/lmgr/lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
{
Expand All @@ -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. "
Expand Down
8 changes: 7 additions & 1 deletion src/backend/utils/misc/guc_gp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down
1 change: 1 addition & 0 deletions src/include/cdb/cdbutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/include/utils/unsync_guc_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading