Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ptrack.map compression and decompression#658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
kr1llin wants to merge1 commit intopostgrespro:master
base:master
Choose a base branch
Loading
fromkr1llin:ptrack_compression
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletionssrc/data.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -794,6 +794,14 @@ backup_non_data_file(pgFile *file, pgFile *prev_file,
return;
}

/* special treatment for global/ptrack.map */
if (strcmp(file->name, "ptrack.map") == 0)
{
copy_ptrackmap_file(from_fullpath, FIO_DB_HOST,
to_fullpath, FIO_BACKUP_HOST, file);
return;
}

/*
* If non-data file exists in previous backup
* and its mtime is less than parent backup start time ... */
Expand DownExpand Up@@ -1383,6 +1391,43 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup,
elog(ERROR, "Cannot close file \"%s\": %s", from_fullpath,
strerror(errno));


/* We have to decompress ptrack.map */
if (tmp_backup->compress_alg > NONE_COMPRESS && strcmp(tmp_file->name, "ptrack.map") == 0){

/* do decompression */
char *buffer;
size_t size;

const char *errormsg = NULL;
buffer = slurpFile(to_fullpath, "", &size, false, FIO_DB_HOST); // not sure about to_location

size_t decompressed_size = tmp_file->size * 2;
void* decompressed = pg_malloc(decompressed_size);

int rc = do_decompress(decompressed, decompressed_size, buffer, size, tmp_backup->compress_alg, &errormsg);

/* Something went wrong and errormsg was assigned, throw a warning */
if (rc < 0 && errormsg != NULL)
elog(WARNING, "An error occured during compressing ptrack.map: %s", errormsg);

/* decompression didn't worked */
if (rc <= 0)
{
elog(ERROR, "An error occured during decompression of ptrack.map: %s", errormsg);
pg_free(buffer);
pg_free(decompressed);
}
else {
decompressed_size = rc;
}

writePtrackMap(decompressed, decompressed_size, to_fullpath, FIO_DB_HOST);

pg_free(decompressed);
pg_free(buffer);
}

return tmp_file->write_size;
}

Expand Down
5 changes: 5 additions & 0 deletionssrc/pg_probackup.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1214,6 +1214,8 @@ extern void get_control_file_or_back_file(const char *pgdata_path, fio_location
ControlFileData *control);
extern void copy_pgcontrol_file(const char *from_fullpath, fio_location from_location,
const char *to_fullpath, fio_location to_location, pgFile *file);
extern void copy_ptrackmap_file(const char *from_fullpath, fio_location from_location,
const char *to_fullpath, fio_location to_location, pgFile *file);

extern void time2iso(char *buf, size_t len, time_t time, bool utc);
extern const char *status2str(BackupStatus status);
Expand All@@ -1239,6 +1241,9 @@ extern PGconn *pgdata_basic_setup(ConnectionOptions conn_opt, PGNodeInfo *nodeIn
extern void check_system_identifiers(PGconn *conn, const char *pgdata);
extern void parse_filelist_filenames(parray *files, const char *root);

extern void writePtrackMap(const char *ptrackMap, const size_t ptrackmap_size,
const char *path, fio_location location);

/* in ptrack.c */
extern void make_pagemap_from_ptrack_2(parray* files, PGconn* backup_conn,
const char *ptrack_schema,
Expand Down
84 changes: 84 additions & 0 deletionssrc/util.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -454,6 +454,90 @@ copy_pgcontrol_file(const char *from_fullpath, fio_location from_location,
pg_free(buffer);
}

/*
* Write page_map_entry to ptrackMap
*/
void
writePtrackMap(const char *ptrackMap, const size_t ptrackmap_size,
const char *path, fio_location location)
{
intfd;
char *buffer = NULL;

// checks?

/* copy ptrackMap */
buffer = pg_malloc0(ptrackmap_size);
memcpy(buffer, ptrackMap, ptrackmap_size);

/* Write ptrackMap */
fd = fio_open(path,
O_RDWR | O_CREAT | O_TRUNC | PG_BINARY, location);

if (fd < 0) {
elog(ERROR, "Failed to open file: %s", path);
}

if (fio_write(fd, buffer, ptrackmap_size) != ptrackmap_size) {
elog(ERROR, "Failed to overwrite file: %s", path);
}

if (fio_flush(fd) != 0) {
elog(ERROR, "Failed to sync file: %s", path);
}

fio_close(fd);
pg_free(buffer);
}

/*
* Copy ptrack.map file to backup. We do apply compression to this file.
*/
void copy_ptrackmap_file(const char *from_fullpath, fio_location from_location,
const char *to_fullpath, fio_location to_location,
pgFile *file) {
char *buffer;
size_t size;

bool missing_ok = true;
bool use_crc32c = true;

const char *errormsg = NULL;

buffer = slurpFile(from_fullpath, "", &size, false, from_location);

size_t compressed_size = size;
void *compressed = pg_malloc(compressed_size);

int rc = do_compress(compressed, compressed_size, buffer, size,
current.compress_alg, current.compress_level, &errormsg);

/* Something went wrong and errormsg was assigned, throw a warning */
if (rc < 0 && errormsg != NULL)
elog(WARNING, "An error occured during compressing ptrack.map: %s",
errormsg);

/* compression didn`t worked */
if (rc <= 0 || rc >= size) {
/* Do not compress ptrack.map */
memcpy(compressed, buffer, size);
} else {
compressed_size = rc;
}

writePtrackMap(compressed, compressed_size, to_fullpath, to_location);

file->crc = pgFileGetCRCgz(to_fullpath, use_crc32c, missing_ok);;
file->size = compressed_size;
file->read_size = size;
file->write_size = compressed_size;
file->uncompressed_size = size;
file->compress_alg = current.compress_alg;

pg_free(compressed);
pg_free(buffer);
}

/*
* Parse string representation of the server version.
*/
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp