1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
5 * Ceph - scalable distributed file system
7 * Copyright (C) 2020 Red Hat, Inc.
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.
20 #include "include/encoding.h"
24 enum class BucketIndexType
: uint8_t {
25 Normal
, // normal hash-based sharded index layout
26 Indexless
, // no bucket index, so listing is unsupported
29 enum class BucketHashType
: uint8_t {
30 Mod
, // rjenkins hash of object name, modulo num_shards
33 inline std::ostream
& operator<<(std::ostream
& out
, const BucketIndexType
&index_type
)
36 case BucketIndexType::Normal
:
37 return out
<< "Normal";
38 case BucketIndexType::Indexless
:
39 return out
<< "Indexless";
41 return out
<< "Unknown";
45 struct bucket_index_normal_layout
{
46 uint32_t num_shards
= 1;
48 BucketHashType hash_type
= BucketHashType::Mod
;
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
);
55 struct bucket_index_layout
{
56 BucketIndexType type
= BucketIndexType::Normal
;
58 // TODO: variant of layout types?
59 bucket_index_normal_layout normal
;
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
);
66 struct bucket_index_layout_generation
{
68 bucket_index_layout layout
;
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
);
75 enum class BucketLogType
: uint8_t {
76 // colocated with bucket index, so the log layout matches the index layout
80 inline std::ostream
& operator<<(std::ostream
& out
, const BucketLogType
&log_type
)
83 case BucketLogType::InIndex
:
84 return out
<< "InIndex";
86 return out
<< "Unknown";
90 struct bucket_index_log_layout
{
92 bucket_index_normal_layout layout
;
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
);
98 struct bucket_log_layout
{
99 BucketLogType type
= BucketLogType::InIndex
;
101 bucket_index_log_layout in_index
;
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
);
108 struct bucket_log_layout_generation
{
110 bucket_log_layout layout
;
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
);
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
)
120 return {gen
, {BucketLogType::InIndex
, {gen
, index
}}};
123 enum class BucketReshardState
: uint8_t {
128 // describes the layout of bucket index objects
129 struct BucketLayout
{
130 BucketReshardState resharding
= BucketReshardState::None
;
132 // current bucket index layout
133 bucket_index_layout_generation current_index
;
135 // target index layout of a resharding operation
136 std::optional
<bucket_index_layout_generation
> target_index
;
138 // history of untrimmed bucket log layout generations, with the current
139 // generation at the back()
140 std::vector
<bucket_log_layout_generation
> logs
;
143 void encode(const BucketLayout
& l
, bufferlist
& bl
, uint64_t f
=0);
144 void decode(BucketLayout
& l
, bufferlist::const_iterator
& bl
);