PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
astreamer_lz4.c File Reference
#include "postgres_fe.h"
#include <unistd.h>
#include "common/logging.h"
#include "fe_utils/astreamer.h"
Include dependency graph for astreamer_lz4.c:

Go to the source code of this file.

Functions

astreamerastreamer_lz4_compressor_new (astreamer *next, pg_compress_specification *compress)
 
astreamerastreamer_lz4_decompressor_new (astreamer *next)
 

Function Documentation

◆ astreamer_lz4_compressor_new()

astreamer * astreamer_lz4_compressor_new ( astreamer next,
pg_compress_specification compress 
)

Definition at line 72 of file astreamer_lz4.c.

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

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

Referenced by CreateBackupStreamer().

◆ astreamer_lz4_decompressor_new()

astreamer * astreamer_lz4_decompressor_new ( astreamer next)

Definition at line 277 of file astreamer_lz4.c.

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

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

Referenced by create_archive_verifier(), and CreateBackupStreamer().