Fix bug in pcp_invalidate_query_cache.
authorTatsuo Ishii <[email protected]>
Thu, 17 Oct 2024 04:59:17 +0000 (13:59 +0900)
committerTatsuo Ishii <[email protected]>
Thu, 17 Oct 2024 04:59:17 +0000 (13:59 +0900)
Buildfarm reported 006.memqcache failure. This was caused by a mistake
in the test script (test.sh). It executes pcp_invalidate_query_cache
then compares the results of a query calling current_timestamp which
is already in query cache (using /*FORCE QUERY CACHE*/ comment). Since
pcp_invalidate_query_cache just places an invalidation request and
next query processes it, comparing the result right after execution of
"SELECT current_timestamp" with the previous cached result indeed
returns an equality and the test failed. To fix this, after
pcp_invalidate_query_cache, executes a different query.

Also I found the test not only fails, but sometimes causes timeout at
my local environment. Inspecting the remaining child process showed
that it is likely the SIGINT handler was not executed (variable
exit_request was not set). I suspect this is because
pool_clear_memory_cache(), which is responsible for actually clearing
the query cache, blocks all signal including SIGINT. I think this is
the reason why the signal handler for SIGINT is not executed. Since
pool_clear_memory_cache() already uses pool_shmem_lock() to protect
the operation on query cache, the signal blocking is not necessary. In
this commit I just removed calls to POOL_SETMASK2 and POOL_SETMASK.

src/query_cache/pool_memqcache.c
src/test/regression/tests/006.memqcache/test.sh

index de50729d1e488f0d1dd312c9a5e3f6305b9d20a8..4c55f0fc404a0a26a1742671e6ebefe12e77c407 100644 (file)
@@ -2126,9 +2126,7 @@ void
 pool_clear_memory_cache(void)
 {
        size_t          size;
-       pool_sigset_t oldmask;
 
-       POOL_SETMASK2(&BlockSig, &oldmask);
        pool_shmem_lock(POOL_MEMQ_EXCLUSIVE_LOCK);
 
        PG_TRY();
@@ -2148,13 +2146,11 @@ pool_clear_memory_cache(void)
        PG_CATCH();
        {
                pool_shmem_unlock();
-               POOL_SETMASK(&oldmask);
                PG_RE_THROW();
        }
        PG_END_TRY();
 
        pool_shmem_unlock();
-       POOL_SETMASK(&oldmask);
 }
 
 #ifdef USE_MEMCACHED
index e915d8c5dc4431b1154d0df2ce584ecff59eb252..4b218e197c3474bb436ba05beef8a4ceb2f1bae4 100755 (executable)
@@ -482,6 +482,7 @@ EOF
            exit 1
        fi
        # make sure query cache has gone
+       $PSQL -t -c "SELECT 1" test     # this query processes query cache invalidation request
        res1=`$PSQL -t -c "/*FORCE QUERY CACHE*/SELECT current_timestamp" test`
        if [ "$res1" = "$res2" ];then
            echo "query cache was not invalidated"