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

typedef void* 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 376 of file walmethods.c.

References DirectoryMethodData::basedir, WalWriteMethod::close, DirectoryMethodData::compression, WalWriteMethod::compression, dir_close(), dir_compression(), dir_existsfile(), dir_finish(), dir_get_current_pos(), dir_get_file_name(), 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_name, 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().

377 {
378  WalWriteMethod *method;
379 
380  method = pg_malloc0(sizeof(WalWriteMethod));
382  method->write = dir_write;
386  method->compression = dir_compression;
387  method->close = dir_close;
388  method->sync = dir_sync;
389  method->existsfile = dir_existsfile;
390  method->finish = dir_finish;
391  method->getlasterror = dir_getlasterror;
392 
394  dir_data->compression = compression;
396  dir_data->sync = sync;
397 
398  return method;
399 }
char *(* get_file_name)(const char *pathname, const char *temp_suffix)
Definition: walmethods.h:59
static off_t dir_get_current_pos(Walfile f)
Definition: walmethods.c:218
int(* close)(Walfile f, WalCloseMethod method)
Definition: walmethods.h:47
int(* sync)(Walfile f)
Definition: walmethods.h:76
static char * basedir
const char *(* getlasterror)(void)
Definition: walmethods.h:87
static char * dir_get_file_name(const char *pathname, const char *temp_suffix)
Definition: walmethods.c:72
off_t(* get_current_pos)(Walfile f)
Definition: walmethods.h:71
static bool dir_finish(void)
Definition: walmethods.c:360
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:68
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:199
static DirectoryMethodData * dir_data
Definition: walmethods.c:47
static int dir_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:227
bool(* finish)(void)
Definition: walmethods.h:84
bool(* existsfile)(const char *pathname)
Definition: walmethods.h:50
static int dir_compression(void)
Definition: walmethods.c:338
int(* compression)(void)
Definition: walmethods.h:62
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:84
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:323
static bool dir_existsfile(const char *pathname)
Definition: walmethods.c:344
static int dir_sync(Walfile f)
Definition: walmethods.c:304

◆ CreateWalTarMethod()

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

Definition at line 1035 of file walmethods.c.

References WalWriteMethod::close, DirectoryMethodData::compression, WalWriteMethod::compression, TarMethodData::compression, WalWriteMethod::existsfile, TarMethodData::fd, WalWriteMethod::finish, WalWriteMethod::get_current_pos, WalWriteMethod::get_file_name, WalWriteMethod::get_file_size, WalWriteMethod::getlasterror, WalWriteMethod::open_for_write, pg_malloc(), pg_malloc0(), sprintf, DirectoryMethodData::sync, WalWriteMethod::sync, TarMethodData::sync, tar_close(), tar_compression(), tar_existsfile(), tar_finish(), tar_get_current_pos(), tar_get_file_name(), 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().

1036 {
1037  WalWriteMethod *method;
1038  const char *suffix = (compression != 0) ? ".tar.gz" : ".tar";
1039 
1040  method = pg_malloc0(sizeof(WalWriteMethod));
1042  method->write = tar_write;
1044  method->get_file_size = tar_get_file_size;
1045  method->get_file_name = tar_get_file_name;
1046  method->compression = tar_compression;
1047  method->close = tar_close;
1048  method->sync = tar_sync;
1049  method->existsfile = tar_existsfile;
1050  method->finish = tar_finish;
1051  method->getlasterror = tar_getlasterror;
1052 
1053  tar_data = pg_malloc0(sizeof(TarMethodData));
1054  tar_data->tarfilename = pg_malloc0(strlen(tarbase) + strlen(suffix) + 1);
1055  sprintf(tar_data->tarfilename, "%s%s", tarbase, suffix);
1056  tar_data->fd = -1;
1057  tar_data->compression = compression;
1058  tar_data->sync = sync;
1059 #ifdef HAVE_LIBZ
1060  if (compression)
1061  tar_data->zlibOut = (char *) pg_malloc(ZLIB_OUT_SIZE + 1);
1062 #endif
1063 
1064  return method;
1065 }
char *(* get_file_name)(const char *pathname, const char *temp_suffix)
Definition: walmethods.h:59
static char * tar_get_file_name(const char *pathname, const char *temp_suffix)
Definition: walmethods.c:560
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:938
int(* sync)(Walfile f)
Definition: walmethods.h:76
static ssize_t tar_write(Walfile f, const void *buf, size_t count)
Definition: walmethods.c:509
const char *(* getlasterror)(void)
Definition: walmethods.h:87
static int tar_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:769
off_t(* get_current_pos)(Walfile f)
Definition: walmethods.h:71
#define sprintf
Definition: port.h:218
static const char * tar_getlasterror(void)
Definition: walmethods.c:442
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:571
ssize_t(* write)(Walfile f, const void *buf, size_t count)
Definition: walmethods.h:68
static ssize_t tar_get_file_size(const char *pathname)
Definition: walmethods.c:725
static bool tar_existsfile(const char *pathname)
Definition: walmethods.c:930
static off_t tar_get_current_pos(Walfile f)
Definition: walmethods.c:741
char * tarfilename
Definition: walmethods.c:425
static int tar_compression(void)
Definition: walmethods.c:735
#define ZLIB_OUT_SIZE
Definition: walmethods.c:31
bool(* finish)(void)
Definition: walmethods.h:84
bool(* existsfile)(const char *pathname)
Definition: walmethods.h:50
int(* compression)(void)
Definition: walmethods.h:62
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:436
static int tar_sync(Walfile f)
Definition: walmethods.c:750

◆ FreeWalDirectoryMethod()

void FreeWalDirectoryMethod ( void  )

Definition at line 402 of file walmethods.c.

References DirectoryMethodData::basedir, and pg_free().

Referenced by LogStreamerMain(), and StreamLog().

403 {
405  pg_free(dir_data);
406 }
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 1068 of file walmethods.c.

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

Referenced by LogStreamerMain().

1069 {
1071 #ifdef HAVE_LIBZ
1072  if (tar_data->compression)
1073  pg_free(tar_data->zlibOut);
1074 #endif
1075  pg_free(tar_data);
1076 }
char * tarfilename
Definition: walmethods.c:425
void pg_free(void *ptr)
Definition: fe_memutils.c:105
static TarMethodData * tar_data
Definition: walmethods.c:436