Skip to content

Commit 92aeff5

Browse files
Fix database does not exists error when is_member(), schema_id() function gets called in parallel query mode. (#289) (#297)
This commit solve the issue of parallel worker not being able to obtain correct logical database name. Whenever get_cur_db_name() is called, it returns static char current_db_name[] which is initialized as empty. Now, parallel workers are not aware of the database name. For them, it is empty whenever get_cur_db_name() gets called. Hence, we were getting the following error: database "" does not exist So, to communicate the logical database name and more data related to babelfish we have introduced a struct BabelfishFixedParallelState. Currently BabelfishFixedParallelState has only 1 field, i.e., logical_db_name, we can add more fields to it whenever necessary. Then we will write the logical_db_name in DSM during initialization (in InitializeParallelDSM) using a hook. Another hook is used while trying to fetch the logical database name in ParallelWorkerMain(). In this way we are introduction a mechanism through which we can communicate any babelfish related information to parallel workers. Issues Resolved: BABEL-4538, BABEL-4481, BABEL-4421 Signed-off-by: Shameem Ahmed <[email protected]>
1 parent 631916e commit 92aeff5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/backend/access/transam/parallel.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
#define PARALLEL_KEY_UNCOMMITTEDENUMS UINT64CONST(0xFFFFFFFFFFFF000E)
7979
#define PARALLEL_KEY_CLIENTCONNINFO UINT64CONST(0xFFFFFFFFFFFF000F)
8080

81+
/* Hooks for communicating babelfish related information to parallel worker */
82+
bbf_InitializeParallelDSM_hook_type bbf_InitializeParallelDSM_hook = NULL;
83+
bbf_ParallelWorkerMain_hook_type bbf_ParallelWorkerMain_hook = NULL;
84+
8185
/* Fixed-size parallel state. */
8286
typedef struct FixedParallelState
8387
{
@@ -295,6 +299,10 @@ InitializeParallelDSM(ParallelContext *pcxt)
295299
shm_toc_estimate_chunk(&pcxt->estimator, strlen(pcxt->library_name) +
296300
strlen(pcxt->function_name) + 2);
297301
shm_toc_estimate_keys(&pcxt->estimator, 1);
302+
303+
/* Estimate how much we'll need for the babelfish fixed parallel state */
304+
if (MyProcPort->is_tds_conn && bbf_InitializeParallelDSM_hook)
305+
(*bbf_InitializeParallelDSM_hook) (pcxt, true);
298306
}
299307

300308
/*
@@ -476,6 +484,10 @@ InitializeParallelDSM(ParallelContext *pcxt)
476484
strcpy(entrypointstate, pcxt->library_name);
477485
strcpy(entrypointstate + lnamelen + 1, pcxt->function_name);
478486
shm_toc_insert(pcxt->toc, PARALLEL_KEY_ENTRYPOINT, entrypointstate);
487+
488+
/* Initialize babelfish fixed-size state in shared memory. */
489+
if (MyProcPort->is_tds_conn && bbf_InitializeParallelDSM_hook)
490+
(*bbf_InitializeParallelDSM_hook) (pcxt, false);
479491
}
480492

481493
/* Restore previous memory context. */
@@ -1508,6 +1520,10 @@ ParallelWorkerMain(Datum main_arg)
15081520
InitializeSystemUser(MyClientConnectionInfo.authn_id,
15091521
hba_authname(MyClientConnectionInfo.auth_method));
15101522

1523+
/* Hook for babelfish to restore babelfish fixed parallel state */
1524+
if (MyFixedParallelState->babelfish_context && bbf_ParallelWorkerMain_hook)
1525+
(*bbf_ParallelWorkerMain_hook) (toc);
1526+
15111527
/* Attach to the leader's serializable transaction, if SERIALIZABLE. */
15121528
AttachSerializableXact(fps->serializable_xact_handle);
15131529

src/include/access/parallel.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,15 @@ extern void ParallelWorkerMain(Datum main_arg);
8282
/* Below helpers are added to support parallel workers in Babelfish context */
8383
extern bool IsBabelfishParallelWorker(void);
8484

85+
/* Key for BabelfishFixedParallelState */
86+
#define BABELFISH_PARALLEL_KEY_FIXED UINT64CONST(0xBBF0000000000001)
87+
88+
/* Hooks for communicating babelfish related information to parallel worker */
89+
typedef void (*bbf_InitializeParallelDSM_hook_type)(ParallelContext *pcxt, bool estimate);
90+
extern PGDLLIMPORT bbf_InitializeParallelDSM_hook_type bbf_InitializeParallelDSM_hook;
91+
92+
typedef void (*bbf_ParallelWorkerMain_hook_type)(shm_toc *toc);
93+
extern PGDLLIMPORT bbf_ParallelWorkerMain_hook_type bbf_ParallelWorkerMain_hook;
94+
95+
8596
#endif /* PARALLEL_H */

0 commit comments

Comments
 (0)