/Users/deen/code/yugabyte-db/src/yb/client/universe_key_client.h
Line | Count | Source |
1 | | // Copyright (c) YugaByte, Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
4 | | // in compliance with the License. You may obtain a copy of the License at |
5 | | // |
6 | | // http://www.apache.org/licenses/LICENSE-2.0 |
7 | | // |
8 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
9 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
10 | | // or implied. See the License for the specific language governing permissions and limitations |
11 | | // under the License. |
12 | | // |
13 | | |
14 | | #ifndef YB_CLIENT_UNIVERSE_KEY_CLIENT_H |
15 | | #define YB_CLIENT_UNIVERSE_KEY_CLIENT_H |
16 | | |
17 | | #include <condition_variable> |
18 | | #include <mutex> |
19 | | #include <unordered_set> |
20 | | |
21 | | #include "yb/encryption/encryption.fwd.h" |
22 | | |
23 | | #include "yb/master/master_encryption.fwd.h" |
24 | | #include "yb/master/master_fwd.h" |
25 | | |
26 | | #include "yb/rpc/rpc_fwd.h" |
27 | | |
28 | | #include "yb/util/status_fwd.h" |
29 | | #include "yb/util/net/net_util.h" |
30 | | |
31 | | namespace yb { |
32 | | |
33 | | namespace client { |
34 | | |
35 | | class UniverseKeyClient { |
36 | | public: |
37 | | UniverseKeyClient(const std::vector<HostPort>& hps, |
38 | | rpc::ProxyCache* proxy_cache, |
39 | | std::function<void(const encryption::UniverseKeysPB&)> callback) |
40 | 11.1k | : hps_(hps), proxy_cache_(proxy_cache), callback_(std::move(callback)) {} |
41 | | |
42 | | void GetUniverseKeyRegistryAsync(); |
43 | | |
44 | | void GetUniverseKeyRegistrySync(); |
45 | | |
46 | | private: |
47 | | |
48 | | void ProcessGetUniverseKeyRegistryResponse( |
49 | | std::shared_ptr<master::GetUniverseKeyRegistryResponsePB> resp, |
50 | | std::shared_ptr<rpc::RpcController> rpc, |
51 | | HostPort hp); |
52 | | |
53 | | void SendAsyncRequest(HostPort host_port); |
54 | | |
55 | | mutable std::mutex mutex_; |
56 | | mutable std::condition_variable cond_; |
57 | | |
58 | | std::vector<HostPort> hps_; |
59 | | rpc::ProxyCache* proxy_cache_; |
60 | | std::function<void(const encryption::UniverseKeysPB&)> callback_; |
61 | | |
62 | | bool callback_triggered_ = false; |
63 | | }; |
64 | | |
65 | | } // namespace client |
66 | | } // namespace yb |
67 | | |
68 | | #endif // YB_CLIENT_UNIVERSE_KEY_CLIENT_H |