1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2017 Red Hat, Inc
9 * Author: Casey Bodley <cbodley@redhat.com>
11 * This is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License version 2.1, as published by the Free Software
14 * Foundation. See file COPYING.
17 #ifndef RGW_SYNC_LOG_TRIM_H
18 #define RGW_SYNC_LOG_TRIM_H
21 #include <boost/utility/string_view.hpp>
22 #include "include/common_fwd.h"
23 #include "include/encoding.h"
24 #include "common/ceph_time.h"
35 /// Interface to inform the trim process about which buckets are most active
36 struct BucketChangeObserver
{
37 virtual ~BucketChangeObserver() = default;
39 virtual void on_bucket_changed(const boost::string_view
& bucket_instance
) = 0;
42 /// Configuration for BucketTrimManager
43 struct BucketTrimConfig
{
44 /// time interval in seconds between bucket trim attempts
45 uint32_t trim_interval_sec
{0};
46 /// maximum number of buckets to track with BucketChangeObserver
47 size_t counter_size
{0};
48 /// maximum number of buckets to process each trim interval
49 uint32_t buckets_per_interval
{0};
50 /// minimum number of buckets to choose from the global bucket instance list
51 uint32_t min_cold_buckets_per_interval
{0};
52 /// maximum number of buckets to process in parallel
53 uint32_t concurrent_buckets
{0};
54 /// timeout in ms for bucket trim notify replies
55 uint64_t notify_timeout_ms
{0};
56 /// maximum number of recently trimmed buckets to remember (should be small
57 /// enough for a linear search)
58 size_t recent_size
{0};
59 /// maximum duration to consider a trim as 'recent' (should be some multiple
60 /// of the trim interval, at least)
61 ceph::timespan recent_duration
{0};
64 /// fill out the BucketTrimConfig from the ceph context
65 void configure_bucket_trim(CephContext
*cct
, BucketTrimConfig
& config
);
67 /// Determines the buckets on which to focus trim activity, using two sources of
68 /// input: the frequency of entries read from the data changes log, and a global
69 /// listing of the bucket.instance metadata. This allows us to trim active
70 /// buckets quickly, while also ensuring that all buckets will eventually trim
71 class BucketTrimManager
: public BucketChangeObserver
{
73 std::unique_ptr
<Impl
> impl
;
75 BucketTrimManager(sal::RGWRadosStore
*store
, const BucketTrimConfig
& config
);
80 /// increment a counter for the given bucket instance
81 void on_bucket_changed(const boost::string_view
& bucket_instance
) override
;
83 /// create a coroutine to run the bucket trim process every trim interval
84 RGWCoroutine
* create_bucket_trim_cr(RGWHTTPManager
*http
);
86 /// create a coroutine to trim buckets directly via radosgw-admin
87 RGWCoroutine
* create_admin_bucket_trim_cr(RGWHTTPManager
*http
);
90 /// provides persistent storage for the trim manager's current position in the
91 /// list of bucket instance metadata
92 struct BucketTrimStatus
{
93 std::string marker
; //< metadata key of current bucket instance
95 void encode(bufferlist
& bl
) const {
96 ENCODE_START(1, 1, bl
);
100 void decode(bufferlist::const_iterator
& p
) {
106 static const std::string oid
;
111 WRITE_CLASS_ENCODER(rgw::BucketTrimStatus
);
113 #endif // RGW_SYNC_LOG_TRIM_H