* Foundation. See file COPYING.
*/
+#include <mutex>
+
+#include "common/bounded_key_counter.h"
#include "rgw_sync_log_trim.h"
#define dout_subsys ceph_subsys_rgw
#define dout_prefix (*_dout << "trim: ")
using rgw::BucketTrimConfig;
+using BucketChangeCounter = BoundedKeyCounter<std::string, int>;
namespace rgw {
RGWRados *const store;
const BucketTrimConfig config;
+ /// count frequency of bucket instance entries in the data changes log
+ BucketChangeCounter counter;
+
+ /// protect data shared between data sync and trim threads
+ std::mutex mutex;
+
Impl(RGWRados *store, const BucketTrimConfig& config)
- : store(store), config(config)
+ : store(store), config(config),
+ counter(config.counter_size)
{}
};
}
BucketTrimManager::~BucketTrimManager() = default;
+void BucketTrimManager::on_bucket_changed(const boost::string_view& bucket)
+{
+ std::lock_guard<std::mutex> lock(impl->mutex);
+ impl->counter.insert(bucket.to_string());
+}
+
} // namespace rgw
#define RGW_SYNC_LOG_TRIM_H
#include <memory>
+#include <boost/utility/string_view.hpp>
class CephContext;
class RGWRados;
namespace rgw {
+/// Interface to inform the trim process about which buckets are most active
+struct BucketChangeObserver {
+ virtual ~BucketChangeObserver() = default;
+
+ virtual void on_bucket_changed(const boost::string_view& bucket_instance) = 0;
+};
+
/// Configuration for BucketTrimManager
struct BucketTrimConfig {
+ /// maximum number of buckets to track with BucketChangeObserver
+ size_t counter_size{0};
};
/// fill out the BucketTrimConfig from the ceph context
/// input: the frequency of entries read from the data changes log, and a global
/// listing of the bucket.instance metadata. This allows us to trim active
/// buckets quickly, while also ensuring that all buckets will eventually trim
-class BucketTrimManager {
+class BucketTrimManager : public BucketChangeObserver {
class Impl;
std::unique_ptr<Impl> impl;
public:
BucketTrimManager(RGWRados *store, const BucketTrimConfig& config);
~BucketTrimManager();
+
+ /// increment a counter for the given bucket instance
+ void on_bucket_changed(const boost::string_view& bucket_instance) override;
};
} // namespace rgw