Hi,

Today, I tried to cancel the change of a tablespace for a table (ALTER
TABLE ... SET TABLESPACE). I got the "Cancel request sent" but the query
continued and finally succeed. It was a big issue for my customer, and I
wanted to look more into that issue. So, I got a look at the source code
and found we didn't check for interrupts in this part of the code. I
added them, and it seems to work as I wanted.

I added a CHECK_FOR_INTERRUPTS call in the copy_relation_data(),
copy_dir(), and copy_file() functions. Works for me on ALTER TABLE ...
SET TABLESPACE and ALTER DATABASE ... SET TABLESPACE, in 9.0 and 8.4.

Not sure we really want that change, and it don't feel like a bug to me.
Should I add it to to the next commitfest?

Comments?


-- 
Guillaume
 http://www.postgresql.fr
 http://dalibo.com
Index: src/backend/commands/tablecmds.c
===================================================================
RCS file: /opt/cvsroot_postgresql/pgsql/src/backend/commands/tablecmds.c,v
retrieving revision 1.330
diff -c -p -c -r1.330 tablecmds.c
*** src/backend/commands/tablecmds.c	28 Apr 2010 16:10:41 -0000	1.330
--- src/backend/commands/tablecmds.c	21 Jun 2010 16:33:30 -0000
*************** copy_relation_data(SMgrRelation src, SMg
*** 7049,7054 ****
--- 7049,7057 ----
  
  	for (blkno = 0; blkno < nblocks; blkno++)
  	{
+         /* If we got a cancel signal during the copy of the data, quit */
+         CHECK_FOR_INTERRUPTS();
+         
  		smgrread(src, forkNum, blkno, buf);
  
  		/* XLOG stuff */
Index: src/port/copydir.c
===================================================================
RCS file: /opt/cvsroot_postgresql/pgsql/src/port/copydir.c,v
retrieving revision 1.36
diff -c -p -c -r1.36 copydir.c
*** src/port/copydir.c	1 Mar 2010 14:54:00 -0000	1.36
--- src/port/copydir.c	21 Jun 2010 16:33:30 -0000
***************
*** 23,28 ****
--- 23,29 ----
  #include <sys/stat.h>
  
  #include "storage/fd.h"
+ #include "miscadmin.h"
  
  /*
   *	On Windows, call non-macro versions of palloc; we can't reference
*************** copydir(char *fromdir, char *todir, bool
*** 67,72 ****
--- 68,76 ----
  
  	while ((xlde = ReadDir(xldir, fromdir)) != NULL)
  	{
+         /* If we got a cancel signal during the copy of the directory, quit */
+         CHECK_FOR_INTERRUPTS();
+ 
  		struct stat fst;
  
  		if (strcmp(xlde->d_name, ".") == 0 ||
*************** copy_file(char *fromfile, char *tofile)
*** 172,177 ****
--- 176,184 ----
  	 */
  	for (offset = 0;; offset += nbytes)
  	{
+         /* If we got a cancel signal during the copy of the file, quit */
+         CHECK_FOR_INTERRUPTS();
+ 
  		nbytes = read(srcfd, buffer, COPY_BUF_SIZE);
  		if (nbytes < 0)
  			ereport(ERROR,
-- 
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