Skip to content

Commit d78283c

Browse files
committed
Merge branch 'REL_2_6_rework_stat' into REL_2_6
2 parents 1de6e5c + 0e24b62 commit d78283c

File tree

18 files changed

+383
-197
lines changed

18 files changed

+383
-197
lines changed

src/archive.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,9 @@ push_file_internal(const char *wal_file_name, const char *pg_xlog_dir,
388388
char to_fullpath[MAXPGPATH];
389389
char to_fullpath_part[MAXPGPATH];
390390
/* partial handling */
391-
struct stat st;
391+
pio_stat_t st;
392392
int partial_try_count = 0;
393-
ssize_t partial_file_size = 0;
393+
int64_t partial_file_size = 0;
394394
bool partial_is_stale = true;
395395
size_t len;
396396
err_i err = $noerr();
@@ -466,11 +466,11 @@ push_file_internal(const char *wal_file_name, const char *pg_xlog_dir,
466466
elog(LOG,
467467
"Temp WAL file already exists, waiting on it %u seconds: \"%s\"",
468468
archive_timeout, to_fullpath_part);
469-
partial_file_size = st.st_size;
469+
partial_file_size = st.pst_size;
470470
}
471471

472472
/* file size is changing */
473-
if (st.st_size != partial_file_size)
473+
if (st.pst_size != partial_file_size)
474474
partial_is_stale = false;
475475

476476
sleep(1);

src/backup.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
391391
pgFile *file = (pgFile *) parray_get(backup_files_list, i);
392392

393393
/* if the entry was a directory, create it in the backup */
394-
if (S_ISDIR(file->mode))
394+
if (file->kind == PIO_KIND_DIRECTORY)
395395
{
396396
char dirpath[MAXPGPATH];
397397

@@ -568,7 +568,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
568568
pgFile *file = (pgFile *) parray_get(backup_files_list, i);
569569

570570
/* TODO: sync directory ? */
571-
if (S_ISDIR(file->mode))
571+
if (file->kind == PIO_KIND_DIRECTORY)
572572
continue;
573573

574574
if (file->write_size <= 0)
@@ -1836,7 +1836,7 @@ pg_stop_backup_write_file_helper(const char *path, const char *filename, const c
18361836
file = pgFileNew(full_filename, filename, true, 0,
18371837
FIO_BACKUP_HOST);
18381838

1839-
if (S_ISREG(file->mode))
1839+
if (file->kind == PIO_KIND_REGULAR)
18401840
{
18411841
file->crc = pgFileGetCRC32C(full_filename, false);
18421842

@@ -1990,7 +1990,7 @@ backup_files(void *arg)
19901990
pgFile *prev_file = NULL;
19911991

19921992
/* We have already copied all directories */
1993-
if (S_ISDIR(file->mode))
1993+
if (file->kind == PIO_KIND_DIRECTORY)
19941994
continue;
19951995

19961996
if (arguments->thread_num == 1)
@@ -2045,9 +2045,9 @@ backup_files(void *arg)
20452045
}
20462046

20472047
/* Encountered some strange beast */
2048-
if (!S_ISREG(file->mode))
2049-
elog(WARNING, "Unexpected type %d of file \"%s\", skipping",
2050-
file->mode, from_fullpath);
2048+
if (file->kind != PIO_KIND_REGULAR)
2049+
elog(WARNING, "Unexpected type %s of file \"%s\", skipping",
2050+
pio_file_kind2str(file->kind, from_fullpath), from_fullpath);
20512051

20522052
/* Check that file exist in previous backup */
20532053
if (current.backup_mode != BACKUP_MODE_FULL)
@@ -2120,7 +2120,7 @@ parse_filelist_filenames(parray *files, const char *root)
21202120
pgFile *file = (pgFile *) parray_get(files, i);
21212121
int sscanf_result;
21222122

2123-
if (S_ISREG(file->mode) &&
2123+
if (file->kind == PIO_KIND_REGULAR &&
21242124
path_is_prefix_of_path(PG_TBLSPC_DIR, file->rel_path))
21252125
{
21262126
/*
@@ -2147,7 +2147,7 @@ parse_filelist_filenames(parray *files, const char *root)
21472147
}
21482148
}
21492149

2150-
if (S_ISREG(file->mode) && file->tblspcOid != 0 &&
2150+
if (file->kind == PIO_KIND_REGULAR && file->tblspcOid != 0 &&
21512151
file->name && file->name[0])
21522152
{
21532153
if (file->forkName == init)
@@ -2217,7 +2217,7 @@ set_cfs_datafiles(parray *files, const char *root, char *relative, size_t i)
22172217

22182218
if (strstr(prev_file->rel_path, cfs_tblspc_path) != NULL)
22192219
{
2220-
if (S_ISREG(prev_file->mode) && prev_file->is_datafile)
2220+
if (prev_file->kind == PIO_KIND_REGULAR && prev_file->is_datafile)
22212221
{
22222222
elog(LOG, "Setting 'is_cfs' on file %s, name %s",
22232223
prev_file->rel_path, prev_file->name);
@@ -2374,7 +2374,7 @@ calculate_datasize_of_filelist(parray *filelist)
23742374
if (file->external_dir_num != 0 || file->excluded)
23752375
continue;
23762376

2377-
if (S_ISDIR(file->mode))
2377+
if (file->kind == PIO_KIND_DIRECTORY)
23782378
{
23792379
// TODO is a dir always 4K?
23802380
bytes += 4096;

src/catalog.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -847,12 +847,22 @@ pgBackupGetBackupMode(pgBackup *backup, bool show_color)
847847
static bool
848848
IsDir(const char *dirpath, const char *entry, fio_location location)
849849
{
850+
FOBJ_FUNC_ARP();
850851
char path[MAXPGPATH];
851-
struct stat st;
852+
pio_stat_t st;
853+
err_i err;
852854

853855
join_path_components(path, dirpath, entry);
854856

855-
return fio_stat(location, path, &st, false) == 0 && S_ISDIR(st.st_mode);
857+
st = $i(pioStat, pioDriveForLocation(location),
858+
.path = path, .follow_symlink = false, .err = &err);
859+
if ($haserr(err))
860+
{
861+
ft_logerr(FT_WARNING, $errmsg(err), "IsDir");
862+
return false;
863+
}
864+
865+
return st.pst_kind == PIO_KIND_DIRECTORY;
856866
}
857867

858868
/*
@@ -1074,6 +1084,7 @@ get_backup_filelist(pgBackup *backup, bool strict)
10741084
char path[MAXPGPATH];
10751085
char linked[MAXPGPATH];
10761086
char compress_alg_string[MAXPGPATH];
1087+
char kind[16];
10771088
int64 write_size,
10781089
uncompressed_size,
10791090
mode, /* bit length of mode_t depends on platforms */
@@ -1115,6 +1126,11 @@ get_backup_filelist(pgBackup *backup, bool strict)
11151126
/*
11161127
* Optional fields
11171128
*/
1129+
if (get_control_value_str(buf, "kind", kind, sizeof(kind), false))
1130+
file->kind = pio_str2file_kind(kind, path);
1131+
else /* fallback to mode for old backups */
1132+
file->kind = pio_statmode2file_kind(file->mode, path);
1133+
11181134
if (get_control_value_str(buf, "linked", linked, sizeof(linked), false) && linked[0])
11191135
{
11201136
file->linked = pgut_strdup(linked);
@@ -1146,7 +1162,7 @@ get_backup_filelist(pgBackup *backup, bool strict)
11461162
if (!file->is_datafile || file->is_cfs)
11471163
file->size = file->uncompressed_size;
11481164

1149-
if (file->external_dir_num == 0 && S_ISREG(file->mode))
1165+
if (file->external_dir_num == 0 && file->kind == PIO_KIND_REGULAR)
11501166
{
11511167
bool is_datafile = file->is_datafile;
11521168
set_forkname(file);
@@ -2564,14 +2580,14 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
25642580
if (file->write_size == FILE_NOT_FOUND)
25652581
continue;
25662582

2567-
if (S_ISDIR(file->mode))
2583+
if (file->kind == PIO_KIND_DIRECTORY)
25682584
{
25692585
backup_size_on_disk += 4096;
25702586
uncompressed_size_on_disk += 4096;
25712587
}
25722588

25732589
/* Count the amount of the data actually copied */
2574-
if (S_ISREG(file->mode) && file->write_size > 0)
2590+
if (file->kind == PIO_KIND_REGULAR && file->write_size > 0)
25752591
{
25762592
/*
25772593
* Size of WAL files in 'pg_wal' is counted separately
@@ -2587,11 +2603,13 @@ write_backup_filelist(pgBackup *backup, parray *files, const char *root,
25872603
}
25882604

25892605
len = sprintf(line, "{\"path\":\"%s\", \"size\":\"" INT64_FORMAT "\", "
2590-
"\"mode\":\"%u\", \"is_datafile\":\"%u\", "
2606+
"\"kind\":\"%s\", \"mode\":\"%u\", \"is_datafile\":\"%u\", "
25912607
"\"is_cfs\":\"%u\", \"crc\":\"%u\", "
25922608
"\"compress_alg\":\"%s\", \"external_dir_num\":\"%d\", "
25932609
"\"dbOid\":\"%u\"",
2594-
file->rel_path, file->write_size, file->mode,
2610+
file->rel_path, file->write_size,
2611+
pio_file_kind2str(file->kind, file->rel_path),
2612+
file->mode,
25952613
file->is_datafile ? 1 : 0,
25962614
file->is_cfs ? 1 : 0,
25972615
file->crc,

src/catchup.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ catchup_thread_runner(void *arg)
378378
pgFile *dest_file = NULL;
379379

380380
/* We have already copied all directories */
381-
if (S_ISDIR(file->mode))
381+
if (file->kind == PIO_KIND_DIRECTORY)
382382
continue;
383383

384384
if (file->excluded)
@@ -400,9 +400,9 @@ catchup_thread_runner(void *arg)
400400
join_path_components(to_fullpath, arguments->to_root, file->rel_path);
401401

402402
/* Encountered some strange beast */
403-
if (!S_ISREG(file->mode))
404-
elog(WARNING, "Unexpected type %d of file \"%s\", skipping",
405-
file->mode, from_fullpath);
403+
if (file->kind != PIO_KIND_REGULAR)
404+
elog(WARNING, "Unexpected kind %s of file \"%s\", skipping",
405+
pio_file_kind2str(file->kind, from_fullpath), from_fullpath);
406406

407407
/* Check that file exist in dest pgdata */
408408
if (arguments->backup_mode != BACKUP_MODE_FULL)
@@ -439,7 +439,7 @@ catchup_thread_runner(void *arg)
439439

440440
if (file->write_size == BYTES_INVALID)
441441
{
442-
elog(LOG, "Skipping the unchanged file: \"%s\", read %zu bytes", from_fullpath, file->read_size);
442+
elog(LOG, "Skipping the unchanged file: \"%s\", read %lld bytes", from_fullpath, (long long)file->read_size);
443443
continue;
444444
}
445445

@@ -546,7 +546,7 @@ catchup_sync_destination_files(const char* pgdata_path, fio_location location, p
546546
* - but PG itself is not relying on fs, its durable_sync
547547
* includes directory sync
548548
*/
549-
if (S_ISDIR(file->mode) || file->excluded)
549+
if (file->kind == PIO_KIND_DIRECTORY || file->excluded)
550550
continue;
551551

552552
Assert(file->external_dir_num == 0);
@@ -630,8 +630,8 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
630630

631631
/* for fancy reporting */
632632
time_t start_time, end_time;
633-
ssize_t transfered_datafiles_bytes = 0;
634-
ssize_t transfered_walfiles_bytes = 0;
633+
int64_t transfered_datafiles_bytes = 0;
634+
int64_t transfered_walfiles_bytes = 0;
635635
char pretty_source_bytes[20];
636636
err_i err = $noerr();
637637

@@ -807,7 +807,7 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
807807
pgFile *file = (pgFile *) parray_get(source_filelist, i);
808808
char parent_dir[MAXPGPATH];
809809

810-
if (!S_ISDIR(file->mode) || file->excluded)
810+
if (file->kind != PIO_KIND_DIRECTORY || file->excluded)
811811
continue;
812812

813813
/*

src/checkdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ check_files(void *arg)
147147
elog(ERROR, "interrupted during checkdb");
148148

149149
/* No need to check directories */
150-
if (S_ISDIR(file->mode))
150+
if (file->kind == PIO_KIND_DIRECTORY)
151151
continue;
152152

153153
if (!pg_atomic_test_set_flag(&file->lock))
@@ -161,7 +161,7 @@ check_files(void *arg)
161161
elog(INFO, "Progress: (%d/%d). Process file \"%s\"",
162162
i + 1, n_files_list, from_fullpath);
163163

164-
if (S_ISREG(file->mode))
164+
if (file->kind == PIO_KIND_REGULAR)
165165
{
166166
/* check only uncompressed by cfs datafiles */
167167
if (file->is_datafile && !file->is_cfs)

src/data.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ backup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpat
507507
* NOTE This is a normal situation, if the file size has changed
508508
* since the moment we computed it.
509509
*/
510-
file->n_blocks = file->size/BLCKSZ;
510+
file->n_blocks = (typeof(file->n_blocks))(file->size/BLCKSZ);
511+
Assert((int64_t)file->n_blocks * BLCKSZ == file->size);
511512

512513
/*
513514
* Skip unchanged file only if it exists in previous backup.
@@ -611,12 +612,15 @@ backup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpat
611612
elog(ERROR, "Cannot read file \"%s\"", from_fullpath);
612613
}
613614

614-
file->read_size = rc * BLCKSZ;
615+
file->read_size = (int64_t)rc * BLCKSZ;
615616

616617
/* refresh n_blocks for FULL and DELTA */
617618
if (backup_mode == BACKUP_MODE_FULL ||
618619
backup_mode == BACKUP_MODE_DIFF_DELTA)
619-
file->n_blocks = file->read_size / BLCKSZ;
620+
{
621+
file->n_blocks = (typeof(file->n_blocks))(file->read_size / BLCKSZ);
622+
Assert((int64_t)file->n_blocks * BLCKSZ == file->read_size);
623+
}
620624

621625
/* Determine that file didn`t changed in case of incremental backup */
622626
if (backup_mode != BACKUP_MODE_FULL &&
@@ -650,7 +654,7 @@ backup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpat
650654
void
651655
catchup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpath,
652656
XLogRecPtr sync_lsn, BackupMode backup_mode,
653-
uint32 checksum_version, size_t prev_size)
657+
uint32 checksum_version, int64_t prev_size)
654658
{
655659
int rc;
656660
bool use_pagemap;
@@ -760,7 +764,7 @@ catchup_data_file(pgFile *file, const char *from_fullpath, const char *to_fullpa
760764
elog(ERROR, "Cannot read file \"%s\"", from_fullpath);
761765
}
762766

763-
file->read_size = rc * BLCKSZ;
767+
file->read_size = (int64_t)rc * BLCKSZ;
764768

765769
/* Determine that file didn`t changed in case of incremental catchup */
766770
if (backup_mode != BACKUP_MODE_FULL &&
@@ -1595,7 +1599,8 @@ check_data_file(ConnectionArgs *arguments, pgFile *file,
15951599
* NOTE This is a normal situation, if the file size has changed
15961600
* since the moment we computed it.
15971601
*/
1598-
nblocks = file->size/BLCKSZ;
1602+
nblocks = (typeof(nblocks))(file->size/BLCKSZ);
1603+
Assert((int64_t)nblocks * BLCKSZ == file->size);
15991604

16001605
for (blknum = 0; blknum < nblocks; blknum++)
16011606
{
@@ -2275,7 +2280,7 @@ copy_pages(const char *to_fullpath, const char *from_fullpath,
22752280
elog(ERROR, "Cannot seek to end of file position in destination file \"%s\": %s",
22762281
to_fullpath, strerror(errno));
22772282
{
2278-
long pos = ftell(out);
2283+
int64_t pos = ftell(out);
22792284

22802285
if (pos < 0)
22812286
elog(ERROR, "Cannot get position in destination file \"%s\": %s",

src/delete.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,8 +794,8 @@ delete_walfiles_in_tli(InstanceState *instanceState, XLogRecPtr keep_lsn, timeli
794794
char first_to_del_str[MAXFNAMELEN];
795795
char oldest_to_keep_str[MAXFNAMELEN];
796796
int i;
797-
size_t wal_size_logical = 0;
798-
size_t wal_size_actual = 0;
797+
int64_t wal_size_logical = 0;
798+
int64_t wal_size_actual = 0;
799799
char wal_pretty_size[20];
800800
bool purge_all = false;
801801

@@ -837,7 +837,7 @@ delete_walfiles_in_tli(InstanceState *instanceState, XLogRecPtr keep_lsn, timeli
837837
/* sanity */
838838
if (OldestToKeepSegNo > FirstToDeleteSegNo)
839839
{
840-
wal_size_logical = (OldestToKeepSegNo - FirstToDeleteSegNo) * xlog_seg_size;
840+
wal_size_logical = (int64_t)(OldestToKeepSegNo - FirstToDeleteSegNo) * xlog_seg_size;
841841

842842
/* In case of 'purge all' scenario OldestToKeepSegNo will be deleted too */
843843
if (purge_all)

0 commit comments

Comments
 (0)