提交 78aed203 编写于 作者: A Ashwin Agrawal

Validation for gp_dbid and gp_contentid between QD catalog and QE.

Since gp_dbid and gp_contentid is stored in conf files on QE, its
helpful to have validation to compare values between QD catalog table
gp_segment_configuration and QE. This validation is performed using
FTS. FTS message includes gp_dbid and gp_contentid values from
catalog. QE validates the value while handling the FTS message and if
finds inconsistency PANICS.

This check is mostly targeted during development to catch missed
handling of gp_dbid and gp_contentid values in config files. For
future features like pg_upgrade and gpexpand which copy master
directory and convert it to segment.
Co-authored-by: NAlexandra Wang <lewang@pivotal.io>
上级 549cd61c
......@@ -18,6 +18,7 @@
#include <replication/slot.h>
#include "access/xlog.h"
#include "cdb/cdbvars.h"
#include "libpq/pqformat.h"
#include "libpq/libpq.h"
#include "postmaster/fts.h"
......@@ -404,6 +405,34 @@ HandleFtsWalRepPromote(void)
void
HandleFtsMessage(const char* query_string)
{
int dbid;
int contid;
char message_type[FTS_MSG_MAX_LEN];
int error_level;
if (sscanf(query_string, FTS_MSG_FORMAT,
message_type, &dbid, &contid) != 3)
{
ereport(ERROR,
(errmsg("received invalid FTS query: %s", query_string)));
}
#ifdef USE_ASSERT_CHECKING
error_level = PANIC;
#else
error_level = WARNING;
#endif
if (dbid != GpIdentity.dbid)
ereport(error_level,
(errmsg("message type: %s received dbid:%d doesn't match this segments configured dbid:%d",
message_type, dbid, GpIdentity.dbid)));
if (contid != GpIdentity.segindex)
ereport(error_level,
(errmsg("message type: %s received contentid:%d doesn't match this segments configured contentid:%d",
message_type, contid, GpIdentity.segindex)));
SIMPLE_FAULT_INJECTOR(FtsHandleMessage);
if (strncmp(query_string, FTS_MSG_PROBE,
......
......@@ -515,7 +515,8 @@ static void
ftsSend(fts_context *context)
{
fts_segment_info *ftsInfo;
const char *message;
const char *message_type;
char message[FTS_MSG_MAX_LEN];
int i;
for (i = 0; i < context->num_pairs; i++)
......@@ -542,11 +543,17 @@ ftsSend(fts_context *context)
!(ftsInfo->poll_revents & POLLOUT))
break;
if (ftsInfo->state == FTS_PROBE_SEGMENT)
message = FTS_MSG_PROBE;
message_type = FTS_MSG_PROBE;
else if (ftsInfo->state == FTS_SYNCREP_OFF_SEGMENT)
message = FTS_MSG_SYNCREP_OFF;
message_type = FTS_MSG_SYNCREP_OFF;
else
message = FTS_MSG_PROMOTE;
message_type = FTS_MSG_PROMOTE;
snprintf(message, FTS_MSG_MAX_LEN, FTS_MSG_FORMAT,
message_type,
ftsInfo->primary_cdbinfo->dbid,
ftsInfo->primary_cdbinfo->segindex);
if (PQsendQuery(ftsInfo->conn, message))
{
/*
......
......@@ -339,6 +339,7 @@ test_ftsConnect_ftsPoll(void **state)
void
test_ftsSend_success(void **state)
{
char message[FTS_MSG_MAX_LEN];
CdbComponentDatabases *cdbs = InitTestCdb(
1, true, GP_SEGMENT_CONFIGURATION_MODE_INSYNC);
fts_context context;
......@@ -347,10 +348,16 @@ test_ftsSend_success(void **state)
fts_segment_info *ftsInfo = &context.perSegInfos[0];
ftsInfo->conn->asyncStatus = PGASYNC_IDLE;
ftsInfo->poll_revents = POLLOUT;
snprintf(message, FTS_MSG_MAX_LEN, FTS_MSG_FORMAT,
FTS_MSG_PROBE,
ftsInfo->primary_cdbinfo->dbid,
ftsInfo->primary_cdbinfo->segindex);
expect_value(PQstatus, conn, ftsInfo->conn);
will_return(PQstatus, CONNECTION_OK);
expect_value(PQsendQuery, conn, ftsInfo->conn);
expect_string(PQsendQuery, query, FTS_MSG_PROBE);
expect_string(PQsendQuery, query, message);
will_return(PQsendQuery, 1);
ftsSend(&context);
......
......@@ -25,6 +25,20 @@
#define FTS_MSG_SYNCREP_OFF "SYNCREP_OFF"
#define FTS_MSG_PROMOTE "PROMOTE"
/*
* This is used for constructing string to store the full fts message request
* string from QD to QE. Format for which is defined using FTS_MSG_FORMAT and
* first part of it string to define type of fts message like FTS_MSG_PROBE,
* FTS_MSG_SYNCREP_OFF or FTS_MSG_PROMOTE.
*/
#define FTS_MSG_MAX_LEN 100
/*
* If altering the fts message format, consider if FTS_MSG_MAX_LEN is enough
* to store the modified format.
*/
#define FTS_MSG_FORMAT "%s dbid=%d contid=%d"
#define Natts_fts_message_response 5
#define Anum_fts_message_response_is_mirror_up 0
#define Anum_fts_message_response_is_in_sync 1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册