On Mon, Nov 17, 2014 at 5:56 AM, Christian Ullrich <ch...@chrullrich.net> wrote:
> * Alvaro Herrera wrote:
>
>> Michael Paquier wrote:
>>
>>> Btw, perhaps this diff should be pushed as a different patch as this is a
>>> rather different thing:
>>> -       if (heapRelation->rd_rel->relpersistence ==
>>> RELPERSISTENCE_UNLOGGED
>>> &&
>>> +       if (indexRelation->rd_rel->relpersistence ==
>>> RELPERSISTENCE_UNLOGGED &&
>>>                  !smgrexists(indexRelation->rd_smgr, INIT_FORKNUM)
>>> As this is a correctness fix, it does not seem necessary to back-patch
>>> it:
>>> the parent relation always has the same persistence as its indexes.
>>
>>
>> There was an argument for doing it this way that only applies if this
>> patch went in, but I can't remember now what it was.
>>
>> Anyway I pushed the patch after some slight additional changes.  Thanks!
>
>
> The buildfarm says -DCLOBBER_CACHE_ALWAYS does not like this patch.
The complaint comes from jaguarundi, like here:
http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=jaguarundi&dt=2014-11-16%2015%3A33%3A23

Adding a new parameter to RelationSetNewRelFile
As Tom mentioned, adding a new parameter to set the persistence
through RelationSetNewRelfilenode works. Patch, actually tested with
CLOBBER_CACHE_ALWAYS, attached.
http://www.postgresql.org/message-id/27238.1416073...@sss.pgh.pa.us
Regards,
-- 
Michael
From a1a7e4182bd1b5d66260220f040aee4a35e91c75 Mon Sep 17 00:00:00 2001
From: Michael Paquier <mpaqu...@otacoo.com>
Date: Mon, 17 Nov 2014 17:04:05 +0000
Subject: [PATCH] Fix CLOBBER_CACHE_ALWAYS broken by 85b506b

Previous commit that removed ATChangeIndexesPersistence to replace it
with a lower-level API able to define a new relpersistence for a relation
when reindexing it failed with CLOBBER_CACHE_ALWAYS enabled. This patch
fixes it by setting the relpersistence of the newly-created relation after
its relfilenode is created by passing a new parameter to RelationSetNewRelfilenode
able to set the persistence of a relation.
---
 src/backend/catalog/index.c        | 5 +----
 src/backend/commands/sequence.c    | 3 ++-
 src/backend/commands/tablecmds.c   | 6 ++++--
 src/backend/utils/cache/relcache.c | 6 +++---
 src/include/utils/relcache.h       | 4 +++-
 5 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index b57aa95..825235a 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -3191,12 +3191,9 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence)
 			indexInfo->ii_ExclusionStrats = NULL;
 		}
 
-		/* Set the relpersistence of the new index */
-		iRel->rd_rel->relpersistence = persistence;
-
 		/* We'll build a new physical relation for the index */
 		RelationSetNewRelfilenode(iRel, InvalidTransactionId,
-								  InvalidMultiXactId);
+								  InvalidMultiXactId, persistence);
 
 		/* Initialize the index and rebuild */
 		/* Note: we do not need to re-establish pkey setting */
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index e5f7765..4f7f586 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -304,7 +304,8 @@ ResetSequence(Oid seq_relid)
 	 * Same with relminmxid, since a sequence will never contain multixacts.
 	 */
 	RelationSetNewRelfilenode(seq_rel, InvalidTransactionId,
-							  InvalidMultiXactId);
+							  InvalidMultiXactId,
+							  seq_rel->rd_rel->relpersistence);
 
 	/*
 	 * Insert the modified tuple into the new storage file.
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 093224f..c57751e 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -1196,7 +1196,8 @@ ExecuteTruncate(TruncateStmt *stmt)
 			 * as the relfilenode value. The old storage file is scheduled for
 			 * deletion at commit.
 			 */
-			RelationSetNewRelfilenode(rel, RecentXmin, minmulti);
+			RelationSetNewRelfilenode(rel, RecentXmin, minmulti,
+									  rel->rd_rel->relpersistence);
 			if (rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED)
 				heap_create_init_fork(rel);
 
@@ -1209,7 +1210,8 @@ ExecuteTruncate(TruncateStmt *stmt)
 			if (OidIsValid(toast_relid))
 			{
 				rel = relation_open(toast_relid, AccessExclusiveLock);
-				RelationSetNewRelfilenode(rel, RecentXmin, minmulti);
+				RelationSetNewRelfilenode(rel, RecentXmin, minmulti,
+										  rel->rd_rel->relpersistence);
 				if (rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED)
 					heap_create_init_fork(rel);
 				heap_close(rel, NoLock);
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 2250c56..fa75771 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -3008,7 +3008,7 @@ RelationBuildLocalRelation(const char *relname,
  */
 void
 RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid,
-						  MultiXactId minmulti)
+						  MultiXactId minmulti, char relpersistence)
 {
 	Oid			newrelfilenode;
 	RelFileNodeBackend newrnode;
@@ -3048,7 +3048,7 @@ RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid,
 	newrnode.node = relation->rd_node;
 	newrnode.node.relNode = newrelfilenode;
 	newrnode.backend = relation->rd_backend;
-	RelationCreateStorage(newrnode.node, relation->rd_rel->relpersistence);
+	RelationCreateStorage(newrnode.node, relpersistence);
 	smgrclosenode(newrnode);
 
 	/*
@@ -3078,7 +3078,7 @@ RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid,
 	}
 	classform->relfrozenxid = freezeXid;
 	classform->relminmxid = minmulti;
-	classform->relpersistence = relation->rd_rel->relpersistence;
+	classform->relpersistence = relpersistence;
 
 	simple_heap_update(pg_class, &tuple->t_self, tuple);
 	CatalogUpdateIndexes(pg_class, tuple);
diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h
index e4ca70f..6e0fc56 100644
--- a/src/include/utils/relcache.h
+++ b/src/include/utils/relcache.h
@@ -96,7 +96,9 @@ extern Relation RelationBuildLocalRelation(const char *relname,
  * Routine to manage assignment of new relfilenode to a relation
  */
 extern void RelationSetNewRelfilenode(Relation relation,
-						  TransactionId freezeXid, MultiXactId minmulti);
+									  TransactionId freezeXid,
+									  MultiXactId minmulti,
+									  char relpersistence);
 
 /*
  * Routines for flushing/rebuilding relcache entries in various scenarios
-- 
2.1.3

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to