]> git.proxmox.com Git - ceph.git/blame - ceph/src/crimson/os/cyanstore/cyan_collection.cc
import quincy beta 17.1.0
[ceph.git] / ceph / src / crimson / os / cyanstore / cyan_collection.cc
CommitLineData
11fdf7f2
TL
1#include "cyan_collection.h"
2
3#include "cyan_object.h"
4
20effc67
TL
5using std::make_pair;
6
9f95a23c 7namespace crimson::os
11fdf7f2
TL
8{
9
10Collection::Collection(const coll_t& c)
9f95a23c 11 : FuturizedCollection{c}
11fdf7f2
TL
12{}
13
14Collection::~Collection() = default;
15
16Collection::ObjectRef Collection::create_object() const
17{
9f95a23c 18 return new crimson::os::Object;
11fdf7f2
TL
19}
20
21Collection::ObjectRef Collection::get_object(ghobject_t oid)
22{
23 auto o = object_hash.find(oid);
24 if (o == object_hash.end())
25 return ObjectRef();
26 return o->second;
27}
28
29Collection::ObjectRef Collection::get_or_create_object(ghobject_t oid)
30{
31 auto result = object_hash.emplace(oid, ObjectRef{});
32 if (result.second)
33 object_map[oid] = result.first->second = create_object();
34 return result.first->second;
35}
36
37uint64_t Collection::used_bytes() const
38{
39 uint64_t result = 0;
40 for (auto& obj : object_map) {
41 result += obj.second->get_size();
42 }
43 return result;
44}
45
46void Collection::encode(bufferlist& bl) const
47{
48 ENCODE_START(1, 1, bl);
49 encode(xattr, bl);
50 encode(use_page_set, bl);
51 uint32_t s = object_map.size();
52 encode(s, bl);
53 for (auto& [oid, obj] : object_map) {
54 encode(oid, bl);
55 obj->encode(bl);
56 }
57 ENCODE_FINISH(bl);
58}
59
60void Collection::decode(bufferlist::const_iterator& p)
61{
62 DECODE_START(1, p);
63 decode(xattr, p);
64 decode(use_page_set, p);
65 uint32_t s;
66 decode(s, p);
67 while (s--) {
68 ghobject_t k;
69 decode(k, p);
70 auto o = create_object();
71 o->decode(p);
72 object_map.insert(make_pair(k, o));
73 object_hash.insert(make_pair(k, o));
74 }
75 DECODE_FINISH(p);
76}
77
78}