Couchbase C++ SDK
1.4.0 (rev. 59aa900)
Toggle main menu visibility
Loading...
Searching...
No Matches
node_id.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 <cstdint>
21
#include <functional>
22
#include <string>
23
24
namespace
couchbase
25
{
26
39
class
node_id
40
{
41
public
:
50
node_id
() =
default
;
51
52
// Copy and move are noexcept: all members (std::string + std::uint16_t)
53
// have noexcept moves on every conforming implementation.
54
node_id
(
const
node_id
&) =
default
;
55
node_id
(
node_id
&&) noexcept = default;
56
auto operator=(const
node_id
&) ->
node_id
& = default;
57
auto operator=(
node_id
&&) noexcept ->
node_id
& = default;
58
~
node_id
() = default;
59
71
[[nodiscard]] auto
id
() const noexcept -> const std::
string
&;
72
79
[[nodiscard]] auto
node_uuid
() const noexcept -> const std::
string
&;
80
87
[[nodiscard]] auto
hostname
() const noexcept -> const std::
string
&;
88
100
[[nodiscard]] auto
port
() const noexcept -> std::uint16_t;
101
108
[[nodiscard]] explicit operator
bool
() const noexcept;
109
111
[[nodiscard]] auto operator==(const
node_id
& other) const noexcept ->
bool
;
113
[[nodiscard]] auto operator!=(const
node_id
& other) const noexcept ->
bool
;
115
[[nodiscard]] auto operator<(const
node_id
& other) const noexcept ->
bool
;
117
[[nodiscard]] auto operator<=(const
node_id
& other) const noexcept ->
bool
;
119
[[nodiscard]] auto operator>(const
node_id
& other) const noexcept ->
bool
;
121
[[nodiscard]] auto operator>=(const
node_id
& other) const noexcept ->
bool
;
122
123
private:
124
// Construction from core-level data is restricted to internal_node_id,
125
// declared in core/impl/node_id.hxx. Public users cannot construct node_id
126
// directly.
127
friend class
internal_node_id
;
128
129
node_id
(std::
string
node_uuid
, std::
string
hostname
, std::uint16_t
port
);
130
131
std::
string
node_uuid_{};
132
std::string hostname_{};
133
std::uint16_t port_{ 0 };
134
// Computed once at construction: node_uuid_ if non-empty, otherwise a
135
// deterministic hex-encoded CRC32 hash of "hostname:port".
136
std::string id_{};
137
};
138
139
}
// namespace couchbase
140
141
template
<>
142
struct
std::hash<
couchbase
::node_id> {
143
// Hashes the full id_ string. For the fallback case id_ is 8 hex chars;
144
// for a server-assigned UUID it is typically 32-36 chars. The cost is well
145
// under 100ns per lookup and not on a critical path; if profiling shows
146
// otherwise, cache the hash on node_id and return it from a friend accessor.
147
auto
operator()
(
const
couchbase::node_id
& nid)
const
noexcept
-> std::size_t
148
{
149
return
std::hash<std::string>{}(nid.id());
150
}
151
};
couchbase::node_id
Identifies a cluster node.
Definition
node_id.hxx:40
couchbase::node_id::node_id
node_id(node_id &&) noexcept=default
couchbase::node_id::node_id
node_id()=default
Creates an empty (invalid) node_id.
couchbase::node_id::hostname
auto hostname() const noexcept -> const std::string &
The hostname of the node.
couchbase::node_id::node_id
node_id(const node_id &)=default
couchbase::node_id::node_uuid
auto node_uuid() const noexcept -> const std::string &
The server-assigned node UUID (empty on servers before 8.0.1).
couchbase::node_id::internal_node_id
friend class internal_node_id
Definition
node_id.hxx:127
couchbase::node_id::port
auto port() const noexcept -> std::uint16_t
The port of the node's key-value service.
couchbase
Represents a single item from the result of scan().
Definition
allow_querying_search_index_options.hxx:28
std::hash< couchbase::node_id >::operator()
auto operator()(const couchbase::node_id &nid) const noexcept -> std::size_t
Definition
node_id.hxx:147
couchbase
node_id.hxx
Generated by
1.17.0