Skip to content

Commit 6514910

Browse files
committed
Add snafs_snapshot option to pg_dump
1 parent 7bdfea3 commit 6514910

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/backend/storage/file/snapfs.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ sfs_make_snapshot(void)
193193
{
194194
SnapshotId snap_id;
195195

196+
if (SFS_IN_SNAPSHOT())
197+
elog(ERROR, "Can not perform operation inside snapshot");
198+
196199
sfs_lock_database();
197200

198201
RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT

src/bin/pg_dump/pg_backup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ typedef struct Archive
194194

195195
int numWorkers; /* number of parallel processes */
196196
char *sync_snapshot_id; /* sync snapshot id for parallel operation */
197+
char *snapfs_snapshot_id; /* snapfs snapshot id for parallel operation */
197198

198199
/* info needed for string escaping */
199200
int encoding; /* libpq code for client_encoding */

src/bin/pg_dump/pg_backup_db.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ ReconnectToServer(ArchiveHandle *AH, const char *dbname, const char *username)
107107
/* Start strict; later phases may override this. */
108108
PQclear(ExecuteSqlQueryForSingleRow((Archive *) AH,
109109
ALWAYS_SECURE_SEARCH_PATH_SQL));
110+
110111
}
111112

112113
/*

src/bin/pg_dump/pg_dump.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static const CatalogId nilCatalogId = {0, 0};
143143
static void help(const char *progname);
144144
static void setup_connection(Archive *AH,
145145
const char *dumpencoding, const char *dumpsnapshot,
146-
char *use_role);
146+
char *use_role, const char* snapfs_snapshot);
147147
static ArchiveFormat parseArchiveFormat(const char *format, ArchiveMode *mode);
148148
static void expand_schema_name_patterns(Archive *fout,
149149
SimpleStringList *patterns,
@@ -305,6 +305,7 @@ main(int argc, char **argv)
305305
Archive *fout; /* the script file */
306306
const char *dumpencoding = NULL;
307307
const char *dumpsnapshot = NULL;
308+
const char *snapfs_snapshot = NULL;
308309
char *use_role = NULL;
309310
int numWorkers = 1;
310311
trivalue prompt_password = TRI_DEFAULT;
@@ -367,6 +368,7 @@ main(int argc, char **argv)
367368
{"section", required_argument, NULL, 5},
368369
{"serializable-deferrable", no_argument, &dopt.serializable_deferrable, 1},
369370
{"snapshot", required_argument, NULL, 6},
371+
{"snapfs-snapshot", required_argument, NULL, 8},
370372
{"strict-names", no_argument, &strict_names, 1},
371373
{"use-set-session-authorization", no_argument, &dopt.use_setsessauth, 1},
372374
{"no-comments", no_argument, &dopt.no_comments, 1},
@@ -561,6 +563,10 @@ main(int argc, char **argv)
561563
dosync = false;
562564
break;
563565

566+
case 8: /* snapfs-snapshot */
567+
snapfs_snapshot = pg_strdup(optarg);
568+
break;
569+
564570
default:
565571
fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
566572
exit_nicely(1);
@@ -696,7 +702,7 @@ main(int argc, char **argv)
696702
* death.
697703
*/
698704
ConnectDatabase(fout, dopt.dbname, dopt.pghost, dopt.pgport, dopt.username, prompt_password);
699-
setup_connection(fout, dumpencoding, dumpsnapshot, use_role);
705+
setup_connection(fout, dumpencoding, dumpsnapshot, use_role, snapfs_snapshot);
700706

701707
/*
702708
* Disable security label support if server version < v9.1.x (prevents
@@ -996,6 +1002,7 @@ help(const char *progname)
9961002
printf(_(" --section=SECTION dump named section (pre-data, data, or post-data)\n"));
9971003
printf(_(" --serializable-deferrable wait until the dump can run without anomalies\n"));
9981004
printf(_(" --snapshot=SNAPSHOT use given snapshot for the dump\n"));
1005+
printf(_(" --snapfs-snapshot=SNAPSHOT use given SNAPFS snapshot for the dump\n"));
9991006
printf(_(" --strict-names require table and/or schema include patterns to\n"
10001007
" match at least one entity each\n"));
10011008
printf(_(" --use-set-session-authorization\n"
@@ -1018,7 +1025,7 @@ help(const char *progname)
10181025

10191026
static void
10201027
setup_connection(Archive *AH, const char *dumpencoding,
1021-
const char *dumpsnapshot, char *use_role)
1028+
const char *dumpsnapshot, char *use_role, const char *snapfs_snapshot)
10221029
{
10231030
DumpOptions *dopt = AH->dopt;
10241031
PGconn *conn = GetConnection(AH);
@@ -1176,6 +1183,15 @@ setup_connection(Archive *AH, const char *dumpencoding,
11761183

11771184
AH->sync_snapshot_id = get_synchronized_snapshot(AH);
11781185
}
1186+
if (snapfs_snapshot)
1187+
AH->snapfs_snapshot_id = pg_strdup(snapfs_snapshot);
1188+
1189+
if (AH->snapfs_snapshot_id)
1190+
{
1191+
char sql[64];
1192+
sprintf(sql, "select pg_set_backend_snapshot(%s)", AH->snapfs_snapshot_id);
1193+
PQclear(ExecuteSqlQueryForSingleRow((Archive *) AH, sql));
1194+
}
11791195
}
11801196

11811197
/* Set up connection for a parallel worker process */
@@ -1191,6 +1207,7 @@ setupDumpWorker(Archive *AH)
11911207
setup_connection(AH,
11921208
pg_encoding_to_char(AH->encoding),
11931209
NULL,
1210+
NULL,
11941211
NULL);
11951212
}
11961213

0 commit comments

Comments
 (0)