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

350 {
351  WalWriteMethod *method;
352 
353  method = pg_malloc0(sizeof(WalWriteMethod));
355  method->write = dir_write;
358  method->close = dir_close;
359  method->sync = dir_sync;
360  method->existsfile = dir_existsfile;
361  method->finish = dir_finish;
362  method->getlasterror = dir_getlasterror;
363 
365  dir_data->compression = compression;
367  dir_data->sync = sync;
368 
369  return method;
370 }
static off_t dir_get_current_pos(Walfile f)
Definition: walmethods.c:205
int(* close)(Walfile f, WalCloseMethod method)
Definition: walmethods.h:47
int(* sync)(Walfile f)
Definition: walmethods.h:67
static char * basedir
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:333
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:186
static DirectoryMethodData * dir_data
Definition: walmethods.c:47
static int dir_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:214
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:302
static bool dir_existsfile(const char *pathname)
Definition: walmethods.c:317
static int dir_sync(Walfile f)
Definition: walmethods.c:283

◆ CreateWalTarMethod()

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

Definition at line 987 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(), sprintf, 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().

988 {
989  WalWriteMethod *method;
990  const char *suffix = (compression != 0) ? ".tar.gz" : ".tar";
991 
992  method = pg_malloc0(sizeof(WalWriteMethod));
994  method->write = tar_write;
997  method->close = tar_close;
998  method->sync = tar_sync;
999  method->existsfile = tar_existsfile;
1000  method->finish = tar_finish;
1001  method->getlasterror = tar_getlasterror;
1002 
1003  tar_data = pg_malloc0(sizeof(TarMethodData));
1004  tar_data->tarfilename = pg_malloc0(strlen(tarbase) + strlen(suffix) + 1);
1005  sprintf(tar_data->tarfilename, "%s%s", tarbase, suffix);
1006  tar_data->fd = -1;
1007  tar_data->compression = compression;
1008  tar_data->sync = sync;
1009 #ifdef HAVE_LIBZ
1010  if (compression)
1011  tar_data->zlibOut = (char *) pg_malloc(ZLIB_OUT_SIZE + 1);
1012 #endif
1013 
1014  return method;
1015 }
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:890
int(* sync)(Walfile f)
Definition: walmethods.h:67
static ssize_t tar_write(Walfile f, const void *buf, size_t count)
Definition: walmethods.c:480
const char *(* getlasterror)(void)
Definition: walmethods.h:78
static int tar_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:721
off_t(* get_current_pos)(Walfile f)
Definition: walmethods.h:62
#define sprintf
Definition: port.h:195
static const char * tar_getlasterror(void)
Definition: walmethods.c:413
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:531
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:683
static bool tar_existsfile(const char *pathname)
Definition: walmethods.c:882
static off_t tar_get_current_pos(Walfile f)
Definition: walmethods.c:693
char * tarfilename
Definition: walmethods.c:396
#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:407
static int tar_sync(Walfile f)
Definition: walmethods.c:702

◆ FreeWalDirectoryMethod()

void FreeWalDirectoryMethod ( void  )

Definition at line 373 of file walmethods.c.

References DirectoryMethodData::basedir, and pg_free().

Referenced by LogStreamerMain(), and StreamLog().

374 {
376  pg_free(dir_data);
377 }
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 1018 of file walmethods.c.

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

Referenced by LogStreamerMain().

1019 {
1021 #ifdef HAVE_LIBZ
1022  if (tar_data->compression)
1023  pg_free(tar_data->zlibOut);
1024 #endif
1025  pg_free(tar_data);
1026 }
char * tarfilename
Definition: walmethods.c:396
void pg_free(void *ptr)
Definition: fe_memutils.c:105
static TarMethodData * tar_data
Definition: walmethods.c:407