summaryrefslogtreecommitdiffstats
path: root/src/rgw/rgw_sal_store.h
blob: 55b43e3d90bda1c795c5534c3bf0bc307b3287e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab ft=cpp

/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2022 Red Hat, Inc.
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation. See file COPYING.
 *
 */

#pragma once

#include "rgw_sal.h"

namespace rgw { namespace sal {

class StoreDriver : public Driver {
  public:
    StoreDriver() {}
    virtual ~StoreDriver() = default;

    virtual uint64_t get_new_req_id() override {
      return ceph::util::generate_random_number<uint64_t>();
    }

    int read_topics(const std::string& tenant, rgw_pubsub_topics& topics, RGWObjVersionTracker* objv_tracker,
        optional_yield y, const DoutPrefixProvider *dpp) override {return -EOPNOTSUPP;}
    int write_topics(const std::string& tenant, const rgw_pubsub_topics& topics, RGWObjVersionTracker* objv_tracker,
	optional_yield y, const DoutPrefixProvider *dpp) override {return -ENOENT;}
    int remove_topics(const std::string& tenant, RGWObjVersionTracker* objv_tracker,
        optional_yield y, const DoutPrefixProvider *dpp) override {return -ENOENT;}
};

class StoreUser : public User {
  protected:
    RGWUserInfo info;
    RGWObjVersionTracker objv_tracker;
    Attrs attrs;

  public:
    StoreUser() : info() {}
    StoreUser(const rgw_user& _u) : info() { info.user_id = _u; }
    StoreUser(const RGWUserInfo& _i) : info(_i) {}
    StoreUser(StoreUser& _o) = default;
    virtual ~StoreUser() = default;

    virtual std::string& get_display_name() override { return info.display_name; }
    virtual const std::string& get_tenant() override { return info.user_id.tenant; }
    virtual void set_tenant(std::string& _t) override { info.user_id.tenant = _t; }
    virtual const std::string& get_ns() override { return info.user_id.ns; }
    virtual void set_ns(std::string& _ns) override { info.user_id.ns = _ns; }
    virtual void clear_ns() override { info.user_id.ns.clear(); }
    virtual const rgw_user& get_id() const override { return info.user_id; }
    virtual uint32_t get_type() const override { return info.type; }
    virtual int32_t get_max_buckets() const override { return info.max_buckets; }
    virtual const RGWUserCaps& get_caps() const override { return info.caps; }
    virtual RGWObjVersionTracker& get_version_tracker() override { return objv_tracker; }
    virtual Attrs& get_attrs() override { return attrs; }
    virtual void set_attrs(Attrs& _attrs) override { attrs = _attrs; }
    virtual bool empty() const override { return info.user_id.id.empty(); }
    virtual RGWUserInfo& get_info() override { return info; }
    virtual void print(std::ostream& out) const override { out << info.user_id; }

    friend class StoreBucket;
};

class StoreBucket : public Bucket {
  protected:
    RGWBucketEnt ent;
    RGWBucketInfo info;
    User* owner = nullptr;
    Attrs attrs;
    obj_version bucket_version;
    ceph::real_time mtime;

  public:

    StoreBucket() = default;
    StoreBucket(User* _u) :
      owner(_u) { }
    StoreBucket(const rgw_bucket& _b) { ent.bucket = _b; info.bucket = _b; }
    StoreBucket(const RGWBucketEnt& _e) : ent(_e) {
      info.bucket = ent.bucket;
      info.placement_rule = ent.placement_rule;
      info.creation_time = ent.creation_time;
    }
    StoreBucket(const RGWBucketInfo& _i) : info(_i) {
      ent.bucket = info.bucket;
      ent.placement_rule = info.placement_rule;
      ent.creation_time = info.creation_time;
    }
    StoreBucket(const rgw_bucket& _b, User* _u) :
      owner(_u) { ent.bucket = _b; info.bucket = _b; }
    StoreBucket(const RGWBucketEnt& _e, User* _u) : ent(_e), owner(_u) {
      info.bucket = ent.bucket;
      info.placement_rule = ent.placement_rule;
      info.creation_time = ent.creation_time;
    }
    StoreBucket(const RGWBucketInfo& _i, User* _u) : info(_i), owner(_u) {
      ent.bucket = info.bucket;
      ent.placement_rule = info.placement_rule;
      ent.creation_time = info.creation_time;
    }
    virtual ~StoreBucket() = default;

    virtual Attrs& get_attrs(void) override { return attrs; }
    virtual int set_attrs(Attrs a) override { attrs = a; return 0; }
    virtual void set_owner(rgw::sal::User* _owner) override {
      owner = _owner;
    }
    virtual User* get_owner(void) override { return owner; };
    virtual ACLOwner get_acl_owner(void) override { return ACLOwner(info.owner); };
    virtual bool empty() const override { return info.bucket.name.empty(); }
    virtual const std::string& get_name() const override { return info.bucket.name; }
    virtual const std::string& get_tenant() const override { return info.bucket.tenant; }
    virtual const std::string& get_marker() const override { return info.bucket.marker; }
    virtual const std::string& get_bucket_id() const override { return info.bucket.bucket_id; }
    virtual size_t get_size() const override { return ent.size; }
    virtual size_t get_size_rounded() const override { return ent.size_rounded; }
    virtual uint64_t get_count() const override { return ent.count; }
    virtual rgw_placement_rule& get_placement_rule() override { return info.placement_rule; }
    virtual ceph::real_time& get_creation_time() override { return info.creation_time; }
    virtual ceph::real_time& get_modification_time() override { return mtime; }
    virtual obj_version& get_version() override { return bucket_version; }
    virtual void set_version(obj_version &ver) override { bucket_version = ver; }
    virtual bool versioned() override { return info.versioned(); }
    virtual bool versioning_enabled() override { return info.versioning_enabled(); }
    virtual rgw_bucket& get_key() override { return info.bucket; }
    virtual RGWBucketInfo& get_info() override { return info; }
    virtual void print(std::ostream& out) const override { out << info.bucket; }
    virtual bool operator==(const Bucket& b) const override {
      if (typeid(*this) != typeid(b)) {
	return false;
      }
      const StoreBucket& sb = dynamic_cast<const StoreBucket&>(b);

      return (info.bucket.tenant == sb.info.bucket.tenant) &&
	     (info.bucket.name == sb.info.bucket.name) &&
	     (info.bucket.bucket_id == sb.info.bucket.bucket_id);
    }
    virtual bool operator!=(const Bucket& b) const override {
      if (typeid(*this) != typeid(b)) {
	return false;
      }
      const StoreBucket& sb = dynamic_cast<const StoreBucket&>(b);

      return (info.bucket.tenant != sb.info.bucket.tenant) ||
	     (info.bucket.name != sb.info.bucket.name) ||
	     (info.bucket.bucket_id != sb.info.bucket.bucket_id);
    }

    int read_topics(rgw_pubsub_bucket_topics& notifications, RGWObjVersionTracker* objv_tracker, 
        optional_yield y, const DoutPrefixProvider *dpp) override {return 0;}
    int write_topics(const rgw_pubsub_bucket_topics& notifications, RGWObjVersionTracker* objv_tracker, 
        optional_yield y, const DoutPrefixProvider *dpp) override {return 0;}
    int remove_topics(RGWObjVersionTracker* objv_tracker, 
        optional_yield y, const DoutPrefixProvider *dpp) override {return 0;}

    friend class BucketList;
  protected:
    virtual void set_ent(RGWBucketEnt& _ent) { ent = _ent; info.bucket = ent.bucket; info.placement_rule = ent.placement_rule; }
};

class StoreObject : public Object {
  protected:
    RGWObjState state;
    Bucket* bucket = nullptr;
    bool delete_marker{false};

  public:
    StoreObject() = default;
    StoreObject(const rgw_obj_key& _k)
    { state.obj.key = _k; }
    StoreObject(const rgw_obj_key& _k, Bucket* _b)
      : bucket(_b)
    { state.obj.init(_b->get_key(), _k); }
    StoreObject(const StoreObject& _o) = default;

    virtual ~StoreObject() = default;

    virtual void set_atomic() override { state.is_atomic = true; }
    virtual bool is_atomic() override { return state.is_atomic; }
    virtual void set_prefetch_data() override { state.prefetch_data = true; }
    virtual bool is_prefetch_data() override { return state.prefetch_data; }
    virtual void set_compressed() override { state.compressed = true; }
    virtual bool is_compressed() override { return state.compressed; }
    virtual void invalidate() override {
      rgw_obj obj = state.obj;
      bool is_atomic = state.is_atomic;
      bool prefetch_data = state.prefetch_data;
      bool compressed = state.compressed;

      state = RGWObjState();
      state.obj = obj;
      state.is_atomic = is_atomic;
      state.prefetch_data = prefetch_data;
      state.compressed = compressed;
    }

    virtual bool empty() const override { return state.obj.empty(); }
    virtual const std::string &get_name() const override { return state.obj.key.name; }
    virtual Attrs& get_attrs(void) override { return state.attrset; }
    virtual const Attrs& get_attrs(void) const override { return state.attrset; }
    virtual int set_attrs(Attrs a) override { state.attrset = a; state.has_attrs = true; return 0; }
    virtual bool has_attrs(void) override { return state.has_attrs; }
    virtual ceph::real_time get_mtime(void) const override { return state.mtime; }
    virtual uint64_t get_obj_size(void) const override { return state.size; }
    virtual Bucket* get_bucket(void) const override { return bucket; }
    virtual void set_bucket(Bucket* b) override { bucket = b; state.obj.bucket = b->get_key(); }
    virtual std::string get_hash_source(void) override { return state.obj.index_hash_source; }
    virtual void set_hash_source(std::string s) override { state.obj.index_hash_source = s; }
    virtual std::string get_oid(void) const override { return state.obj.key.get_oid(); }
    virtual bool get_delete_marker(void) override { return delete_marker; }
    virtual bool get_in_extra_data(void) override { return state.obj.is_in_extra_data(); }
    virtual void set_in_extra_data(bool i) override { state.obj.set_in_extra_data(i); }
    int range_to_ofs(uint64_t obj_size, int64_t &ofs, int64_t &end);
    virtual void set_obj_size(uint64_t s) override { state.size = s; }
    virtual void set_name(const std::string& n) override { state.obj.key = n; }
    virtual void set_key(const rgw_obj_key& k) override { state.obj.key = k; }
    virtual rgw_obj get_obj(void) const override { return state.obj; }
    virtual rgw_obj_key& get_key() override { return state.obj.key; }
    virtual void set_instance(const std::string &i) override { state.obj.key.set_instance(i); }
    virtual const std::string &get_instance() const override { return state.obj.key.instance; }
    virtual bool have_instance(void) override { return state.obj.key.have_instance(); }
    virtual void clear_instance() override { state.obj.key.instance.clear(); }
    virtual int transition_to_cloud(Bucket* bucket,
			   rgw::sal::PlacementTier* tier,
			   rgw_bucket_dir_entry& o,
			   std::set<std::string>& cloud_targets,
			   CephContext* cct,
			   bool update_object,
			   const DoutPrefixProvider* dpp,
			   optional_yield y) override {
      /* Return failure here, so stores which don't transition to cloud will
       * work with lifecycle */
      return -1;
    }

    virtual void print(std::ostream& out) const override {
      if (bucket)
	out << bucket << ":";
      out << state.obj.key;
    }
};

class StoreMultipartPart : public MultipartPart {
  protected:
    std::string oid;
public:
  StoreMultipartPart() = default;
  virtual ~StoreMultipartPart() = default;
};

class StoreMultipartUpload : public MultipartUpload {
protected:
  Bucket* bucket;
  std::map<uint32_t, std::unique_ptr<MultipartPart>> parts;
  jspan_context trace_ctx{false, false};
public:
  StoreMultipartUpload(Bucket* _bucket) : bucket(_bucket) {}
  virtual ~StoreMultipartUpload() = default;

  virtual std::map<uint32_t, std::unique_ptr<MultipartPart>>& get_parts() override { return parts; }

  virtual const jspan_context& get_trace() override { return trace_ctx; }

  virtual void print(std::ostream& out) const override {
    out << get_meta();
    if (!get_upload_id().empty())
      out << ":" << get_upload_id();
  }
};

class StoreMPSerializer : public MPSerializer {
protected:
  bool locked;
  std::string oid;
public:
  StoreMPSerializer() : locked(false) {}
  StoreMPSerializer(std::string _oid) : locked(false), oid(_oid) {}
  virtual ~StoreMPSerializer() = default;

  virtual void clear_locked() override {
    locked = false;
  }
  virtual bool is_locked() override { return locked; }

  virtual void print(std::ostream& out) const override { out << oid; }
};

class StoreLCSerializer : public LCSerializer {
protected:
  std::string oid;
public:
  StoreLCSerializer() {}
  StoreLCSerializer(std::string _oid) : oid(_oid) {}
  virtual ~StoreLCSerializer() = default;

  virtual void print(std::ostream& out) const override { out << oid; }
};

class StoreLifecycle : public Lifecycle {
public:
  struct StoreLCHead : LCHead {
    time_t start_date{0};
    time_t shard_rollover_date{0};
    std::string marker;

    StoreLCHead() = default;
    StoreLCHead(time_t _start_date, time_t _rollover_date, std::string& _marker) : start_date(_start_date), shard_rollover_date(_rollover_date), marker(_marker) {}

    StoreLCHead& operator=(LCHead& _h) {
      start_date = _h.get_start_date();
      shard_rollover_date = _h.get_shard_rollover_date();
      marker = _h.get_marker();

      return *this;
    }

    virtual time_t& get_start_date() override { return start_date; }
    virtual void set_start_date(time_t _date) override { start_date = _date; }
    virtual std::string& get_marker() override { return marker; }
    virtual void set_marker(const std::string& _marker) override { marker = _marker; }
    virtual time_t& get_shard_rollover_date() override { return shard_rollover_date; }
    virtual void set_shard_rollover_date(time_t _date) override { shard_rollover_date = _date; }
  };

  struct StoreLCEntry : LCEntry {
    std::string bucket;
    std::string oid;
    uint64_t start_time{0};
    uint32_t status{0};

    StoreLCEntry() = default;
    StoreLCEntry(std::string& _bucket, uint64_t _time, uint32_t _status) : bucket(_bucket), start_time(_time), status(_status) {}
    StoreLCEntry(std::string& _bucket, std::string _oid, uint64_t _time, uint32_t _status) : bucket(_bucket), oid(_oid), start_time(_time), status(_status) {}
    StoreLCEntry(const StoreLCEntry& _e) = default;

    StoreLCEntry& operator=(LCEntry& _e) {
      bucket = _e.get_bucket();
      oid = _e.get_oid();
      start_time = _e.get_start_time();
      status = _e.get_status();

      return *this;
    }

    virtual std::string& get_bucket() override { return bucket; }
    virtual void set_bucket(const std::string& _bucket) override { bucket = _bucket; }
    virtual std::string& get_oid() override { return oid; }
    virtual void set_oid(const std::string& _oid) override { oid = _oid; }
    virtual uint64_t get_start_time() override { return start_time; }
    virtual void set_start_time(uint64_t _time) override { start_time = _time; }
    virtual uint32_t get_status() override { return status; }
    virtual void set_status(uint32_t _status) override { status = _status; }
    virtual void print(std::ostream& out) const override {
      out << bucket << ":" << oid << ":" << start_time << ":" << status;
    }
  };

  StoreLifecycle() = default;
  virtual ~StoreLifecycle() = default;

  virtual std::unique_ptr<LCEntry> get_entry() override {
      return std::make_unique<StoreLCEntry>();
  }
  using Lifecycle::get_entry;
};

class StoreNotification : public Notification {
protected:
  Object* obj;
  Object* src_obj;
  rgw::notify::EventType event_type;

  public:
    StoreNotification(Object* _obj, Object* _src_obj, rgw::notify::EventType _type)
      : obj(_obj), src_obj(_src_obj), event_type(_type)
    {}

    virtual ~StoreNotification() = default;
};

class StoreWriter : public Writer {
protected:
  const DoutPrefixProvider* dpp;

public:
  StoreWriter(const DoutPrefixProvider *_dpp, optional_yield y) : dpp(_dpp) {}
  virtual ~StoreWriter() = default;

};

class StorePlacementTier : public PlacementTier {
public:
  virtual ~StorePlacementTier() = default;
};

class StoreZoneGroup : public ZoneGroup {
public:
  virtual ~StoreZoneGroup() = default;
};

class StoreZone : public Zone {
  public:
    virtual ~StoreZone() = default;
};

class StoreLuaManager : public LuaManager {
public:
  virtual ~StoreLuaManager() = default;
};

} } // namespace rgw::sal