13
13
*/
14
14
15
15
#include "postgres.h"
16
+ #include "access/parallel.h" /* Just for IsParallelWorker() */
16
17
#include "miscadmin.h"
17
18
18
19
#include "aqo.h"
@@ -227,7 +228,7 @@ init_with_dsm(OkNNrdata *data, dsm_block_hdr *hdr, List **reloids)
227
228
Assert (LWLockHeldByMeInMode (& aqo_state -> lock ,LW_EXCLUSIVE )||
228
229
LWLockHeldByMeInMode (& aqo_state -> lock ,LW_SHARED ));
229
230
Assert (hdr -> magic == AQO_SHARED_MAGIC );
230
- Assert (hdr && ptr );
231
+ Assert (hdr && ptr && hdr -> rows > 0 );
231
232
232
233
data -> rows = hdr -> rows ;
233
234
data -> cols = hdr -> cols ;
@@ -245,6 +246,12 @@ init_with_dsm(OkNNrdata *data, dsm_block_hdr *hdr, List **reloids)
245
246
}
246
247
}
247
248
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
+
248
255
memcpy (data -> targets ,ptr ,sizeof (double )* hdr -> rows );
249
256
ptr += sizeof (double )* aqo_K ;
250
257
memcpy (data -> rfactors ,ptr ,sizeof (double )* hdr -> rows );
@@ -261,7 +268,7 @@ init_with_dsm(OkNNrdata *data, dsm_block_hdr *hdr, List **reloids)
261
268
return calculate_size (hdr -> cols ,* reloids );
262
269
}
263
270
264
- /* It is just read operation. No any interest in size calculation. */
271
+ /* It is justa read operation. No any interest in size calculation. */
265
272
return 0 ;
266
273
}
267
274
@@ -310,20 +317,25 @@ lc_assign_hook(bool newval, void *extra)
310
317
HASH_SEQ_STATUS status ;
311
318
htab_entry * entry ;
312
319
313
- if (!fss_htab || !IsUnderPostmaster )
320
+ if (!fss_htab || !IsUnderPostmaster || IsParallelWorker ())
321
+ /* Clean this shared cache only in main backend process. */
314
322
return ;
315
323
316
324
/* Remove all entries, reset memory context. */
317
325
318
326
elog (DEBUG5 ,"[AQO] Cleanup local cache of ML data." );
319
327
320
- /* Remove allfrozen plans from a plancache . */
328
+ /* Remove allentries in the shared hash table . */
321
329
LWLockAcquire (& aqo_state -> lock ,LW_EXCLUSIVE );
322
330
hash_seq_init (& status ,fss_htab );
323
331
while ((entry = (htab_entry * )hash_seq_search (& status ))!= NULL )
324
332
{
325
333
if (!hash_search (fss_htab , (void * )& entry -> key ,HASH_REMOVE ,NULL ))
326
334
elog (PANIC ,"[AQO] The local ML cache is corrupted." );
327
335
}
336
+
337
+ /* Now, clean additional DSM block */
338
+ reset_dsm_cache ();
339
+
328
340
LWLockRelease (& aqo_state -> lock );
329
341
}