PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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

Definition at line 13 of file walmethods.h.

Definition at line 22 of file walmethods.h.

Enumeration Type Documentation

Enumerator
CLOSE_NORMAL 
CLOSE_UNLINK 
CLOSE_NO_RENAME 

Definition at line 15 of file walmethods.h.

Function Documentation

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(), WalWriteMethod::sync, DirectoryMethodData::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
char *(* getlasterror)(void)
Definition: walmethods.h:34
bool(* existsfile)(const char *pathname)
Definition: walmethods.h:27
static char * basedir
Definition: pg_basebackup.c:79
bool(* finish)(void)
Definition: walmethods.h:33
ssize_t(* get_file_size)(const char *pathname)
Definition: walmethods.h:28
static bool dir_finish(void)
Definition: walmethods.c:330
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
off_t(* get_current_pos)(Walfile f)
Definition: walmethods.h:31
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 char * dir_getlasterror(void)
Definition: walmethods.c:65
int(* sync)(Walfile f)
Definition: walmethods.h:32
static DirectoryMethodData * dir_data
Definition: walmethods.c:47
static int dir_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:211
ssize_t(* write)(Walfile f, const void *buf, size_t count)
Definition: walmethods.h:30
Walfile(* open_for_write)(const char *pathname, const char *temp_suffix, size_t pad_to_size)
Definition: walmethods.h:25
static Walfile dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_size)
Definition: walmethods.c:72
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
int(* close)(Walfile f, WalCloseMethod method)
Definition: walmethods.h:26
WalWriteMethod* CreateWalTarMethod ( const char *  tarbase,
int  compression,
bool  sync 
)

Definition at line 947 of file walmethods.c.

References WalWriteMethod::close, 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(), 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 }
char *(* getlasterror)(void)
Definition: walmethods.h:34
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
bool(* existsfile)(const char *pathname)
Definition: walmethods.h:27
static bool tar_finish(void)
Definition: walmethods.c:868
static ssize_t tar_write(Walfile f, const void *buf, size_t count)
Definition: walmethods.c:469
bool(* finish)(void)
Definition: walmethods.h:33
ssize_t(* get_file_size)(const char *pathname)
Definition: walmethods.h:28
static int tar_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:707
static 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
off_t(* get_current_pos)(Walfile f)
Definition: walmethods.h:31
static ssize_t tar_get_file_size(const char *pathname)
Definition: walmethods.c:669
int(* sync)(Walfile f)
Definition: walmethods.h:32
static bool tar_existsfile(const char *pathname)
Definition: walmethods.c:860
ssize_t(* write)(Walfile f, const void *buf, size_t count)
Definition: walmethods.h:30
static off_t tar_get_current_pos(Walfile f)
Definition: walmethods.c:679
char * tarfilename
Definition: walmethods.c:393
Walfile(* open_for_write)(const char *pathname, const char *temp_suffix, size_t pad_to_size)
Definition: walmethods.h:25
#define ZLIB_OUT_SIZE
Definition: walmethods.c:31
static TarMethodData * tar_data
Definition: walmethods.c:404
static int tar_sync(Walfile f)
Definition: walmethods.c:688
int(* close)(Walfile f, WalCloseMethod method)
Definition: walmethods.h:26
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
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