/Users/deen/code/yugabyte-db/src/yb/consensus/peer_manager.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. 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, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // |
18 | | // The following only applies to changes made to this file as part of YugaByte development. |
19 | | // |
20 | | // Portions Copyright (c) YugaByte, Inc. |
21 | | // |
22 | | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
23 | | // in compliance with the License. You may obtain a copy of the License at |
24 | | // |
25 | | // http://www.apache.org/licenses/LICENSE-2.0 |
26 | | // |
27 | | // Unless required by applicable law or agreed to in writing, software distributed under the License |
28 | | // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
29 | | // or implied. See the License for the specific language governing permissions and limitations |
30 | | // under the License. |
31 | | // |
32 | | #ifndef YB_CONSENSUS_PEER_MANAGER_H |
33 | | #define YB_CONSENSUS_PEER_MANAGER_H |
34 | | |
35 | | #include <string> |
36 | | #include <unordered_map> |
37 | | |
38 | | #include <gflags/gflags_declare.h> |
39 | | |
40 | | #include "yb/consensus/log_fwd.h" |
41 | | #include "yb/consensus/consensus_util.h" |
42 | | #include "yb/consensus/multi_raft_batcher.h" |
43 | | |
44 | | #include "yb/gutil/integral_types.h" |
45 | | #include "yb/gutil/macros.h" |
46 | | #include "yb/gutil/ref_counted.h" |
47 | | |
48 | | #include "yb/util/status_fwd.h" |
49 | | #include "yb/util/locks.h" |
50 | | #include "yb/util/shared_lock.h" |
51 | | |
52 | | namespace yb { |
53 | | |
54 | | class MemTracker; |
55 | | class ThreadPoolToken; |
56 | | |
57 | | namespace consensus { |
58 | | |
59 | | class Consensus; |
60 | | class Peer; |
61 | | class PeerMessageQueue; |
62 | | class PeerProxyFactory; |
63 | | class RaftConfigPB; |
64 | | |
65 | | // Manages the set of local and remote peers that pull data from the queue into the local log/remote |
66 | | // machines. Methods are virtual to ease mocking. |
67 | | class PeerManager { |
68 | | public: |
69 | | // All of the raw pointer arguments are not owned by the PeerManager and must live at least as |
70 | | // long as the PeerManager. |
71 | | PeerManager(const std::string tablet_id, |
72 | | const std::string local_uuid, |
73 | | PeerProxyFactory* peer_proxy_factory, |
74 | | PeerMessageQueue* queue, |
75 | | ThreadPoolToken* raft_pool_token, |
76 | | MultiRaftManager* multi_raft_manager); |
77 | | |
78 | | virtual ~PeerManager(); |
79 | | |
80 | 88.7k | virtual void SetConsensus(Consensus* consensus) {consensus_ = consensus; } |
81 | | |
82 | | // Updates 'peers_' according to the new configuration config. |
83 | | virtual void UpdateRaftConfig(const RaftConfigPB& config); |
84 | | |
85 | | // Signals all peers of the current configuration that there is a new request pending. |
86 | | virtual void SignalRequest(RequestTriggerMode trigger_mode); |
87 | | |
88 | | // Closes all peers. |
89 | | virtual void Close(); |
90 | | |
91 | | // Closes connections to those peers that are not in config. |
92 | | virtual void ClosePeersNotInConfig(const RaftConfigPB& config); |
93 | | |
94 | | private: |
95 | | std::string LogPrefix() const; |
96 | | |
97 | | typedef std::unordered_map<std::string, std::shared_ptr<Peer>> PeersMap; |
98 | | const std::string tablet_id_; |
99 | | const std::string local_uuid_; |
100 | | PeerProxyFactory* peer_proxy_factory_; |
101 | | PeerMessageQueue* queue_; |
102 | | ThreadPoolToken* raft_pool_token_; |
103 | | MultiRaftManager* multi_raft_manager_; |
104 | | PeersMap peers_; |
105 | | Consensus* consensus_ = nullptr; |
106 | | mutable simple_spinlock lock_; |
107 | | |
108 | | DISALLOW_COPY_AND_ASSIGN(PeerManager); |
109 | | }; |
110 | | |
111 | | } // namespace consensus |
112 | | } // namespace yb |
113 | | |
114 | | #endif /* YB_CONSENSUS_PEER_MANAGER_H */ |