1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
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"
17 class RGWBucketReshard
{
18 friend class RGWReshard
;
21 RGWBucketInfo bucket_info
;
22 std::map
<string
, bufferlist
> bucket_attrs
;
25 rados::cls::lock::Lock reshard_lock
;
29 int set_resharding_status(const string
& new_instance_id
, int32_t num_shards
, cls_rgw_reshard_status status
);
30 int clear_resharding();
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
,
38 Formatter
*formatter
);
40 RGWBucketReshard(RGWRados
*_store
, const RGWBucketInfo
& _bucket_info
,
41 const std::map
<string
, bufferlist
>& _bucket_attrs
);
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);
48 int get_status(std::list
<cls_rgw_bucket_instance_entry
> *status
);
54 rados::cls::lock::Lock instance_lock
;
61 void get_logshard_oid(int shard_num
, string
*shard
);
63 class ReshardWorker
: public Thread
{
70 ReshardWorker(CephContext
* const _cct
,
71 RGWReshard
* const _reshard
)
74 lock("ReshardWorker") {
77 void *entry() override
;
81 ReshardWorker
*worker
= nullptr;
82 std::atomic
<bool> down_flag
= { false };
84 string
get_logshard_key(const string
& tenant
, const string
& bucket_name
);
85 void get_bucket_logshard_oid(const string
& tenant
, const string
& bucket_name
, string
*oid
);
88 RGWReshard(RGWRados
* _store
, bool _verbose
= false, ostream
*_out
= nullptr, Formatter
*_formatter
= nullptr);
89 int add(cls_rgw_reshard_entry
& entry
);
90 int update(const RGWBucketInfo
& bucket_info
, const RGWBucketInfo
& new_bucket_info
);
91 int get(cls_rgw_reshard_entry
& entry
);
92 int remove(cls_rgw_reshard_entry
& entry
);
93 int list(int logshard_num
, string
& marker
, uint32_t max
, std::list
<cls_rgw_reshard_entry
>& entries
, bool *is_truncated
);
94 int clear_bucket_resharding(const string
& bucket_instance_oid
, cls_rgw_reshard_entry
& entry
);
97 int process_single_logshard(int logshard_num
);
98 int process_all_logshards();
100 void start_processor();
101 void stop_processor();
105 class RGWReshardWait
{
107 Mutex lock
{"RGWReshardWait::lock"};
110 bool going_down
{false};
114 RGWReshardWait(RGWRados
*_store
) : store(_store
) {}
118 int block_while_resharding(RGWRados::BucketShard
*bs
, string
*new_bucket_id
);
121 Mutex::Locker
l(lock
);