multi_compress 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +51 -0
  3. data/GET_STARTED.md +5 -3
  4. data/README.md +2 -2
  5. data/THIRD_PARTY_NOTICES.md +3 -3
  6. data/ext/multi_compress/exports.darwin +1 -0
  7. data/ext/multi_compress/exports.map +4 -0
  8. data/ext/multi_compress/extconf.rb +20 -0
  9. data/ext/multi_compress/multi_compress.c +352 -149
  10. data/ext/multi_compress/vendor/.vendored +2 -2
  11. data/ext/multi_compress/vendor/brotli/c/common/version.h +2 -2
  12. data/ext/multi_compress/vendor/brotli/c/dec/decode.c +59 -30
  13. data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +1 -3
  14. data/ext/multi_compress/vendor/zstd/lib/BUCK +10 -5
  15. data/ext/multi_compress/vendor/zstd/lib/README.md +25 -5
  16. data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +6 -2
  17. data/ext/multi_compress/vendor/zstd/lib/common/bits.h +1 -1
  18. data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +3 -3
  19. data/ext/multi_compress/vendor/zstd/lib/common/bmi2.h +40 -0
  20. data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +37 -11
  21. data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +7 -6
  22. data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +4 -3
  23. data/ext/multi_compress/vendor/zstd/lib/common/pool.c +16 -19
  24. data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +31 -0
  25. data/ext/multi_compress/vendor/zstd/lib/common/threading.c +16 -2
  26. data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +9 -0
  27. data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +4 -2
  28. data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +300 -3
  29. data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +4 -0
  30. data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +4 -1
  31. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +775 -214
  32. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +35 -6
  33. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +9 -5
  34. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +14 -5
  35. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +2 -2
  36. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +2 -2
  37. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +49 -5
  38. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +11 -11
  39. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +11 -0
  40. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +16 -18
  41. data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +3 -3
  42. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +64 -39
  43. data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +30 -2
  44. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +78 -64
  45. data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +182 -18
  46. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +59 -27
  47. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +11 -0
  48. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +194 -93
  49. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +225 -85
  50. data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +19 -2
  51. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +136 -91
  52. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.c +77 -77
  53. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +48 -42
  54. data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +18 -14
  55. data/ext/multi_compress/vendor/zstd/lib/dll/example/build_package.bat +66 -20
  56. data/ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.vcxproj +10 -6
  57. data/ext/multi_compress/vendor/zstd/lib/install_oses.mk +17 -0
  58. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +10 -8
  59. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +5 -364
  60. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +4 -5
  61. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +7 -3
  62. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +8 -5
  63. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +3 -3
  64. data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +1 -0
  65. data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +8 -7
  66. data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +1 -0
  67. data/ext/multi_compress/vendor/zstd/lib/module.modulemap +0 -21
  68. data/ext/multi_compress/vendor/zstd/lib/zstd.h +209 -112
  69. data/lib/multi_compress/active_record.rb +11 -5
  70. data/lib/multi_compress/codec.rb +164 -94
  71. data/lib/multi_compress/database/api.rb +42 -0
  72. data/lib/multi_compress/database/decoding.rb +42 -0
  73. data/lib/multi_compress/database/dictionary.rb +72 -0
  74. data/lib/multi_compress/database/encoding.rb +31 -0
  75. data/lib/multi_compress/database/header.rb +71 -0
  76. data/lib/multi_compress/database/operations.rb +73 -0
  77. data/lib/multi_compress/database/validation.rb +95 -0
  78. data/lib/multi_compress/database.rb +10 -282
  79. data/lib/multi_compress/db_deployment/bundle_archiver.rb +70 -0
  80. data/lib/multi_compress/db_deployment/bundle_metadata.rb +56 -0
  81. data/lib/multi_compress/db_deployment/bundle_stager.rb +62 -0
  82. data/lib/multi_compress/db_deployment/commands.rb +309 -0
  83. data/lib/multi_compress/db_deployment/deployment_bundle.rb +80 -0
  84. data/lib/multi_compress/db_deployment/deterministic_tar_writer.rb +76 -0
  85. data/lib/multi_compress/db_deployment/dictionary_registry.rb +244 -0
  86. data/lib/multi_compress/db_deployment/readable_view.rb +112 -0
  87. data/lib/multi_compress/db_deployment/readable_view_options.rb +51 -0
  88. data/lib/multi_compress/db_deployment/sql_identifiers.rb +45 -0
  89. data/lib/multi_compress/db_deployment.rb +10 -844
  90. data/lib/multi_compress/reader/buffer_operations.rb +57 -0
  91. data/lib/multi_compress/reader/read_operations.rb +69 -0
  92. data/lib/multi_compress/reader.rb +97 -0
  93. data/lib/multi_compress/stream_io.rb +13 -0
  94. data/lib/multi_compress/version.rb +1 -1
  95. data/lib/multi_compress/writer.rb +85 -0
  96. data/lib/multi_compress.rb +42 -333
  97. data/multi_compress.gemspec +2 -0
  98. data/mysql_udf/Makefile +12 -5
  99. data/mysql_udf/multi_compress_mysql.exports +6 -0
  100. data/postgres_extension/Makefile +2 -1
  101. data/postgres_extension/test/run_e2e.sh +28 -10
  102. metadata +30 -10
  103. data/ext/multi_compress/vendor/lz4/lib/Makefile +0 -244
  104. data/ext/multi_compress/vendor/lz4/lib/dll/example/Makefile +0 -63
  105. data/ext/multi_compress/vendor/zstd/lib/Makefile +0 -389
  106. data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +0 -48
@@ -5,11 +5,11 @@ require "multi_compress/version"
5
5
  begin
6
6
  require "multi_compress/multi_compress"
7
7
  rescue LoadError
8
- ext_dir = File.expand_path("../multi_compress", __FILE__)
8
+ ext_dir = File.expand_path("multi_compress", __dir__)
9
9
 
10
10
  so_path = %w[.bundle .so]
11
- .map { |ext| File.join(ext_dir, "multi_compress#{ext}") }
12
- .find { |path| File.exist?(path) }
11
+ .map { |ext| File.join(ext_dir, "multi_compress#{ext}") }
12
+ .find { |path| File.exist?(path) }
13
13
 
14
14
  raise LoadError, "Could not find compiled MultiCompress extension. Run: bundle exec rake compile" unless so_path
15
15
 
@@ -25,10 +25,10 @@ module MultiCompress
25
25
  DEFAULT_STREAMING_MAX_OUTPUT_SIZE = 2 * 1024 * 1024 * 1024
26
26
 
27
27
  EXTENSION_MAP = {
28
- ".zst" => :zstd,
28
+ ".zst" => :zstd,
29
29
  ".zstd" => :zstd,
30
- ".lz4" => :lz4,
31
- ".br" => :brotli,
30
+ ".lz4" => :lz4,
31
+ ".br" => :brotli
32
32
  }.freeze
33
33
 
34
34
  private_constant :EXTENSION_MAP
@@ -91,361 +91,70 @@ module MultiCompress
91
91
  end
92
92
 
93
93
  unless private_method_defined?(:_c_decompress)
94
- alias_method :_c_decompress, :decompress
94
+ alias _c_decompress decompress
95
95
  private :_c_decompress
96
96
  end
97
- end
98
-
99
- def self.zstd(data, level: nil)
100
- compress(data, algo: :zstd, level: level)
101
- end
102
-
103
- def self.lz4(data, level: nil, format: nil)
104
- if format
105
- compress(data, algo: :lz4, level: level, format: format)
106
- else
107
- compress(data, algo: :lz4, level: level)
108
- end
109
- end
110
-
111
- def self.brotli(data, level: nil)
112
- compress(data, algo: :brotli, level: level)
113
- end
114
-
115
- def self.decompress(data, **opts)
116
- _c_decompress(data, **resolved_one_shot_options(opts))
117
- end
118
-
119
- def self.zstd_decompress(data)
120
- decompress(data, algo: :zstd)
121
- end
122
-
123
- def self.lz4_decompress(data, format: nil)
124
- if format
125
- decompress(data, algo: :lz4, format: format)
126
- else
127
- decompress(data, algo: :lz4)
128
- end
129
- end
130
-
131
- def self.brotli_decompress(data)
132
- decompress(data, algo: :brotli)
133
- end
134
-
135
- def self.algo_from_ext(path)
136
- EXTENSION_MAP[File.extname(path).downcase]
137
- end
138
-
139
- def self.resolved_one_shot_options(opts)
140
- return opts.merge(max_output_size: config.max_output_size) unless opts.key?(:max_output_size)
141
-
142
- opts
143
- end
144
-
145
- private_class_method :resolved_one_shot_options
146
-
147
- module InflaterDefaults
148
- def initialize(*args, **opts)
149
- resolved = opts.dup
150
- resolved[:max_output_size] = MultiCompress.config.streaming_max_output_size unless resolved.key?(:max_output_size)
151
- super(*args, **resolved)
152
- end
153
- end
154
-
155
- Inflater.prepend(InflaterDefaults)
156
97
 
157
- class Writer
158
- CHUNK_BUFFER_SIZE = 8192
159
-
160
- def self.open(path_or_io, algo: nil, level: nil, dictionary: nil, &block)
161
- io, algo, owned = resolve_io(path_or_io, algo, mode: "wb")
162
- writer = new(io, algo: algo || :zstd, level: level, dictionary: dictionary)
163
- writer.instance_variable_set(:@owned_io, owned)
164
-
165
- return writer unless block
166
-
167
- begin
168
- yield writer
169
- ensure
170
- writer.close
171
- end
98
+ def zstd(data, level: nil)
99
+ compress(data, algo: :zstd, level: level)
172
100
  end
173
101
 
174
- def initialize(io, algo: :zstd, level: nil, dictionary: nil)
175
- @io = io
176
- @deflater = Deflater.new(algo: algo, level: level, dictionary: dictionary)
177
- @closed = false
178
- @owned_io = false
179
- end
180
-
181
- def write(data)
182
- ensure_open!
183
- bytes = data.to_s
184
- flush_compressed(@deflater.write(bytes))
185
- bytes.bytesize
186
- end
187
-
188
- def flush
189
- ensure_open!
190
- flush_compressed(@deflater.flush)
191
- @io.flush if @io.respond_to?(:flush)
192
- self
193
- end
194
-
195
- def close
196
- return if @closed
197
-
198
- flush_compressed(@deflater.finish)
199
- @deflater.close
200
- @io.close if @owned_io && @io.respond_to?(:close)
201
- @closed = true
202
- nil
203
- end
204
-
205
- def closed?
206
- @closed
207
- end
208
-
209
- def <<(data)
210
- write(data)
211
- self
212
- end
213
-
214
- def puts(*args)
215
- args.flatten.each do |arg|
216
- str = arg.to_s
217
- write(str)
218
- write("\n") unless str.end_with?("\n")
219
- end
220
- nil
221
- end
222
-
223
- def print(*args)
224
- args.each { |arg| write(arg.to_s) }
225
- nil
226
- end
227
-
228
- private
229
-
230
- def ensure_open!
231
- raise StreamError, "writer is closed" if @closed
232
- end
233
-
234
- def flush_compressed(compressed)
235
- @io.write(compressed) if compressed && !compressed.empty?
236
- end
237
-
238
- def self.resolve_io(path_or_io, algo, mode:)
239
- if path_or_io.is_a?(String)
240
- [File.open(path_or_io, mode), algo || MultiCompress.algo_from_ext(path_or_io), true]
102
+ def lz4(data, level: nil, format: nil)
103
+ if format
104
+ compress(data, algo: :lz4, level: level, format: format)
241
105
  else
242
- [path_or_io, algo, false]
106
+ compress(data, algo: :lz4, level: level)
243
107
  end
244
108
  end
245
109
 
246
- private_class_method :resolve_io
247
- end
248
-
249
- class Reader
250
- CHUNK_SIZE = 8192
251
- BUFFER_COMPACT_THRESHOLD = 64 * 1024
252
-
253
- def self.open(path_or_io, algo: nil, dictionary: nil, **opts, &block)
254
- io, algo, owned = resolve_io(path_or_io, algo, mode: "rb")
255
- reader = new(io, algo: algo, dictionary: dictionary, **opts)
256
- reader.instance_variable_set(:@owned_io, owned)
257
-
258
- return reader unless block
259
-
260
- begin
261
- yield reader
262
- ensure
263
- reader.close
264
- end
110
+ def brotli(data, level: nil)
111
+ compress(data, algo: :brotli, level: level)
265
112
  end
266
113
 
267
- def initialize(io, algo: nil, dictionary: nil, **opts)
268
- @io = io
269
- @inflater = Inflater.new(algo: algo, dictionary: dictionary, **opts)
270
- @closed = false
271
- @owned_io = false
272
- @buffer = +"".b
273
- @buffer_pos = 0
274
- @eof = false
114
+ def decompress(data, **opts)
115
+ _c_decompress(data, **resolved_one_shot_options(opts))
275
116
  end
276
117
 
277
- def read(length = nil)
278
- ensure_open!
279
- return read_all if length.nil?
280
-
281
- read_exactly(length)
282
- end
283
-
284
- def gets(separator = "\n")
285
- ensure_open!
286
- return nil if @eof && buffer_empty?
287
-
288
- fill_buffer_until { buffer_includes?(separator) }
289
-
290
- return extract_line(separator) if buffer_includes?(separator)
291
- return consume_buffer unless buffer_empty?
292
-
293
- nil
118
+ def zstd_decompress(data)
119
+ decompress(data, algo: :zstd)
294
120
  end
295
121
 
296
- def close
297
- return if @closed
298
-
299
- @inflater.close
300
- @io.close if @owned_io && @io.respond_to?(:close)
301
- @closed = true
302
- nil
303
- end
304
-
305
- def closed?
306
- @closed
307
- end
308
-
309
- def eof?
310
- @eof && buffer_empty?
311
- end
312
-
313
- def each_line
314
- return enum_for(:each_line) unless block_given?
315
-
316
- while (line = gets)
317
- yield line
122
+ def lz4_decompress(data, format: nil)
123
+ if format
124
+ decompress(data, algo: :lz4, format: format)
125
+ else
126
+ decompress(data, algo: :lz4)
318
127
  end
319
128
  end
320
129
 
321
- def each_chunk(size)
322
- return enum_for(:each_chunk, size) unless block_given?
323
-
324
- while (chunk = read(size))
325
- yield chunk
326
- end
130
+ def brotli_decompress(data)
131
+ decompress(data, algo: :brotli)
327
132
  end
328
133
 
329
- def readline
330
- gets || raise(EOFError, "end of file reached")
134
+ def algo_from_ext(path)
135
+ EXTENSION_MAP[File.extname(path).downcase]
331
136
  end
332
137
 
333
138
  private
334
139
 
335
- def ensure_open!
336
- raise StreamError, "reader is closed" if @closed
337
- end
338
-
339
- def buffer_size
340
- @buffer.bytesize - @buffer_pos
341
- end
342
-
343
- def buffer_empty?
344
- @buffer_pos >= @buffer.bytesize
345
- end
346
-
347
- def buffer_append(data)
348
- compact_buffer_if_needed
349
- @buffer << data
350
- end
351
-
352
- def compact_buffer_if_needed
353
- return if @buffer_pos == 0
354
-
355
- total = @buffer.bytesize
356
- return unless @buffer_pos >= BUFFER_COMPACT_THRESHOLD && @buffer_pos * 2 >= total
140
+ def resolved_one_shot_options(opts)
141
+ return opts.merge(max_output_size: config.max_output_size) unless opts.key?(:max_output_size)
357
142
 
358
- @buffer = @buffer.byteslice(@buffer_pos, total - @buffer_pos)
359
- @buffer_pos = 0
360
- end
361
-
362
- def buffer_includes?(separator)
363
- idx = @buffer.index(separator, @buffer_pos)
364
- !idx.nil?
365
- end
366
-
367
- def read_all
368
- return nil if @eof && buffer_empty?
369
-
370
- result = if buffer_empty?
371
- +"".b
372
- else
373
- @buffer.byteslice(@buffer_pos, @buffer.bytesize - @buffer_pos) || +"".b
374
- end
375
- @buffer.clear
376
- @buffer_pos = 0
377
-
378
- until @eof
379
- chunk = read_compressed_chunk
380
- break unless chunk && !chunk.empty?
381
-
382
- decompressed = @inflater.write(chunk)
383
- result << decompressed if decompressed
384
- end
385
-
386
- final = @inflater.finish
387
- result << final if final && !final.empty?
388
-
389
- result.empty? ? nil : result
390
- end
391
-
392
- def read_exactly(length)
393
- return nil if @eof && buffer_empty?
394
-
395
- fill_buffer_until { buffer_size >= length }
396
-
397
- if buffer_size >= length
398
- result = @buffer.byteslice(@buffer_pos, length)
399
- @buffer_pos += length
400
- compact_buffer_if_needed
401
- result
402
- elsif !buffer_empty?
403
- consume_buffer
404
- end
405
- end
406
-
407
- def fill_buffer_until
408
- until yield || @eof
409
- chunk = read_compressed_chunk
410
- if chunk.nil? || chunk.empty?
411
- @eof = true
412
- break
413
- end
414
- decompressed = @inflater.write(chunk)
415
- buffer_append(decompressed) if decompressed
416
- end
417
- end
418
-
419
- def extract_line(separator)
420
- idx = @buffer.index(separator, @buffer_pos)
421
- end_pos = idx + separator.bytesize
422
- result = @buffer.byteslice(@buffer_pos, end_pos - @buffer_pos)
423
- @buffer_pos = end_pos
424
- compact_buffer_if_needed
425
- result
426
- end
427
-
428
- def consume_buffer
429
- result = @buffer.byteslice(@buffer_pos, @buffer.bytesize - @buffer_pos) || +"".b
430
- @buffer.clear
431
- @buffer_pos = 0
432
- result
143
+ opts
433
144
  end
145
+ end
434
146
 
435
- def read_compressed_chunk
436
- @io.read(CHUNK_SIZE)
437
- rescue EOFError
438
- nil
147
+ module InflaterDefaults
148
+ def initialize(*args, **opts)
149
+ resolved = opts.dup
150
+ resolved[:max_output_size] = MultiCompress.config.streaming_max_output_size unless resolved.key?(:max_output_size)
151
+ super(*args, **resolved)
439
152
  end
153
+ end
440
154
 
441
- def self.resolve_io(path_or_io, algo, mode:)
442
- if path_or_io.is_a?(String)
443
- [File.open(path_or_io, mode), algo || MultiCompress.algo_from_ext(path_or_io), true]
444
- else
445
- [path_or_io, algo, false]
446
- end
447
- end
155
+ Inflater.prepend(InflaterDefaults)
448
156
 
449
- private_class_method :resolve_io
450
- end
157
+ require "multi_compress/stream_io"
158
+ require "multi_compress/writer"
159
+ require "multi_compress/reader"
451
160
  end
@@ -25,6 +25,8 @@ Gem::Specification.new do |spec|
25
25
  "exe/*",
26
26
  "docs/**/*.md",
27
27
  "ext/**/*.{c,h,rb}",
28
+ "ext/multi_compress/exports.darwin",
29
+ "ext/multi_compress/exports.map",
28
30
  "ext/multi_compress/vendor/**/*",
29
31
  "ext/multi_compress/vendor/.vendored",
30
32
  "db_core/**/*.{c,h}",
data/mysql_udf/Makefile CHANGED
@@ -21,6 +21,13 @@ WARNFLAGS ?= -Wall -Wextra -Werror
21
21
  CFLAGS ?= -O2 -fPIC -std=c99 $(WARNFLAGS) -I$(ZSTD_DIR) -I$(CORE_DIR)/include
22
22
  ZSTD_CFLAGS ?= -O2 -fPIC -std=c99 -I$(ZSTD_DIR) -I$(ZSTD_DIR)/common
23
23
 
24
+ ZSTD_PRIVATE_DEFS := -DZSTDLIB_VISIBLE= -DZSTDERRORLIB_VISIBLE= -DZDICTLIB_VISIBLE= -DZSTD_TRACE=0
25
+ ZSTD_PRIVATE_FLAGS := -fvisibility=hidden $(ZSTD_PRIVATE_DEFS)
26
+ UDF_EXPORT_MAP := $(CURDIR)/multi_compress_mysql.exports
27
+ ifeq ($(shell uname -s),Linux)
28
+ UDF_LDFLAGS := -Wl,--version-script=$(UDF_EXPORT_MAP)
29
+ endif
30
+
24
31
  ZSTD_OBJ_DIR := $(BUILD)/zstd
25
32
  ZSTD_C_SRCS := $(wildcard $(ZSTD_DIR)/common/*.c) $(wildcard $(ZSTD_DIR)/decompress/*.c)
26
33
  ZSTD_C_OBJS := $(patsubst $(ZSTD_DIR)/%.c,$(ZSTD_OBJ_DIR)/%.o,$(ZSTD_C_SRCS))
@@ -48,7 +55,7 @@ $(BUILD):
48
55
 
49
56
  $(ZSTD_OBJ_DIR)/%.o: $(ZSTD_DIR)/%.c
50
57
  @mkdir -p $(dir $@)
51
- $(CC) $(ZSTD_CFLAGS) -MMD -MP -c $< -o $@
58
+ $(CC) $(ZSTD_CFLAGS) $(ZSTD_PRIVATE_FLAGS) -MMD -MP -c $< -o $@
52
59
 
53
60
  $(ZSTD_OBJ_DIR)/%.o: $(ZSTD_DIR)/%.S
54
61
  @mkdir -p $(dir $@)
@@ -57,17 +64,17 @@ $(ZSTD_OBJ_DIR)/%.o: $(ZSTD_DIR)/%.S
57
64
  $(ZSTD_LIB): $(ZSTD_OBJS) | $(BUILD)
58
65
  $(AR) rcs $@ $^
59
66
 
60
- $(UDF_SO): src/multi_compress_mysql.c $(CORE_DIR)/src/mcdb_format.c $(CORE_DIR)/include/mcdb_format.h $(ZSTD_LIB) | $(BUILD)
67
+ $(UDF_SO): src/multi_compress_mysql.c $(CORE_DIR)/src/mcdb_format.c $(CORE_DIR)/include/mcdb_format.h $(ZSTD_LIB) $(UDF_EXPORT_MAP) | $(BUILD)
61
68
  @$(MYSQL_UDF_HEADER_CHECK)
62
- $(CC) $(CFLAGS) $(MYSQL_UDF_CPPFLAGS) -shared \
69
+ $(CC) $(CFLAGS) $(ZSTD_PRIVATE_DEFS) $(MYSQL_UDF_CPPFLAGS) -shared \
63
70
  src/multi_compress_mysql.c $(CORE_DIR)/src/mcdb_format.c $(ZSTD_LIB) \
64
- -o $@
71
+ $(UDF_LDFLAGS) -o $@
65
72
  @echo "built $@"
66
73
 
67
74
  udf: $(UDF_SO)
68
75
 
69
76
  $(CLI): $(CORE_DIR)/src/mcdb_format.c $(CORE_DIR)/include/mcdb_format.h test/mcdb_cli.c $(ZSTD_LIB) | $(BUILD)
70
- $(CC) $(CFLAGS) $(CORE_DIR)/src/mcdb_format.c test/mcdb_cli.c $(ZSTD_LIB) -o $@
77
+ $(CC) $(CFLAGS) $(ZSTD_PRIVATE_DEFS) $(CORE_DIR)/src/mcdb_format.c test/mcdb_cli.c $(ZSTD_LIB) -o $@
71
78
 
72
79
  fixtures:
73
80
  RUBYLIB=../lib ruby $(FIXTURES)/generate.rb
@@ -0,0 +1,6 @@
1
+ {
2
+ global:
3
+ multi_compress_db_*;
4
+ local:
5
+ *;
6
+ };
@@ -18,6 +18,7 @@ SHLIB_LINK += -Wl,--version-script=$(EXPORT_MAP) $(ZSTD_LIB)
18
18
  EXTRA_CLEAN += $(BUILD)
19
19
 
20
20
  ZSTD_CFLAGS ?= -O2 -fPIC -std=c99 -I$(ZSTD_DIR) -I$(ZSTD_DIR)/common
21
+ ZSTD_PRIVATE_FLAGS := -fvisibility=hidden -DZSTDLIB_VISIBLE= -DZSTDERRORLIB_VISIBLE= -DZDICTLIB_VISIBLE= -DZSTD_TRACE=0
21
22
  ZSTD_OBJ_DIR := $(BUILD)/zstd
22
23
  ZSTD_C_SRCS := $(wildcard $(ZSTD_DIR)/common/*.c) $(wildcard $(ZSTD_DIR)/decompress/*.c)
23
24
  ZSTD_C_OBJS := $(patsubst $(ZSTD_DIR)/%.c,$(ZSTD_OBJ_DIR)/%.o,$(ZSTD_C_SRCS))
@@ -47,7 +48,7 @@ $(BUILD):
47
48
 
48
49
  $(ZSTD_OBJ_DIR)/%.o: $(ZSTD_DIR)/%.c
49
50
  @mkdir -p $(dir $@)
50
- $(CC) $(ZSTD_CFLAGS) -MMD -MP -c $< -o $@
51
+ $(CC) $(ZSTD_CFLAGS) $(ZSTD_PRIVATE_FLAGS) -MMD -MP -c $< -o $@
51
52
 
52
53
  $(ZSTD_OBJ_DIR)/%.o: $(ZSTD_DIR)/%.S
53
54
  @mkdir -p $(dir $@)
@@ -28,6 +28,18 @@ if [ -z "${MCDB_POSTGRES_WORK_ROOT:-}" ]; then
28
28
  REMOVE_WORK_ROOT=1
29
29
  fi
30
30
 
31
+ wait_for_postgres() {
32
+ local deadline=$(( $(date +%s) + WAIT_SECONDS ))
33
+ until docker exec "$CONTAINER" pg_isready -U postgres -d postgres >/dev/null 2>&1; do
34
+ if [ "$(date +%s)" -ge "$deadline" ]; then
35
+ echo "PostgreSQL did not become ready within ${WAIT_SECONDS}s" >&2
36
+ docker logs "$CONTAINER" >&2 || true
37
+ exit 1
38
+ fi
39
+ sleep 2
40
+ done
41
+ }
42
+
31
43
  ensure_ruby_extension() {
32
44
  if ruby -Ilib -e 'require "multi_compress"; require "multi_compress/database"' >/dev/null 2>&1; then
33
45
  return
@@ -252,15 +264,7 @@ docker run --platform "$PLATFORM" -d --name "$CONTAINER" \
252
264
  -e POSTGRES_HOST_AUTH_METHOD=trust "$IMAGE" >/dev/null
253
265
 
254
266
  echo "waiting for PostgreSQL in $IMAGE..."
255
- deadline=$(( $(date +%s) + WAIT_SECONDS ))
256
- until docker exec "$CONTAINER" pg_isready -U postgres -d postgres >/dev/null 2>&1; do
257
- if [ "$(date +%s)" -ge "$deadline" ]; then
258
- echo "PostgreSQL did not become ready within ${WAIT_SECONDS}s" >&2
259
- docker logs "$CONTAINER" >&2 || true
260
- exit 1
261
- fi
262
- sleep 2
263
- done
267
+ wait_for_postgres
264
268
 
265
269
  q() { docker exec "$CONTAINER" psql -X -U postgres -d postgres -Atq -v ON_ERROR_STOP=1 -c "$1"; }
266
270
  qfail() {
@@ -273,7 +277,21 @@ q_read_fail() {
273
277
 
274
278
  RUNTIME_PG_CONFIG=$(docker exec "$CONTAINER" sh -ceu 'command -v pg_config' | tr -d '\r\n')
275
279
  [ -n "$RUNTIME_PG_CONFIG" ] || { echo "PostgreSQL runtime does not provide pg_config" >&2; exit 2; }
280
+ IMAGE_SERVER_VERSION="$(q 'SHOW server_version;' | awk '{print $1}')"
276
281
  BUILD_PG_CONFIG=$(install_postgres_build_tools "$RUNTIME_PG_CONFIG")
282
+ DISK_VERSION="$(docker exec "$CONTAINER" "$RUNTIME_PG_CONFIG" --version | awk '{print $2}')"
283
+ SERVER_VERSION="$(q 'SHOW server_version;' | awk '{print $1}')"
284
+ if [ "$SERVER_VERSION" != "$DISK_VERSION" ]; then
285
+ echo "restarting PostgreSQL after package update ($SERVER_VERSION -> $DISK_VERSION)..."
286
+ docker restart "$CONTAINER" >/dev/null
287
+ wait_for_postgres
288
+ SERVER_VERSION="$(q 'SHOW server_version;' | awk '{print $1}')"
289
+ if [ "$SERVER_VERSION" != "$DISK_VERSION" ]; then
290
+ echo "PostgreSQL server $SERVER_VERSION does not match installed files $DISK_VERSION" >&2
291
+ exit 1
292
+ fi
293
+ fi
294
+ echo "PostgreSQL e2e server: $SERVER_VERSION (pinned image started at $IMAGE_SERVER_VERSION)"
277
295
  install_bundle_on_db_host "$BUNDLE_NAME" "$BUILD_PG_CONFIG" "$RUNTIME_PG_CONFIG"
278
296
 
279
297
  q "CREATE ROLE app_migrations LOGIN;
@@ -349,7 +367,7 @@ check_err() {
349
367
 
350
368
  check "UTF8 database" "$(q 'SHOW server_encoding;' | tr -d '\r\n')" "UTF8"
351
369
  check "deployment bundle version() smoke" "$(q 'SELECT strpos(multi_compress.multi_compress_db_version(), chr(77) || chr(67) || chr(68) || chr(66) || chr(49)) > 0;' | tr -d '\r\n')" "t"
352
- check "PostgreSQL reader uses vendored zstd" "$(q "SELECT strpos(multi_compress.multi_compress_db_version(), 'zstd 1.5.7') > 0;" | tr -d '\r\n')" "t"
370
+ check "PostgreSQL reader uses vendored zstd" "$(q "SELECT strpos(multi_compress.multi_compress_db_version(), 'zstd 1.6.0') > 0;" | tr -d '\r\n')" "t"
353
371
  check "decode roundtrip" "$(q 'SELECT multi_compress.multi_compress_db_decompress(payload_compressed) FROM app.events WHERE id=1;' | tr -d '\r')" "$TEXT"
354
372
  check "NULL -> NULL" "$(q 'SELECT multi_compress.multi_compress_db_decompress(payload_compressed) IS NULL FROM app.events WHERE id=2;' | tr -d '\r\n')" "t"
355
373
  check "big (>255, >input)" "$(q 'SELECT octet_length(multi_compress.multi_compress_db_decompress(payload_compressed)) FROM app.events WHERE id=3;' | tr -d '\r\n')" "300"
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_compress
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Haydarov
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2026-07-06 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -109,6 +108,8 @@ files:
109
108
  - exe/multi_compress
110
109
  - ext/multi_compress/brotli_dec_static_init.c
111
110
  - ext/multi_compress/brotli_enc_static_init.c
111
+ - ext/multi_compress/exports.darwin
112
+ - ext/multi_compress/exports.map
112
113
  - ext/multi_compress/extconf.rb
113
114
  - ext/multi_compress/multi_compress.c
114
115
  - ext/multi_compress/vendor/.vendored
@@ -222,9 +223,7 @@ files:
222
223
  - ext/multi_compress/vendor/brotli/c/include/brotli/types.h
223
224
  - ext/multi_compress/vendor/lz4/LICENSE
224
225
  - ext/multi_compress/vendor/lz4/lib/LICENSE
225
- - ext/multi_compress/vendor/lz4/lib/Makefile
226
226
  - ext/multi_compress/vendor/lz4/lib/README.md
227
- - ext/multi_compress/vendor/lz4/lib/dll/example/Makefile
228
227
  - ext/multi_compress/vendor/lz4/lib/dll/example/README.md
229
228
  - ext/multi_compress/vendor/lz4/lib/dll/example/fullbench-dll.sln
230
229
  - ext/multi_compress/vendor/lz4/lib/dll/example/fullbench-dll.vcxproj
@@ -244,11 +243,11 @@ files:
244
243
  - ext/multi_compress/vendor/zstd/COPYING
245
244
  - ext/multi_compress/vendor/zstd/LICENSE
246
245
  - ext/multi_compress/vendor/zstd/lib/BUCK
247
- - ext/multi_compress/vendor/zstd/lib/Makefile
248
246
  - ext/multi_compress/vendor/zstd/lib/README.md
249
247
  - ext/multi_compress/vendor/zstd/lib/common/allocations.h
250
248
  - ext/multi_compress/vendor/zstd/lib/common/bits.h
251
249
  - ext/multi_compress/vendor/zstd/lib/common/bitstream.h
250
+ - ext/multi_compress/vendor/zstd/lib/common/bmi2.h
252
251
  - ext/multi_compress/vendor/zstd/lib/common/compiler.h
253
252
  - ext/multi_compress/vendor/zstd/lib/common/cpu.h
254
253
  - ext/multi_compress/vendor/zstd/lib/common/debug.c
@@ -318,11 +317,11 @@ files:
318
317
  - ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h
319
318
  - ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c
320
319
  - ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c
321
- - ext/multi_compress/vendor/zstd/lib/dll/example/Makefile
322
320
  - ext/multi_compress/vendor/zstd/lib/dll/example/README.md
323
321
  - ext/multi_compress/vendor/zstd/lib/dll/example/build_package.bat
324
322
  - ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.sln
325
323
  - ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.vcxproj
324
+ - ext/multi_compress/vendor/zstd/lib/install_oses.mk
326
325
  - ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h
327
326
  - ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c
328
327
  - ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h
@@ -348,11 +347,34 @@ files:
348
347
  - lib/multi_compress/active_record.rb
349
348
  - lib/multi_compress/codec.rb
350
349
  - lib/multi_compress/database.rb
350
+ - lib/multi_compress/database/api.rb
351
+ - lib/multi_compress/database/decoding.rb
352
+ - lib/multi_compress/database/dictionary.rb
353
+ - lib/multi_compress/database/encoding.rb
354
+ - lib/multi_compress/database/header.rb
355
+ - lib/multi_compress/database/operations.rb
356
+ - lib/multi_compress/database/validation.rb
351
357
  - lib/multi_compress/db_deployment.rb
358
+ - lib/multi_compress/db_deployment/bundle_archiver.rb
359
+ - lib/multi_compress/db_deployment/bundle_metadata.rb
360
+ - lib/multi_compress/db_deployment/bundle_stager.rb
361
+ - lib/multi_compress/db_deployment/commands.rb
362
+ - lib/multi_compress/db_deployment/deployment_bundle.rb
363
+ - lib/multi_compress/db_deployment/deterministic_tar_writer.rb
364
+ - lib/multi_compress/db_deployment/dictionary_registry.rb
365
+ - lib/multi_compress/db_deployment/readable_view.rb
366
+ - lib/multi_compress/db_deployment/readable_view_options.rb
367
+ - lib/multi_compress/db_deployment/sql_identifiers.rb
368
+ - lib/multi_compress/reader.rb
369
+ - lib/multi_compress/reader/buffer_operations.rb
370
+ - lib/multi_compress/reader/read_operations.rb
371
+ - lib/multi_compress/stream_io.rb
352
372
  - lib/multi_compress/version.rb
373
+ - lib/multi_compress/writer.rb
353
374
  - multi_compress.gemspec
354
375
  - mysql_udf/Makefile
355
376
  - mysql_udf/README.md
377
+ - mysql_udf/multi_compress_mysql.exports
356
378
  - mysql_udf/sql/examples.sql
357
379
  - mysql_udf/sql/install.sql
358
380
  - mysql_udf/sql/uninstall.sql
@@ -381,7 +403,6 @@ metadata:
381
403
  homepage_uri: https://github.com/roman-haidarov/multi_compress
382
404
  source_code_uri: https://github.com/roman-haidarov/multi_compress
383
405
  changelog_uri: https://github.com/roman-haidarov/multi_compress/blob/main/CHANGELOG.md
384
- post_install_message:
385
406
  rdoc_options: []
386
407
  require_paths:
387
408
  - lib
@@ -396,8 +417,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
396
417
  - !ruby/object:Gem::Version
397
418
  version: '0'
398
419
  requirements: []
399
- rubygems_version: 3.4.22
400
- signing_key:
420
+ rubygems_version: 3.6.7
401
421
  specification_version: 4
402
422
  summary: 'Modern fiber-friendly compression for Ruby: zstd, lz4, brotli in one gem'
403
423
  test_files: []