char xlog[MAXPGPATH]; /* directory or tarfile depending on mode */
char *sysidentifier;
int timeline;
- WalCompressionMethod wal_compress_method;
+ pg_compress_algorithm wal_compress_algorithm;
int wal_compress_level;
} logstreamer_param;
stream.replication_slot = replication_slot;
if (format == 'p')
stream.walmethod = CreateWalDirectoryMethod(param->xlog,
- COMPRESSION_NONE, 0,
+ PG_COMPRESSION_NONE, 0,
stream.do_sync);
else
stream.walmethod = CreateWalTarMethod(param->xlog,
- param->wal_compress_method,
+ param->wal_compress_algorithm,
param->wal_compress_level,
stream.do_sync);
*/
static void
StartLogStreamer(char *startpos, uint32 timeline, char *sysidentifier,
- WalCompressionMethod wal_compress_method,
+ pg_compress_algorithm wal_compress_algorithm,
int wal_compress_level)
{
logstreamer_param *param;
param = pg_malloc0(sizeof(logstreamer_param));
param->timeline = timeline;
param->sysidentifier = sysidentifier;
- param->wal_compress_method = wal_compress_method;
+ param->wal_compress_algorithm = wal_compress_algorithm;
param->wal_compress_level = wal_compress_level;
/* Convert the starting position */
*/
if (includewal == STREAM_WAL)
{
- WalCompressionMethod wal_compress_method;
+ pg_compress_algorithm wal_compress_algorithm;
int wal_compress_level;
if (verbose)
if (client_compress->algorithm == PG_COMPRESSION_GZIP)
{
- wal_compress_method = COMPRESSION_GZIP;
+ wal_compress_algorithm = PG_COMPRESSION_GZIP;
wal_compress_level =
(client_compress->options & PG_COMPRESSION_OPTION_LEVEL)
!= 0 ? client_compress->level : 0;
}
else
{
- wal_compress_method = COMPRESSION_NONE;
+ wal_compress_algorithm = PG_COMPRESSION_NONE;
wal_compress_level = 0;
}
StartLogStreamer(xlogstart, starttli, sysidentifier,
- wal_compress_method, wal_compress_level);
+ wal_compress_algorithm, wal_compress_level);
}
if (serverMajor >= 1500)
static bool do_sync = true;
static bool synchronous = false;
static char *replication_slot = NULL;
-static WalCompressionMethod compression_method = COMPRESSION_NONE;
+static pg_compress_algorithm compression_algorithm = PG_COMPRESSION_NONE;
static XLogRecPtr endpos = InvalidXLogRecPtr;
*/
static bool
is_xlogfilename(const char *filename, bool *ispartial,
- WalCompressionMethod *wal_compression_method)
+ pg_compress_algorithm *wal_compression_algorithm)
{
size_t fname_len = strlen(filename);
size_t xlog_pattern_len = strspn(filename, "0123456789ABCDEF");
if (fname_len == XLOG_FNAME_LEN)
{
*ispartial = false;
- *wal_compression_method = COMPRESSION_NONE;
+ *wal_compression_algorithm = PG_COMPRESSION_NONE;
return true;
}
strcmp(filename + XLOG_FNAME_LEN, ".gz") == 0)
{
*ispartial = false;
- *wal_compression_method = COMPRESSION_GZIP;
+ *wal_compression_algorithm = PG_COMPRESSION_GZIP;
return true;
}
strcmp(filename + XLOG_FNAME_LEN, ".lz4") == 0)
{
*ispartial = false;
- *wal_compression_method = COMPRESSION_LZ4;
+ *wal_compression_algorithm = PG_COMPRESSION_LZ4;
return true;
}
strcmp(filename + XLOG_FNAME_LEN, ".partial") == 0)
{
*ispartial = true;
- *wal_compression_method = COMPRESSION_NONE;
+ *wal_compression_algorithm = PG_COMPRESSION_NONE;
return true;
}
strcmp(filename + XLOG_FNAME_LEN, ".gz.partial") == 0)
{
*ispartial = true;
- *wal_compression_method = COMPRESSION_GZIP;
+ *wal_compression_algorithm = PG_COMPRESSION_GZIP;
return true;
}
strcmp(filename + XLOG_FNAME_LEN, ".lz4.partial") == 0)
{
*ispartial = true;
- *wal_compression_method = COMPRESSION_LZ4;
+ *wal_compression_algorithm = PG_COMPRESSION_LZ4;
return true;
}
{
uint32 tli;
XLogSegNo segno;
- WalCompressionMethod wal_compression_method;
+ pg_compress_algorithm wal_compression_algorithm;
bool ispartial;
if (!is_xlogfilename(dirent->d_name,
- &ispartial, &wal_compression_method))
+ &ispartial, &wal_compression_algorithm))
continue;
/*
* where WAL segments could have been compressed by a different source
* than pg_receivewal, like an archive_command with lz4.
*/
- if (!ispartial && wal_compression_method == COMPRESSION_NONE)
+ if (!ispartial && wal_compression_algorithm == PG_COMPRESSION_NONE)
{
struct stat statbuf;
char fullpath[MAXPGPATH * 2];
continue;
}
}
- else if (!ispartial && wal_compression_method == COMPRESSION_GZIP)
+ else if (!ispartial && wal_compression_algorithm == PG_COMPRESSION_GZIP)
{
int fd;
char buf[4];
continue;
}
}
- else if (!ispartial && wal_compression_method == COMPRESSION_LZ4)
+ else if (!ispartial && wal_compression_algorithm == PG_COMPRESSION_LZ4)
{
#ifdef USE_LZ4
#define LZ4_CHUNK_SZ 64 * 1024 /* 64kB as maximum chunk size read */
stream.do_sync = do_sync;
stream.mark_done = false;
stream.walmethod = CreateWalDirectoryMethod(basedir,
- compression_method,
+ compression_algorithm,
compresslevel,
stream.do_sync);
stream.partial_suffix = ".partial";
break;
case 6:
if (pg_strcasecmp(optarg, "gzip") == 0)
- compression_method = COMPRESSION_GZIP;
+ compression_algorithm = PG_COMPRESSION_GZIP;
else if (pg_strcasecmp(optarg, "lz4") == 0)
- compression_method = COMPRESSION_LZ4;
+ compression_algorithm = PG_COMPRESSION_LZ4;
else if (pg_strcasecmp(optarg, "none") == 0)
- compression_method = COMPRESSION_NONE;
+ compression_algorithm = PG_COMPRESSION_NONE;
else
pg_fatal("invalid value \"%s\" for option %s",
optarg, "--compression-method");
/*
* Compression-related options.
*/
- switch (compression_method)
+ switch (compression_algorithm)
{
- case COMPRESSION_NONE:
+ case PG_COMPRESSION_NONE:
if (compresslevel != 0)
{
pg_log_error("cannot use --compress with --compression-method=%s",
exit(1);
}
break;
- case COMPRESSION_GZIP:
+ case PG_COMPRESSION_GZIP:
#ifdef HAVE_LIBZ
if (compresslevel == 0)
{
"gzip");
#endif
break;
- case COMPRESSION_LZ4:
+ case PG_COMPRESSION_LZ4:
#ifdef USE_LZ4
if (compresslevel != 0)
{
"LZ4");
#endif
break;
- case COMPRESSION_ZSTD:
+ case PG_COMPRESSION_ZSTD:
pg_fatal("compression with %s is not yet supported", "ZSTD");
break;
}
typedef struct DirectoryMethodData
{
char *basedir;
- WalCompressionMethod compression_method;
+ pg_compress_algorithm compression_algorithm;
int compression_level;
bool sync;
const char *lasterrstring; /* if set, takes precedence over lasterrno */
snprintf(filename, MAXPGPATH, "%s%s%s",
pathname,
- dir_data->compression_method == COMPRESSION_GZIP ? ".gz" :
- dir_data->compression_method == COMPRESSION_LZ4 ? ".lz4" : "",
+ dir_data->compression_algorithm == PG_COMPRESSION_GZIP ? ".gz" :
+ dir_data->compression_algorithm == PG_COMPRESSION_LZ4 ? ".lz4" : "",
temp_suffix ? temp_suffix : "");
return filename;
}
#ifdef HAVE_LIBZ
- if (dir_data->compression_method == COMPRESSION_GZIP)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
gzfp = gzdopen(fd, "wb");
if (gzfp == NULL)
}
#endif
#ifdef USE_LZ4
- if (dir_data->compression_method == COMPRESSION_LZ4)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4)
{
size_t ctx_out;
size_t header_size;
#endif
/* Do pre-padding on non-compressed files */
- if (pad_to_size && dir_data->compression_method == COMPRESSION_NONE)
+ if (pad_to_size && dir_data->compression_algorithm == PG_COMPRESSION_NONE)
{
PGAlignedXLogBlock zerobuf;
int bytes;
{
dir_data->lasterrno = errno;
#ifdef HAVE_LIBZ
- if (dir_data->compression_method == COMPRESSION_GZIP)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP)
gzclose(gzfp);
else
#endif
#ifdef USE_LZ4
- if (dir_data->compression_method == COMPRESSION_LZ4)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4)
{
(void) LZ4F_compressEnd(ctx, lz4buf, lz4bufsize, NULL);
(void) LZ4F_freeCompressionContext(ctx);
f = pg_malloc0(sizeof(DirectoryMethodFile));
#ifdef HAVE_LIBZ
- if (dir_data->compression_method == COMPRESSION_GZIP)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP)
f->gzfp = gzfp;
#endif
#ifdef USE_LZ4
- if (dir_data->compression_method == COMPRESSION_LZ4)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4)
{
f->ctx = ctx;
f->lz4buf = lz4buf;
dir_clear_error();
#ifdef HAVE_LIBZ
- if (dir_data->compression_method == COMPRESSION_GZIP)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
errno = 0;
r = (ssize_t) gzwrite(df->gzfp, buf, count);
else
#endif
#ifdef USE_LZ4
- if (dir_data->compression_method == COMPRESSION_LZ4)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4)
{
size_t chunk;
size_t remaining;
dir_clear_error();
#ifdef HAVE_LIBZ
- if (dir_data->compression_method == COMPRESSION_GZIP)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
errno = 0; /* in case gzclose() doesn't set it */
r = gzclose(df->gzfp);
else
#endif
#ifdef USE_LZ4
- if (dir_data->compression_method == COMPRESSION_LZ4)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4)
{
size_t compressed;
return 0;
#ifdef HAVE_LIBZ
- if (dir_data->compression_method == COMPRESSION_GZIP)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
if (gzflush(((DirectoryMethodFile *) f)->gzfp, Z_SYNC_FLUSH) != Z_OK)
{
}
#endif
#ifdef USE_LZ4
- if (dir_data->compression_method == COMPRESSION_LZ4)
+ if (dir_data->compression_algorithm == PG_COMPRESSION_LZ4)
{
DirectoryMethodFile *df = (DirectoryMethodFile *) f;
size_t compressed;
return statbuf.st_size;
}
-static WalCompressionMethod
-dir_compression_method(void)
+static pg_compress_algorithm
+dir_compression_algorithm(void)
{
- return dir_data->compression_method;
+ return dir_data->compression_algorithm;
}
static bool
WalWriteMethod *
CreateWalDirectoryMethod(const char *basedir,
- WalCompressionMethod compression_method,
+ pg_compress_algorithm compression_algorithm,
int compression_level, bool sync)
{
WalWriteMethod *method;
method->get_current_pos = dir_get_current_pos;
method->get_file_size = dir_get_file_size;
method->get_file_name = dir_get_file_name;
- method->compression_method = dir_compression_method;
+ method->compression_algorithm = dir_compression_algorithm;
method->close = dir_close;
method->sync = dir_sync;
method->existsfile = dir_existsfile;
method->getlasterror = dir_getlasterror;
dir_data = pg_malloc0(sizeof(DirectoryMethodData));
- dir_data->compression_method = compression_method;
+ dir_data->compression_algorithm = compression_algorithm;
dir_data->compression_level = compression_level;
dir_data->basedir = pg_strdup(basedir);
dir_data->sync = sync;
{
char *tarfilename;
int fd;
- WalCompressionMethod compression_method;
+ pg_compress_algorithm compression_algorithm;
int compression_level;
bool sync;
TarMethodFile *currentfile;
tar_clear_error();
/* Tarfile will always be positioned at the end */
- if (tar_data->compression_method == COMPRESSION_NONE)
+ if (tar_data->compression_algorithm == PG_COMPRESSION_NONE)
{
errno = 0;
r = write(tar_data->fd, buf, count);
return r;
}
#ifdef HAVE_LIBZ
- else if (tar_data->compression_method == COMPRESSION_GZIP)
+ else if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
if (!tar_write_compressed_data(unconstify(void *, buf), count, false))
return -1;
}
#ifdef HAVE_LIBZ
- if (tar_data->compression_method == COMPRESSION_GZIP)
+ if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
tar_data->zp = (z_streamp) pg_malloc(sizeof(z_stream));
tar_data->zp->zalloc = Z_NULL;
pg_free(tmppath);
#ifdef HAVE_LIBZ
- if (tar_data->compression_method == COMPRESSION_GZIP)
+ if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
/* Flush existing data */
if (!tar_write_compressed_data(NULL, 0, true))
}
tar_data->currentfile->currpos = 0;
- if (tar_data->compression_method == COMPRESSION_NONE)
+ if (tar_data->compression_algorithm == PG_COMPRESSION_NONE)
{
errno = 0;
if (write(tar_data->fd, tar_data->currentfile->header,
}
}
#ifdef HAVE_LIBZ
- else if (tar_data->compression_method == COMPRESSION_GZIP)
+ else if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
/* Write header through the zlib APIs but with no compression */
if (!tar_write_compressed_data(tar_data->currentfile->header,
if (pad_to_size)
{
tar_data->currentfile->pad_to_size = pad_to_size;
- if (tar_data->compression_method == COMPRESSION_NONE)
+ if (tar_data->compression_algorithm == PG_COMPRESSION_NONE)
{
/* Uncompressed, so pad now */
if (!tar_write_padding_data(tar_data->currentfile, pad_to_size))
return -1;
}
-static WalCompressionMethod
-tar_compression_method(void)
+static pg_compress_algorithm
+tar_compression_algorithm(void)
{
- return tar_data->compression_method;
+ return tar_data->compression_algorithm;
}
static off_t
* Always sync the whole tarfile, because that's all we can do. This makes
* no sense on compressed files, so just ignore those.
*/
- if (tar_data->compression_method != COMPRESSION_NONE)
+ if (tar_data->compression_algorithm != PG_COMPRESSION_NONE)
return 0;
r = fsync(tar_data->fd);
if (method == CLOSE_UNLINK)
{
- if (tar_data->compression_method != COMPRESSION_NONE)
+ if (tar_data->compression_algorithm != PG_COMPRESSION_NONE)
{
tar_set_error("unlink not supported with compression");
return -1;
*/
if (tf->pad_to_size)
{
- if (tar_data->compression_method == COMPRESSION_GZIP)
+ if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
/*
* A compressed tarfile is padded on close since we cannot know
#ifdef HAVE_LIBZ
- if (tar_data->compression_method == COMPRESSION_GZIP)
+ if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
/* Flush the current buffer */
if (!tar_write_compressed_data(NULL, 0, true))
tar_data->lasterrno = errno;
return -1;
}
- if (tar_data->compression_method == COMPRESSION_NONE)
+ if (tar_data->compression_algorithm == PG_COMPRESSION_NONE)
{
errno = 0;
if (write(tar_data->fd, tf->header, TAR_BLOCK_SIZE) != TAR_BLOCK_SIZE)
}
}
#ifdef HAVE_LIBZ
- else if (tar_data->compression_method == COMPRESSION_GZIP)
+ else if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
/* Turn off compression */
if (deflateParams(tar_data->zp, 0, 0) != Z_OK)
/* A tarfile always ends with two empty blocks */
MemSet(zerobuf, 0, sizeof(zerobuf));
- if (tar_data->compression_method == COMPRESSION_NONE)
+ if (tar_data->compression_algorithm == PG_COMPRESSION_NONE)
{
errno = 0;
if (write(tar_data->fd, zerobuf, sizeof(zerobuf)) != sizeof(zerobuf))
}
}
#ifdef HAVE_LIBZ
- else if (tar_data->compression_method == COMPRESSION_GZIP)
+ else if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP)
{
if (!tar_write_compressed_data(zerobuf, sizeof(zerobuf), false))
return false;
}
/*
- * The argument compression_method is currently ignored. It is in place for
+ * The argument compression_algorithm is currently ignored. It is in place for
* symmetry with CreateWalDirectoryMethod which uses it for distinguishing
* between the different compression methods. CreateWalTarMethod and its family
* of functions handle only zlib compression.
*/
WalWriteMethod *
CreateWalTarMethod(const char *tarbase,
- WalCompressionMethod compression_method,
+ pg_compress_algorithm compression_algorithm,
int compression_level, bool sync)
{
WalWriteMethod *method;
- const char *suffix = (compression_method == COMPRESSION_GZIP) ?
+ const char *suffix = (compression_algorithm == PG_COMPRESSION_GZIP) ?
".tar.gz" : ".tar";
method = pg_malloc0(sizeof(WalWriteMethod));
method->get_current_pos = tar_get_current_pos;
method->get_file_size = tar_get_file_size;
method->get_file_name = tar_get_file_name;
- method->compression_method = tar_compression_method;
+ method->compression_algorithm = tar_compression_algorithm;
method->close = tar_close;
method->sync = tar_sync;
method->existsfile = tar_existsfile;
tar_data->tarfilename = pg_malloc0(strlen(tarbase) + strlen(suffix) + 1);
sprintf(tar_data->tarfilename, "%s%s", tarbase, suffix);
tar_data->fd = -1;
- tar_data->compression_method = compression_method;
+ tar_data->compression_algorithm = compression_algorithm;
tar_data->compression_level = compression_level;
tar_data->sync = sync;
#ifdef HAVE_LIBZ
- if (compression_method == COMPRESSION_GZIP)
+ if (compression_algorithm == PG_COMPRESSION_GZIP)
tar_data->zlibOut = (char *) pg_malloc(ZLIB_OUT_SIZE + 1);
#endif
{
pg_free(tar_data->tarfilename);
#ifdef HAVE_LIBZ
- if (tar_data->compression_method == COMPRESSION_GZIP)
+ if (tar_data->compression_algorithm == PG_COMPRESSION_GZIP)
pg_free(tar_data->zlibOut);
#endif
pg_free(tar_data);