]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_sys_obj_core_types.h
002f2763a909b07dbeedbca7c754f2c333ce2b53
[ceph.git] / ceph / src / rgw / services / svc_sys_obj_core_types.h
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 #pragma once
5
6
7 #include "rgw/rgw_service.h"
8
9 #include "svc_rados.h"
10 #include "svc_sys_obj_types.h"
11
12
13
14 struct RGWSI_SysObj_Core_GetObjState : public RGWSI_SysObj_Obj_GetObjState {
15 RGWSI_RADOS::Obj rados_obj;
16 bool has_rados_obj{false};
17 uint64_t last_ver{0};
18
19 RGWSI_SysObj_Core_GetObjState() {}
20
21 int get_rados_obj(RGWSI_RADOS *rados_svc,
22 RGWSI_Zone *zone_svc,
23 const rgw_raw_obj& obj,
24 RGWSI_RADOS::Obj **pobj);
25 };
26
27 struct RGWSI_SysObj_Core_PoolListImplInfo : public RGWSI_SysObj_Pool_ListInfo {
28 RGWSI_RADOS::Pool pool;
29 RGWSI_RADOS::Pool::List op;
30 RGWAccessListFilterPrefix filter;
31
32 RGWSI_SysObj_Core_PoolListImplInfo(const string& prefix) : op(pool.op()), filter(prefix) {}
33 };
34
35 struct RGWSysObjState {
36 rgw_raw_obj obj;
37 bool has_attrs{false};
38 bool exists{false};
39 uint64_t size{0};
40 ceph::real_time mtime;
41 uint64_t epoch{0};
42 bufferlist obj_tag;
43 bool has_data{false};
44 bufferlist data;
45 bool prefetch_data{false};
46 uint64_t pg_ver{0};
47
48 /* important! don't forget to update copy constructor */
49
50 RGWObjVersionTracker objv_tracker;
51
52 map<string, bufferlist> attrset;
53 RGWSysObjState() {}
54 RGWSysObjState(const RGWSysObjState& rhs) : obj (rhs.obj) {
55 has_attrs = rhs.has_attrs;
56 exists = rhs.exists;
57 size = rhs.size;
58 mtime = rhs.mtime;
59 epoch = rhs.epoch;
60 if (rhs.obj_tag.length()) {
61 obj_tag = rhs.obj_tag;
62 }
63 has_data = rhs.has_data;
64 if (rhs.data.length()) {
65 data = rhs.data;
66 }
67 prefetch_data = rhs.prefetch_data;
68 pg_ver = rhs.pg_ver;
69 objv_tracker = rhs.objv_tracker;
70 }
71 };
72
73
74 class RGWSysObjectCtxBase {
75 std::map<rgw_raw_obj, RGWSysObjState> objs_state;
76 ceph::shared_mutex lock = ceph::make_shared_mutex("RGWSysObjectCtxBase");
77
78 public:
79 RGWSysObjectCtxBase() = default;
80
81 RGWSysObjectCtxBase(const RGWSysObjectCtxBase& rhs) : objs_state(rhs.objs_state) {}
82 RGWSysObjectCtxBase(RGWSysObjectCtxBase&& rhs) : objs_state(std::move(rhs.objs_state)) {}
83
84 RGWSysObjState *get_state(const rgw_raw_obj& obj) {
85 RGWSysObjState *result;
86 std::map<rgw_raw_obj, RGWSysObjState>::iterator iter;
87 lock.lock_shared();
88 assert (!obj.empty());
89 iter = objs_state.find(obj);
90 if (iter != objs_state.end()) {
91 result = &iter->second;
92 lock.unlock_shared();
93 } else {
94 lock.unlock_shared();
95 lock.lock();
96 result = &objs_state[obj];
97 lock.unlock();
98 }
99 return result;
100 }
101
102 void set_prefetch_data(rgw_raw_obj& obj) {
103 std::unique_lock wl{lock};
104 assert (!obj.empty());
105 objs_state[obj].prefetch_data = true;
106 }
107 void invalidate(const rgw_raw_obj& obj) {
108 std::unique_lock wl{lock};
109 auto iter = objs_state.find(obj);
110 if (iter == objs_state.end()) {
111 return;
112 }
113 objs_state.erase(iter);
114 }
115 };
116