my-ship-it commented on code in PR #1585:
URL: https://github.com/apache/cloudberry/pull/1585#discussion_r2882796103
##########
src/backend/commands/dbcommands.c:
##########
@@ -2459,28 +2499,32 @@ dbase_redo(XLogReaderState *record)
}
/*
- * It is possible that the tablespace was later dropped, but we
are
- * re-redoing database create before that. In that case,
- * either src_path or dst_path is probably missing here and
needs to
- * be created. We create directories here so that copy_dir()
won't
- * fail, but do not bother to create the symlink under pg_tblspc
- * if the tablespace is not global/default.
+ * If the parent of the target path doesn't exist, create it
now. This
+ * enables us to create the target underneath later. Note that
if
+ * the database dir is not in a tablespace, the parent will
always
+ * exist, so this never runs in that case.
*/
- if (stat(src_path, &st) != 0 && pg_mkdir_p(src_path, S_IRWXU)
!= 0)
- {
- ereport(WARNING,
- (errmsg("can not recursively create
directory \"%s\"",
- src_path)));
- }
- parentdir = pstrdup(dst_path);
- get_parent_directory(parentdir);
- if (stat(parentdir, &st) != 0 && pg_mkdir_p(parentdir, S_IRWXU)
!= 0)
+ parent_path = pstrdup(dst_path);
+ get_parent_directory(parent_path);
+ if (stat(parent_path, &st) < 0)
{
- ereport(WARNING,
- (errmsg("can not recursively create
directory \"%s\"",
- parentdir)));
+ if (errno != ENOENT)
+ ereport(FATAL,
+ errmsg("could not stat
directory \"%s\": %m",
+ dst_path));
+
+ recovery_create_dbdir(parent_path, true);
}
- pfree(parentdir);
+ pfree(parent_path);
+
+ /*
+ * There's a case where the copy source directory is missing
for the
+ * same reason above. Create the emtpy source directory so that
Review Comment:
Typo: emtpy instead of empty
##########
src/backend/commands/dbcommands.c:
##########
@@ -2422,6 +2423,45 @@ get_database_name(Oid dbid)
return result;
}
+/*
+ * recovery_create_dbdir()
+ *
+ * During recovery, there's a case where we validly need to recover a missing
+ * tablespace directory so that recovery can continue. This happens when
+ * recovery wants to create a database but the holding tablespace has been
+ * removed before the server stopped. Since we expect that the directory will
+ * be gone before reaching recovery consistency, and we have no knowledge about
+ * the tablespace other than its OID here, we create a real directory under
+ * pg_tblspc here instead of restoring the symlink.
+ *
+ * If only_tblspc is true, then the requested directory must be in pg_tblspc/
+ */
+static void
+recovery_create_dbdir(char *path, bool only_tblspc)
+{
+ struct stat st;
+
+ Assert(RecoveryInProgress());
+
+ if (stat(path, &st) == 0)
+ return;
+
+ if (only_tblspc && strstr(path, "pg_tblspc/") == NULL)
+ elog(PANIC, "requested to created invalid directory: %s", path);
Review Comment:
Typo: requested to create invalid directory
##########
src/backend/access/transam/xlog.c:
##########
@@ -8740,6 +8781,13 @@ CheckRecoveryConsistency(void)
if (xlog_check_consistency_hook) {
xlog_check_consistency_hook();
}
+ /*
+ * Check that pg_tblspc doesn't contain any real directories.
Replay
+ * of Database/CREATE_* records may have created ficticious
tablespace
Review Comment:
typo: fictitious
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]