Couchbase C++ SDK 1.5.0 (rev. 380784c)
Loading...
Searching...
No Matches
get_replica_strategy.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2026-Present Couchbase, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#include <cstddef>
21
22namespace couchbase
23{
31enum class replica_index {
32 first = 0,
33 second = 1,
34 third = 2,
35};
36
50 struct built {
51 bool wrap;
52 };
53
80 {
81 wrap_ = value;
82 return *this;
83 }
84
93 [[nodiscard]] auto build() const -> built
94 {
95 return { wrap_ };
96 }
97
98private:
99 bool wrap_{ false };
100};
101
108class get_replica_strategy
109{
110public:
121 [[nodiscard]] static auto from_index(replica_index index,
122 const get_replica_strategy_from_index_options& options = {})
124 {
125 return get_replica_strategy{ static_cast<std::size_t>(index), options.build() };
126 }
127
134 struct built {
135 std::size_t replica_index;
136 bool wrap;
137 };
138
147 [[nodiscard]] auto build() const -> built
148 {
149 return built_;
150 }
151
152private:
153 get_replica_strategy(std::size_t index,
155 : built_{ index, options.wrap }
156 {
157 }
158
159 built built_;
160};
161} // namespace couchbase
Selects the replica that get_replica() reads from.
Definition get_replica_strategy.hxx:109
auto build() const -> built
Returns the strategy as an immutable value.
Definition get_replica_strategy.hxx:147
static auto from_index(replica_index index, const get_replica_strategy_from_index_options &options={}) -> get_replica_strategy
Read from the replica at the given index.
Definition get_replica_strategy.hxx:121
Represents a single item from the result of scan().
Definition allow_querying_search_index_options.hxx:28
replica_index
Replica to read from, where first is the first replica of the vbucket.
Definition get_replica_strategy.hxx:31
@ first
Definition get_replica_strategy.hxx:32
@ second
Definition get_replica_strategy.hxx:33
@ third
Definition get_replica_strategy.hxx:34
Immutable value object representing a consistent strategy.
Definition get_replica_strategy.hxx:134
std::size_t replica_index
Definition get_replica_strategy.hxx:135
bool wrap
Definition get_replica_strategy.hxx:136
Immutable value object representing consistent options.
Definition get_replica_strategy.hxx:50
bool wrap
Definition get_replica_strategy.hxx:51
Options for from_index().
Definition get_replica_strategy.hxx:43
auto build() const -> built
Returns the options as an immutable value.
Definition get_replica_strategy.hxx:93
auto wrap(bool value) -> get_replica_strategy_from_index_options &
Resolve an index that cannot be read as requested to the next one that can, instead of failing with r...
Definition get_replica_strategy.hxx:79