Re: crash-recovery replay of CREATE TABLESPACE is broken in HEAD
От | Bruce Momjian |
---|---|
Тема | Re: crash-recovery replay of CREATE TABLESPACE is broken in HEAD |
Дата | |
Msg-id | 201007201821.o6KILlW29119@momjian.us обсуждение исходный текст |
Ответ на | Re: crash-recovery replay of CREATE TABLESPACE is broken in HEAD (Bruce Momjian <bruce@momjian.us>) |
Список | pgsql-hackers |
Bruce Momjian wrote: > Bruce Momjian wrote: > > > The attached patch does as suggested. I added the recovery code to the > > > create tablespace function so I didn't have to duplicate all the code > > > that computes the path names. > > > > > > Attached. > > > > Uh, another question. Looking at the createdb recovery, I see: > > > > /* > > * Our theory for replaying a CREATE is to forcibly drop the target > > * subdirectory if present, then re-copy the source data. This may be > > * more work than needed, but it is simple to implement. > > */ > > if (stat(dst_path, &st) == 0 && S_ISDIR(st.st_mode)) > > { > > if (!rmtree(dst_path, true)) > > ereport(WARNING, > > (errmsg("some useless files may be left behind in old database directory \"%s\"", > > dst_path))); > > } > > > > Should I be using rmtree() on the mkdir target? > > > > Also, the original tablespace recovery code did not drop the symlink > > first. I assume that was not a bug only because we don't support moving > > tablespaces: > > For consistency with CREATE DATABASE recovery and for reliablity, I > coded the rmtree() call instead. Patch attached. Attached patch applied to HEAD and 9.0. 9.0 open item moved to completed. -- Bruce Momjian <bruce@momjian.us> http://momjian.us EnterpriseDB http://enterprisedb.com + None of us is going to be here forever. + Index: src/backend/commands/dbcommands.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v retrieving revision 1.235 diff -c -c -r1.235 dbcommands.c *** src/backend/commands/dbcommands.c 26 Feb 2010 02:00:38 -0000 1.235 --- src/backend/commands/dbcommands.c 20 Jul 2010 18:11:06 -0000 *************** *** 1908,1913 **** --- 1908,1914 ---- if (stat(dst_path, &st) == 0 && S_ISDIR(st.st_mode)) { if (!rmtree(dst_path, true)) + /* If this failed, copydir() below is going to error. */ ereport(WARNING, (errmsg("some useless files may be left behind in old database directory \"%s\"", dst_path))); Index: src/backend/commands/tablespace.c =================================================================== RCS file: /cvsroot/pgsql/src/backend/commands/tablespace.c,v retrieving revision 1.77 diff -c -c -r1.77 tablespace.c *** src/backend/commands/tablespace.c 18 Jul 2010 04:47:46 -0000 1.77 --- src/backend/commands/tablespace.c 20 Jul 2010 18:11:07 -0000 *************** *** 562,567 **** --- 562,586 ---- location))); } + if (InRecovery) + { + struct stat st; + + /* + * Our theory for replaying a CREATE is to forcibly drop the target + * subdirectory if present, and then recreate it. This may be + * more work than needed, but it is simple to implement. + */ + if (stat(location_with_version_dir, &st) == 0 && S_ISDIR(st.st_mode)) + { + if (!rmtree(location_with_version_dir, true)) + /* If this failed, mkdir() below is going to error. */ + ereport(WARNING, + (errmsg("some useless files may be left behind in old database directory \"%s\"", + location_with_version_dir))); + } + } + /* * The creation of the version directory prevents more than one tablespace * in a single location. *************** *** 580,585 **** --- 599,614 ---- location_with_version_dir))); } + /* Remove old symlink in recovery, in case it points to the wrong place */ + if (InRecovery) + { + if (unlink(linkloc) < 0 && errno != ENOENT) + ereport(ERROR, + (errcode_for_file_access(), + errmsg("could not remove symbolic link \"%s\": %m", + linkloc))); + } + /* * Create the symlink under PGDATA */
В списке pgsql-hackers по дате отправления: