71{
72#ifdef USE_ZSTD
73 astreamer_zstd_frame *streamer;
74 size_t ret;
75
77
78 streamer =
palloc0(
sizeof(astreamer_zstd_frame));
79
81 &astreamer_zstd_compressor_ops;
82
83 streamer->base.bbs_next =
next;
86
87 streamer->cctx = ZSTD_createCCtx();
88 if (!streamer->cctx)
89 pg_fatal(
"could not create zstd compression context");
90
91 /* Set compression level */
92 ret = ZSTD_CCtx_setParameter(streamer->cctx, ZSTD_c_compressionLevel,
94 if (ZSTD_isError(ret))
95 pg_fatal(
"could not set zstd compression level to %d: %s",
96 compress->
level, ZSTD_getErrorName(ret));
97
98 /* Set # of workers, if specified */
100 {
101 /*
102 * On older versions of libzstd, this option does not exist, and
103 * trying to set it will fail. Similarly for newer versions if they
104 * are compiled without threading support.
105 */
106 ret = ZSTD_CCtx_setParameter(streamer->cctx, ZSTD_c_nbWorkers,
108 if (ZSTD_isError(ret))
109 pg_fatal(
"could not set compression worker count to %d: %s",
110 compress->
workers, ZSTD_getErrorName(ret));
111 }
112
114 {
115 ret = ZSTD_CCtx_setParameter(streamer->cctx,
116 ZSTD_c_enableLongDistanceMatching,
118 if (ZSTD_isError(ret))
119 {
121 ZSTD_getErrorName(ret));
122 exit(1);
123 }
124 }
125
126 /* Initialize the ZSTD output buffer. */
127 streamer->zstd_outBuf.dst = streamer->base.bbs_buffer.data;
128 streamer->zstd_outBuf.size = streamer->base.bbs_buffer.maxlen;
129 streamer->zstd_outBuf.pos = 0;
130
131 return &streamer->base;
132#else
133 pg_fatal(
"this build does not support compression with %s",
"ZSTD");
134 return NULL; /* keep compiler quiet */
135#endif
136}
#define PG_COMPRESSION_OPTION_WORKERS
#define PG_COMPRESSION_OPTION_LONG_DISTANCE
Assert(PointerIsAligned(start, uint64))
#define pg_log_error(...)
void * palloc0(Size size)
void enlargeStringInfo(StringInfo str, int needed)
void initStringInfo(StringInfo str)