Every table and sstable set keeps track of the total file size of contained sstables. Due to a feature request, we also want to keep track of the hypothetical file size if Data files were uncompressed, to add a metric that shows the compression ratio of sstables. We achieve this by replacing the relevant `uint_64 bytes_on_disk` counters everywhere with a struct that contains both the actual (post-compression) size and the hypothetical pre-compression size. This patch isn't supposed to change any observable behavior. In the next patch, we will use these changes to add a new metric.
43 lines
1.4 KiB
C++
43 lines
1.4 KiB
C++
/*
|
|
* Copyright (C) 2025-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
namespace sstables {
|
|
|
|
struct file_size_stats {
|
|
// Actual size of files on disk.
|
|
// In particular, for compressed sstables, this includes the post-compression size of data files.
|
|
int64_t on_disk = 0;
|
|
// The hypothetical size of files on disk if the data files were uncompressed.
|
|
// (Not fully accurate. This is equivalent to `on_disk - physical_data_db_size + logical_data_db_size`.
|
|
// For full accuracy, we would have to account for the replacement of CompressionInfo.db with CRC.db, etc.
|
|
// We don't bother with that. This value is only used for estimation and metrics anyway).
|
|
int64_t before_compression = 0;
|
|
|
|
file_size_stats& operator+=(const file_size_stats& other) {
|
|
on_disk += other.on_disk;
|
|
before_compression += other.before_compression;
|
|
return *this;
|
|
}
|
|
file_size_stats& operator-=(const file_size_stats& other) {
|
|
on_disk -= other.on_disk;
|
|
before_compression -= other.before_compression;
|
|
return *this;
|
|
}
|
|
friend file_size_stats operator+(const file_size_stats& lhs, const file_size_stats& rhs) {
|
|
file_size_stats result = lhs;
|
|
result += rhs;
|
|
return result;
|
|
}
|
|
bool operator==(const file_size_stats& other) const = default;
|
|
};
|
|
|
|
} // namespace sstables
|