]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_bucket_layout.h
import ceph quincy 17.2.6
[ceph.git] / ceph / src / rgw / rgw_bucket_layout.h
CommitLineData
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
22namespace rgw {
23
24enum class BucketIndexType : uint8_t {
25 Normal, // normal hash-based sharded index layout
26 Indexless, // no bucket index, so listing is unsupported
27};
28
29enum class BucketHashType : uint8_t {
30 Mod, // rjenkins hash of object name, modulo num_shards
31};
32
33inline 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
45struct bucket_index_normal_layout {
46 uint32_t num_shards = 1;
47
48 BucketHashType hash_type = BucketHashType::Mod;
49};
50
51void encode(const bucket_index_normal_layout& l, bufferlist& bl, uint64_t f=0);
52void decode(bucket_index_normal_layout& l, bufferlist::const_iterator& bl);
53
54
55struct bucket_index_layout {
56 BucketIndexType type = BucketIndexType::Normal;
57
58 // TODO: variant of layout types?
59 bucket_index_normal_layout normal;
60};
61
62void encode(const bucket_index_layout& l, bufferlist& bl, uint64_t f=0);
63void decode(bucket_index_layout& l, bufferlist::const_iterator& bl);
64
65
66struct bucket_index_layout_generation {
67 uint64_t gen = 0;
68 bucket_index_layout layout;
69};
70
71void encode(const bucket_index_layout_generation& l, bufferlist& bl, uint64_t f=0);
72void decode(bucket_index_layout_generation& l, bufferlist::const_iterator& bl);
73
74
75enum class BucketLogType : uint8_t {
76 // colocated with bucket index, so the log layout matches the index layout
77 InIndex,
78};
79
80inline 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
90struct bucket_index_log_layout {
91 uint64_t gen = 0;
92 bucket_index_normal_layout layout;
93};
94
95void encode(const bucket_index_log_layout& l, bufferlist& bl, uint64_t f=0);
96void decode(bucket_index_log_layout& l, bufferlist::const_iterator& bl);
97
98struct bucket_log_layout {
99 BucketLogType type = BucketLogType::InIndex;
100
101 bucket_index_log_layout in_index;
102};
103
104void encode(const bucket_log_layout& l, bufferlist& bl, uint64_t f=0);
105void decode(bucket_log_layout& l, bufferlist::const_iterator& bl);
106
107
108struct bucket_log_layout_generation {
109 uint64_t gen = 0;
110 bucket_log_layout layout;
111};
112
113void encode(const bucket_log_layout_generation& l, bufferlist& bl, uint64_t f=0);
114void decode(bucket_log_layout_generation& l, bufferlist::const_iterator& bl);
115
116// return a log layout that shares its layout with the index
117inline 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
123enum class BucketReshardState : uint8_t {
124 None,
125 InProgress,
126};
127
128// describes the layout of bucket index objects
129struct 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
143void encode(const BucketLayout& l, bufferlist& bl, uint64_t f=0);
144void decode(BucketLayout& l, bufferlist::const_iterator& bl);
145
146} // namespace rgw