]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_trim_bilog.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / rgw / rgw_trim_bilog.h
CommitLineData
b32b8144 1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
9f95a23c 2// vim: ts=8 sw=2 smarttab ft=cpp
11fdf7f2 3
b32b8144
FG
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>
f67539c2
TL
21#include <string_view>
22
9f95a23c 23#include "include/common_fwd.h"
b32b8144
FG
24#include "include/encoding.h"
25#include "common/ceph_time.h"
26
b32b8144
FG
27class RGWCoroutine;
28class RGWHTTPManager;
b32b8144
FG
29
30namespace rgw {
31
9f95a23c
TL
32namespace sal {
33 class RGWRadosStore;
34}
35
b32b8144
FG
36/// Interface to inform the trim process about which buckets are most active
37struct BucketChangeObserver {
38 virtual ~BucketChangeObserver() = default;
39
f67539c2 40 virtual void on_bucket_changed(const std::string_view& bucket_instance) = 0;
b32b8144
FG
41};
42
43/// Configuration for BucketTrimManager
44struct BucketTrimConfig {
45 /// time interval in seconds between bucket trim attempts
46 uint32_t trim_interval_sec{0};
47 /// maximum number of buckets to track with BucketChangeObserver
48 size_t counter_size{0};
49 /// maximum number of buckets to process each trim interval
50 uint32_t buckets_per_interval{0};
51 /// minimum number of buckets to choose from the global bucket instance list
52 uint32_t min_cold_buckets_per_interval{0};
53 /// maximum number of buckets to process in parallel
54 uint32_t concurrent_buckets{0};
55 /// timeout in ms for bucket trim notify replies
56 uint64_t notify_timeout_ms{0};
57 /// maximum number of recently trimmed buckets to remember (should be small
58 /// enough for a linear search)
59 size_t recent_size{0};
60 /// maximum duration to consider a trim as 'recent' (should be some multiple
61 /// of the trim interval, at least)
62 ceph::timespan recent_duration{0};
63};
64
65/// fill out the BucketTrimConfig from the ceph context
66void configure_bucket_trim(CephContext *cct, BucketTrimConfig& config);
67
68/// Determines the buckets on which to focus trim activity, using two sources of
69/// input: the frequency of entries read from the data changes log, and a global
70/// listing of the bucket.instance metadata. This allows us to trim active
71/// buckets quickly, while also ensuring that all buckets will eventually trim
72class BucketTrimManager : public BucketChangeObserver {
73 class Impl;
74 std::unique_ptr<Impl> impl;
75 public:
9f95a23c 76 BucketTrimManager(sal::RGWRadosStore *store, const BucketTrimConfig& config);
b32b8144
FG
77 ~BucketTrimManager();
78
79 int init();
80
81 /// increment a counter for the given bucket instance
f67539c2 82 void on_bucket_changed(const std::string_view& bucket_instance) override;
b32b8144
FG
83
84 /// create a coroutine to run the bucket trim process every trim interval
85 RGWCoroutine* create_bucket_trim_cr(RGWHTTPManager *http);
86
87 /// create a coroutine to trim buckets directly via radosgw-admin
88 RGWCoroutine* create_admin_bucket_trim_cr(RGWHTTPManager *http);
89};
90
91/// provides persistent storage for the trim manager's current position in the
92/// list of bucket instance metadata
93struct BucketTrimStatus {
94 std::string marker; //< metadata key of current bucket instance
95
96 void encode(bufferlist& bl) const {
97 ENCODE_START(1, 1, bl);
11fdf7f2 98 encode(marker, bl);
b32b8144
FG
99 ENCODE_FINISH(bl);
100 }
11fdf7f2 101 void decode(bufferlist::const_iterator& p) {
b32b8144 102 DECODE_START(1, p);
11fdf7f2 103 decode(marker, p);
b32b8144
FG
104 DECODE_FINISH(p);
105 }
106
107 static const std::string oid;
108};
109
110} // namespace rgw
111
112WRITE_CLASS_ENCODER(rgw::BucketTrimStatus);
113
114#endif // RGW_SYNC_LOG_TRIM_H