Skip to content

Commit 4d7714e

Browse files
committed
[refactoring] move fio_location argument in first place (part 2)
1 parent f128e20 commit 4d7714e

File tree

9 files changed

+56
-51
lines changed

9 files changed

+56
-51
lines changed

src/backup.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
136136
#if PG_VERSION_NUM >= 90600
137137
current.tli = get_current_timeline(backup_conn);
138138
#else
139-
current.tli = get_current_timeline_from_control(instance_config.pgdata, FIO_DB_HOST, false);
139+
/* PG-9.5 */
140+
current.tli = get_current_timeline_from_control(FIO_DB_HOST, instance_config.pgdata, false);
140141
#endif
141142

142143
/*
@@ -943,7 +944,7 @@ check_system_identifiers(PGconn *conn, const char *pgdata)
943944
uint64 system_id_conn;
944945
uint64 system_id_pgdata;
945946

946-
system_id_pgdata = get_system_identifier(pgdata, FIO_DB_HOST, false);
947+
system_id_pgdata = get_system_identifier(FIO_DB_HOST, pgdata, false);
947948
system_id_conn = get_remote_system_identifier(conn);
948949

949950
/* 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, pg_probackup 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(VERBOSE, "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

@@ -656,7 +657,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
656657
filter_filelist(dest_filelist, dest_pgdata, exclude_absolute_paths_list, exclude_relative_paths_list, "Destination");
657658

658659
// fill dest_redo.lsn and dest_redo.tli
659-
get_redo(dest_pgdata, FIO_LOCAL_HOST, &dest_redo);
660+
get_redo(FIO_LOCAL_HOST, dest_pgdata, &dest_redo);
660661
elog(INFO, "syncLSN = %X/%X", (uint32) (dest_redo.lsn >> 32), (uint32) dest_redo.lsn);
661662

662663
/*
@@ -969,8 +970,8 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
969970
char to_fullpath[MAXPGPATH];
970971
join_path_components(from_fullpath, source_pgdata, source_pg_control_file->rel_path);
971972
join_path_components(to_fullpath, dest_pgdata, source_pg_control_file->rel_path);
972-
copy_pgcontrol_file(from_fullpath, FIO_DB_HOST,
973-
to_fullpath, FIO_LOCAL_HOST, source_pg_control_file);
973+
copy_pgcontrol_file(FIO_DB_HOST, from_fullpath,
974+
FIO_LOCAL_HOST, to_fullpath, source_pg_control_file);
974975
transfered_datafiles_bytes += source_pg_control_file->size;
975976
}
976977

src/data.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,8 @@ backup_non_data_file(pgFile *file, pgFile *prev_file,
787787
/* special treatment for global/pg_control */
788788
if (file->external_dir_num == 0 && strcmp(file->rel_path, XLOG_CONTROL_FILE) == 0)
789789
{
790-
copy_pgcontrol_file(from_fullpath, FIO_DB_HOST,
791-
to_fullpath, FIO_BACKUP_HOST, file);
790+
copy_pgcontrol_file(FIO_DB_HOST, from_fullpath,
791+
FIO_BACKUP_HOST, to_fullpath, file);
792792
return;
793793
}
794794

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
@@ -833,7 +833,7 @@ main(int argc, char *argv[])
833833
if (wal_file_path == NULL)
834834
{
835835
/* 1st case */
836-
system_id = get_system_identifier(current_dir, FIO_DB_HOST, false);
836+
system_id = get_system_identifier(FIO_DB_HOST, current_dir, false);
837837
join_path_components(archive_push_xlog_dir, current_dir, XLOGDIR);
838838
}
839839
else
@@ -852,7 +852,7 @@ main(int argc, char *argv[])
852852
if (fio_is_same_file(FIO_DB_HOST, stripped_wal_file_path, archive_push_xlog_dir, true))
853853
{
854854
/* 2nd case */
855-
system_id = get_system_identifier(instance_config.pgdata, FIO_DB_HOST, false);
855+
system_id = get_system_identifier(FIO_DB_HOST, instance_config.pgdata, false);
856856
/* archive_push_xlog_dir already have right value */
857857
}
858858
else
@@ -862,7 +862,7 @@ main(int argc, char *argv[])
862862
else
863863
elog(ERROR, "Value specified to --wal_file_path is too long");
864864

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

868868
if (system_id == 0)

src/pg_probackup.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -914,11 +914,11 @@ extern void do_delete_status(InstanceState *instanceState,
914914
InstanceConfig *instance_config, const char *status);
915915

916916
/* in fetch.c */
917-
extern char *slurpFile(const char *datadir,
917+
extern char *slurpFile(fio_location location,
918+
const char *datadir,
918919
const char *path,
919920
size_t *filesize,
920-
bool safe,
921-
fio_location location);
921+
bool safe);
922922
extern char *fetchFile(PGconn *conn, const char *filename, size_t *filesize);
923923

924924
/* in help.c */
@@ -1148,19 +1148,19 @@ extern XLogRecPtr get_next_record_lsn(const char *archivedir, XLogSegNo segno, T
11481148

11491149
/* in util.c */
11501150
extern TimeLineID get_current_timeline(PGconn *conn);
1151-
extern TimeLineID get_current_timeline_from_control(const char *pgdata_path, fio_location location, bool safe);
1151+
extern TimeLineID get_current_timeline_from_control(fio_location location, const char *pgdata_path, bool safe);
11521152
extern XLogRecPtr get_checkpoint_location(PGconn *conn);
1153-
extern uint64 get_system_identifier(const char *pgdata_path, fio_location location, bool safe);
1153+
extern uint64 get_system_identifier(fio_location location, const char *pgdata_path, bool safe);
11541154
extern uint64 get_remote_system_identifier(PGconn *conn);
11551155
extern uint32 get_data_checksum_version(bool safe);
11561156
extern pg_crc32c get_pgcontrol_checksum(const char *pgdata_path);
1157-
extern DBState get_system_dbstate(const char *pgdata_path, fio_location location);
1157+
extern DBState get_system_dbstate(fio_location location, const char *pgdata_path);
11581158
extern uint32 get_xlog_seg_size(const char *pgdata_path);
1159-
extern void get_redo(const char *pgdata_path, fio_location pgdata_location, RedoParams *redo);
1159+
extern void get_redo(fio_location location, const char *pgdata_path, RedoParams *redo);
11601160
extern void set_min_recovery_point(pgFile *file, const char *backup_path,
11611161
XLogRecPtr stop_backup_lsn);
1162-
extern void copy_pgcontrol_file(const char *from_fullpath, fio_location from_location,
1163-
const char *to_fullpath, fio_location to_location, pgFile *file);
1162+
extern void copy_pgcontrol_file(fio_location from_location, const char *from_fullpath,
1163+
fio_location to_location, const char *to_fullpath, pgFile *file);
11641164

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

src/restore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ do_restore_or_validate(InstanceState *instanceState, time_t target_backup_id, pg
485485
{
486486
RedoParams redo;
487487
parray *timelines = NULL;
488-
get_redo(instance_config.pgdata, FIO_DB_HOST, &redo);
488+
get_redo(FIO_DB_HOST, instance_config.pgdata, &redo);
489489

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

src/util.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ digestControlFile(ControlFileData *ControlFile, char *src, size_t size)
122122
* Write ControlFile to pg_control
123123
*/
124124
static void
125-
writeControlFile(ControlFileData *ControlFile, const char *path, fio_location location)
125+
writeControlFile(fio_location location, const char *path, ControlFileData *ControlFile)
126126
{
127127
int fd;
128128
char *buffer = NULL;
@@ -172,31 +172,31 @@ get_current_timeline(PGconn *conn)
172172
if (PQresultStatus(res) == PGRES_TUPLES_OK)
173173
val = PQgetvalue(res, 0, 0);
174174
else
175-
return get_current_timeline_from_control(instance_config.pgdata, FIO_DB_HOST, false);
175+
return get_current_timeline_from_control(FIO_DB_HOST, instance_config.pgdata, false);
176176

177177
if (!parse_uint32(val, &tli, 0))
178178
{
179179
PQclear(res);
180180
elog(WARNING, "Invalid value of timeline_id %s", val);
181181

182182
/* TODO 3.0 remove it and just error out */
183-
return get_current_timeline_from_control(instance_config.pgdata, FIO_DB_HOST, false);
183+
return get_current_timeline_from_control(FIO_DB_HOST, instance_config.pgdata, false);
184184
}
185185

186186
return tli;
187187
}
188188

189189
/* Get timeline from pg_control file */
190190
TimeLineID
191-
get_current_timeline_from_control(const char *pgdata_path, fio_location location, bool safe)
191+
get_current_timeline_from_control(fio_location location, const char *pgdata_path, bool safe)
192192
{
193193
ControlFileData ControlFile;
194194
char *buffer;
195195
size_t size;
196196

197197
/* First fetch file... */
198-
buffer = slurpFile(pgdata_path, XLOG_CONTROL_FILE, &size,
199-
safe, location);
198+
buffer = slurpFile(location, pgdata_path, XLOG_CONTROL_FILE,
199+
&size, safe);
200200
if (safe && buffer == NULL)
201201
return 0;
202202

@@ -234,11 +234,12 @@ get_checkpoint_location(PGconn *conn)
234234

235235
return lsn;
236236
#else
237+
/* PG-9.5 */
237238
char *buffer;
238239
size_t size;
239240
ControlFileData ControlFile;
240241

241-
buffer = slurpFile(instance_config.pgdata, XLOG_CONTROL_FILE, &size, false, FIO_DB_HOST);
242+
buffer = slurpFile(FIO_DB_HOST, instance_config.pgdata, XLOG_CONTROL_FILE, &size, false);
242243
digestControlFile(&ControlFile, buffer, size);
243244
pg_free(buffer);
244245

@@ -247,14 +248,14 @@ get_checkpoint_location(PGconn *conn)
247248
}
248249

249250
uint64
250-
get_system_identifier(const char *pgdata_path, fio_location location, bool safe)
251+
get_system_identifier(fio_location location, const char *pgdata_path, bool safe)
251252
{
252253
ControlFileData ControlFile;
253254
char *buffer;
254255
size_t size;
255256

256257
/* First fetch file... */
257-
buffer = slurpFile(pgdata_path, XLOG_CONTROL_FILE, &size, safe, location);
258+
buffer = slurpFile(location, pgdata_path, XLOG_CONTROL_FILE, &size, safe);
258259
if (safe && buffer == NULL)
259260
return 0;
260261
digestControlFile(&ControlFile, buffer, size);
@@ -284,11 +285,12 @@ get_remote_system_identifier(PGconn *conn)
284285

285286
return system_id_conn;
286287
#else
288+
/* PG-9.5 */
287289
char *buffer;
288290
size_t size;
289291
ControlFileData ControlFile;
290292

291-
buffer = slurpFile(instance_config.pgdata, XLOG_CONTROL_FILE, &size, false, FIO_DB_HOST);
293+
buffer = slurpFile(FIO_DB_HOST, instance_config.pgdata, XLOG_CONTROL_FILE, &size, false);
292294
digestControlFile(&ControlFile, buffer, size);
293295
pg_free(buffer);
294296

@@ -305,7 +307,7 @@ get_xlog_seg_size(const char *pgdata_path)
305307
size_t size;
306308

307309
/* First fetch file... */
308-
buffer = slurpFile(pgdata_path, XLOG_CONTROL_FILE, &size, false, FIO_DB_HOST);
310+
buffer = slurpFile(FIO_DB_HOST, pgdata_path, XLOG_CONTROL_FILE, &size, false);
309311
digestControlFile(&ControlFile, buffer, size);
310312
pg_free(buffer);
311313

@@ -323,8 +325,8 @@ get_data_checksum_version(bool safe)
323325
size_t size;
324326

325327
/* First fetch file... */
326-
buffer = slurpFile(instance_config.pgdata, XLOG_CONTROL_FILE, &size,
327-
safe, FIO_DB_HOST);
328+
buffer = slurpFile(FIO_DB_HOST, instance_config.pgdata, XLOG_CONTROL_FILE,
329+
&size, safe);
328330
if (buffer == NULL)
329331
return 0;
330332
digestControlFile(&ControlFile, buffer, size);
@@ -341,22 +343,23 @@ get_pgcontrol_checksum(const char *pgdata_path)
341343
size_t size;
342344

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

346348
digestControlFile(&ControlFile, buffer, size);
347349
pg_free(buffer);
348350

349351
return ControlFile.crc;
350352
}
351353

354+
/* unused function */
352355
DBState
353-
get_system_dbstate(const char *pgdata_path, fio_location location)
356+
get_system_dbstate(fio_location location, const char *pgdata_path)
354357
{
355358
ControlFileData ControlFile;
356359
char *buffer;
357360
size_t size;
358361

359-
buffer = slurpFile(pgdata_path, XLOG_CONTROL_FILE, &size, false, location);
362+
buffer = slurpFile(location, pgdata_path, XLOG_CONTROL_FILE, &size, false);
360363
if (buffer == NULL)
361364
return 0;
362365
digestControlFile(&ControlFile, buffer, size);
@@ -366,14 +369,14 @@ get_system_dbstate(const char *pgdata_path, fio_location location)
366369
}
367370

368371
void
369-
get_redo(const char *pgdata_path, fio_location pgdata_location, RedoParams *redo)
372+
get_redo(fio_location location, const char *pgdata_path, RedoParams *redo)
370373
{
371374
ControlFileData ControlFile;
372375
char *buffer;
373376
size_t size;
374377

375378
/* First fetch file... */
376-
buffer = slurpFile(pgdata_path, XLOG_CONTROL_FILE, &size, false, pgdata_location);
379+
buffer = slurpFile(location, pgdata_path, XLOG_CONTROL_FILE, &size, false);
377380

378381
digestControlFile(&ControlFile, buffer, size);
379382
pg_free(buffer);
@@ -412,7 +415,7 @@ set_min_recovery_point(pgFile *file, const char *backup_path,
412415
char fullpath[MAXPGPATH];
413416

414417
/* First fetch file content */
415-
buffer = slurpFile(instance_config.pgdata, XLOG_CONTROL_FILE, &size, false, FIO_DB_HOST);
418+
buffer = slurpFile(FIO_DB_HOST, instance_config.pgdata, XLOG_CONTROL_FILE, &size, false);
416419
digestControlFile(&ControlFile, buffer, size);
417420

418421
elog(LOG, "Current minRecPoint %X/%X",
@@ -433,7 +436,7 @@ set_min_recovery_point(pgFile *file, const char *backup_path,
433436

434437
/* overwrite pg_control */
435438
join_path_components(fullpath, backup_path, XLOG_CONTROL_FILE);
436-
writeControlFile(&ControlFile, fullpath, FIO_LOCAL_HOST);
439+
writeControlFile(FIO_LOCAL_HOST, fullpath, &ControlFile);
437440

438441
/* Update pg_control checksum in backup_list */
439442
file->crc = ControlFile.crc;
@@ -445,14 +448,14 @@ set_min_recovery_point(pgFile *file, const char *backup_path,
445448
* Copy pg_control file to backup. We do not apply compression to this file.
446449
*/
447450
void
448-
copy_pgcontrol_file(const char *from_fullpath, fio_location from_location,
449-
const char *to_fullpath, fio_location to_location, pgFile *file)
451+
copy_pgcontrol_file(fio_location from_location, const char *from_fullpath,
452+
fio_location to_location, const char *to_fullpath, pgFile *file)
450453
{
451454
ControlFileData ControlFile;
452455
char *buffer;
453456
size_t size;
454457

455-
buffer = slurpFile(from_fullpath, "", &size, false, from_location);
458+
buffer = slurpFile(from_location, from_fullpath, "", &size, false);
456459

457460
digestControlFile(&ControlFile, buffer, size);
458461

@@ -461,7 +464,7 @@ copy_pgcontrol_file(const char *from_fullpath, fio_location from_location,
461464
file->write_size = size;
462465
file->uncompressed_size = size;
463466

464-
writeControlFile(&ControlFile, to_fullpath, to_location);
467+
writeControlFile(to_location, to_fullpath, &ControlFile);
465468

466469
pg_free(buffer);
467470
}

0 commit comments

Comments
 (0)