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 346 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().

347 {
348  WalWriteMethod *method;
349 
350  method = pg_malloc0(sizeof(WalWriteMethod));
352  method->write = dir_write;
355  method->close = dir_close;
356  method->sync = dir_sync;
357  method->existsfile = dir_existsfile;
358  method->finish = dir_finish;
359  method->getlasterror = dir_getlasterror;
360 
362  dir_data->compression = compression;
364  dir_data->sync = sync;
365 
366  return method;
367 }
static off_t dir_get_current_pos(Walfile f)
Definition: walmethods.c:202
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:78
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:330
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:183
static DirectoryMethodData * dir_data
Definition: walmethods.c:47
static int dir_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:211
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:72
ssize_t(* get_file_size)(const char *pathname)
Definition: walmethods.h:53
static const char * dir_getlasterror(void)
Definition: walmethods.c:65
static ssize_t dir_get_file_size(const char *pathname)
Definition: walmethods.c:299
static bool dir_existsfile(const char *pathname)
Definition: walmethods.c:314
static int dir_sync(Walfile f)
Definition: walmethods.c:280

◆ CreateWalTarMethod()

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

Definition at line 947 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().

948 {
949  WalWriteMethod *method;
950  const char *suffix = (compression != 0) ? ".tar.gz" : ".tar";
951 
952  method = pg_malloc0(sizeof(WalWriteMethod));
954  method->write = tar_write;
957  method->close = tar_close;
958  method->sync = tar_sync;
959  method->existsfile = tar_existsfile;
960  method->finish = tar_finish;
961  method->getlasterror = tar_getlasterror;
962 
963  tar_data = pg_malloc0(sizeof(TarMethodData));
964  tar_data->tarfilename = pg_malloc0(strlen(tarbase) + strlen(suffix) + 1);
965  sprintf(tar_data->tarfilename, "%s%s", tarbase, suffix);
966  tar_data->fd = -1;
967  tar_data->compression = compression;
968  tar_data->sync = sync;
969 #ifdef HAVE_LIBZ
970  if (compression)
971  tar_data->zlibOut = (char *) pg_malloc(ZLIB_OUT_SIZE + 1);
972 #endif
973 
974  return method;
975 }
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:868
int(* sync)(Walfile f)
Definition: walmethods.h:67
static ssize_t tar_write(Walfile f, const void *buf, size_t count)
Definition: walmethods.c:469
const char *(* getlasterror)(void)
Definition: walmethods.h:78
static int tar_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:707
off_t(* get_current_pos)(Walfile f)
Definition: walmethods.h:62
static const char * tar_getlasterror(void)
Definition: walmethods.c:410
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:524
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:669
static bool tar_existsfile(const char *pathname)
Definition: walmethods.c:860
static off_t tar_get_current_pos(Walfile f)
Definition: walmethods.c:679
char * tarfilename
Definition: walmethods.c:393
#define ZLIB_OUT_SIZE
Definition: walmethods.c:31
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:404
static int tar_sync(Walfile f)
Definition: walmethods.c:688

◆ FreeWalDirectoryMethod()

void FreeWalDirectoryMethod ( void  )

Definition at line 370 of file walmethods.c.

References DirectoryMethodData::basedir, and pg_free().

Referenced by LogStreamerMain(), and StreamLog().

371 {
373  pg_free(dir_data);
374 }
static DirectoryMethodData * dir_data
Definition: walmethods.c:47
void pg_free(void *ptr)
Definition: fe_memutils.c:105

◆ FreeWalTarMethod()

void FreeWalTarMethod ( void  )

Definition at line 978 of file walmethods.c.

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

Referenced by LogStreamerMain().

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