]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_sal_store.h
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / rgw / rgw_sal_store.h
CommitLineData
1e59de90
TL
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) 2022 Red Hat, Inc.
8 *
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
13 *
14 */
15
16#pragma once
17
18#include "rgw_sal.h"
19
20namespace rgw { namespace sal {
21
22class StoreDriver : public Driver {
23 public:
24 StoreDriver() {}
25 virtual ~StoreDriver() = default;
26
27 virtual uint64_t get_new_req_id() override {
28 return ceph::util::generate_random_number<uint64_t>();
29 }
30
31 int read_topics(const std::string& tenant, rgw_pubsub_topics& topics, RGWObjVersionTracker* objv_tracker,
32 optional_yield y, const DoutPrefixProvider *dpp) override {return -EOPNOTSUPP;}
33 int write_topics(const std::string& tenant, const rgw_pubsub_topics& topics, RGWObjVersionTracker* objv_tracker,
34 optional_yield y, const DoutPrefixProvider *dpp) override {return -ENOENT;}
35 int remove_topics(const std::string& tenant, RGWObjVersionTracker* objv_tracker,
36 optional_yield y, const DoutPrefixProvider *dpp) override {return -ENOENT;}
37};
38
39class StoreUser : public User {
40 protected:
41 RGWUserInfo info;
42 RGWObjVersionTracker objv_tracker;
43 Attrs attrs;
44
45 public:
46 StoreUser() : info() {}
47 StoreUser(const rgw_user& _u) : info() { info.user_id = _u; }
48 StoreUser(const RGWUserInfo& _i) : info(_i) {}
49 StoreUser(StoreUser& _o) = default;
50 virtual ~StoreUser() = default;
51
52 virtual std::string& get_display_name() override { return info.display_name; }
53 virtual const std::string& get_tenant() override { return info.user_id.tenant; }
54 virtual void set_tenant(std::string& _t) override { info.user_id.tenant = _t; }
55 virtual const std::string& get_ns() override { return info.user_id.ns; }
56 virtual void set_ns(std::string& _ns) override { info.user_id.ns = _ns; }
57 virtual void clear_ns() override { info.user_id.ns.clear(); }
58 virtual const rgw_user& get_id() const override { return info.user_id; }
59 virtual uint32_t get_type() const override { return info.type; }
60 virtual int32_t get_max_buckets() const override { return info.max_buckets; }
61 virtual const RGWUserCaps& get_caps() const override { return info.caps; }
62 virtual RGWObjVersionTracker& get_version_tracker() override { return objv_tracker; }
63 virtual Attrs& get_attrs() override { return attrs; }
64 virtual void set_attrs(Attrs& _attrs) override { attrs = _attrs; }
65 virtual bool empty() const override { return info.user_id.id.empty(); }
66 virtual RGWUserInfo& get_info() override { return info; }
67 virtual void print(std::ostream& out) const override { out << info.user_id; }
68
69 friend class StoreBucket;
70};
71
72class StoreBucket : public Bucket {
73 protected:
74 RGWBucketEnt ent;
75 RGWBucketInfo info;
76 User* owner = nullptr;
77 Attrs attrs;
78 obj_version bucket_version;
79 ceph::real_time mtime;
80
81 public:
82
83 StoreBucket() = default;
84 StoreBucket(User* _u) :
85 owner(_u) { }
86 StoreBucket(const rgw_bucket& _b) { ent.bucket = _b; info.bucket = _b; }
87 StoreBucket(const RGWBucketEnt& _e) : ent(_e) {
88 info.bucket = ent.bucket;
89 info.placement_rule = ent.placement_rule;
90 info.creation_time = ent.creation_time;
91 }
92 StoreBucket(const RGWBucketInfo& _i) : info(_i) {
93 ent.bucket = info.bucket;
94 ent.placement_rule = info.placement_rule;
95 ent.creation_time = info.creation_time;
96 }
97 StoreBucket(const rgw_bucket& _b, User* _u) :
98 owner(_u) { ent.bucket = _b; info.bucket = _b; }
99 StoreBucket(const RGWBucketEnt& _e, User* _u) : ent(_e), owner(_u) {
100 info.bucket = ent.bucket;
101 info.placement_rule = ent.placement_rule;
102 info.creation_time = ent.creation_time;
103 }
104 StoreBucket(const RGWBucketInfo& _i, User* _u) : info(_i), owner(_u) {
105 ent.bucket = info.bucket;
106 ent.placement_rule = info.placement_rule;
107 ent.creation_time = info.creation_time;
108 }
109 virtual ~StoreBucket() = default;
110
111 virtual Attrs& get_attrs(void) override { return attrs; }
112 virtual int set_attrs(Attrs a) override { attrs = a; return 0; }
113 virtual void set_owner(rgw::sal::User* _owner) override {
114 owner = _owner;
115 }
116 virtual User* get_owner(void) override { return owner; };
117 virtual ACLOwner get_acl_owner(void) override { return ACLOwner(info.owner); };
118 virtual bool empty() const override { return info.bucket.name.empty(); }
119 virtual const std::string& get_name() const override { return info.bucket.name; }
120 virtual const std::string& get_tenant() const override { return info.bucket.tenant; }
121 virtual const std::string& get_marker() const override { return info.bucket.marker; }
122 virtual const std::string& get_bucket_id() const override { return info.bucket.bucket_id; }
123 virtual size_t get_size() const override { return ent.size; }
124 virtual size_t get_size_rounded() const override { return ent.size_rounded; }
125 virtual uint64_t get_count() const override { return ent.count; }
126 virtual rgw_placement_rule& get_placement_rule() override { return info.placement_rule; }
127 virtual ceph::real_time& get_creation_time() override { return info.creation_time; }
128 virtual ceph::real_time& get_modification_time() override { return mtime; }
129 virtual obj_version& get_version() override { return bucket_version; }
130 virtual void set_version(obj_version &ver) override { bucket_version = ver; }
131 virtual bool versioned() override { return info.versioned(); }
132 virtual bool versioning_enabled() override { return info.versioning_enabled(); }
133 virtual rgw_bucket& get_key() override { return info.bucket; }
134 virtual RGWBucketInfo& get_info() override { return info; }
135 virtual void print(std::ostream& out) const override { out << info.bucket; }
136 virtual bool operator==(const Bucket& b) const override {
137 if (typeid(*this) != typeid(b)) {
138 return false;
139 }
140 const StoreBucket& sb = dynamic_cast<const StoreBucket&>(b);
141
142 return (info.bucket.tenant == sb.info.bucket.tenant) &&
143 (info.bucket.name == sb.info.bucket.name) &&
144 (info.bucket.bucket_id == sb.info.bucket.bucket_id);
145 }
146 virtual bool operator!=(const Bucket& b) const override {
147 if (typeid(*this) != typeid(b)) {
148 return false;
149 }
150 const StoreBucket& sb = dynamic_cast<const StoreBucket&>(b);
151
152 return (info.bucket.tenant != sb.info.bucket.tenant) ||
153 (info.bucket.name != sb.info.bucket.name) ||
154 (info.bucket.bucket_id != sb.info.bucket.bucket_id);
155 }
156
157 int read_topics(rgw_pubsub_bucket_topics& notifications, RGWObjVersionTracker* objv_tracker,
158 optional_yield y, const DoutPrefixProvider *dpp) override {return 0;}
159 int write_topics(const rgw_pubsub_bucket_topics& notifications, RGWObjVersionTracker* objv_tracker,
160 optional_yield y, const DoutPrefixProvider *dpp) override {return 0;}
161 int remove_topics(RGWObjVersionTracker* objv_tracker,
162 optional_yield y, const DoutPrefixProvider *dpp) override {return 0;}
163
164 friend class BucketList;
165 protected:
166 virtual void set_ent(RGWBucketEnt& _ent) { ent = _ent; info.bucket = ent.bucket; info.placement_rule = ent.placement_rule; }
167};
168
169class StoreObject : public Object {
170 protected:
171 RGWObjState state;
172 Bucket* bucket = nullptr;
173 bool delete_marker{false};
174
175 public:
176 StoreObject() = default;
177 StoreObject(const rgw_obj_key& _k)
178 { state.obj.key = _k; }
179 StoreObject(const rgw_obj_key& _k, Bucket* _b)
180 : bucket(_b)
181 { state.obj.init(_b->get_key(), _k); }
182 StoreObject(const StoreObject& _o) = default;
183
184 virtual ~StoreObject() = default;
185
186 virtual void set_atomic() override { state.is_atomic = true; }
187 virtual bool is_atomic() override { return state.is_atomic; }
188 virtual void set_prefetch_data() override { state.prefetch_data = true; }
189 virtual bool is_prefetch_data() override { return state.prefetch_data; }
190 virtual void set_compressed() override { state.compressed = true; }
191 virtual bool is_compressed() override { return state.compressed; }
192 virtual void invalidate() override {
193 rgw_obj obj = state.obj;
194 bool is_atomic = state.is_atomic;
195 bool prefetch_data = state.prefetch_data;
196 bool compressed = state.compressed;
197
198 state = RGWObjState();
199 state.obj = obj;
200 state.is_atomic = is_atomic;
201 state.prefetch_data = prefetch_data;
202 state.compressed = compressed;
203 }
204
205 virtual bool empty() const override { return state.obj.empty(); }
206 virtual const std::string &get_name() const override { return state.obj.key.name; }
207 virtual Attrs& get_attrs(void) override { return state.attrset; }
208 virtual const Attrs& get_attrs(void) const override { return state.attrset; }
209 virtual int set_attrs(Attrs a) override { state.attrset = a; state.has_attrs = true; return 0; }
210 virtual bool has_attrs(void) override { return state.has_attrs; }
211 virtual ceph::real_time get_mtime(void) const override { return state.mtime; }
212 virtual uint64_t get_obj_size(void) const override { return state.size; }
213 virtual Bucket* get_bucket(void) const override { return bucket; }
214 virtual void set_bucket(Bucket* b) override { bucket = b; state.obj.bucket = b->get_key(); }
215 virtual std::string get_hash_source(void) override { return state.obj.index_hash_source; }
216 virtual void set_hash_source(std::string s) override { state.obj.index_hash_source = s; }
217 virtual std::string get_oid(void) const override { return state.obj.key.get_oid(); }
218 virtual bool get_delete_marker(void) override { return delete_marker; }
219 virtual bool get_in_extra_data(void) override { return state.obj.is_in_extra_data(); }
220 virtual void set_in_extra_data(bool i) override { state.obj.set_in_extra_data(i); }
221 int range_to_ofs(uint64_t obj_size, int64_t &ofs, int64_t &end);
222 virtual void set_obj_size(uint64_t s) override { state.size = s; }
223 virtual void set_name(const std::string& n) override { state.obj.key = n; }
224 virtual void set_key(const rgw_obj_key& k) override { state.obj.key = k; }
225 virtual rgw_obj get_obj(void) const override { return state.obj; }
226 virtual rgw_obj_key& get_key() override { return state.obj.key; }
227 virtual void set_instance(const std::string &i) override { state.obj.key.set_instance(i); }
228 virtual const std::string &get_instance() const override { return state.obj.key.instance; }
229 virtual bool have_instance(void) override { return state.obj.key.have_instance(); }
230 virtual void clear_instance() override { state.obj.key.instance.clear(); }
231 virtual int transition_to_cloud(Bucket* bucket,
232 rgw::sal::PlacementTier* tier,
233 rgw_bucket_dir_entry& o,
234 std::set<std::string>& cloud_targets,
235 CephContext* cct,
236 bool update_object,
237 const DoutPrefixProvider* dpp,
238 optional_yield y) override {
239 /* Return failure here, so stores which don't transition to cloud will
240 * work with lifecycle */
241 return -1;
242 }
243
244 virtual void print(std::ostream& out) const override {
245 if (bucket)
246 out << bucket << ":";
247 out << state.obj.key;
248 }
249};
250
251class StoreMultipartPart : public MultipartPart {
252 protected:
253 std::string oid;
254public:
255 StoreMultipartPart() = default;
256 virtual ~StoreMultipartPart() = default;
257};
258
259class StoreMultipartUpload : public MultipartUpload {
260protected:
261 Bucket* bucket;
262 std::map<uint32_t, std::unique_ptr<MultipartPart>> parts;
263 jspan_context trace_ctx{false, false};
264public:
265 StoreMultipartUpload(Bucket* _bucket) : bucket(_bucket) {}
266 virtual ~StoreMultipartUpload() = default;
267
268 virtual std::map<uint32_t, std::unique_ptr<MultipartPart>>& get_parts() override { return parts; }
269
270 virtual const jspan_context& get_trace() override { return trace_ctx; }
271
272 virtual void print(std::ostream& out) const override {
273 out << get_meta();
274 if (!get_upload_id().empty())
275 out << ":" << get_upload_id();
276 }
277};
278
279class StoreMPSerializer : public MPSerializer {
280protected:
281 bool locked;
282 std::string oid;
283public:
284 StoreMPSerializer() : locked(false) {}
285 StoreMPSerializer(std::string _oid) : locked(false), oid(_oid) {}
286 virtual ~StoreMPSerializer() = default;
287
288 virtual void clear_locked() override {
289 locked = false;
290 }
291 virtual bool is_locked() override { return locked; }
292
293 virtual void print(std::ostream& out) const override { out << oid; }
294};
295
296class StoreLCSerializer : public LCSerializer {
297protected:
298 std::string oid;
299public:
300 StoreLCSerializer() {}
301 StoreLCSerializer(std::string _oid) : oid(_oid) {}
302 virtual ~StoreLCSerializer() = default;
303
304 virtual void print(std::ostream& out) const override { out << oid; }
305};
306
307class StoreLifecycle : public Lifecycle {
308public:
309 struct StoreLCHead : LCHead {
310 time_t start_date{0};
311 time_t shard_rollover_date{0};
312 std::string marker;
313
314 StoreLCHead() = default;
315 StoreLCHead(time_t _start_date, time_t _rollover_date, std::string& _marker) : start_date(_start_date), shard_rollover_date(_rollover_date), marker(_marker) {}
316
317 StoreLCHead& operator=(LCHead& _h) {
318 start_date = _h.get_start_date();
319 shard_rollover_date = _h.get_shard_rollover_date();
320 marker = _h.get_marker();
321
322 return *this;
323 }
324
325 virtual time_t& get_start_date() override { return start_date; }
326 virtual void set_start_date(time_t _date) override { start_date = _date; }
327 virtual std::string& get_marker() override { return marker; }
328 virtual void set_marker(const std::string& _marker) override { marker = _marker; }
329 virtual time_t& get_shard_rollover_date() override { return shard_rollover_date; }
330 virtual void set_shard_rollover_date(time_t _date) override { shard_rollover_date = _date; }
331 };
332
333 struct StoreLCEntry : LCEntry {
334 std::string bucket;
335 std::string oid;
336 uint64_t start_time{0};
337 uint32_t status{0};
338
339 StoreLCEntry() = default;
340 StoreLCEntry(std::string& _bucket, uint64_t _time, uint32_t _status) : bucket(_bucket), start_time(_time), status(_status) {}
341 StoreLCEntry(std::string& _bucket, std::string _oid, uint64_t _time, uint32_t _status) : bucket(_bucket), oid(_oid), start_time(_time), status(_status) {}
342 StoreLCEntry(const StoreLCEntry& _e) = default;
343
344 StoreLCEntry& operator=(LCEntry& _e) {
345 bucket = _e.get_bucket();
346 oid = _e.get_oid();
347 start_time = _e.get_start_time();
348 status = _e.get_status();
349
350 return *this;
351 }
352
353 virtual std::string& get_bucket() override { return bucket; }
354 virtual void set_bucket(const std::string& _bucket) override { bucket = _bucket; }
355 virtual std::string& get_oid() override { return oid; }
356 virtual void set_oid(const std::string& _oid) override { oid = _oid; }
357 virtual uint64_t get_start_time() override { return start_time; }
358 virtual void set_start_time(uint64_t _time) override { start_time = _time; }
359 virtual uint32_t get_status() override { return status; }
360 virtual void set_status(uint32_t _status) override { status = _status; }
361 virtual void print(std::ostream& out) const override {
362 out << bucket << ":" << oid << ":" << start_time << ":" << status;
363 }
364 };
365
366 StoreLifecycle() = default;
367 virtual ~StoreLifecycle() = default;
368
369 virtual std::unique_ptr<LCEntry> get_entry() override {
370 return std::make_unique<StoreLCEntry>();
371 }
372 using Lifecycle::get_entry;
373};
374
375class StoreNotification : public Notification {
376protected:
377 Object* obj;
378 Object* src_obj;
379 rgw::notify::EventType event_type;
380
381 public:
382 StoreNotification(Object* _obj, Object* _src_obj, rgw::notify::EventType _type)
383 : obj(_obj), src_obj(_src_obj), event_type(_type)
384 {}
385
386 virtual ~StoreNotification() = default;
387};
388
389class StoreWriter : public Writer {
390protected:
391 const DoutPrefixProvider* dpp;
392
393public:
394 StoreWriter(const DoutPrefixProvider *_dpp, optional_yield y) : dpp(_dpp) {}
395 virtual ~StoreWriter() = default;
396
397};
398
399class StorePlacementTier : public PlacementTier {
400public:
401 virtual ~StorePlacementTier() = default;
402};
403
404class StoreZoneGroup : public ZoneGroup {
405public:
406 virtual ~StoreZoneGroup() = default;
407};
408
409class StoreZone : public Zone {
410 public:
411 virtual ~StoreZone() = default;
412};
413
414class StoreLuaManager : public LuaManager {
415public:
416 virtual ~StoreLuaManager() = default;
417};
418
419} } // namespace rgw::sal