PostgreSQL Source Code  git master
walmethods.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  WalWriteMethod
 

Typedefs

typedef void * Walfile
 
typedef struct WalWriteMethod WalWriteMethod
 

Enumerations

enum  WalCloseMethod { CLOSE_NORMAL, CLOSE_UNLINK, CLOSE_NO_RENAME }
 

Functions

WalWriteMethodCreateWalDirectoryMethod (const char *basedir, int compression, bool sync)
 
WalWriteMethodCreateWalTarMethod (const char *tarbase, int compression, bool sync)
 
void FreeWalDirectoryMethod (void)
 
void FreeWalTarMethod (void)
 

Typedef Documentation

◆ Walfile

Definition at line 13 of file walmethods.h.

◆ WalWriteMethod

Definition at line 32 of file walmethods.h.

Enumeration Type Documentation

◆ WalCloseMethod

Enumerator
CLOSE_NORMAL 
CLOSE_UNLINK 
CLOSE_NO_RENAME 

Definition at line 15 of file walmethods.h.

Function Documentation

◆ CreateWalDirectoryMethod()

WalWriteMethod* CreateWalDirectoryMethod ( const char *  basedir,
int  compression,
bool  sync 
)

Definition at line 347 of file walmethods.c.

References DirectoryMethodData::basedir, WalWriteMethod::close, DirectoryMethodData::compression, dir_close(), dir_existsfile(), dir_finish(), dir_get_current_pos(), dir_get_file_size(), dir_getlasterror(), dir_open_for_write(), dir_sync(), dir_write(), WalWriteMethod::existsfile, WalWriteMethod::finish, WalWriteMethod::get_current_pos, WalWriteMethod::get_file_size, WalWriteMethod::getlasterror, WalWriteMethod::open_for_write, pg_malloc0(), pg_strdup(), DirectoryMethodData::sync, WalWriteMethod::sync, and WalWriteMethod::write.

Referenced by LogStreamerMain(), and StreamLog().

348 {
349  WalWriteMethod *method;
350 
351  method = pg_malloc0(sizeof(WalWriteMethod));
353  method->write = dir_write;
356  method->close = dir_close;
357  method->sync = dir_sync;
358  method->existsfile = dir_existsfile;
359  method->finish = dir_finish;
360  method->getlasterror = dir_getlasterror;
361 
363  dir_data->compression = compression;
365  dir_data->sync = sync;
366 
367  return method;
368 }
static off_t dir_get_current_pos(Walfile f)
Definition: walmethods.c:203
int(* close)(Walfile f, WalCloseMethod method)
Definition: walmethods.h:47
int(* sync)(Walfile f)
Definition: walmethods.h:67
static char * basedir
Definition: pg_basebackup.c:80
const char *(* getlasterror)(void)
Definition: walmethods.h:78
off_t(* get_current_pos)(Walfile f)
Definition: walmethods.h:62
static bool dir_finish(void)
Definition: walmethods.c:331
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
ssize_t(* write)(Walfile f, const void *buf, size_t count)
Definition: walmethods.h:59
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static ssize_t dir_write(Walfile f, const void *buf, size_t count)
Definition: walmethods.c:184
static DirectoryMethodData * dir_data
Definition: walmethods.c:48
static int dir_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:212
bool(* finish)(void)
Definition: walmethods.h:75
bool(* existsfile)(const char *pathname)
Definition: walmethods.h:50
Walfile(* open_for_write)(const char *pathname, const char *temp_suffix, size_t pad_to_size)
Definition: walmethods.h:41
static Walfile dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_size)
Definition: walmethods.c:73
ssize_t(* get_file_size)(const char *pathname)
Definition: walmethods.h:53
static const char * dir_getlasterror(void)
Definition: walmethods.c:66
static ssize_t dir_get_file_size(const char *pathname)
Definition: walmethods.c:300
static bool dir_existsfile(const char *pathname)
Definition: walmethods.c:315
static int dir_sync(Walfile f)
Definition: walmethods.c:281

◆ CreateWalTarMethod()

WalWriteMethod* CreateWalTarMethod ( const char *  tarbase,
int  compression,
bool  sync 
)

Definition at line 949 of file walmethods.c.

References WalWriteMethod::close, DirectoryMethodData::compression, TarMethodData::compression, WalWriteMethod::existsfile, TarMethodData::fd, WalWriteMethod::finish, WalWriteMethod::get_current_pos, WalWriteMethod::get_file_size, WalWriteMethod::getlasterror, WalWriteMethod::open_for_write, pg_malloc(), pg_malloc0(), DirectoryMethodData::sync, WalWriteMethod::sync, TarMethodData::sync, tar_close(), tar_existsfile(), tar_finish(), tar_get_current_pos(), tar_get_file_size(), tar_getlasterror(), tar_open_for_write(), tar_sync(), tar_write(), TarMethodData::tarfilename, WalWriteMethod::write, and ZLIB_OUT_SIZE.

Referenced by LogStreamerMain().

950 {
951  WalWriteMethod *method;
952  const char *suffix = (compression != 0) ? ".tar.gz" : ".tar";
953 
954  method = pg_malloc0(sizeof(WalWriteMethod));
956  method->write = tar_write;
959  method->close = tar_close;
960  method->sync = tar_sync;
961  method->existsfile = tar_existsfile;
962  method->finish = tar_finish;
963  method->getlasterror = tar_getlasterror;
964 
965  tar_data = pg_malloc0(sizeof(TarMethodData));
966  tar_data->tarfilename = pg_malloc0(strlen(tarbase) + strlen(suffix) + 1);
967  sprintf(tar_data->tarfilename, "%s%s", tarbase, suffix);
968  tar_data->fd = -1;
969  tar_data->compression = compression;
970  tar_data->sync = sync;
971 #ifdef HAVE_LIBZ
972  if (compression)
973  tar_data->zlibOut = (char *) pg_malloc(ZLIB_OUT_SIZE + 1);
974 #endif
975 
976  return method;
977 }
int(* close)(Walfile f, WalCloseMethod method)
Definition: walmethods.h:47
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
static bool tar_finish(void)
Definition: walmethods.c:870
int(* sync)(Walfile f)
Definition: walmethods.h:67
static ssize_t tar_write(Walfile f, const void *buf, size_t count)
Definition: walmethods.c:470
const char *(* getlasterror)(void)
Definition: walmethods.h:78
static int tar_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:709
off_t(* get_current_pos)(Walfile f)
Definition: walmethods.h:62
static const char * tar_getlasterror(void)
Definition: walmethods.c:411
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
static Walfile tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_size)
Definition: walmethods.c:525
ssize_t(* write)(Walfile f, const void *buf, size_t count)
Definition: walmethods.h:59
static ssize_t tar_get_file_size(const char *pathname)
Definition: walmethods.c:671
static bool tar_existsfile(const char *pathname)
Definition: walmethods.c:862
static off_t tar_get_current_pos(Walfile f)
Definition: walmethods.c:681
char * tarfilename
Definition: walmethods.c:394
#define ZLIB_OUT_SIZE
Definition: walmethods.c:32
bool(* finish)(void)
Definition: walmethods.h:75
bool(* existsfile)(const char *pathname)
Definition: walmethods.h:50
Walfile(* open_for_write)(const char *pathname, const char *temp_suffix, size_t pad_to_size)
Definition: walmethods.h:41
ssize_t(* get_file_size)(const char *pathname)
Definition: walmethods.h:53
static TarMethodData * tar_data
Definition: walmethods.c:405
static int tar_sync(Walfile f)
Definition: walmethods.c:690

◆ FreeWalDirectoryMethod()

void FreeWalDirectoryMethod ( void  )

Definition at line 371 of file walmethods.c.

References DirectoryMethodData::basedir, and pg_free().

Referenced by LogStreamerMain(), and StreamLog().

372 {
374  pg_free(dir_data);
375 }
static DirectoryMethodData * dir_data
Definition: walmethods.c:48
void pg_free(void *ptr)
Definition: fe_memutils.c:105

◆ FreeWalTarMethod()

void FreeWalTarMethod ( void  )

Definition at line 980 of file walmethods.c.

References TarMethodData::compression, pg_free(), and TarMethodData::tarfilename.

Referenced by LogStreamerMain().

981 {
983 #ifdef HAVE_LIBZ
984  if (tar_data->compression)
985  pg_free(tar_data->zlibOut);
986 #endif
987  pg_free(tar_data);
988 }
char * tarfilename
Definition: walmethods.c:394
void pg_free(void *ptr)
Definition: fe_memutils.c:105
static TarMethodData * tar_data
Definition: walmethods.c:405