]>
Commit | Line | Data |
---|---|---|
f67539c2 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) 2020 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 <optional> | |
19 | #include <string> | |
20 | #include "include/encoding.h" | |
21 | ||
22 | namespace rgw { | |
23 | ||
24 | enum class BucketIndexType : uint8_t { | |
25 | Normal, // normal hash-based sharded index layout | |
26 | Indexless, // no bucket index, so listing is unsupported | |
27 | }; | |
28 | ||
29 | enum class BucketHashType : uint8_t { | |
30 | Mod, // rjenkins hash of object name, modulo num_shards | |
31 | }; | |
32 | ||
33 | inline std::ostream& operator<<(std::ostream& out, const BucketIndexType &index_type) | |
34 | { | |
35 | switch (index_type) { | |
36 | case BucketIndexType::Normal: | |
37 | return out << "Normal"; | |
38 | case BucketIndexType::Indexless: | |
39 | return out << "Indexless"; | |
40 | default: | |
41 | return out << "Unknown"; | |
42 | } | |
43 | } | |
44 | ||
45 | struct bucket_index_normal_layout { | |
46 | uint32_t num_shards = 1; | |
47 | ||
48 | BucketHashType hash_type = BucketHashType::Mod; | |
49 | }; | |
50 | ||
51 | void encode(const bucket_index_normal_layout& l, bufferlist& bl, uint64_t f=0); | |
52 | void decode(bucket_index_normal_layout& l, bufferlist::const_iterator& bl); | |
53 | ||
54 | ||
55 | struct bucket_index_layout { | |
56 | BucketIndexType type = BucketIndexType::Normal; | |
57 | ||
58 | // TODO: variant of layout types? | |
59 | bucket_index_normal_layout normal; | |
60 | }; | |
61 | ||
62 | void encode(const bucket_index_layout& l, bufferlist& bl, uint64_t f=0); | |
63 | void decode(bucket_index_layout& l, bufferlist::const_iterator& bl); | |
64 | ||
65 | ||
66 | struct bucket_index_layout_generation { | |
67 | uint64_t gen = 0; | |
68 | bucket_index_layout layout; | |
69 | }; | |
70 | ||
71 | void encode(const bucket_index_layout_generation& l, bufferlist& bl, uint64_t f=0); | |
72 | void decode(bucket_index_layout_generation& l, bufferlist::const_iterator& bl); | |
73 | ||
74 | ||
75 | enum class BucketLogType : uint8_t { | |
76 | // colocated with bucket index, so the log layout matches the index layout | |
77 | InIndex, | |
78 | }; | |
79 | ||
80 | inline std::ostream& operator<<(std::ostream& out, const BucketLogType &log_type) | |
81 | { | |
82 | switch (log_type) { | |
83 | case BucketLogType::InIndex: | |
84 | return out << "InIndex"; | |
85 | default: | |
86 | return out << "Unknown"; | |
87 | } | |
88 | } | |
89 | ||
90 | struct bucket_index_log_layout { | |
91 | uint64_t gen = 0; | |
92 | bucket_index_normal_layout layout; | |
93 | }; | |
94 | ||
95 | void encode(const bucket_index_log_layout& l, bufferlist& bl, uint64_t f=0); | |
96 | void decode(bucket_index_log_layout& l, bufferlist::const_iterator& bl); | |
97 | ||
98 | struct bucket_log_layout { | |
99 | BucketLogType type = BucketLogType::InIndex; | |
100 | ||
101 | bucket_index_log_layout in_index; | |
102 | }; | |
103 | ||
104 | void encode(const bucket_log_layout& l, bufferlist& bl, uint64_t f=0); | |
105 | void decode(bucket_log_layout& l, bufferlist::const_iterator& bl); | |
106 | ||
107 | ||
108 | struct bucket_log_layout_generation { | |
109 | uint64_t gen = 0; | |
110 | bucket_log_layout layout; | |
111 | }; | |
112 | ||
113 | void encode(const bucket_log_layout_generation& l, bufferlist& bl, uint64_t f=0); | |
114 | void decode(bucket_log_layout_generation& l, bufferlist::const_iterator& bl); | |
115 | ||
116 | // return a log layout that shares its layout with the index | |
117 | inline bucket_log_layout_generation log_layout_from_index( | |
118 | uint64_t gen, const bucket_index_normal_layout& index) | |
119 | { | |
120 | return {gen, {BucketLogType::InIndex, {gen, index}}}; | |
121 | } | |
122 | ||
123 | enum class BucketReshardState : uint8_t { | |
124 | None, | |
125 | InProgress, | |
126 | }; | |
127 | ||
128 | // describes the layout of bucket index objects | |
129 | struct BucketLayout { | |
130 | BucketReshardState resharding = BucketReshardState::None; | |
131 | ||
132 | // current bucket index layout | |
133 | bucket_index_layout_generation current_index; | |
134 | ||
135 | // target index layout of a resharding operation | |
136 | std::optional<bucket_index_layout_generation> target_index; | |
137 | ||
138 | // history of untrimmed bucket log layout generations, with the current | |
139 | // generation at the back() | |
140 | std::vector<bucket_log_layout_generation> logs; | |
141 | }; | |
142 | ||
143 | void encode(const BucketLayout& l, bufferlist& bl, uint64_t f=0); | |
144 | void decode(BucketLayout& l, bufferlist::const_iterator& bl); | |
145 | ||
146 | } // namespace rgw |