PostgreSQL Source Code  git master
bbstreamer_lz4.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include "bbstreamer.h"
#include "common/logging.h"
#include "common/file_perm.h"
#include "common/string.h"
Include dependency graph for bbstreamer_lz4.c:

Go to the source code of this file.

Functions

bbstreamerbbstreamer_lz4_compressor_new (bbstreamer *next, pg_compress_specification *compress)
 
bbstreamerbbstreamer_lz4_decompressor_new (bbstreamer *next)
 

Function Documentation

◆ bbstreamer_lz4_compressor_new()

bbstreamer* bbstreamer_lz4_compressor_new ( bbstreamer next,
pg_compress_specification compress 
)

Definition at line 70 of file bbstreamer_lz4.c.

71 {
72 #ifdef USE_LZ4
73  bbstreamer_lz4_frame *streamer;
74  LZ4F_errorCode_t ctxError;
75  LZ4F_preferences_t *prefs;
76 
77  Assert(next != NULL);
78 
79  streamer = palloc0(sizeof(bbstreamer_lz4_frame));
80  *((const bbstreamer_ops **) &streamer->base.bbs_ops) =
81  &bbstreamer_lz4_compressor_ops;
82 
83  streamer->base.bbs_next = next;
84  initStringInfo(&streamer->base.bbs_buffer);
85  streamer->header_written = false;
86 
87  /* Initialize stream compression preferences */
88  prefs = &streamer->prefs;
89  memset(prefs, 0, sizeof(LZ4F_preferences_t));
90  prefs->frameInfo.blockSizeID = LZ4F_max256KB;
91  if ((compress->options & PG_COMPRESSION_OPTION_LEVEL) != 0)
92  prefs->compressionLevel = compress->level;
93 
94  ctxError = LZ4F_createCompressionContext(&streamer->cctx, LZ4F_VERSION);
95  if (LZ4F_isError(ctxError))
96  pg_log_error("could not create lz4 compression context: %s",
97  LZ4F_getErrorName(ctxError));
98 
99  return &streamer->base;
100 #else
101  pg_fatal("this build does not support lz4 compression");
102  return NULL; /* keep compiler quiet */
103 #endif
104 }
static int32 next
Definition: blutils.c:219
#define PG_COMPRESSION_OPTION_LEVEL
Definition: compression.h:25
Assert(fmt[strlen(fmt) - 1] !='\n')
#define pg_log_error(...)
Definition: logging.h:106
void * palloc0(Size size)
Definition: mcxt.c:1099
#define pg_fatal(...)
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59

References Assert(), initStringInfo(), pg_compress_specification::level, next, pg_compress_specification::options, palloc0(), PG_COMPRESSION_OPTION_LEVEL, pg_fatal, and pg_log_error.

Referenced by CreateBackupStreamer().

◆ bbstreamer_lz4_decompressor_new()

bbstreamer* bbstreamer_lz4_decompressor_new ( bbstreamer next)

Definition at line 276 of file bbstreamer_lz4.c.

277 {
278 #ifdef USE_LZ4
279  bbstreamer_lz4_frame *streamer;
280  LZ4F_errorCode_t ctxError;
281 
282  Assert(next != NULL);
283 
284  streamer = palloc0(sizeof(bbstreamer_lz4_frame));
285  *((const bbstreamer_ops **) &streamer->base.bbs_ops) =
286  &bbstreamer_lz4_decompressor_ops;
287 
288  streamer->base.bbs_next = next;
289  initStringInfo(&streamer->base.bbs_buffer);
290 
291  /* Initialize internal stream state for decompression */
292  ctxError = LZ4F_createDecompressionContext(&streamer->dctx, LZ4F_VERSION);
293  if (LZ4F_isError(ctxError))
294  pg_fatal("could not initialize compression library: %s",
295  LZ4F_getErrorName(ctxError));
296 
297  return &streamer->base;
298 #else
299  pg_fatal("this build does not support lz4 compression");
300  return NULL; /* keep compiler quiet */
301 #endif
302 }

References Assert(), initStringInfo(), next, palloc0(), and pg_fatal.

Referenced by CreateBackupStreamer().