wal-optimize-noah-tests-v1.patch

text/plain

Filename: wal-optimize-noah-tests-v1.patch
Type: text/plain
Part: 0
Message: Re: [HACKERS] WAL logging problem in 9.4.3?

Patch

Format: unified
Series: patch v1
File+
src/test/recovery/t/016_wal_optimize.pl 63 3
diff --git a/src/test/recovery/t/016_wal_optimize.pl b/src/test/recovery/t/016_wal_optimize.pl
index 310772a..988ccaf 100644
--- a/src/test/recovery/t/016_wal_optimize.pl
+++ b/src/test/recovery/t/016_wal_optimize.pl
@@ -11,7 +11,24 @@ use warnings;
 
 use PostgresNode;
 use TestLib;
-use Test::More tests => 14;
+use Test::More tests => 20;
+
+sub check_orphan_relfilenodes
+{
+	my($node) = @_;
+
+	my $db_oid = $node->safe_psql('postgres',
+	   "SELECT oid FROM pg_database WHERE datname = 'postgres'");
+	my $prefix = "base/$db_oid/";
+	my $filepaths_referenced = $node->safe_psql('postgres', "
+	   SELECT pg_relation_filepath(oid) FROM pg_class
+	   WHERE reltablespace = 0 and pg_relation_filepath(oid) IS NOT NULL;");
+	is_deeply([sort(map { "$prefix$_" }
+					grep(/^[0-9]+$/,
+						 slurp_dir($node->data_dir . "/$prefix")))],
+			  [sort split /\n/, $filepaths_referenced]);
+	return;
+}
 
 # Wrapper routine tunable for wal_level.
 sub run_wal_optimize
@@ -26,6 +43,13 @@ wal_level = $wal_level
 ));
 	$node->start;
 
+	# Setup
+	my $tablespace_dir = $node->basedir . '/tablespace_other';
+	mkdir ($tablespace_dir);
+	$tablespace_dir = TestLib::real_dir($tablespace_dir);
+	$node->safe_psql('postgres',
+	   "CREATE TABLESPACE other LOCATION '$tablespace_dir';");
+
 	# Test direct truncation optimization.  No tuples
 	$node->safe_psql('postgres', "
 		BEGIN;
@@ -79,6 +103,36 @@ wal_level = $wal_level
 	is($result, qq(3),
 	   "wal_level = $wal_level, optimized truncation with copied table");
 
+	# Like previous test, but rollback SET TABLESPACE in a subtransaction.
+	$node->safe_psql('postgres', "
+		BEGIN;
+		CREATE TABLE test3a (id serial PRIMARY KEY, id2 int);
+		INSERT INTO test3a (id, id2) VALUES (DEFAULT, generate_series(1,10000));
+		TRUNCATE test3a;
+		SAVEPOINT s; ALTER TABLE test3a SET TABLESPACE other; ROLLBACK TO s;
+		COPY test3a FROM '$copy_file' DELIMITER ',';
+		COMMIT;");
+	$node->stop('immediate');
+	$node->start;
+	$result = $node->safe_psql('postgres', "SELECT count(*) FROM test3a;");
+	is($result, qq(3),
+	   "wal_level = $wal_level, SET TABLESPACE in subtransaction");
+
+	# UPDATE touches two buffers; one is BufferNeedsWAL(); the other is not.
+	$node->safe_psql('postgres', "
+		BEGIN;
+		CREATE TABLE test3b (id serial PRIMARY KEY, id2 int);
+		INSERT INTO test3b (id, id2) VALUES (DEFAULT, generate_series(1,10000));
+		COPY test3b FROM '$copy_file' DELIMITER ',';  -- set sync_above
+		UPDATE test3b SET id2 = id2 + 1;
+		DELETE FROM test3b;
+		COMMIT;");
+	$node->stop('immediate');
+	$node->start;
+	$result = $node->safe_psql('postgres', "SELECT count(*) FROM test3b;");
+	is($result, qq(0),
+	   "wal_level = $wal_level, UPDATE of logged page extends relation");
+
 	# Test truncation with inserted tuples using both INSERT and COPY. Tuples
 	# inserted after the truncation should be seen.
 	$node->safe_psql('postgres', "
@@ -182,8 +236,14 @@ wal_level = $wal_level
 	is($result, qq(4),
 	   "wal_level = $wal_level, replay of optimized copy with before trigger");
 
-	$node->teardown_node;
-	$node->clean_node;
+	# Test redo of temp table creation.
+	$node->safe_psql('postgres', "
+		CREATE TEMP TABLE test8 (id serial PRIMARY KEY, id2 text);");
+	$node->stop('immediate');
+	$node->start;
+
+	check_orphan_relfilenodes $node;
+
 	return;
 }