Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / rgw / rgw_object_expirer_core.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 CEPH_OBJEXP_H
5 #define CEPH_OBJEXP_H
6
7 #include <atomic>
8 #include <string>
9 #include <cerrno>
10 #include <sstream>
11 #include <iostream>
12
13 #include "auth/Crypto.h"
14
15 #include "common/armor.h"
16 #include "common/ceph_json.h"
17 #include "common/config.h"
18 #include "common/ceph_argparse.h"
19 #include "common/Formatter.h"
20 #include "common/errno.h"
21
22 #include "common/Mutex.h"
23 #include "common/Cond.h"
24 #include "common/Thread.h"
25
26 #include "global/global_init.h"
27
28 #include "include/utime.h"
29 #include "include/str_list.h"
30
31 #include "rgw_user.h"
32 #include "rgw_bucket.h"
33 #include "rgw_rados.h"
34 #include "rgw_acl.h"
35 #include "rgw_acl_s3.h"
36 #include "rgw_log.h"
37 #include "rgw_formats.h"
38 #include "rgw_usage.h"
39 #include "rgw_replica_log.h"
40
41 class RGWObjectExpirer {
42 protected:
43   RGWRados *store;
44
45   int init_bucket_info(const std::string& tenant_name,
46                        const std::string& bucket_name,
47                        const std::string& bucket_id,
48                        RGWBucketInfo& bucket_info);
49
50   class OEWorker : public Thread {
51     CephContext *cct;
52     RGWObjectExpirer *oe;
53     Mutex lock;
54     Cond cond;
55
56   public:
57     OEWorker(CephContext * const cct,
58              RGWObjectExpirer * const oe)
59       : cct(cct),
60         oe(oe),
61         lock("OEWorker") {
62     }
63
64     void *entry() override;
65     void stop();
66   };
67
68   OEWorker *worker{nullptr};
69   std::atomic<bool> down_flag = { false };
70
71 public:
72   explicit RGWObjectExpirer(RGWRados *_store)
73     : store(_store), worker(NULL) {
74   }
75   ~RGWObjectExpirer() {
76     stop_processor();
77   }
78
79   int garbage_single_object(objexp_hint_entry& hint);
80
81   void garbage_chunk(std::list<cls_timeindex_entry>& entries, /* in  */
82                      bool& need_trim);                        /* out */
83
84   void trim_chunk(const std::string& shard,
85                   const utime_t& from,
86                   const utime_t& to,
87                   const string& from_marker,
88                   const string& to_marker);
89
90   bool process_single_shard(const std::string& shard,
91                             const utime_t& last_run,
92                             const utime_t& round_start);
93
94   bool inspect_all_shards(const utime_t& last_run,
95                           const utime_t& round_start);
96
97   bool going_down();
98   void start_processor();
99   void stop_processor();
100 };
101 #endif /* CEPH_OBJEXP_H */