b45b1cde3e
Summary: This is a feature to sample data-block compressibility and and report them as stats. 1 in N (tunable) blocks is sampled for compressibility using two algorithms: 1. lz4 or snappy for fast compression 2. zstd or zlib for slow but higher compression. The stats are reported to the caller as raw-bytes and compressed-bytes. The block continues to be compressed for storage using the specified CompressionType. The db_bench_tool how has a command line option for specifying the sampling rate. It's default value is 0 (no sampling). To test the overhead for a certain value, users can compare the performance of db_bench_tool, varying the sampling rate. It is unlikely to have a noticeable impact for high values like 20. Pull Request resolved: https://github.com/facebook/rocksdb/pull/4842 Differential Revision: D13629011 Pulled By: shobhitdayal fbshipit-source-id: 14ca668bcab6499b2a1734edf848eb62a4f4fafa
93 lines
3.0 KiB
C++
93 lines
3.0 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
// (found in the LICENSE.Apache file in the root directory).
|
|
|
|
#pragma once
|
|
#include <string>
|
|
#include "rocksdb/types.h"
|
|
#include "util/string_util.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
// Table Properties that are specific to tables created by SstFileWriter.
|
|
struct ExternalSstFilePropertyNames {
|
|
// value of this property is a fixed uint32 number.
|
|
static const std::string kVersion;
|
|
// value of this property is a fixed uint64 number.
|
|
static const std::string kGlobalSeqno;
|
|
};
|
|
|
|
// PropertiesCollector used to add properties specific to tables
|
|
// generated by SstFileWriter
|
|
class SstFileWriterPropertiesCollector : public IntTblPropCollector {
|
|
public:
|
|
explicit SstFileWriterPropertiesCollector(int32_t version,
|
|
SequenceNumber global_seqno)
|
|
: version_(version), global_seqno_(global_seqno) {}
|
|
|
|
virtual Status InternalAdd(const Slice& /*key*/, const Slice& /*value*/,
|
|
uint64_t /*file_size*/) override {
|
|
// Intentionally left blank. Have no interest in collecting stats for
|
|
// individual key/value pairs.
|
|
return Status::OK();
|
|
}
|
|
|
|
virtual void BlockAdd(uint64_t /* blockRawBytes */,
|
|
uint64_t /* blockCompressedBytesFast */,
|
|
uint64_t /* blockCompressedBytesSlow */) override {
|
|
// Intentionally left blank. No interest in collecting stats for
|
|
// blocks.
|
|
return;
|
|
}
|
|
|
|
virtual Status Finish(UserCollectedProperties* properties) override {
|
|
// File version
|
|
std::string version_val;
|
|
PutFixed32(&version_val, static_cast<uint32_t>(version_));
|
|
properties->insert({ExternalSstFilePropertyNames::kVersion, version_val});
|
|
|
|
// Global Sequence number
|
|
std::string seqno_val;
|
|
PutFixed64(&seqno_val, static_cast<uint64_t>(global_seqno_));
|
|
properties->insert({ExternalSstFilePropertyNames::kGlobalSeqno, seqno_val});
|
|
|
|
return Status::OK();
|
|
}
|
|
|
|
virtual const char* Name() const override {
|
|
return "SstFileWriterPropertiesCollector";
|
|
}
|
|
|
|
virtual UserCollectedProperties GetReadableProperties() const override {
|
|
return {{ExternalSstFilePropertyNames::kVersion, ToString(version_)}};
|
|
}
|
|
|
|
private:
|
|
int32_t version_;
|
|
SequenceNumber global_seqno_;
|
|
};
|
|
|
|
class SstFileWriterPropertiesCollectorFactory
|
|
: public IntTblPropCollectorFactory {
|
|
public:
|
|
explicit SstFileWriterPropertiesCollectorFactory(int32_t version,
|
|
SequenceNumber global_seqno)
|
|
: version_(version), global_seqno_(global_seqno) {}
|
|
|
|
virtual IntTblPropCollector* CreateIntTblPropCollector(
|
|
uint32_t /*column_family_id*/) override {
|
|
return new SstFileWriterPropertiesCollector(version_, global_seqno_);
|
|
}
|
|
|
|
virtual const char* Name() const override {
|
|
return "SstFileWriterPropertiesCollector";
|
|
}
|
|
|
|
private:
|
|
int32_t version_;
|
|
SequenceNumber global_seqno_;
|
|
};
|
|
|
|
} // namespace rocksdb
|