Skip to content

Commit a3a4e97

Browse files
kulaginmgsmolk
authored andcommitted
[refactoring] move fio_location argument in first place (part 2)
1 parent 15d3937 commit a3a4e97

File tree

9 files changed

+52
-48
lines changed

9 files changed

+52
-48
lines changed

src/backup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
134134
#if PG_VERSION_NUM >= 90600
135135
current.tli = get_current_timeline(backup_conn);
136136
#else
137-
current.tli = get_current_timeline_from_control(instance_config.pgdata, FIO_DB_HOST, false);
137+
/* PG-9.5 */
138+
current.tli = get_current_timeline_from_control(FIO_DB_HOST, instance_config.pgdata, false);
138139
#endif
139140

140141
/*
@@ -1004,7 +1005,7 @@ check_system_identifiers(PGconn *conn, const char *pgdata)
10041005
uint64 system_id_conn;
10051006
uint64 system_id_pgdata;
10061007

1007-
system_id_pgdata = get_system_identifier(pgdata, FIO_DB_HOST, false);
1008+
system_id_pgdata = get_system_identifier(FIO_DB_HOST, pgdata, false);
10081009
system_id_conn = get_remote_system_identifier(conn);
10091010

10101011
/* for checkdb check only system_id_pgdata and system_id_conn */

src/catchup.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ catchup_init_state(PGNodeInfo *source_node_info, const char *source_pgdata, cons
4848

4949
/* Get WAL segments size and system ID of source PG instance */
5050
instance_config.xlog_seg_size = get_xlog_seg_size(source_pgdata);
51-
instance_config.system_identifier = get_system_identifier(source_pgdata, FIO_DB_HOST, false);
51+
instance_config.system_identifier = get_system_identifier(FIO_DB_HOST, source_pgdata, false);
5252
current.start_time = time(NULL);
5353

5454
strlcpy(current.program_version, PROGRAM_VERSION, sizeof(current.program_version));
@@ -69,8 +69,9 @@ catchup_init_state(PGNodeInfo *source_node_info, const char *source_pgdata, cons
6969
#if PG_VERSION_NUM >= 90600
7070
current.tli = get_current_timeline(source_conn);
7171
#else
72+
/* PG-9.5 */
7273
instance_config.pgdata = source_pgdata;
73-
current.tli = get_current_timeline_from_control(source_pgdata, FIO_DB_HOST, false);
74+
current.tli = get_current_timeline_from_control(FIO_DB_HOST, source_pgdata, false);
7475
#endif
7576

7677
elog(INFO, "Catchup start, %s version: %s, "
@@ -163,15 +164,15 @@ catchup_preflight_checks(PGNodeInfo *source_node_info, PGconn *source_conn,
163164
uint64 source_conn_id, source_id, dest_id;
164165

165166
source_conn_id = get_remote_system_identifier(source_conn);
166-
source_id = get_system_identifier(source_pgdata, FIO_DB_HOST, false); /* same as instance_config.system_identifier */
167+
source_id = get_system_identifier(FIO_DB_HOST, source_pgdata, false); /* same as instance_config.system_identifier */
167168

168169
if (source_conn_id != source_id)
169170
elog(ERROR, "Database identifiers mismatch: we connected to DB id %lu, but in \"%s\" we found id %lu",
170171
source_conn_id, source_pgdata, source_id);
171172

172173
if (current.backup_mode != BACKUP_MODE_FULL)
173174
{
174-
dest_id = get_system_identifier(dest_pgdata, FIO_LOCAL_HOST, false);
175+
dest_id = get_system_identifier(FIO_LOCAL_HOST, dest_pgdata, false);
175176
if (source_conn_id != dest_id)
176177
elog(ERROR, "Database identifiers mismatch: we connected to DB id %lu, but in \"%s\" we found id %lu",
177178
source_conn_id, dest_pgdata, dest_id);
@@ -202,7 +203,7 @@ catchup_preflight_checks(PGNodeInfo *source_node_info, PGconn *source_conn,
202203
RedoParams dest_redo = { 0, InvalidXLogRecPtr, 0 };
203204

204205
/* fill dest_redo.lsn and dest_redo.tli */
205-
get_redo(dest_pgdata, FIO_LOCAL_HOST, &dest_redo);
206+
get_redo(FIO_LOCAL_HOST, dest_pgdata, &dest_redo);
206207
elog(LOG, "source.tli = %X, dest_redo.lsn = %X/%X, dest_redo.tli = %X",
207208
current.tli, (uint32) (dest_redo.lsn >> 32), (uint32) dest_redo.lsn, dest_redo.tli);
208209

@@ -659,7 +660,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
659660
filter_filelist(dest_filelist, dest_pgdata, exclude_absolute_paths_list, exclude_relative_paths_list, "Destination");
660661

661662
// fill dest_redo.lsn and dest_redo.tli
662-
get_redo(dest_pgdata, FIO_LOCAL_HOST, &dest_redo);
663+
get_redo(FIO_LOCAL_HOST, dest_pgdata, &dest_redo);
663664
elog(INFO, "syncLSN = %X/%X", (uint32) (dest_redo.lsn >> 32), (uint32) dest_redo.lsn);
664665

665666
/*
@@ -982,8 +983,8 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
982983
char to_fullpath[MAXPGPATH];
983984
join_path_components(from_fullpath, source_pgdata, source_pg_control_file->rel_path);
984985
join_path_components(to_fullpath, dest_pgdata, source_pg_control_file->rel_path);
985-
copy_pgcontrol_file(from_fullpath, FIO_DB_HOST,
986-
to_fullpath, FIO_LOCAL_HOST, source_pg_control_file);
986+
copy_pgcontrol_file(FIO_DB_HOST, from_fullpath,
987+
FIO_LOCAL_HOST, to_fullpath, source_pg_control_file);
987988
transfered_datafiles_bytes += source_pg_control_file->size;
988989
}
989990

src/data.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,8 @@ backup_non_data_file(pgFile *file, pgFile *prev_file,
789789
/* special treatment for global/pg_control */
790790
if (file->external_dir_num == 0 && strcmp(file->rel_path, XLOG_CONTROL_FILE) == 0)
791791
{
792-
copy_pgcontrol_file(from_fullpath, FIO_DB_HOST,
793-
to_fullpath, FIO_BACKUP_HOST, file);
792+
copy_pgcontrol_file(FIO_DB_HOST, from_fullpath,
793+
FIO_BACKUP_HOST, to_fullpath, file);
794794
return;
795795
}
796796

src/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
*/
2727
char *
28-
slurpFile(const char *datadir, const char *path, size_t *filesize, bool safe, fio_location location)
28+
slurpFile(fio_location location, const char *datadir, const char *path, size_t *filesize, bool safe)
2929
{
3030
int fd;
3131
char *buffer;

src/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ do_add_instance(InstanceState *instanceState, InstanceConfig *instance)
5757
"(-D, --pgdata)");
5858

5959
/* Read system_identifier from PGDATA */
60-
instance->system_identifier = get_system_identifier(instance->pgdata, FIO_DB_HOST, false);
60+
instance->system_identifier = get_system_identifier(FIO_DB_HOST, instance->pgdata, false);
6161
/* Starting from PostgreSQL 11 read WAL segment size from PGDATA */
6262
instance->xlog_seg_size = get_xlog_seg_size(instance->pgdata);
6363

src/pg_probackup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ main(int argc, char *argv[])
878878
if (wal_file_path == NULL)
879879
{
880880
/* 1st case */
881-
system_id = get_system_identifier(current_dir, FIO_DB_HOST, false);
881+
system_id = get_system_identifier(FIO_DB_HOST, current_dir, false);
882882
join_path_components(archive_push_xlog_dir, current_dir, XLOGDIR);
883883
}
884884
else
@@ -897,7 +897,7 @@ main(int argc, char *argv[])
897897
if (fio_is_same_file(FIO_DB_HOST, stripped_wal_file_path, archive_push_xlog_dir, true))
898898
{
899899
/* 2nd case */
900-
system_id = get_system_identifier(instance_config.pgdata, FIO_DB_HOST, false);
900+
system_id = get_system_identifier(FIO_DB_HOST, instance_config.pgdata, false);
901901
/* archive_push_xlog_dir already have right value */
902902
}
903903
else
@@ -907,7 +907,7 @@ main(int argc, char *argv[])
907907
else
908908
elog(ERROR, "Value specified to --wal_file_path is too long");
909909

910-
system_id = get_system_identifier(current_dir, FIO_DB_HOST, true);
910+
system_id = get_system_identifier(FIO_DB_HOST, current_dir, true);
911911
/* 3rd case if control file present -- i.e. system_id != 0 */
912912

913913
if (system_id == 0)

src/pg_probackup.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -936,11 +936,11 @@ extern void do_delete_status(InstanceState *instanceState,
936936
InstanceConfig *instance_config, const char *status);
937937

938938
/* in fetch.c */
939-
extern char *slurpFile(const char *datadir,
939+
extern char *slurpFile(fio_location location,
940+
const char *datadir,
940941
const char *path,
941942
size_t *filesize,
942-
bool safe,
943-
fio_location location);
943+
bool safe);
944944
extern char *fetchFile(PGconn *conn, const char *filename, size_t *filesize);
945945

946946
/* in help.c */
@@ -1173,18 +1173,18 @@ extern XLogRecPtr get_next_record_lsn(const char *archivedir, XLogSegNo segno, T
11731173

11741174
/* in util.c */
11751175
extern TimeLineID get_current_timeline(PGconn *conn);
1176-
extern TimeLineID get_current_timeline_from_control(const char *pgdata_path, fio_location location, bool safe);
1176+
extern TimeLineID get_current_timeline_from_control(fio_location location, const char *pgdata_path, bool safe);
11771177
extern XLogRecPtr get_checkpoint_location(PGconn *conn);
1178-
extern uint64 get_system_identifier(const char *pgdata_path, fio_location location, bool safe);
1178+
extern uint64 get_system_identifier(fio_location location, const char *pgdata_path, bool safe);
11791179
extern uint64 get_remote_system_identifier(PGconn *conn);
11801180
extern uint32 get_data_checksum_version(bool safe);
11811181
extern pg_crc32c get_pgcontrol_checksum(const char *pgdata_path);
11821182
extern uint32 get_xlog_seg_size(const char *pgdata_path);
1183-
extern void get_redo(const char *pgdata_path, fio_location pgdata_location, RedoParams *redo);
1183+
extern void get_redo(fio_location location, const char *pgdata_path, RedoParams *redo);
11841184
extern void set_min_recovery_point(pgFile *file, const char *backup_path,
11851185
XLogRecPtr stop_backup_lsn);
1186-
extern void copy_pgcontrol_file(const char *from_fullpath, fio_location from_location,
1187-
const char *to_fullpath, fio_location to_location, pgFile *file);
1186+
extern void copy_pgcontrol_file(fio_location from_location, const char *from_fullpath,
1187+
fio_location to_location, const char *to_fullpath, pgFile *file);
11881188

11891189
extern void time2iso(char *buf, size_t len, time_t time, bool utc);
11901190
extern const char *status2str(BackupStatus status);

src/restore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ do_restore_or_validate(InstanceState *instanceState, time_t target_backup_id, pg
480480
{
481481
RedoParams redo;
482482
parray *timelines = NULL;
483-
get_redo(instance_config.pgdata, FIO_DB_HOST, &redo);
483+
get_redo(FIO_DB_HOST, instance_config.pgdata, &redo);
484484

485485
if (redo.checksum_version == 0)
486486
elog(ERROR, "Incremental restore in 'lsn' mode require "

src/util.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ digestControlFile(ControlFileData *ControlFile, char *src, size_t size)
106106
* Write ControlFile to pg_control
107107
*/
108108
static void
109-
writeControlFile(ControlFileData *ControlFile, const char *path, fio_location location)
109+
writeControlFile(fio_location location, const char *path, ControlFileData *ControlFile)
110110
{
111111
int fd;
112112
char *buffer = NULL;
@@ -156,31 +156,31 @@ get_current_timeline(PGconn *conn)
156156
if (PQresultStatus(res) == PGRES_TUPLES_OK)
157157
val = PQgetvalue(res, 0, 0);
158158
else
159-
return get_current_timeline_from_control(instance_config.pgdata, FIO_DB_HOST, false);
159+
return get_current_timeline_from_control(FIO_DB_HOST, instance_config.pgdata, false);
160160

161161
if (!parse_uint32(val, &tli, 0))
162162
{
163163
PQclear(res);
164164
elog(WARNING, "Invalid value of timeline_id %s", val);
165165

166166
/* TODO 3.0 remove it and just error out */
167-
return get_current_timeline_from_control(instance_config.pgdata, FIO_DB_HOST, false);
167+
return get_current_timeline_from_control(FIO_DB_HOST, instance_config.pgdata, false);
168168
}
169169

170170
return tli;
171171
}
172172

173173
/* Get timeline from pg_control file */
174174
TimeLineID
175-
get_current_timeline_from_control(const char *pgdata_path, fio_location location, bool safe)
175+
get_current_timeline_from_control(fio_location location, const char *pgdata_path, bool safe)
176176
{
177177
ControlFileData ControlFile;
178178
char *buffer;
179179
size_t size;
180180

181181
/* First fetch file... */
182-
buffer = slurpFile(pgdata_path, XLOG_CONTROL_FILE, &size,
183-
safe, location);
182+
buffer = slurpFile(location, pgdata_path, XLOG_CONTROL_FILE,
183+
&size, safe);
184184
if (safe && buffer == NULL)
185185
return 0;
186186

@@ -218,11 +218,12 @@ get_checkpoint_location(PGconn *conn)
218218

219219
return lsn;
220220
#else
221+
/* PG-9.5 */
221222
char *buffer;
222223
size_t size;
223224
ControlFileData ControlFile;
224225

225-
buffer = slurpFile(instance_config.pgdata, XLOG_CONTROL_FILE, &size, false, FIO_DB_HOST);
226+
buffer = slurpFile(FIO_DB_HOST, instance_config.pgdata, XLOG_CONTROL_FILE, &size, false);
226227
digestControlFile(&ControlFile, buffer, size);
227228
pg_free(buffer);
228229

@@ -231,14 +232,14 @@ get_checkpoint_location(PGconn *conn)
231232
}
232233

233234
uint64
234-
get_system_identifier(const char *pgdata_path, fio_location location, bool safe)
235+
get_system_identifier(fio_location location, const char *pgdata_path, bool safe)
235236
{
236237
ControlFileData ControlFile;
237238
char *buffer;
238239
size_t size;
239240

240241
/* First fetch file... */
241-
buffer = slurpFile(pgdata_path, XLOG_CONTROL_FILE, &size, safe, location);
242+
buffer = slurpFile(location, pgdata_path, XLOG_CONTROL_FILE, &size, safe);
242243
if (safe && buffer == NULL)
243244
return 0;
244245
digestControlFile(&ControlFile, buffer, size);
@@ -268,11 +269,12 @@ get_remote_system_identifier(PGconn *conn)
268269

269270
return system_id_conn;
270271
#else
272+
/* PG-9.5 */
271273
char *buffer;
272274
size_t size;
273275
ControlFileData ControlFile;
274276

275-
buffer = slurpFile(instance_config.pgdata, XLOG_CONTROL_FILE, &size, false, FIO_DB_HOST);
277+
buffer = slurpFile(FIO_DB_HOST, instance_config.pgdata, XLOG_CONTROL_FILE, &size, false);
276278
digestControlFile(&ControlFile, buffer, size);
277279
pg_free(buffer);
278280

@@ -289,7 +291,7 @@ get_xlog_seg_size(const char *pgdata_path)
289291
size_t size;
290292

291293
/* First fetch file... */
292-
buffer = slurpFile(pgdata_path, XLOG_CONTROL_FILE, &size, false, FIO_DB_HOST);
294+
buffer = slurpFile(FIO_DB_HOST, pgdata_path, XLOG_CONTROL_FILE, &size, false);
293295
digestControlFile(&ControlFile, buffer, size);
294296
pg_free(buffer);
295297

@@ -307,8 +309,8 @@ get_data_checksum_version(bool safe)
307309
size_t size;
308310

309311
/* First fetch file... */
310-
buffer = slurpFile(instance_config.pgdata, XLOG_CONTROL_FILE, &size,
311-
safe, FIO_DB_HOST);
312+
buffer = slurpFile(FIO_DB_HOST, instance_config.pgdata, XLOG_CONTROL_FILE,
313+
&size, safe);
312314
if (buffer == NULL)
313315
return 0;
314316
digestControlFile(&ControlFile, buffer, size);
@@ -325,7 +327,7 @@ get_pgcontrol_checksum(const char *pgdata_path)
325327
size_t size;
326328

327329
/* First fetch file... */
328-
buffer = slurpFile(pgdata_path, XLOG_CONTROL_FILE, &size, false, FIO_BACKUP_HOST);
330+
buffer = slurpFile(FIO_BACKUP_HOST, pgdata_path, XLOG_CONTROL_FILE, &size, false);
329331

330332
digestControlFile(&ControlFile, buffer, size);
331333
pg_free(buffer);
@@ -334,14 +336,14 @@ get_pgcontrol_checksum(const char *pgdata_path)
334336
}
335337

336338
void
337-
get_redo(const char *pgdata_path, fio_location pgdata_location, RedoParams *redo)
339+
get_redo(fio_location location, const char *pgdata_path, RedoParams *redo)
338340
{
339341
ControlFileData ControlFile;
340342
char *buffer;
341343
size_t size;
342344

343345
/* First fetch file... */
344-
buffer = slurpFile(pgdata_path, XLOG_CONTROL_FILE, &size, false, pgdata_location);
346+
buffer = slurpFile(location, pgdata_path, XLOG_CONTROL_FILE, &size, false);
345347

346348
digestControlFile(&ControlFile, buffer, size);
347349
pg_free(buffer);
@@ -380,7 +382,7 @@ set_min_recovery_point(pgFile *file, const char *backup_path,
380382
char fullpath[MAXPGPATH];
381383

382384
/* First fetch file content */
383-
buffer = slurpFile(instance_config.pgdata, XLOG_CONTROL_FILE, &size, false, FIO_DB_HOST);
385+
buffer = slurpFile(FIO_DB_HOST, instance_config.pgdata, XLOG_CONTROL_FILE, &size, false);
384386
digestControlFile(&ControlFile, buffer, size);
385387

386388
elog(LOG, "Current minRecPoint %X/%X",
@@ -401,7 +403,7 @@ set_min_recovery_point(pgFile *file, const char *backup_path,
401403

402404
/* overwrite pg_control */
403405
join_path_components(fullpath, backup_path, XLOG_CONTROL_FILE);
404-
writeControlFile(&ControlFile, fullpath, FIO_LOCAL_HOST);
406+
writeControlFile(FIO_LOCAL_HOST, fullpath, &ControlFile);
405407

406408
/* Update pg_control checksum in backup_list */
407409
file->crc = ControlFile.crc;
@@ -413,14 +415,14 @@ set_min_recovery_point(pgFile *file, const char *backup_path,
413415
* Copy pg_control file to backup. We do not apply compression to this file.
414416
*/
415417
void
416-
copy_pgcontrol_file(const char *from_fullpath, fio_location from_location,
417-
const char *to_fullpath, fio_location to_location, pgFile *file)
418+
copy_pgcontrol_file(fio_location from_location, const char *from_fullpath,
419+
fio_location to_location, const char *to_fullpath, pgFile *file)
418420
{
419421
ControlFileData ControlFile;
420422
char *buffer;
421423
size_t size;
422424

423-
buffer = slurpFile(from_fullpath, "", &size, false, from_location);
425+
buffer = slurpFile(from_location, from_fullpath, "", &size, false);
424426

425427
digestControlFile(&ControlFile, buffer, size);
426428

@@ -429,7 +431,7 @@ copy_pgcontrol_file(const char *from_fullpath, fio_location from_location,
429431
file->write_size = size;
430432
file->uncompressed_size = size;
431433

432-
writeControlFile(&ControlFile, to_fullpath, to_location);
434+
writeControlFile(to_location, to_fullpath, &ControlFile);
433435

434436
pg_free(buffer);
435437
}

0 commit comments

Comments
 (0)