mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-31 18:57:21 +02:00
Reproduce debug_query_string==NULL on parallel workers.
Certain background workers initiate parallel queries while
debug_query_string==NULL, at which point they attempted strlen(NULL) and
died to SIGSEGV. Older debug_query_string observers allow NULL, so do
likewise in these newer ones. Back-patch to v11, where commit
7de4a1bcc5
introduced the first of these.
Discussion: https://postgr.es/m/20201014022636.GA1962668@rfd.leadboat.com
This commit is contained in:
parent
24d769b905
commit
0454666758
@ -1245,7 +1245,6 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
|
|||||||
BTLeader *btleader = (BTLeader *) palloc0(sizeof(BTLeader));
|
BTLeader *btleader = (BTLeader *) palloc0(sizeof(BTLeader));
|
||||||
BufferUsage *bufferusage;
|
BufferUsage *bufferusage;
|
||||||
bool leaderparticipates = true;
|
bool leaderparticipates = true;
|
||||||
char *sharedquery;
|
|
||||||
int querylen;
|
int querylen;
|
||||||
|
|
||||||
#ifdef DISABLE_LEADER_PARTICIPATION
|
#ifdef DISABLE_LEADER_PARTICIPATION
|
||||||
@ -1308,9 +1307,14 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
|
|||||||
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
||||||
|
|
||||||
/* Finally, estimate PARALLEL_KEY_QUERY_TEXT space */
|
/* Finally, estimate PARALLEL_KEY_QUERY_TEXT space */
|
||||||
querylen = strlen(debug_query_string);
|
if (debug_query_string)
|
||||||
shm_toc_estimate_chunk(&pcxt->estimator, querylen + 1);
|
{
|
||||||
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
querylen = strlen(debug_query_string);
|
||||||
|
shm_toc_estimate_chunk(&pcxt->estimator, querylen + 1);
|
||||||
|
shm_toc_estimate_keys(&pcxt->estimator, 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
querylen = 0; /* keep compiler quiet */
|
||||||
|
|
||||||
/* Everyone's had a chance to ask for space, so now create the DSM */
|
/* Everyone's had a chance to ask for space, so now create the DSM */
|
||||||
InitializeParallelDSM(pcxt);
|
InitializeParallelDSM(pcxt);
|
||||||
@ -1372,9 +1376,14 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Store query string for workers */
|
/* Store query string for workers */
|
||||||
sharedquery = (char *) shm_toc_allocate(pcxt->toc, querylen + 1);
|
if (debug_query_string)
|
||||||
memcpy(sharedquery, debug_query_string, querylen + 1);
|
{
|
||||||
shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, sharedquery);
|
char *sharedquery;
|
||||||
|
|
||||||
|
sharedquery = (char *) shm_toc_allocate(pcxt->toc, querylen + 1);
|
||||||
|
memcpy(sharedquery, debug_query_string, querylen + 1);
|
||||||
|
shm_toc_insert(pcxt->toc, PARALLEL_KEY_QUERY_TEXT, sharedquery);
|
||||||
|
}
|
||||||
|
|
||||||
/* Allocate space for each worker's BufferUsage; no need to initialize */
|
/* Allocate space for each worker's BufferUsage; no need to initialize */
|
||||||
bufferusage = shm_toc_allocate(pcxt->toc,
|
bufferusage = shm_toc_allocate(pcxt->toc,
|
||||||
@ -1577,7 +1586,7 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
|
|||||||
#endif /* BTREE_BUILD_STATS */
|
#endif /* BTREE_BUILD_STATS */
|
||||||
|
|
||||||
/* Set debug_query_string for individual workers first */
|
/* Set debug_query_string for individual workers first */
|
||||||
sharedquery = shm_toc_lookup(toc, PARALLEL_KEY_QUERY_TEXT, false);
|
sharedquery = shm_toc_lookup(toc, PARALLEL_KEY_QUERY_TEXT, true);
|
||||||
debug_query_string = sharedquery;
|
debug_query_string = sharedquery;
|
||||||
|
|
||||||
/* Report the query string from leader */
|
/* Report the query string from leader */
|
||||||
|
Loading…
Reference in New Issue
Block a user