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.
20 #include <string_view>
22 #include "include/common_fwd.h"
23 #include "include/encoding.h"
24 #include "common/ceph_time.h"
25 #include "common/dout.h"
26 #include "rgw_common.h"
37 /// Interface to inform the trim process about which buckets are most active
38 struct BucketChangeObserver
{
39 virtual ~BucketChangeObserver() = default;
41 virtual void on_bucket_changed(const std::string_view
& bucket_instance
) = 0;
44 /// Configuration for BucketTrimManager
45 struct BucketTrimConfig
{
46 /// time interval in seconds between bucket trim attempts
47 uint32_t trim_interval_sec
{0};
48 /// maximum number of buckets to track with BucketChangeObserver
49 size_t counter_size
{0};
50 /// maximum number of buckets to process each trim interval
51 uint32_t buckets_per_interval
{0};
52 /// minimum number of buckets to choose from the global bucket instance list
53 uint32_t min_cold_buckets_per_interval
{0};
54 /// maximum number of buckets to process in parallel
55 uint32_t concurrent_buckets
{0};
56 /// timeout in ms for bucket trim notify replies
57 uint64_t notify_timeout_ms
{0};
58 /// maximum number of recently trimmed buckets to remember (should be small
59 /// enough for a linear search)
60 size_t recent_size
{0};
61 /// maximum duration to consider a trim as 'recent' (should be some multiple
62 /// of the trim interval, at least)
63 ceph::timespan recent_duration
{0};
66 /// fill out the BucketTrimConfig from the ceph context
67 void configure_bucket_trim(CephContext
*cct
, BucketTrimConfig
& config
);
69 /// Determines the buckets on which to focus trim activity, using two sources of
70 /// input: the frequency of entries read from the data changes log, and a global
71 /// listing of the bucket.instance metadata. This allows us to trim active
72 /// buckets quickly, while also ensuring that all buckets will eventually trim
73 class BucketTrimManager
: public BucketChangeObserver
, public DoutPrefixProvider
{
75 std::unique_ptr
<Impl
> impl
;
77 BucketTrimManager(sal::RadosStore
*store
, const BucketTrimConfig
& config
);
82 /// increment a counter for the given bucket instance
83 void on_bucket_changed(const std::string_view
& bucket_instance
) override
;
85 /// create a coroutine to run the bucket trim process every trim interval
86 RGWCoroutine
* create_bucket_trim_cr(RGWHTTPManager
*http
);
88 /// create a coroutine to trim buckets directly via radosgw-admin
89 RGWCoroutine
* create_admin_bucket_trim_cr(RGWHTTPManager
*http
);
91 CephContext
*get_cct() const override
;
92 unsigned get_subsys() const;
93 std::ostream
& gen_prefix(std::ostream
& out
) const;
96 /// provides persistent storage for the trim manager's current position in the
97 /// list of bucket instance metadata
98 struct BucketTrimStatus
{
99 std::string marker
; //< metadata key of current bucket instance
101 void encode(bufferlist
& bl
) const {
102 ENCODE_START(1, 1, bl
);
106 void decode(bufferlist::const_iterator
& p
) {
112 static const std::string oid
;
117 WRITE_CLASS_ENCODER(rgw::BucketTrimStatus
);
119 int bilog_trim(const DoutPrefixProvider
* p
, rgw::sal::RadosStore
* store
,
120 RGWBucketInfo
& bucket_info
, uint64_t gen
, int shard_id
,
121 std::string_view start_marker
, std::string_view end_marker
);