From 2a7f66ba5dc9020bf2f5e0f5d94bdb545cd2ba09 Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Tue, 11 Feb 2014 16:21:41 -0500 Subject: [PATCH] v1.6.0 Fixed lock wait counter not being reset in partitioning functions --- CHANGELOG | 1 + bin/dump_partition.py | 4 ++-- sql/functions/partition_data_id.sql | 2 +- sql/functions/partition_data_time.sql | 2 +- updates/pg_partman--1.5.1--1.6.0.sql | 3 +++ 5 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e5bde2f1..21f4cbcd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,7 @@ -- For id-based partitioning, only the partition starting at the given value (plus premake) will be made. -- pg_jobmon is now truly optional. Additonal configuration option for each individual partition set to turn it off and on. run_maintenance() now has an optional parameter to turn it off when being run. If you tried to partition pg_jobmon tables before, it would cause a permanent lockwait. Turn pg_jobmon off for those tables to avoid this. -- Fixed partition_data_time() & partition_data_id() functions to recreate the parent trigger function when static partitioning is used. Without this, partitioning more recent data that may have gotten into the parent table could possibly leave the function without conditions for the new partitions. run_maintenance() would eventually fix this for time partitioning, but id partitioning could be left in a broken state forever. (Github issue #16) +-- Fixed bug in partition_data_time() & partition_data_id() to reset the lock wait counter properly between loops. Bug reported & fixed by bougyman from #postgresql on Freenode. -- pg_partman only supports id intervals greater than 1. May see if I can get an interval of 1 working later, but changed create_parent() to check for this and not allow it since it won't work properly at this time. New partitions were not automatically created if interval was set to 1. (Github issue #15) -- Clarify in docs that the id interval value passed to create_parent() must actually be in text type format. -- Changed drop & undo partition functions to use transaction based advistory locks. diff --git a/bin/dump_partition.py b/bin/dump_partition.py index 377f664d..0420361e 100755 --- a/bin/dump_partition.py +++ b/bin/dump_partition.py @@ -78,7 +78,7 @@ def create_hash(table_name): break shash.update(data) except IOError, (ErrorNo, ErrorMsg): - print "Cannot access dump file for hash creation: " + ErrorMessage + print "Cannot access dump file for hash creation: " + ErrorMsg sys.exit(2) hash_file = os.path.join(args.output, args.schema + "." + table_name + ".hash") @@ -88,7 +88,7 @@ def create_hash(table_name): with open(hash_file, "w") as fh: fh.write(shash.hexdigest() + " " + os.path.basename(output_file)) except IOError, (ErroNo, ErrorMsg): - print "Unable to write to hash file: " + ErrorMessage + print "Unable to write to hash file: " + ErrorMsg sys.exit(2) diff --git a/sql/functions/partition_data_id.sql b/sql/functions/partition_data_id.sql index bf3abb32..39985141 100644 --- a/sql/functions/partition_data_id.sql +++ b/sql/functions/partition_data_id.sql @@ -59,6 +59,7 @@ FOR i IN 1..p_batch_count LOOP -- do some locking with timeout, if required IF p_lock_wait > 0 THEN + v_lock_iter := 0; WHILE v_lock_iter <= 5 LOOP v_lock_iter := v_lock_iter + 1; BEGIN @@ -103,4 +104,3 @@ RETURN v_total_rows; END $$; - diff --git a/sql/functions/partition_data_time.sql b/sql/functions/partition_data_time.sql index e6a98697..5eb978ae 100644 --- a/sql/functions/partition_data_time.sql +++ b/sql/functions/partition_data_time.sql @@ -104,6 +104,7 @@ FOR i IN 1..p_batch_count LOOP -- do some locking with timeout, if required IF p_lock_wait > 0 THEN + v_lock_iter := 0; WHILE v_lock_iter <= 5 LOOP v_lock_iter := v_lock_iter + 1; BEGIN @@ -148,4 +149,3 @@ RETURN v_total_rows; END $$; - diff --git a/updates/pg_partman--1.5.1--1.6.0.sql b/updates/pg_partman--1.5.1--1.6.0.sql index 9d2e2529..7a7bea34 100644 --- a/updates/pg_partman--1.5.1--1.6.0.sql +++ b/updates/pg_partman--1.5.1--1.6.0.sql @@ -6,6 +6,7 @@ -- For id-based partitioning, only the partition starting at the given value (plus premake) will be made. -- pg_jobmon is now truly optional. Additonal configuration option for each individual partition set to turn it off and on. run_maintenance() now has an optional parameter to turn it off when being run. If you tried to partition pg_jobmon tables before, it would cause a permanent lockwait. Turn pg_jobmon off for those tables to avoid this. -- Fixed partition_data_time() & partition_data_id() functions to recreate the parent trigger function when static partitioning is used. Without this, partitioning more recent data that may have gotten into the parent table could possibly leave the function without conditions for the new partitions. run_maintenance() would eventually fix this for time partitioning, but id partitioning could be left in a broken state forever. (Github issue #16) +-- Fixed bug in partition_data_time() & partition_data_id() to reset the lock wait counter properly between loops. Bug reported & fixed by bougyman from #postgresql on Freenode. -- pg_partman only supports id intervals greater than 1. May see if I can get an interval of 1 working later, but changed create_parent() to check for this and not allow it since it won't work properly at this time. New partitions were not automatically created if interval was set to 1. (Github issue #15) -- Clarify in docs that the id interval value passed to create_parent() must actually be in text type format. -- Changed drop & undo partition functions to use transaction based advistory locks. @@ -930,6 +931,7 @@ FOR i IN 1..p_batch_count LOOP -- do some locking with timeout, if required IF p_lock_wait > 0 THEN + v_lock_iter := 0; WHILE v_lock_iter <= 5 LOOP v_lock_iter := v_lock_iter + 1; BEGIN @@ -1984,6 +1986,7 @@ FOR i IN 1..p_batch_count LOOP -- do some locking with timeout, if required IF p_lock_wait > 0 THEN + v_lock_iter := 0; WHILE v_lock_iter <= 5 LOOP v_lock_iter := v_lock_iter + 1; BEGIN