Couchbase C++ SDK 1.3.2 (rev. 49d3be2)
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 2024-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
24namespace couchbase
25{
26
40{
41public:
48 node_id() = default;
49
61 [[nodiscard]] auto id() const -> const std::string&;
62
69 [[nodiscard]] auto node_uuid() const -> const std::string&;
70
77 [[nodiscard]] auto hostname() const -> const std::string&;
78
88 [[nodiscard]] auto port() const -> std::uint16_t;
89
96 explicit operator bool() const;
97
98 auto operator==(const node_id& other) const -> bool;
99 auto operator!=(const node_id& other) const -> bool;
100 auto operator<(const node_id& other) const -> bool;
101
102private:
103 friend class internal_node_id;
104
105 node_id(std::string node_uuid, std::string hostname, std::uint16_t port);
106
107 std::string node_uuid_{};
108 std::string hostname_{};
109 std::uint16_t port_{ 0 };
110 // Computed once at construction: node_uuid_ if non-empty, otherwise a
111 // deterministic hex-encoded CRC32 hash of "hostname:port".
112 std::string id_{};
113};
114
115} // namespace couchbase
116
117template<>
118struct std::hash<couchbase::node_id> {
119 auto operator()(const couchbase::node_id& nid) const noexcept -> std::size_t
120 {
121 return std::hash<std::string>{}(nid.id());
122 }
123};
Uniquely identifies a cluster node.
Definition node_id.hxx:40
auto node_uuid() const -> const std::string &
The server-assigned node UUID (empty on servers before 8.0.1).
auto id() const -> const std::string &
User-facing identifier string.
node_id()=default
Creates an empty (invalid) node_id.
friend class internal_node_id
Definition node_id.hxx:103
auto port() const -> std::uint16_t
The port of the node's key-value service.
auto hostname() const -> const std::string &
The hostname of the node.
Represents a single item from the result of scan().
Definition allow_querying_search_index_options.hxx:28
auto operator()(const couchbase::node_id &nid) const noexcept -> std::size_t
Definition node_id.hxx:119