#include "utils/pg_rusage.h"
/* To access sequences */
-#define MyCoordName \
+#define GetMyCoordName \
OidIsValid(MyCoordId) ? get_pgxc_nodename(MyCoordId) : ""
/* Configuration variables */
char *GtmHost = "localhost";
{
GTM_Sequence ret = -1;
GTM_SequenceKeyData seqkey;
- char *coordName = IS_PGXC_COORDINATOR ? PGXCNodeName : MyCoordName;
+ char *coordName = IS_PGXC_COORDINATOR ? PGXCNodeName : GetMyCoordName;
int coordPid = IS_PGXC_COORDINATOR ? MyProcPid : MyCoordPid;
int status;
{
GTM_Sequence ret = -1;
GTM_SequenceKeyData seqkey;
- char *coordName = IS_PGXC_COORDINATOR ? PGXCNodeName : MyCoordName;
+ char *coordName = IS_PGXC_COORDINATOR ? PGXCNodeName : GetMyCoordName;
int coordPid = IS_PGXC_COORDINATOR ? MyProcPid : MyCoordPid;
int status;
SetValGTM(char *seqname, GTM_Sequence nextval, bool iscalled)
{
GTM_SequenceKeyData seqkey;
- char *coordName = IS_PGXC_COORDINATOR ? PGXCNodeName : MyCoordName;
+ char *coordName = IS_PGXC_COORDINATOR ? PGXCNodeName : GetMyCoordName;
int coordPid = IS_PGXC_COORDINATOR ? MyProcPid : MyCoordPid;
CheckConnection();
coordid = HeapTupleGetOid(coordTup);
+ /*
+ * Save the coordinator name is a global variable so that we don't need
+ * to do catalog lookups later, especially if we running outside a
+ * transaction block or in an aborted transaction
+ */
+ if (OidIsValid(coordid))
+ strncpy(MyCoordName, *newval, NAMEDATALEN);
+
*separatorPos = '_';
ReleaseSysCache(coordTup);
}
myextra = (global_session_extra *) malloc(sizeof(global_session_extra));
if (!myextra)
return false;
+
myextra->coordid = coordid;
myextra->coordpid = coordpid;
*extra = (void *) myextra;
appendStringInfo(session_params, "SET global_session TO %s_%d;",
PGXCNodeName, MyProcPid);
get_set_command(session_param_list, session_params, false);
+ appendStringInfo(session_params, "SET parentPGXCPid TO %d;",
+ MyProcPid);
}
return session_params->len == 0 ? NULL : session_params->data;
}
#ifdef XCP
char *parentPGXCNode = NULL;
int parentPGXCNodeId = -1;
+int parentPGXCPid = -1;
char parentPGXCNodeType = PGXC_NODE_DATANODE;
#endif
appendStringInfoString(buf, unpack_sql_state(edata->sqlerrcode));
break;
#ifdef XCP
- case 'C':
- if (MyProc != NULL)
+ case 'R':
+ if (padding != 0)
{
- if (padding != 0)
- appendStringInfo(buf, "%*u", padding, MyProc->coordId);
- else
- appendStringInfo(buf, "%u", MyProc->coordId);
+ char strfbuf[128];
+
+ snprintf(strfbuf, sizeof(strfbuf) - 1, "(%c/%s/%d)",
+ remoteConnType == REMOTE_CONN_APP ? 'A' :
+ remoteConnType == REMOTE_CONN_DATANODE ? 'D' :
+ remoteConnType == REMOTE_CONN_COORD ? 'C' : 'U',
+ parentPGXCNode, parentPGXCPid);
+ appendStringInfo(buf, "%*s", padding, strfbuf);
}
- else if (padding != 0)
- appendStringInfoSpaces(buf,
- padding > 0 ? padding : -padding);
+ else
+ appendStringInfo(buf, "(%c/%s/%d)",
+ remoteConnType == REMOTE_CONN_APP ? 'A' :
+ remoteConnType == REMOTE_CONN_DATANODE ? 'D' :
+ remoteConnType == REMOTE_CONN_COORD ? 'C' : 'U',
+ parentPGXCNode, parentPGXCPid);
break;
- case 'R':
+ case 'C':
if (MyProc != NULL)
{
if (padding != 0)
- appendStringInfo(buf, "%*u", padding, MyProc->coordPid);
+ {
+ char strfbuf[128];
+
+ snprintf(strfbuf, sizeof(strfbuf) - 1, "(%s/%u)",
+ MyCoordName, MyProc->coordPid);
+ appendStringInfo(buf, "%*s", padding, strfbuf);
+ }
else
- appendStringInfo(buf, "%u", MyProc->coordPid);
+ appendStringInfo(buf, "(%s/%u)", MyCoordName, MyProc->coordPid);
}
else if (padding != 0)
appendStringInfoSpaces(buf,
padding > 0 ? padding : -padding);
break;
+ case 'S':
+ if (padding != NULL)
+ appendStringInfo(buf, "%*s", padding, global_session_string);
+ else
+ appendStringInfo(buf, "%s", global_session_string);
+
+ break;
#endif
default:
/* format error - ignore it */
#ifdef XCP
Oid MyCoordId = InvalidOid;
+char MyCoordName[NAMEDATALEN];
int MyCoordPid = 0;
LocalTransactionId MyCoordLxid = 0;
#include "utils/snapmgr.h"
#endif
#include "utils/syscache.h"
+#include "utils/lsyscache.h"
#define DIRECTORY_LOCK_FILE "postmaster.pid"
static char *data_directory;
static char *session_authorization_string;
#ifdef XCP
-static char *global_session_string;
+char *global_session_string;
#endif
static int max_function_args;
static int max_index_keys;
NULL, NULL, NULL
},
+ {
+ {"parentPGXCPid", PGC_USERSET, UNGROUPED,
+ gettext_noop("PID of the remote process attached to this session."),
+ gettext_noop("This GUC only makes sense when a coordinator or a "
+ "datanode has opened the session"),
+ GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_AUTO_FILE | GUC_DISALLOW_IN_FILE | GUC_NO_SHOW_ALL
+ },
+ &parentPGXCPid,
+ -1, -1, INT_MAX,
+ NULL, NULL, NULL
+ },
+
#endif
#endif /* PGXC */
extern bool isPGXCDataNode;
extern bool isRestoreMode;
extern char *parentPGXCNode;
+extern int parentPGXCPid;
extern int parentPGXCNodeId;
extern char parentPGXCNodeType;
* of other backends under the same postmaster.
*/
extern PGDLLIMPORT Oid MyCoordId;
+extern PGDLLIMPORT char MyCoordName[NAMEDATALEN];
extern PGDLLIMPORT int MyCoordPid;
extern PGDLLIMPORT LocalTransactionId MyCoordLxid;
#ifdef XCP
extern char *storm_catalog_remap_string;
+extern char *global_session_string;
#endif
#ifdef TRACE_SORT
extern bool trace_sort;