Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29512d9

Browse files
danolivoAlena0704
authored andcommitted
Several bugfixes here:
1. don't enable statement timeout in parallel worker and 2. minor DSM cache fix. 3. don't clear learn_cache in a parallel worker.
1 parent fcfff8f commit 29512d9

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

aqo_shared.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,10 @@ reset_dsm_cache(void)
7777

7878
Assert(LWLockHeldByMeInMode(&aqo_state->lock, LW_EXCLUSIVE));
7979

80-
if (aqo_state->dsm_handler == DSM_HANDLE_INVALID)
80+
if (aqo_state->dsm_handler == DSM_HANDLE_INVALID || !seg)
8181
/* Fast path. No any cached data exists. */
8282
return;
8383

84-
Assert(seg);
85-
8684
hdr = (dsm_seg_hdr *) dsm_segment_address(seg);
8785
start = (char *) hdr + sizeof(dsm_seg_hdr);
8886

learn_cache.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#include "postgres.h"
16+
#include "access/parallel.h" /* Just for IsParallelWorker() */
1617
#include "miscadmin.h"
1718

1819
#include "aqo.h"
@@ -227,7 +228,7 @@ init_with_dsm(OkNNrdata *data, dsm_block_hdr *hdr, List **reloids)
227228
Assert(LWLockHeldByMeInMode(&aqo_state->lock, LW_EXCLUSIVE) ||
228229
LWLockHeldByMeInMode(&aqo_state->lock, LW_SHARED));
229230
Assert(hdr->magic == AQO_SHARED_MAGIC);
230-
Assert(hdr && ptr);
231+
Assert(hdr && ptr && hdr->rows > 0);
231232

232233
data->rows = hdr->rows;
233234
data->cols = hdr->cols;
@@ -245,6 +246,12 @@ init_with_dsm(OkNNrdata *data, dsm_block_hdr *hdr, List **reloids)
245246
}
246247
}
247248

249+
/*
250+
* Kludge code. But we should rewrite this code because now all knowledge
251+
* base lives in non-transactional shared memory.
252+
*/
253+
ptr = (char *) hdr + sizeof(dsm_block_hdr) + (sizeof(double) * data->cols * aqo_K);
254+
248255
memcpy(data->targets, ptr, sizeof(double) * hdr->rows);
249256
ptr += sizeof(double) * aqo_K;
250257
memcpy(data->rfactors, ptr, sizeof(double) * hdr->rows);
@@ -261,7 +268,7 @@ init_with_dsm(OkNNrdata *data, dsm_block_hdr *hdr, List **reloids)
261268
return calculate_size(hdr->cols, *reloids);
262269
}
263270

264-
/* It is just read operation. No any interest in size calculation. */
271+
/* It is just a read operation. No any interest in size calculation. */
265272
return 0;
266273
}
267274

@@ -310,20 +317,25 @@ lc_assign_hook(bool newval, void *extra)
310317
HASH_SEQ_STATUS status;
311318
htab_entry *entry;
312319

313-
if (!fss_htab || !IsUnderPostmaster)
320+
if (!fss_htab || !IsUnderPostmaster || IsParallelWorker())
321+
/* Clean this shared cache only in main backend process. */
314322
return;
315323

316324
/* Remove all entries, reset memory context. */
317325

318326
elog(DEBUG5, "[AQO] Cleanup local cache of ML data.");
319327

320-
/* Remove all frozen plans from a plancache. */
328+
/* Remove all entries in the shared hash table. */
321329
LWLockAcquire(&aqo_state->lock, LW_EXCLUSIVE);
322330
hash_seq_init(&status, fss_htab);
323331
while ((entry = (htab_entry *) hash_seq_search(&status)) != NULL)
324332
{
325333
if (!hash_search(fss_htab, (void *) &entry->key, HASH_REMOVE, NULL))
326334
elog(PANIC, "[AQO] The local ML cache is corrupted.");
327335
}
336+
337+
/* Now, clean additional DSM block */
338+
reset_dsm_cache();
339+
328340
LWLockRelease(&aqo_state->lock);
329341
}

postprocessing.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,13 @@ set_timeout_if_need(QueryDesc *queryDesc)
640640
{
641641
TimestampTz fin_time;
642642

643+
if (IsParallelWorker())
644+
/*
645+
* AQO timeout should stop only main worker. Other workers would be
646+
* terminated by a regular ERROR machinery.
647+
*/
648+
return false;
649+
643650
if (!get_timeout_active(STATEMENT_TIMEOUT) || !aqo_learn_statement_timeout)
644651
return false;
645652

0 commit comments

Comments
 (0)