This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit a245727a4a8a4113906e044451ba59c7c37a69f1
Author: Soumyadeep Chakraborty <soumyadeep2...@gmail.com>
AuthorDate: Thu Jun 29 17:34:16 2023 -0700

    function_extensions: Fix tmpdir ls flake
    
    The function_extensions test used to flake as follows:
    
    -- Temp file number before running INITPLAN function
     SELECT get_temp_file_num();
          get_temp_file_num
     ------------
    - 0 files and 0 directories
    + 0 files and 1 directories
     (1 row)
    
    It is possible that some temp directories are present sometimes before
    the we execute the INITPLAN function, just like this old comment
    suggests that temp dirs like pgsql_tmp3889679.0.sharedfileset may hang
    around:
    
    -- Temp file number after running INITPLAN function. All the files should've
    -- been cleaned up, but it's normal that the temp directory to hold them is
    -- still around.
    
    So, in this commit, we don't even bother about the directories, we just
    look at the files. That too, we also eliminate any other possibility of
    flakes by doing a before-and-after-equality-check.
    
    PS: Tried to use pg_ls_tmpdir(), however it doesn't recurse into
    SharedFileSets, as this thread suggests:
    https://www.postgresql.org/message-id/20191227170220.GE12890%40telsasoft.com
---
 src/test/regress/expected/function_extensions.out  | 28 +++++++++-------------
 .../expected/function_extensions_optimizer.out     | 28 +++++++++-------------
 src/test/regress/sql/function_extensions.sql       | 18 +++++++-------
 3 files changed, 31 insertions(+), 43 deletions(-)

diff --git a/src/test/regress/expected/function_extensions.out 
b/src/test/regress/expected/function_extensions.out
index 40c76a2ad2..f2464c3e15 100644
--- a/src/test/regress/expected/function_extensions.out
+++ b/src/test/regress/expected/function_extensions.out
@@ -460,17 +460,14 @@ NOTICE:  unique_violation
 -- the function on initplan to overcome the above issue.
 -- Helper function to count the number of temporary files in
 -- pgsql_tmp.
-CREATE or replace FUNCTION get_temp_file_num() returns text as
+CREATE or replace FUNCTION get_temp_file_num() returns int as
 $$
 import os
 fileNum = 0
-dirNum = 0
 for root, directories, filenames in os.walk('base/pgsql_tmp'):
   for filename in filenames:
     fileNum += 1
-  for dir in directories:
-    dirNum += 1
-return '{} files and {} directories'.format(fileNum, dirNum)
+return fileNum
 $$ language plpython3u;
 CREATE OR REPLACE FUNCTION get_country()
  RETURNS TABLE (
@@ -496,12 +493,8 @@ AS $$
   end; $$
 LANGUAGE 'plpgsql' EXECUTE ON INITPLAN;
 -- Temp file number before running INITPLAN function
-SELECT get_temp_file_num();
-     get_temp_file_num     
----------------------------
- 0 files and 0 directories
-(1 row)
-
+SELECT get_temp_file_num() AS num_temp_files_before
+\gset
 SELECT * FROM get_country();
 NOTICE:  table "country" does not exist, skipping
 NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 
'country_id' as the Cloudberry Database data distribution key for this table.
@@ -648,12 +641,13 @@ NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- 
Using column(s) named '?c
 HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make 
sure column(s) chosen are the optimal data distribution key to minimize skew.
 ERROR:  division by zero  (entry db 10.146.0.4:7000 pid=20360)
 -- Temp file number after running INITPLAN function. All the files should've
--- been cleaned up, but it's normal that the temp directory to hold them is
--- still around.
-SELECT get_temp_file_num();
-     get_temp_file_num     
----------------------------
- 0 files and 1 directories
+-- been cleaned up
+SELECT get_temp_file_num() AS num_temp_files_after
+\gset
+SELECT :num_temp_files_before = :num_temp_files_after;
+ ?column? 
+----------
+ t
 (1 row)
 
 -- test join case with two INITPLAN functions
diff --git a/src/test/regress/expected/function_extensions_optimizer.out 
b/src/test/regress/expected/function_extensions_optimizer.out
index 6ef674af08..39457f3c60 100644
--- a/src/test/regress/expected/function_extensions_optimizer.out
+++ b/src/test/regress/expected/function_extensions_optimizer.out
@@ -464,17 +464,14 @@ NOTICE:  unique_violation
 -- the function on initplan to overcome the above issue.
 -- Helper function to count the number of temporary files in
 -- pgsql_tmp.
-CREATE or replace FUNCTION get_temp_file_num() returns text as
+CREATE or replace FUNCTION get_temp_file_num() returns int as
 $$
 import os
 fileNum = 0
-dirNum = 0
 for root, directories, filenames in os.walk('base/pgsql_tmp'):
   for filename in filenames:
     fileNum += 1
-  for dir in directories:
-    dirNum += 1
-return '{} files and {} directories'.format(fileNum, dirNum)
+return fileNum
 $$ language plpython3u;
 CREATE OR REPLACE FUNCTION get_country()
  RETURNS TABLE (
@@ -500,12 +497,8 @@ AS $$
   end; $$
 LANGUAGE 'plpgsql' EXECUTE ON INITPLAN;
 -- Temp file number before running INITPLAN function
-SELECT get_temp_file_num();
-     get_temp_file_num     
----------------------------
- 0 files and 0 directories
-(1 row)
-
+SELECT get_temp_file_num() AS num_temp_files_before
+\gset
 SELECT * FROM get_country();
 NOTICE:  table "country" does not exist, skipping
 NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 
'country_id' as the Cloudberry Database data distribution key for this table.
@@ -652,12 +645,13 @@ NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause -- 
Using column(s) named '?c
 HINT:  The 'DISTRIBUTED BY' clause determines the distribution of data. Make 
sure column(s) chosen are the optimal data distribution key to minimize skew.
 ERROR:  division by zero  (entry db 10.146.0.4:7000 pid=20360)
 -- Temp file number after running INITPLAN function. All the files should've
--- been cleaned up, but it's normal that the temp directory to hold them is
--- still around.
-SELECT get_temp_file_num();
-     get_temp_file_num     
----------------------------
- 0 files and 1 directories
+-- been cleaned up
+SELECT get_temp_file_num() AS num_temp_files_after
+\gset
+SELECT :num_temp_files_before = :num_temp_files_after;
+ ?column? 
+----------
+ t
 (1 row)
 
 -- test join case with two INITPLAN functions
diff --git a/src/test/regress/sql/function_extensions.sql 
b/src/test/regress/sql/function_extensions.sql
index 49f33f4c87..468d4f9f5b 100644
--- a/src/test/regress/sql/function_extensions.sql
+++ b/src/test/regress/sql/function_extensions.sql
@@ -268,17 +268,14 @@ SELECT trigger_unique();
 
 -- Helper function to count the number of temporary files in
 -- pgsql_tmp.
-CREATE or replace FUNCTION get_temp_file_num() returns text as
+CREATE or replace FUNCTION get_temp_file_num() returns int as
 $$
 import os
 fileNum = 0
-dirNum = 0
 for root, directories, filenames in os.walk('base/pgsql_tmp'):
   for filename in filenames:
     fileNum += 1
-  for dir in directories:
-    dirNum += 1
-return '{} files and {} directories'.format(fileNum, dirNum)
+return fileNum
 $$ language plpython3u;
 
 CREATE OR REPLACE FUNCTION get_country()
@@ -307,7 +304,9 @@ AS $$
 LANGUAGE 'plpgsql' EXECUTE ON INITPLAN;
 
 -- Temp file number before running INITPLAN function
-SELECT get_temp_file_num();
+SELECT get_temp_file_num() AS num_temp_files_before
+\gset
+
 SELECT * FROM get_country();
 SELECT get_country();
 
@@ -364,9 +363,10 @@ DROP TABLE IF EXISTS t4_function_scan;
 CREATE TABLE t4_function_scan AS SELECT 444, (1 / (0* random()))::text UNION 
ALL SELECT * FROM get_country();
 
 -- Temp file number after running INITPLAN function. All the files should've
--- been cleaned up, but it's normal that the temp directory to hold them is
--- still around.
-SELECT get_temp_file_num();
+-- been cleaned up
+SELECT get_temp_file_num() AS num_temp_files_after
+\gset
+SELECT :num_temp_files_before = :num_temp_files_after;
 
 -- test join case with two INITPLAN functions
 DROP TABLE IF EXISTS t5_function_scan;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cloudberry.apache.org
For additional commands, e-mail: commits-h...@cloudberry.apache.org

Reply via email to