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