PostgreSQL Source Code  git master
bbstreamer.h File Reference
#include "common/compression.h"
#include "lib/stringinfo.h"
#include "pqexpbuffer.h"
Include dependency graph for bbstreamer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  bbstreamer_member
 
struct  bbstreamer
 
struct  bbstreamer_ops
 

Typedefs

typedef struct bbstreamer bbstreamer
 
typedef struct bbstreamer_ops bbstreamer_ops
 

Enumerations

enum  bbstreamer_archive_context {
  BBSTREAMER_UNKNOWN , BBSTREAMER_MEMBER_HEADER , BBSTREAMER_MEMBER_CONTENTS , BBSTREAMER_MEMBER_TRAILER ,
  BBSTREAMER_ARCHIVE_TRAILER
}
 

Functions

static void bbstreamer_content (bbstreamer *streamer, bbstreamer_member *member, const char *data, int len, bbstreamer_archive_context context)
 
static void bbstreamer_finalize (bbstreamer *streamer)
 
static void bbstreamer_free (bbstreamer *streamer)
 
static void bbstreamer_buffer_bytes (bbstreamer *streamer, const char **data, int *len, int nbytes)
 
static bool bbstreamer_buffer_until (bbstreamer *streamer, const char **data, int *len, int target_bytes)
 
bbstreamerbbstreamer_plain_writer_new (char *pathname, FILE *file)
 
bbstreamerbbstreamer_gzip_writer_new (char *pathname, FILE *file, pg_compress_specification *compress)
 
bbstreamerbbstreamer_extractor_new (const char *basepath, const char *(*link_map)(const char *), void(*report_output_file)(const char *))
 
bbstreamerbbstreamer_gzip_decompressor_new (bbstreamer *next)
 
bbstreamerbbstreamer_lz4_compressor_new (bbstreamer *next, pg_compress_specification *compress)
 
bbstreamerbbstreamer_lz4_decompressor_new (bbstreamer *next)
 
bbstreamerbbstreamer_zstd_compressor_new (bbstreamer *next, pg_compress_specification *compress)
 
bbstreamerbbstreamer_zstd_decompressor_new (bbstreamer *next)
 
bbstreamerbbstreamer_tar_parser_new (bbstreamer *next)
 
bbstreamerbbstreamer_tar_terminator_new (bbstreamer *next)
 
bbstreamerbbstreamer_tar_archiver_new (bbstreamer *next)
 
bbstreamerbbstreamer_recovery_injector_new (bbstreamer *next, bool is_recovery_guc_supported, PQExpBuffer recoveryconfcontents)
 
void bbstreamer_inject_file (bbstreamer *streamer, char *pathname, char *data, int len)
 

Typedef Documentation

◆ bbstreamer

typedef struct bbstreamer bbstreamer

Definition at line 1 of file bbstreamer.h.

◆ bbstreamer_ops

Definition at line 1 of file bbstreamer.h.

Enumeration Type Documentation

◆ bbstreamer_archive_context

Enumerator
BBSTREAMER_UNKNOWN 
BBSTREAMER_MEMBER_HEADER 
BBSTREAMER_MEMBER_CONTENTS 
BBSTREAMER_MEMBER_TRAILER 
BBSTREAMER_ARCHIVE_TRAILER 

Definition at line 53 of file bbstreamer.h.

54 {
bbstreamer_archive_context
Definition: bbstreamer.h:54
@ BBSTREAMER_ARCHIVE_TRAILER
Definition: bbstreamer.h:59
@ BBSTREAMER_MEMBER_HEADER
Definition: bbstreamer.h:56
@ BBSTREAMER_MEMBER_TRAILER
Definition: bbstreamer.h:58
@ BBSTREAMER_UNKNOWN
Definition: bbstreamer.h:55
@ BBSTREAMER_MEMBER_CONTENTS
Definition: bbstreamer.h:57

Function Documentation

◆ bbstreamer_buffer_bytes()

static void bbstreamer_buffer_bytes ( bbstreamer streamer,
const char **  data,
int *  len,
int  nbytes 
)
inlinestatic

Definition at line 157 of file bbstreamer.h.

159 {
160  Assert(nbytes <= *len);
161 
162  appendBinaryStringInfo(&streamer->bbs_buffer, *data, nbytes);
163  *len -= nbytes;
164  *data += nbytes;
165 }
Assert(fmt[strlen(fmt) - 1] !='\n')
const void size_t len
const void * data
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
Definition: stringinfo.c:227
StringInfoData bbs_buffer
Definition: bbstreamer.h:102

References appendBinaryStringInfo(), Assert(), bbstreamer::bbs_buffer, data, and len.

Referenced by bbstreamer_buffer_until(), and bbstreamer_tar_parser_content().

◆ bbstreamer_buffer_until()

static bool bbstreamer_buffer_until ( bbstreamer streamer,
const char **  data,
int *  len,
int  target_bytes 
)
inlinestatic

Definition at line 175 of file bbstreamer.h.

177 {
178  int buflen = streamer->bbs_buffer.len;
179 
180  if (buflen >= target_bytes)
181  {
182  /* Target length already reached; nothing to do. */
183  return true;
184  }
185 
186  if (buflen + *len < target_bytes)
187  {
188  /* Not enough data to reach target length; buffer all of it. */
189  bbstreamer_buffer_bytes(streamer, data, len, *len);
190  return false;
191  }
192 
193  /* Buffer just enough to reach the target length. */
194  bbstreamer_buffer_bytes(streamer, data, len, target_bytes - buflen);
195  return true;
196 }
static void bbstreamer_buffer_bytes(bbstreamer *streamer, const char **data, int *len, int nbytes)
Definition: bbstreamer.h:157

References bbstreamer::bbs_buffer, bbstreamer_buffer_bytes(), data, StringInfoData::len, and len.

Referenced by bbstreamer_tar_parser_content().

◆ bbstreamer_content()

static void bbstreamer_content ( bbstreamer streamer,
bbstreamer_member member,
const char *  data,
int  len,
bbstreamer_archive_context  context 
)
inlinestatic

Definition at line 126 of file bbstreamer.h.

129 {
130  Assert(streamer != NULL);
131  streamer->bbs_ops->content(streamer, member, data, len, context);
132 }
void(* content)(bbstreamer *streamer, bbstreamer_member *member, const char *data, int len, bbstreamer_archive_context context)
Definition: bbstreamer.h:117
const bbstreamer_ops * bbs_ops
Definition: bbstreamer.h:100

References Assert(), bbstreamer::bbs_ops, bbstreamer_ops::content, data, and len.

Referenced by bbstreamer_inject_file(), bbstreamer_recovery_injector_content(), bbstreamer_tar_archiver_content(), bbstreamer_tar_header(), bbstreamer_tar_parser_content(), bbstreamer_tar_parser_finalize(), bbstreamer_tar_terminator_content(), bbstreamer_tar_terminator_finalize(), ReceiveArchiveStreamChunk(), and ReceiveTarCopyChunk().

◆ bbstreamer_extractor_new()

bbstreamer* bbstreamer_extractor_new ( const char *  basepath,
const char *(*)(const char *)  link_map,
void(*)(const char *)  report_output_file 
)

Definition at line 183 of file bbstreamer_file.c.

186 {
187  bbstreamer_extractor *streamer;
188 
189  streamer = palloc0(sizeof(bbstreamer_extractor));
190  *((const bbstreamer_ops **) &streamer->base.bbs_ops) =
192  streamer->basepath = pstrdup(basepath);
193  streamer->link_map = link_map;
194  streamer->report_output_file = report_output_file;
195 
196  return &streamer->base;
197 }
const bbstreamer_ops bbstreamer_extractor_ops
char * pstrdup(const char *in)
Definition: mcxt.c:1305
void * palloc0(Size size)
Definition: mcxt.c:1099
const char *(* link_map)(const char *)
void(* report_output_file)(const char *)

References bbstreamer_extractor::base, bbstreamer_extractor::basepath, bbstreamer::bbs_ops, bbstreamer_extractor_ops, bbstreamer_extractor::link_map, palloc0(), pstrdup(), and bbstreamer_extractor::report_output_file.

Referenced by CreateBackupStreamer().

◆ bbstreamer_finalize()

static void bbstreamer_finalize ( bbstreamer streamer)
inlinestatic

◆ bbstreamer_free()

static void bbstreamer_free ( bbstreamer streamer)
inlinestatic

◆ bbstreamer_gzip_decompressor_new()

bbstreamer* bbstreamer_gzip_decompressor_new ( bbstreamer next)

Definition at line 214 of file bbstreamer_gzip.c.

215 {
216 #ifdef HAVE_LIBZ
217  bbstreamer_gzip_decompressor *streamer;
218  z_stream *zs;
219 
220  Assert(next != NULL);
221 
222  streamer = palloc0(sizeof(bbstreamer_gzip_decompressor));
223  *((const bbstreamer_ops **) &streamer->base.bbs_ops) =
224  &bbstreamer_gzip_decompressor_ops;
225 
226  streamer->base.bbs_next = next;
227  initStringInfo(&streamer->base.bbs_buffer);
228 
229  /* Initialize internal stream state for decompression */
230  zs = &streamer->zstream;
231  zs->zalloc = gzip_palloc;
232  zs->zfree = gzip_pfree;
233  zs->next_out = (uint8 *) streamer->base.bbs_buffer.data;
234  zs->avail_out = streamer->base.bbs_buffer.maxlen;
235 
236  /*
237  * Data compression was initialized using deflateInit2 to request a gzip
238  * header. Similarly, we are using inflateInit2 to initialize data
239  * decompression.
240  *
241  * Per the documentation for inflateInit2, the second argument is
242  * "windowBits" and its value must be greater than or equal to the value
243  * provided while compressing the data, so we are using the maximum
244  * possible value for safety.
245  */
246  if (inflateInit2(zs, 15 + 16) != Z_OK)
247  pg_fatal("could not initialize compression library");
248 
249  return &streamer->base;
250 #else
251  pg_fatal("this build does not support gzip compression");
252  return NULL; /* keep compiler quiet */
253 #endif
254 }
static int32 next
Definition: blutils.c:219
unsigned char uint8
Definition: c.h:439
#define pg_fatal(...)
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59

References Assert(), _z_stream::avail_out, if(), initStringInfo(), next, _z_stream::next_out, palloc0(), and pg_fatal.

Referenced by CreateBackupStreamer().

◆ bbstreamer_gzip_writer_new()

bbstreamer* bbstreamer_gzip_writer_new ( char *  pathname,
FILE *  file,
pg_compress_specification compress 
)

Definition at line 79 of file bbstreamer_gzip.c.

81 {
82 #ifdef HAVE_LIBZ
83  bbstreamer_gzip_writer *streamer;
84 
85  streamer = palloc0(sizeof(bbstreamer_gzip_writer));
86  *((const bbstreamer_ops **) &streamer->base.bbs_ops) =
87  &bbstreamer_gzip_writer_ops;
88 
89  streamer->pathname = pstrdup(pathname);
90 
91  if (file == NULL)
92  {
93  streamer->gzfile = gzopen(pathname, "wb");
94  if (streamer->gzfile == NULL)
95  pg_fatal("could not create compressed file \"%s\": %m",
96  pathname);
97  }
98  else
99  {
100  int fd = dup(fileno(file));
101 
102  if (fd < 0)
103  pg_fatal("could not duplicate stdout: %m");
104 
105  streamer->gzfile = gzdopen(fd, "wb");
106  if (streamer->gzfile == NULL)
107  pg_fatal("could not open output file: %m");
108  }
109 
110  if ((compress->options & PG_COMPRESSION_OPTION_LEVEL) != 0 &&
111  gzsetparams(streamer->gzfile, compress->level,
112  Z_DEFAULT_STRATEGY) != Z_OK)
113  pg_fatal("could not set compression level %d: %s",
114  compress->level, get_gz_error(streamer->gzfile));
115 
116  return &streamer->base;
117 #else
118  pg_fatal("this build does not support gzip compression");
119  return NULL; /* keep compiler quiet */
120 #endif
121 }
#define PG_COMPRESSION_OPTION_LEVEL
Definition: compression.h:25
static int fd(const char *x, int i)
Definition: preproc-init.c:105

References fd(), pg_compress_specification::level, pg_compress_specification::options, palloc0(), PG_COMPRESSION_OPTION_LEVEL, pg_fatal, and pstrdup().

Referenced by CreateBackupStreamer().

◆ bbstreamer_inject_file()

void bbstreamer_inject_file ( bbstreamer streamer,
char *  pathname,
char *  data,
int  len 
)

Definition at line 219 of file bbstreamer_inject.c.

221 {
222  bbstreamer_member member;
223 
224  strlcpy(member.pathname, pathname, MAXPGPATH);
225  member.size = len;
226  member.mode = pg_file_create_mode;
227  member.is_directory = false;
228  member.is_link = false;
229  member.linktarget[0] = '\0';
230 
231  /*
232  * There seems to be no principled argument for these values, but they are
233  * what PostgreSQL has historically used.
234  */
235  member.uid = 04000;
236  member.gid = 02000;
237 
238  /*
239  * We don't know here how to generate valid member headers and trailers
240  * for the archiving format in use, so if those are needed, some successor
241  * bbstreamer will have to generate them using the data from 'member'.
242  */
243  bbstreamer_content(streamer, &member, NULL, 0,
245  bbstreamer_content(streamer, &member, data, len,
247  bbstreamer_content(streamer, &member, NULL, 0,
249 }
static void bbstreamer_content(bbstreamer *streamer, bbstreamer_member *member, const char *data, int len, bbstreamer_archive_context context)
Definition: bbstreamer.h:126
int pg_file_create_mode
Definition: file_perm.c:19
#define MAXPGPATH
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
char pathname[MAXPGPATH]
Definition: bbstreamer.h:72
char linktarget[MAXPGPATH]
Definition: bbstreamer.h:79

References bbstreamer_content(), BBSTREAMER_MEMBER_CONTENTS, BBSTREAMER_MEMBER_HEADER, BBSTREAMER_MEMBER_TRAILER, data, bbstreamer_member::gid, bbstreamer_member::is_directory, bbstreamer_member::is_link, len, bbstreamer_member::linktarget, MAXPGPATH, bbstreamer_member::mode, bbstreamer_member::pathname, pg_file_create_mode, bbstreamer_member::size, strlcpy(), and bbstreamer_member::uid.

Referenced by bbstreamer_recovery_injector_content(), ReceiveArchiveStream(), and ReceiveTarFile().

◆ 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 }
#define pg_log_error(...)
Definition: logging.h:106

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

◆ bbstreamer_plain_writer_new()

bbstreamer* bbstreamer_plain_writer_new ( char *  pathname,
FILE *  file 
)

Definition at line 78 of file bbstreamer_file.c.

79 {
80  bbstreamer_plain_writer *streamer;
81 
82  streamer = palloc0(sizeof(bbstreamer_plain_writer));
83  *((const bbstreamer_ops **) &streamer->base.bbs_ops) =
85 
86  streamer->pathname = pstrdup(pathname);
87  streamer->file = file;
88 
89  if (file == NULL)
90  {
91  streamer->file = fopen(pathname, "wb");
92  if (streamer->file == NULL)
93  pg_fatal("could not create file \"%s\": %m", pathname);
94  streamer->should_close_file = true;
95  }
96 
97  return &streamer->base;
98 }
const bbstreamer_ops bbstreamer_plain_writer_ops

References bbstreamer_plain_writer::base, bbstreamer::bbs_ops, bbstreamer_plain_writer_ops, bbstreamer_plain_writer::file, palloc0(), bbstreamer_plain_writer::pathname, pg_fatal, pstrdup(), and bbstreamer_plain_writer::should_close_file.

Referenced by CreateBackupStreamer().

◆ bbstreamer_recovery_injector_new()

bbstreamer* bbstreamer_recovery_injector_new ( bbstreamer next,
bool  is_recovery_guc_supported,
PQExpBuffer  recoveryconfcontents 
)

◆ bbstreamer_tar_archiver_new()

bbstreamer* bbstreamer_tar_archiver_new ( bbstreamer next)

Definition at line 358 of file bbstreamer_tar.c.

359 {
360  bbstreamer_tar_archiver *streamer;
361 
362  streamer = palloc0(sizeof(bbstreamer_tar_archiver));
363  *((const bbstreamer_ops **) &streamer->base.bbs_ops) =
365  streamer->base.bbs_next = next;
366 
367  return &streamer->base;
368 }
const bbstreamer_ops bbstreamer_tar_archiver_ops

References bbstreamer_tar_archiver::base, bbstreamer::bbs_next, bbstreamer::bbs_ops, bbstreamer_tar_archiver_ops, next, and palloc0().

Referenced by CreateBackupStreamer().

◆ bbstreamer_tar_parser_new()

bbstreamer* bbstreamer_tar_parser_new ( bbstreamer next)

Definition at line 93 of file bbstreamer_tar.c.

94 {
95  bbstreamer_tar_parser *streamer;
96 
97  streamer = palloc0(sizeof(bbstreamer_tar_parser));
98  *((const bbstreamer_ops **) &streamer->base.bbs_ops) =
100  streamer->base.bbs_next = next;
101  initStringInfo(&streamer->base.bbs_buffer);
103 
104  return &streamer->base;
105 }
const bbstreamer_ops bbstreamer_tar_parser_ops
bbstreamer_archive_context next_context

References bbstreamer_tar_parser::base, bbstreamer::bbs_buffer, bbstreamer::bbs_next, bbstreamer::bbs_ops, BBSTREAMER_MEMBER_HEADER, bbstreamer_tar_parser_ops, initStringInfo(), next, bbstreamer_tar_parser::next_context, and palloc0().

Referenced by CreateBackupStreamer().

◆ bbstreamer_tar_terminator_new()

bbstreamer* bbstreamer_tar_terminator_new ( bbstreamer next)

Definition at line 464 of file bbstreamer_tar.c.

465 {
466  bbstreamer *streamer;
467 
468  streamer = palloc0(sizeof(bbstreamer));
469  *((const bbstreamer_ops **) &streamer->bbs_ops) =
471  streamer->bbs_next = next;
472 
473  return streamer;
474 }
const bbstreamer_ops bbstreamer_tar_terminator_ops

References bbstreamer::bbs_next, bbstreamer::bbs_ops, bbstreamer_tar_terminator_ops, next, and palloc0().

Referenced by CreateBackupStreamer().

◆ bbstreamer_zstd_compressor_new()

bbstreamer* bbstreamer_zstd_compressor_new ( bbstreamer next,
pg_compress_specification compress 
)

Definition at line 66 of file bbstreamer_zstd.c.

67 {
68 #ifdef USE_ZSTD
69  bbstreamer_zstd_frame *streamer;
70  size_t ret;
71 
72  Assert(next != NULL);
73 
74  streamer = palloc0(sizeof(bbstreamer_zstd_frame));
75 
76  *((const bbstreamer_ops **) &streamer->base.bbs_ops) =
77  &bbstreamer_zstd_compressor_ops;
78 
79  streamer->base.bbs_next = next;
80  initStringInfo(&streamer->base.bbs_buffer);
81  enlargeStringInfo(&streamer->base.bbs_buffer, ZSTD_DStreamOutSize());
82 
83  streamer->cctx = ZSTD_createCCtx();
84  if (!streamer->cctx)
85  pg_fatal("could not create zstd compression context");
86 
87  /* Set compression level, if specified */
88  if ((compress->options & PG_COMPRESSION_OPTION_LEVEL) != 0)
89  {
90  ret = ZSTD_CCtx_setParameter(streamer->cctx, ZSTD_c_compressionLevel,
91  compress->level);
92  if (ZSTD_isError(ret))
93  pg_fatal("could not set zstd compression level to %d: %s",
94  compress->level, ZSTD_getErrorName(ret));
95  }
96 
97  /* Set # of workers, if specified */
98  if ((compress->options & PG_COMPRESSION_OPTION_WORKERS) != 0)
99  {
100  /*
101  * On older versions of libzstd, this option does not exist, and
102  * trying to set it will fail. Similarly for newer versions if they
103  * are compiled without threading support.
104  */
105  ret = ZSTD_CCtx_setParameter(streamer->cctx, ZSTD_c_nbWorkers,
106  compress->workers);
107  if (ZSTD_isError(ret))
108  pg_fatal("could not set compression worker count to %d: %s",
109  compress->workers, ZSTD_getErrorName(ret));
110  }
111 
112  /* Initialize the ZSTD output buffer. */
113  streamer->zstd_outBuf.dst = streamer->base.bbs_buffer.data;
114  streamer->zstd_outBuf.size = streamer->base.bbs_buffer.maxlen;
115  streamer->zstd_outBuf.pos = 0;
116 
117  return &streamer->base;
118 #else
119  pg_fatal("this build does not support zstd compression");
120  return NULL; /* keep compiler quiet */
121 #endif
122 }
#define PG_COMPRESSION_OPTION_WORKERS
Definition: compression.h:26
void enlargeStringInfo(StringInfo str, int needed)
Definition: stringinfo.c:283

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

Referenced by CreateBackupStreamer().

◆ bbstreamer_zstd_decompressor_new()

bbstreamer* bbstreamer_zstd_decompressor_new ( bbstreamer next)

Definition at line 248 of file bbstreamer_zstd.c.

249 {
250 #ifdef USE_ZSTD
251  bbstreamer_zstd_frame *streamer;
252 
253  Assert(next != NULL);
254 
255  streamer = palloc0(sizeof(bbstreamer_zstd_frame));
256  *((const bbstreamer_ops **) &streamer->base.bbs_ops) =
257  &bbstreamer_zstd_decompressor_ops;
258 
259  streamer->base.bbs_next = next;
260  initStringInfo(&streamer->base.bbs_buffer);
261  enlargeStringInfo(&streamer->base.bbs_buffer, ZSTD_DStreamOutSize());
262 
263  streamer->dctx = ZSTD_createDCtx();
264  if (!streamer->dctx)
265  pg_fatal("could not create zstd decompression context");
266 
267  /* Initialize the ZSTD output buffer. */
268  streamer->zstd_outBuf.dst = streamer->base.bbs_buffer.data;
269  streamer->zstd_outBuf.size = streamer->base.bbs_buffer.maxlen;
270  streamer->zstd_outBuf.pos = 0;
271 
272  return &streamer->base;
273 #else
274  pg_fatal("this build does not support zstd compression");
275  return NULL; /* keep compiler quiet */
276 #endif
277 }

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

Referenced by CreateBackupStreamer().