]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_reshard.h
6fe43129906f0fdd642d37594c3895a693a7d076
[ceph.git] / ceph / src / rgw / rgw_reshard.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef RGW_RESHARD_H
5 #define RGW_RESHARD_H
6
7 #include <vector>
8 #include "include/rados/librados.hpp"
9 #include "cls/rgw/cls_rgw_types.h"
10 #include "cls/lock/cls_lock_client.h"
11 #include "rgw_bucket.h"
12
13 class CephContext;
14 class RGWRados;
15
16
17 class RGWBucketReshard {
18 friend class RGWReshard;
19
20 RGWRados *store;
21 RGWBucketInfo bucket_info;
22 std::map<string, bufferlist> bucket_attrs;
23
24 string reshard_oid;
25 rados::cls::lock::Lock reshard_lock;
26
27 int lock_bucket();
28 void unlock_bucket();
29 int set_resharding_status(const string& new_instance_id, int32_t num_shards, cls_rgw_reshard_status status);
30 int clear_resharding();
31
32 int create_new_bucket_instance(int new_num_shards, RGWBucketInfo& new_bucket_info);
33 int do_reshard(int num_shards,
34 RGWBucketInfo& new_bucket_info,
35 int max_entries,
36 bool verbose,
37 ostream *os,
38 Formatter *formatter);
39 public:
40 RGWBucketReshard(RGWRados *_store, const RGWBucketInfo& _bucket_info,
41 const std::map<string, bufferlist>& _bucket_attrs);
42
43 int execute(int num_shards, int max_op_entries,
44 bool verbose = false, ostream *out = nullptr,
45 Formatter *formatter = nullptr,
46 RGWReshard *reshard_log = nullptr);
47 int abort();
48 int get_status(std::list<cls_rgw_bucket_instance_entry> *status);
49 int cancel();
50 };
51
52 class RGWReshard {
53 RGWRados *store;
54 string lock_name;
55 rados::cls::lock::Lock instance_lock;
56 int num_logshards;
57
58 bool verbose;
59 ostream *out;
60 Formatter *formatter;
61
62 void get_logshard_oid(int shard_num, string *shard);
63 protected:
64 class ReshardWorker : public Thread {
65 CephContext *cct;
66 RGWReshard *reshard;
67 Mutex lock;
68 Cond cond;
69
70 public:
71 ReshardWorker(CephContext * const _cct,
72 RGWReshard * const _reshard)
73 : cct(_cct),
74 reshard(_reshard),
75 lock("ReshardWorker") {
76 }
77
78 void *entry() override;
79 void stop();
80 };
81
82 ReshardWorker *worker = nullptr;
83 std::atomic<bool> down_flag = { false };
84
85 string get_logshard_key(const string& tenant, const string& bucket_name);
86 void get_bucket_logshard_oid(const string& tenant, const string& bucket_name, string *oid);
87
88 public:
89 RGWReshard(RGWRados* _store, bool _verbose = false, ostream *_out = nullptr, Formatter *_formatter = nullptr);
90 int add(cls_rgw_reshard_entry& entry);
91 int update(const RGWBucketInfo& bucket_info, const RGWBucketInfo& new_bucket_info);
92 int get(cls_rgw_reshard_entry& entry);
93 int remove(cls_rgw_reshard_entry& entry);
94 int list(int logshard_num, string& marker, uint32_t max, std::list<cls_rgw_reshard_entry>& entries, bool *is_truncated);
95 int clear_bucket_resharding(const string& bucket_instance_oid, cls_rgw_reshard_entry& entry);
96
97 /* reshard thread */
98 int process_single_logshard(int logshard_num);
99 int process_all_logshards();
100 bool going_down();
101 void start_processor();
102 void stop_processor();
103 };
104
105
106 class RGWReshardWait {
107 RGWRados *store;
108 Mutex lock{"RGWReshardWait::lock"};
109 Cond cond;
110
111 bool going_down{false};
112
113 int do_wait();
114 public:
115 RGWReshardWait(RGWRados *_store) : store(_store) {}
116 ~RGWReshardWait() {
117 assert(going_down);
118 }
119 int block_while_resharding(RGWRados::BucketShard *bs, string *new_bucket_id);
120
121 void stop() {
122 Mutex::Locker l(lock);
123 going_down = true;
124 cond.SignalAll();
125 }
126 };
127
128 #endif