]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/driver/rados/rgw_trim_bilog.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rgw / driver / rados / rgw_trim_bilog.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2017 Red Hat, Inc
8 *
9 * Author: Casey Bodley <cbodley@redhat.com>
10 *
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.
15 */
16
17 #pragma once
18
19 #include <memory>
20 #include <string_view>
21
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"
27
28 class RGWCoroutine;
29 class RGWHTTPManager;
30
31 namespace rgw {
32
33 namespace sal {
34 class RadosStore;
35 }
36
37 /// Interface to inform the trim process about which buckets are most active
38 struct BucketChangeObserver {
39 virtual ~BucketChangeObserver() = default;
40
41 virtual void on_bucket_changed(const std::string_view& bucket_instance) = 0;
42 };
43
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};
64 };
65
66 /// fill out the BucketTrimConfig from the ceph context
67 void configure_bucket_trim(CephContext *cct, BucketTrimConfig& config);
68
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 {
74 class Impl;
75 std::unique_ptr<Impl> impl;
76 public:
77 BucketTrimManager(sal::RadosStore *store, const BucketTrimConfig& config);
78 ~BucketTrimManager();
79
80 int init();
81
82 /// increment a counter for the given bucket instance
83 void on_bucket_changed(const std::string_view& bucket_instance) override;
84
85 /// create a coroutine to run the bucket trim process every trim interval
86 RGWCoroutine* create_bucket_trim_cr(RGWHTTPManager *http);
87
88 /// create a coroutine to trim buckets directly via radosgw-admin
89 RGWCoroutine* create_admin_bucket_trim_cr(RGWHTTPManager *http);
90
91 CephContext *get_cct() const override;
92 unsigned get_subsys() const;
93 std::ostream& gen_prefix(std::ostream& out) const;
94 };
95
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
100
101 void encode(bufferlist& bl) const {
102 ENCODE_START(1, 1, bl);
103 encode(marker, bl);
104 ENCODE_FINISH(bl);
105 }
106 void decode(bufferlist::const_iterator& p) {
107 DECODE_START(1, p);
108 decode(marker, p);
109 DECODE_FINISH(p);
110 }
111
112 static const std::string oid;
113 };
114
115 } // namespace rgw
116
117 WRITE_CLASS_ENCODER(rgw::BucketTrimStatus);
118
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);