Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix database does not exists error when is_member(), schema_id() function gets called in parallel query mode. #289

Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 21 additions & 0 deletions src/backend/access/transam/parallel.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
#define PARALLEL_KEY_RELMAPPER_STATE UINT64CONST(0xFFFFFFFFFFFF000D)
#define PARALLEL_KEY_UNCOMMITTEDENUMS UINT64CONST(0xFFFFFFFFFFFF000E)

/* Hooks for communicating babelfish related information to parallel worker */
babelfixedparallelstate_insert_hook_type babelfixedparallelstate_insert_hook;
babelfixedparallelstate_restore_hook_type babelfixedparallelstate_restore_hook;

ahmed-shameem marked this conversation as resolved.
Show resolved Hide resolved
/* Fixed-size parallel state. */
typedef struct FixedParallelState
{
Expand Down Expand Up @@ -291,8 +295,14 @@ InitializeParallelDSM(ParallelContext *pcxt)
shm_toc_estimate_chunk(&pcxt->estimator, strlen(pcxt->library_name) +
strlen(pcxt->function_name) + 2);
shm_toc_estimate_keys(&pcxt->estimator, 1);

/* Estimate how much we'll need for the babelfish fixed parallel state */
if (MyProcPort->is_tds_conn && babelfixedparallelstate_insert_hook)
(*babelfixedparallelstate_insert_hook) (pcxt, true);
}



ahmed-shameem marked this conversation as resolved.
Show resolved Hide resolved
/*
* Create DSM and initialize with new table of contents. But if the user
* didn't request any workers, then don't bother creating a dynamic shared
Expand Down Expand Up @@ -465,7 +475,12 @@ InitializeParallelDSM(ParallelContext *pcxt)
strcpy(entrypointstate, pcxt->library_name);
strcpy(entrypointstate + lnamelen + 1, pcxt->function_name);
shm_toc_insert(pcxt->toc, PARALLEL_KEY_ENTRYPOINT, entrypointstate);

/* Initialize babelfish fixed-size state in shared memory. */
if (MyProcPort->is_tds_conn && babelfixedparallelstate_insert_hook)
(*babelfixedparallelstate_insert_hook) (pcxt, false);
}

ahmed-shameem marked this conversation as resolved.
Show resolved Hide resolved

/* Restore previous memory context. */
MemoryContextSwitchTo(oldcontext);
Expand Down Expand Up @@ -1486,6 +1501,12 @@ ParallelWorkerMain(Datum main_arg)
/* Attach to the leader's serializable transaction, if SERIALIZABLE. */
AttachSerializableXact(fps->serializable_xact_handle);


/* Hook for babelfish to restore babelfish fixed parallel state */
if (MyFixedParallelState->babelfish_context && babelfixedparallelstate_restore_hook)
ahmed-shameem marked this conversation as resolved.
Show resolved Hide resolved
(*babelfixedparallelstate_restore_hook) (toc);


/*
* We've initialized all of our state now; nothing should change
* hereafter.
Expand Down
8 changes: 8 additions & 0 deletions src/include/access/parallel.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,12 @@ extern void ParallelWorkerMain(Datum main_arg);
/* Below helpers are added to support parallel workers in Babelfish context */
extern bool IsBabelfishParallelWorker(void);

/* Hooks for communicating babelfish related information to parallel worker */
typedef void (*babelfixedparallelstate_insert_hook_type)(ParallelContext *pcxt, bool estimate);
extern PGDLLIMPORT babelfixedparallelstate_insert_hook_type babelfixedparallelstate_insert_hook;

typedef void (*babelfixedparallelstate_restore_hook_type)(shm_toc *toc);
extern PGDLLIMPORT babelfixedparallelstate_restore_hook_type babelfixedparallelstate_restore_hook;


#endif /* PARALLEL_H */
Loading