Skip to content

Commit 45220ba

Browse files
committed
add is_partial_backup flag
1 parent aa6facb commit 45220ba

File tree

4 files changed

+21
-64
lines changed

4 files changed

+21
-64
lines changed

contrib/pg_probackup/backup.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ backup_files(void *arg)
12861286
continue;
12871287
}
12881288
}
1289-
else if (is_compressed_data_file(file, arguments->files))
1289+
else if (is_compressed_data_file(file))
12901290
{
12911291
size_t skip_size = 0;
12921292
if (backup_compressed_file_partially(file, arguments, &skip_size))
@@ -1398,13 +1398,6 @@ add_files(parray *files, const char *root, bool add_root, bool is_pgdata)
13981398

13991399
pre_search_file = (pgFile **) parray_bsearch(list_file, &tmp_file, pgFileComparePath);
14001400

1401-
// if (is_compressed_data_file(&tmp_file, list_file))
1402-
// {
1403-
// elog(NOTICE, "file %s is compressed, don't remove it from list", tmp_file.path);
1404-
// pg_free(tmp_file.path);
1405-
// break;
1406-
// }
1407-
14081401
if (pre_search_file != NULL)
14091402
{
14101403
search_file = *pre_search_file;

contrib/pg_probackup/data.c

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -513,43 +513,12 @@ restore_compressed_file(const char *from_root,
513513
const char *to_root,
514514
pgFile *file)
515515
{
516-
char to_path[MAXPGPATH];
517-
pgFile tmp_file;
518-
519-
join_path_components(to_path, to_root, file->path + strlen(from_root) + 1);
520-
tmp_file.path = psprintf("%s.cfm", to_path);
521-
522-
FileMap* map;
523-
int md = open(tmp_file.path, O_RDWR|PG_BINARY, 0);
524-
if (md < 0)
525-
{
526-
elog(LOG, "restore_compressed_file(). cannot open cfm file '%s'", tmp_file.path);
527-
copy_file(from_root, to_root, file);
528-
pfree(tmp_file.path);
529-
return;
530-
}
531-
532-
elog(NOTICE, "restore_compressed_file(). map %s", tmp_file.path);
533-
map = cfs_mmap(md);
534-
if (map == MAP_FAILED)
535-
{
536-
elog(LOG, "restore_compressed_file(). cfs_compression_ration failed to map file %s: %m", tmp_file.path);
537-
if (close(md) < 0)
538-
elog(LOG, "restore_compressed_file(). CFS failed to close file %s: %m", tmp_file.path);
539-
pfree(tmp_file.path);
540-
return;
541-
}
542-
543-
if (map->generation != file->generation)
516+
if (file->is_partial_copy == 0)
544517
copy_file(from_root, to_root, file);
545-
else
518+
else if (file->is_partial_copy == 1)
546519
restore_file_partly(from_root, to_root, file);
547-
548-
if (cfs_munmap(map) < 0)
549-
elog(LOG, "restore_compressed_file(). CFS failed to unmap file %s: %m", tmp_file.path);
550-
if (close(md) < 0)
551-
elog(LOG, "restore_compressed_file(). CFS failed to close file %s: %m", tmp_file.path);
552-
pfree(tmp_file.path);
520+
else
521+
elog(ERROR, "restore_compressed_file()");
553522
}
554523

555524
/*
@@ -700,22 +669,14 @@ restore_data_file(const char *from_root,
700669
fclose(out);
701670
}
702671

703-
/* */
672+
/* If someone's want to use this function before correct
673+
* generation values is set, he can look up for corresponding
674+
* .cfm file in the file_list
675+
*/
704676
bool
705-
is_compressed_data_file(pgFile *file, parray *file_list)
677+
is_compressed_data_file(pgFile *file)
706678
{
707-
// return (file->generation != -1);
708-
pgFile map_file;
709-
pgFile **pre_search_file;
710-
711-
map_file.path = psprintf("%s.cfm", file->path);
712-
pre_search_file = (pgFile **) parray_bsearch(file_list, &map_file, pgFileComparePath);
713-
pg_free(map_file.path);
714-
715-
if (pre_search_file != NULL)
716-
return true;
717-
718-
return false;
679+
return (file->generation != -1);
719680
}
720681

721682
bool
@@ -958,10 +919,8 @@ copy_file_partly(const char *from_root, const char *to_root,
958919
strerror(errno_tmp));
959920
}
960921

922+
file->is_partial_copy = 1;
961923
elog(NOTICE, "copy_file_partly(). %s file->write_size %lu", to_path, file->write_size);
962-
// pgFile newfile;
963-
// newfile.path = pg_strdup(to_path);
964-
// file->crc = pgFileGetCRC(&newfile);
965924

966925
fclose(in);
967926
fclose(out);

contrib/pg_probackup/dir.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pgFileNew(const char *path, bool omit_symlink)
9393
file->segno = 0;
9494
file->path = pgut_malloc(strlen(path) + 1);
9595
file->generation = -1;
96+
file->is_partial_copy = 0;
9697
strcpy(file->path, path); /* enough buffer size guaranteed */
9798

9899
return file;
@@ -523,7 +524,7 @@ dir_print_file_list(FILE *out, const parray *files, const char *root, const char
523524
fprintf(out, " %s", timestamp);
524525
}
525526

526-
fprintf(out, " %d\n", file->generation);
527+
fprintf(out, " %d %d\n", file->generation, file->is_partial_copy);
527528
}
528529
}
529530

@@ -550,18 +551,19 @@ dir_read_file_list(const char *root, const char *file_txt)
550551
char path[MAXPGPATH];
551552
char type;
552553
int generation;
554+
int is_partial_copy;
553555
unsigned long write_size;
554556
pg_crc32 crc;
555557
unsigned int mode; /* bit length of mode_t depends on platforms */
556558
struct tm tm;
557559
pgFile *file;
558560

559561
memset(&tm, 0, sizeof(tm));
560-
if (sscanf(buf, "%s %c %lu %u %o %d-%d-%d %d:%d:%d %d",
562+
if (sscanf(buf, "%s %c %lu %u %o %d-%d-%d %d:%d:%d %d %d",
561563
path, &type, &write_size, &crc, &mode,
562564
&tm.tm_year, &tm.tm_mon, &tm.tm_mday,
563565
&tm.tm_hour, &tm.tm_min, &tm.tm_sec,
564-
&generation) != 12)
566+
&generation, &is_partial_copy) != 13)
565567
{
566568
elog(ERROR, "invalid format found in \"%s\"",
567569
file_txt);
@@ -587,6 +589,7 @@ dir_read_file_list(const char *root, const char *file_txt)
587589
((type == 'f' || type == 'F') ? S_IFREG :
588590
type == 'd' ? S_IFDIR : type == 'l' ? S_IFLNK : 0);
589591
file->generation = generation;
592+
file->is_partial_copy = is_partial_copy;
590593
file->size = 0;
591594
file->read_size = 0;
592595
file->write_size = write_size;

contrib/pg_probackup/pg_probackup.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ typedef struct pgFile
7373
int segno; /* Segment number for ptrack */
7474
int generation; /* Generation of compressed file.
7575
* -1 for non-compressed files */
76+
int is_partial_copy; /* for compressed files.
77+
* 1 if backed up via copy_file_partly() */
7678
volatile uint32 lock;
7779
datapagemap_t pagemap;
7880
} pgFile;
@@ -317,7 +319,7 @@ extern bool backup_data_file(const char *from_root, const char *to_root,
317319
pgFile *file, const XLogRecPtr *lsn);
318320
extern void restore_data_file(const char *from_root, const char *to_root,
319321
pgFile *file, pgBackup *backup);
320-
extern bool is_compressed_data_file(pgFile *file, parray *file_list);
322+
extern bool is_compressed_data_file(pgFile *file);
321323
extern bool backup_compressed_file_partially(pgFile *file,
322324
void *arg,
323325
size_t *skip_size);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy