]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_trim_bilog.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / rgw / 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 #ifndef RGW_SYNC_LOG_TRIM_H
18 #define RGW_SYNC_LOG_TRIM_H
19
20 #include <memory>
21 #include <boost/utility/string_view.hpp>
22 #include "include/common_fwd.h"
23 #include "include/encoding.h"
24 #include "common/ceph_time.h"
25
26 class RGWCoroutine;
27 class RGWHTTPManager;
28
29 namespace rgw {
30
31 namespace sal {
32 class RGWRadosStore;
33 }
34
35 /// Interface to inform the trim process about which buckets are most active
36 struct BucketChangeObserver {
37 virtual ~BucketChangeObserver() = default;
38
39 virtual void on_bucket_changed(const boost::string_view& bucket_instance) = 0;
40 };
41
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};
62 };
63
64 /// fill out the BucketTrimConfig from the ceph context
65 void configure_bucket_trim(CephContext *cct, BucketTrimConfig& config);
66
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 {
72 class Impl;
73 std::unique_ptr<Impl> impl;
74 public:
75 BucketTrimManager(sal::RGWRadosStore *store, const BucketTrimConfig& config);
76 ~BucketTrimManager();
77
78 int init();
79
80 /// increment a counter for the given bucket instance
81 void on_bucket_changed(const boost::string_view& bucket_instance) override;
82
83 /// create a coroutine to run the bucket trim process every trim interval
84 RGWCoroutine* create_bucket_trim_cr(RGWHTTPManager *http);
85
86 /// create a coroutine to trim buckets directly via radosgw-admin
87 RGWCoroutine* create_admin_bucket_trim_cr(RGWHTTPManager *http);
88 };
89
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
94
95 void encode(bufferlist& bl) const {
96 ENCODE_START(1, 1, bl);
97 encode(marker, bl);
98 ENCODE_FINISH(bl);
99 }
100 void decode(bufferlist::const_iterator& p) {
101 DECODE_START(1, p);
102 decode(marker, p);
103 DECODE_FINISH(p);
104 }
105
106 static const std::string oid;
107 };
108
109 } // namespace rgw
110
111 WRITE_CLASS_ENCODER(rgw::BucketTrimStatus);
112
113 #endif // RGW_SYNC_LOG_TRIM_H