@@ -49,11 +49,11 @@ Status BlobFileReader::Create(
49
49
50
50
Statistics* const statistics = immutable_options.stats ;
51
51
52
- CompressionType compression_type = kNoCompression ;
52
+ std::shared_ptr<Compressor> compressor ;
53
53
54
54
{
55
55
const Status s = ReadHeader (file_reader.get (), column_family_id, statistics,
56
- &compression_type );
56
+ &compressor );
57
57
if (!s.ok ()) {
58
58
return s;
59
59
}
@@ -67,7 +67,7 @@ Status BlobFileReader::Create(
67
67
}
68
68
69
69
blob_file_reader->reset (
70
- new BlobFileReader (std::move (file_reader), file_size, compression_type ,
70
+ new BlobFileReader (std::move (file_reader), file_size, compressor ,
71
71
immutable_options.clock , statistics));
72
72
73
73
return Status::OK ();
@@ -136,9 +136,9 @@ Status BlobFileReader::OpenFile(
136
136
Status BlobFileReader::ReadHeader (const RandomAccessFileReader* file_reader,
137
137
uint32_t column_family_id,
138
138
Statistics* statistics,
139
- CompressionType* compression_type ) {
139
+ std::shared_ptr<Compressor>* compressor ) {
140
140
assert (file_reader);
141
- assert (compression_type );
141
+ assert (compressor );
142
142
143
143
Slice header_slice;
144
144
Buffer buf;
@@ -181,7 +181,7 @@ Status BlobFileReader::ReadHeader(const RandomAccessFileReader* file_reader,
181
181
return Status::Corruption (" Column family ID mismatch" );
182
182
}
183
183
184
- *compression_type = header.compression ;
184
+ *compressor = BuiltinCompressor::GetCompressor ( header.compression ) ;
185
185
186
186
return Status::OK ();
187
187
}
@@ -272,11 +272,11 @@ Status BlobFileReader::ReadFromFile(const RandomAccessFileReader* file_reader,
272
272
273
273
BlobFileReader::BlobFileReader (
274
274
std::unique_ptr<RandomAccessFileReader>&& file_reader, uint64_t file_size,
275
- CompressionType compression_type , SystemClock* clock,
275
+ const std::shared_ptr<Compressor>& compressor , SystemClock* clock,
276
276
Statistics* statistics)
277
277
: file_reader_(std::move(file_reader)),
278
278
file_size_ (file_size),
279
- compression_type_(compression_type ),
279
+ compressor_(compressor ),
280
280
clock_(clock),
281
281
statistics_(statistics) {
282
282
assert (file_reader_);
@@ -286,7 +286,7 @@ BlobFileReader::~BlobFileReader() = default;
286
286
287
287
Status BlobFileReader::GetBlob (
288
288
const ReadOptions& read_options, const Slice& user_key, uint64_t offset,
289
- uint64_t value_size, CompressionType compression_type ,
289
+ uint64_t value_size, const std::shared_ptr<Compressor>& compressor ,
290
290
FilePrefetchBuffer* prefetch_buffer, MemoryAllocator* allocator,
291
291
std::unique_ptr<BlobContents>* result, uint64_t * bytes_read) const {
292
292
assert (result);
@@ -297,7 +297,7 @@ Status BlobFileReader::GetBlob(
297
297
return Status::Corruption (" Invalid blob offset" );
298
298
}
299
299
300
- if (compression_type != compression_type_ ) {
300
+ if (compressor-> GetCompressionType () != compressor_-> GetCompressionType () ) {
301
301
return Status::Corruption (" Compression type mismatch when reading blob" );
302
302
}
303
303
@@ -361,7 +361,7 @@ Status BlobFileReader::GetBlob(
361
361
362
362
{
363
363
const Status s = UncompressBlobIfNeeded (
364
- value_slice, compression_type , allocator, clock_, statistics_, result);
364
+ value_slice, compressor. get () , allocator, clock_, statistics_, result);
365
365
if (!s.ok ()) {
366
366
return s;
367
367
}
@@ -407,7 +407,8 @@ void BlobFileReader::MultiGetBlob(
407
407
*req->status = Status::Corruption (" Invalid blob offset" );
408
408
continue ;
409
409
}
410
- if (req->compression != compression_type_) {
410
+ if (req->compressor ->GetCompressionType () !=
411
+ compressor_->GetCompressionType ()) {
411
412
*req->status =
412
413
Status::Corruption (" Compression type mismatch when reading a blob" );
413
414
continue ;
@@ -506,7 +507,7 @@ void BlobFileReader::MultiGetBlob(
506
507
// Uncompress blob if needed
507
508
Slice value_slice (record_slice.data () + adjustments[i], req->len );
508
509
*req->status =
509
- UncompressBlobIfNeeded (value_slice, compression_type_ , allocator,
510
+ UncompressBlobIfNeeded (value_slice, compressor_. get () , allocator,
510
511
clock_, statistics_, &blob_reqs[i].second );
511
512
if (req->status ->ok ()) {
512
513
total_bytes += record_slice.size ();
@@ -563,31 +564,28 @@ Status BlobFileReader::VerifyBlob(const Slice& record_slice,
563
564
}
564
565
565
566
Status BlobFileReader::UncompressBlobIfNeeded (
566
- const Slice& value_slice, CompressionType compression_type ,
567
+ const Slice& value_slice, Compressor* compressor ,
567
568
MemoryAllocator* allocator, SystemClock* clock, Statistics* statistics,
568
569
std::unique_ptr<BlobContents>* result) {
570
+ assert (compressor);
569
571
assert (result);
570
572
571
- if (compression_type == kNoCompression ) {
573
+ if (compressor-> GetCompressionType () == kNoCompression ) {
572
574
BlobContentsCreator::Create (result, nullptr , value_slice, allocator);
573
575
return Status::OK ();
574
576
}
575
577
576
- UncompressionContext context (compression_type);
577
- UncompressionInfo info (context, UncompressionDict::GetEmptyDict (),
578
- compression_type);
578
+ UncompressionInfo info;
579
579
580
580
size_t uncompressed_size = 0 ;
581
- constexpr uint32_t compression_format_version = 2 ;
582
581
583
582
CacheAllocationPtr output;
584
583
585
584
{
586
585
PERF_TIMER_GUARD (blob_decompress_time);
587
586
StopWatch stop_watch (clock, statistics, BLOB_DB_DECOMPRESSION_MICROS);
588
- output = UncompressData (info, value_slice.data (), value_slice.size (),
589
- &uncompressed_size, compression_format_version,
590
- allocator);
587
+ output = info.UncompressData (compressor, value_slice.data (),
588
+ value_slice.size (), &uncompressed_size);
591
589
}
592
590
593
591
TEST_SYNC_POINT_CALLBACK (
0 commit comments