@@ -50,12 +50,11 @@ Status BlobFileReader::Create(
50
50
51
51
Statistics* const statistics = immutable_options.stats ;
52
52
53
- CompressionType compression_type = kNoCompression ;
53
+ std::shared_ptr<Compressor> compressor ;
54
54
55
55
{
56
- const Status s =
57
- ReadHeader (file_reader.get (), read_options, column_family_id,
58
- statistics, &compression_type);
56
+ const Status s = ReadHeader (file_reader.get (), read_options,
57
+ column_family_id, statistics, &compressor);
59
58
if (!s.ok ()) {
60
59
return s;
61
60
}
@@ -70,7 +69,7 @@ Status BlobFileReader::Create(
70
69
}
71
70
72
71
blob_file_reader->reset (
73
- new BlobFileReader (std::move (file_reader), file_size, compression_type ,
72
+ new BlobFileReader (std::move (file_reader), file_size, compressor ,
74
73
immutable_options.clock , statistics));
75
74
76
75
return Status::OK ();
@@ -140,9 +139,9 @@ Status BlobFileReader::ReadHeader(const RandomAccessFileReader* file_reader,
140
139
const ReadOptions& read_options,
141
140
uint32_t column_family_id,
142
141
Statistics* statistics,
143
- CompressionType* compression_type ) {
142
+ std::shared_ptr<Compressor>* compressor ) {
144
143
assert (file_reader);
145
- assert (compression_type );
144
+ assert (compressor );
146
145
147
146
Slice header_slice;
148
147
Buffer buf;
@@ -184,7 +183,7 @@ Status BlobFileReader::ReadHeader(const RandomAccessFileReader* file_reader,
184
183
return Status::Corruption (" Column family ID mismatch" );
185
184
}
186
185
187
- *compression_type = header.compression ;
186
+ *compressor = BuiltinCompressor::GetCompressor ( header.compression ) ;
188
187
189
188
return Status::OK ();
190
189
}
@@ -281,11 +280,11 @@ Status BlobFileReader::ReadFromFile(const RandomAccessFileReader* file_reader,
281
280
282
281
BlobFileReader::BlobFileReader (
283
282
std::unique_ptr<RandomAccessFileReader>&& file_reader, uint64_t file_size,
284
- CompressionType compression_type , SystemClock* clock,
283
+ const std::shared_ptr<Compressor>& compressor , SystemClock* clock,
285
284
Statistics* statistics)
286
285
: file_reader_(std::move(file_reader)),
287
286
file_size_ (file_size),
288
- compression_type_(compression_type ),
287
+ compressor_(compressor ),
289
288
clock_(clock),
290
289
statistics_(statistics) {
291
290
assert (file_reader_);
@@ -295,7 +294,7 @@ BlobFileReader::~BlobFileReader() = default;
295
294
296
295
Status BlobFileReader::GetBlob (
297
296
const ReadOptions& read_options, const Slice& user_key, uint64_t offset,
298
- uint64_t value_size, CompressionType compression_type ,
297
+ uint64_t value_size, const std::shared_ptr<Compressor>& compressor ,
299
298
FilePrefetchBuffer* prefetch_buffer, MemoryAllocator* allocator,
300
299
std::unique_ptr<BlobContents>* result, uint64_t * bytes_read) const {
301
300
assert (result);
@@ -306,7 +305,7 @@ Status BlobFileReader::GetBlob(
306
305
return Status::Corruption (" Invalid blob offset" );
307
306
}
308
307
309
- if (compression_type != compression_type_ ) {
308
+ if (compressor-> GetCompressionType () != compressor_-> GetCompressionType () ) {
310
309
return Status::Corruption (" Compression type mismatch when reading blob" );
311
310
}
312
311
@@ -374,7 +373,7 @@ Status BlobFileReader::GetBlob(
374
373
375
374
{
376
375
const Status s = UncompressBlobIfNeeded (
377
- value_slice, compression_type , allocator, clock_, statistics_, result);
376
+ value_slice, compressor. get () , allocator, clock_, statistics_, result);
378
377
if (!s.ok ()) {
379
378
return s;
380
379
}
@@ -420,7 +419,8 @@ void BlobFileReader::MultiGetBlob(
420
419
*req->status = Status::Corruption (" Invalid blob offset" );
421
420
continue ;
422
421
}
423
- if (req->compression != compression_type_) {
422
+ if (req->compressor ->GetCompressionType () !=
423
+ compressor_->GetCompressionType ()) {
424
424
*req->status =
425
425
Status::Corruption (" Compression type mismatch when reading a blob" );
426
426
continue ;
@@ -522,7 +522,7 @@ void BlobFileReader::MultiGetBlob(
522
522
// Uncompress blob if needed
523
523
Slice value_slice (record_slice.data () + adjustments[i], req->len );
524
524
*req->status =
525
- UncompressBlobIfNeeded (value_slice, compression_type_ , allocator,
525
+ UncompressBlobIfNeeded (value_slice, compressor_. get () , allocator,
526
526
clock_, statistics_, &blob_reqs[i].second );
527
527
if (req->status ->ok ()) {
528
528
total_bytes += record_slice.size ();
@@ -579,31 +579,28 @@ Status BlobFileReader::VerifyBlob(const Slice& record_slice,
579
579
}
580
580
581
581
Status BlobFileReader::UncompressBlobIfNeeded (
582
- const Slice& value_slice, CompressionType compression_type ,
582
+ const Slice& value_slice, Compressor* compressor ,
583
583
MemoryAllocator* allocator, SystemClock* clock, Statistics* statistics,
584
584
std::unique_ptr<BlobContents>* result) {
585
+ assert (compressor);
585
586
assert (result);
586
587
587
- if (compression_type == kNoCompression ) {
588
+ if (compressor-> GetCompressionType () == kNoCompression ) {
588
589
BlobContentsCreator::Create (result, nullptr , value_slice, allocator);
589
590
return Status::OK ();
590
591
}
591
592
592
- UncompressionContext context (compression_type);
593
- UncompressionInfo info (context, UncompressionDict::GetEmptyDict (),
594
- compression_type);
593
+ UncompressionInfo info;
595
594
596
595
size_t uncompressed_size = 0 ;
597
- constexpr uint32_t compression_format_version = 2 ;
598
596
599
597
CacheAllocationPtr output;
600
598
601
599
{
602
600
PERF_TIMER_GUARD (blob_decompress_time);
603
601
StopWatch stop_watch (clock, statistics, BLOB_DB_DECOMPRESSION_MICROS);
604
- output = UncompressData (info, value_slice.data (), value_slice.size (),
605
- &uncompressed_size, compression_format_version,
606
- allocator);
602
+ output = info.UncompressData (compressor, value_slice.data (),
603
+ value_slice.size (), &uncompressed_size);
607
604
}
608
605
609
606
TEST_SYNC_POINT_CALLBACK (
0 commit comments