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 }
 
enum  WalCompressionMethod { COMPRESSION_GZIP , COMPRESSION_LZ4 , COMPRESSION_NONE }
 

Functions

WalWriteMethodCreateWalDirectoryMethod (const char *basedir, WalCompressionMethod compression_method, int compression, bool sync)
 
WalWriteMethodCreateWalTarMethod (const char *tarbase, WalCompressionMethod compression_method, 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 13 of file walmethods.h.

Enumeration Type Documentation

◆ WalCloseMethod

Enumerator
CLOSE_NORMAL 
CLOSE_UNLINK 
CLOSE_NO_RENAME 

Definition at line 15 of file walmethods.h.

16 {
WalCloseMethod
Definition: walmethods.h:16
@ CLOSE_UNLINK
Definition: walmethods.h:18
@ CLOSE_NO_RENAME
Definition: walmethods.h:19
@ CLOSE_NORMAL
Definition: walmethods.h:17

◆ WalCompressionMethod

Enumerator
COMPRESSION_GZIP 
COMPRESSION_LZ4 
COMPRESSION_NONE 

Definition at line 23 of file walmethods.h.

24 {
WalCompressionMethod
Definition: walmethods.h:24
@ COMPRESSION_LZ4
Definition: walmethods.h:26
@ COMPRESSION_NONE
Definition: walmethods.h:27
@ COMPRESSION_GZIP
Definition: walmethods.h:25

Function Documentation

◆ CreateWalDirectoryMethod()

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

Definition at line 610 of file walmethods.c.

613 {
614  WalWriteMethod *method;
615 
616  method = pg_malloc0(sizeof(WalWriteMethod));
618  method->write = dir_write;
623  method->close = dir_close;
624  method->sync = dir_sync;
625  method->existsfile = dir_existsfile;
626  method->finish = dir_finish;
627  method->getlasterror = dir_getlasterror;
628 
631  dir_data->compression_level = compression_level;
633  dir_data->sync = sync;
634 
635  return method;
636 }
void * pg_malloc0(size_t size)
Definition: fe_memutils.c:53
char * pg_strdup(const char *in)
Definition: fe_memutils.c:85
static char * basedir
static WalCompressionMethod compression_method
Definition: pg_receivewal.c:55
WalCompressionMethod compression_method
Definition: walmethods.c:52
const char *(* getlasterror)(void)
Definition: walmethods.h:95
off_t(* get_current_pos)(Walfile f)
Definition: walmethods.h:79
ssize_t(* get_file_size)(const char *pathname)
Definition: walmethods.h:61
Walfile(* open_for_write)(const char *pathname, const char *temp_suffix, size_t pad_to_size)
Definition: walmethods.h:49
bool(* existsfile)(const char *pathname)
Definition: walmethods.h:58
int(* close)(Walfile f, WalCloseMethod method)
Definition: walmethods.h:55
char *(* get_file_name)(const char *pathname, const char *temp_suffix)
Definition: walmethods.h:67
int(* sync)(Walfile f)
Definition: walmethods.h:84
ssize_t(* write)(Walfile f, const void *buf, size_t count)
Definition: walmethods.h:76
WalCompressionMethod(* compression_method)(void)
Definition: walmethods.h:70
bool(* finish)(void)
Definition: walmethods.h:92
static bool dir_existsfile(const char *pathname)
Definition: walmethods.c:571
static Walfile dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_size)
Definition: walmethods.c:108
static const char * dir_getlasterror(void)
Definition: walmethods.c:86
static ssize_t dir_write(Walfile f, const void *buf, size_t count)
Definition: walmethods.c:288
static bool dir_finish(void)
Definition: walmethods.c:589
static char * dir_get_file_name(const char *pathname, const char *temp_suffix)
Definition: walmethods.c:94
static ssize_t dir_get_file_size(const char *pathname)
Definition: walmethods.c:547
static off_t dir_get_current_pos(Walfile f)
Definition: walmethods.c:369
static int dir_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:379
static WalCompressionMethod dir_compression_method(void)
Definition: walmethods.c:565
static int dir_sync(Walfile f)
Definition: walmethods.c:496
static DirectoryMethodData * dir_data
Definition: walmethods.c:58

References basedir, DirectoryMethodData::basedir, WalWriteMethod::close, DirectoryMethodData::compression_level, compression_method, DirectoryMethodData::compression_method, WalWriteMethod::compression_method, dir_close(), dir_compression_method(), dir_data, 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().

◆ CreateWalTarMethod()

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

Definition at line 1310 of file walmethods.c.

1313 {
1314  WalWriteMethod *method;
1315  const char *suffix = (compression_level != 0) ? ".tar.gz" : ".tar";
1316 
1317  method = pg_malloc0(sizeof(WalWriteMethod));
1319  method->write = tar_write;
1321  method->get_file_size = tar_get_file_size;
1322  method->get_file_name = tar_get_file_name;
1324  method->close = tar_close;
1325  method->sync = tar_sync;
1326  method->existsfile = tar_existsfile;
1327  method->finish = tar_finish;
1328  method->getlasterror = tar_getlasterror;
1329 
1330  tar_data = pg_malloc0(sizeof(TarMethodData));
1331  tar_data->tarfilename = pg_malloc0(strlen(tarbase) + strlen(suffix) + 1);
1332  sprintf(tar_data->tarfilename, "%s%s", tarbase, suffix);
1333  tar_data->fd = -1;
1335  tar_data->compression_level = compression_level;
1336  tar_data->sync = sync;
1337 #ifdef HAVE_LIBZ
1338  if (compression_level)
1339  tar_data->zlibOut = (char *) pg_malloc(ZLIB_OUT_SIZE + 1);
1340 #endif
1341 
1342  return method;
1343 }
void * pg_malloc(size_t size)
Definition: fe_memutils.c:47
#define sprintf
Definition: port.h:224
int compression_level
Definition: walmethods.c:666
char * tarfilename
Definition: walmethods.c:663
WalCompressionMethod compression_method
Definition: walmethods.c:665
static bool tar_finish(void)
Definition: walmethods.c:1201
static int tar_sync(Walfile f)
Definition: walmethods.c:998
static WalCompressionMethod tar_compression_method(void)
Definition: walmethods.c:983
static Walfile tar_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_size)
Definition: walmethods.c:815
static const char * tar_getlasterror(void)
Definition: walmethods.c:684
static off_t tar_get_current_pos(Walfile f)
Definition: walmethods.c:989
#define ZLIB_OUT_SIZE
Definition: walmethods.c:36
static int tar_close(Walfile f, WalCloseMethod method)
Definition: walmethods.c:1022
static TarMethodData * tar_data
Definition: walmethods.c:676
static ssize_t tar_get_file_size(const char *pathname)
Definition: walmethods.c:973
static char * tar_get_file_name(const char *pathname, const char *temp_suffix)
Definition: walmethods.c:804
static ssize_t tar_write(Walfile f, const void *buf, size_t count)
Definition: walmethods.c:744
static bool tar_existsfile(const char *pathname)
Definition: walmethods.c:1193

References WalWriteMethod::close, TarMethodData::compression_level, compression_method, TarMethodData::compression_method, WalWriteMethod::compression_method, 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, TarMethodData::sync, WalWriteMethod::sync, tar_close(), tar_compression_method(), tar_data, 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().

◆ FreeWalDirectoryMethod()

void FreeWalDirectoryMethod ( void  )

Definition at line 639 of file walmethods.c.

640 {
642  pg_free(dir_data);
643  dir_data = NULL;
644 }
void pg_free(void *ptr)
Definition: fe_memutils.c:105

References DirectoryMethodData::basedir, dir_data, and pg_free().

Referenced by LogStreamerMain(), and StreamLog().

◆ FreeWalTarMethod()

void FreeWalTarMethod ( void  )

Definition at line 1346 of file walmethods.c.

1347 {
1349 #ifdef HAVE_LIBZ
1351  pg_free(tar_data->zlibOut);
1352 #endif
1353  pg_free(tar_data);
1354  tar_data = NULL;
1355 }

References TarMethodData::compression_level, pg_free(), tar_data, and TarMethodData::tarfilename.

Referenced by LogStreamerMain().