Add max buffers to CompactionStrategy.
#pragma once
#include <iosfwd>
+#include <cstdint>
namespace vespalib {
@@ -26,6 +27,7 @@ public:
private:
double _maxDeadBytesRatio; // Max ratio of dead bytes before compaction
double _maxDeadAddressSpaceRatio; // Max ratio of dead address space before compaction
+ uint32_t _max_buffers; // Max number of buffers to compact for each reason (memory usage, address space usage)
bool should_compact_memory(size_t used_bytes, size_t dead_bytes) const {
return ((dead_bytes >= DEAD_BYTES_SLACK) &&
(dead_bytes > used_bytes * getMaxDeadBytesRatio()));
@@ -37,19 +39,29 @@ private:
public:
CompactionStrategy() noexcept
: _maxDeadBytesRatio(0.05),
- _maxDeadAddressSpaceRatio(0.2)
+ _maxDeadAddressSpaceRatio(0.2),
+ _max_buffers(1)
{
}
CompactionStrategy(double maxDeadBytesRatio, double maxDeadAddressSpaceRatio) noexcept
: _maxDeadBytesRatio(maxDeadBytesRatio),
- _maxDeadAddressSpaceRatio(maxDeadAddressSpaceRatio)
+ _maxDeadAddressSpaceRatio(maxDeadAddressSpaceRatio),
+ _max_buffers(1)
+ {
+ }
+ CompactionStrategy(double maxDeadBytesRatio, double maxDeadAddressSpaceRatio, uint32_t max_buffers) noexcept
+ : _maxDeadBytesRatio(maxDeadBytesRatio),
+ _maxDeadAddressSpaceRatio(maxDeadAddressSpaceRatio),
+ _max_buffers(max_buffers)
{
}
double getMaxDeadBytesRatio() const { return _maxDeadBytesRatio; }
double getMaxDeadAddressSpaceRatio() const { return _maxDeadAddressSpaceRatio; }
+ uint32_t get_max_buffers() const noexcept { return _max_buffers; }
bool operator==(const CompactionStrategy & rhs) const {
- return _maxDeadBytesRatio == rhs._maxDeadBytesRatio &&
- _maxDeadAddressSpaceRatio == rhs._maxDeadAddressSpaceRatio;
+ return (_maxDeadBytesRatio == rhs._maxDeadBytesRatio) &&
+ (_maxDeadAddressSpaceRatio == rhs._maxDeadAddressSpaceRatio) &&
+ (_max_buffers == rhs._max_buffers);
}
bool operator!=(const CompactionStrategy & rhs) const { return !(operator==(rhs)); }
