/Users/deen/code/yugabyte-db/src/yb/consensus/consensus_context.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_CONSENSUS_CONSENSUS_CONTEXT_H  | 
15  |  | #define YB_CONSENSUS_CONSENSUS_CONTEXT_H  | 
16  |  |  | 
17  |  | #include "yb/common/common_fwd.h"  | 
18  |  |  | 
19  |  | #include "yb/consensus/consensus_fwd.h"  | 
20  |  | #include "yb/consensus/consensus_types.pb.h"  | 
21  |  |  | 
22  |  | #include "yb/util/status_fwd.h"  | 
23  |  |  | 
24  |  | namespace yb { | 
25  |  | namespace consensus { | 
26  |  |  | 
27  |  | class ConsensusContext { | 
28  |  |  public:  | 
29  |  |   // Factory for replica transactions.  | 
30  |  |   // An implementation of this factory must be registered prior to consensus  | 
31  |  |   // start, and is used to create transactions when the consensus implementation receives  | 
32  |  |   // messages from the leader.  | 
33  |  |   //  | 
34  |  |   // Replica transactions execute the following way:  | 
35  |  |   //  | 
36  |  |   // - When a ReplicateMsg is first received from the leader, the Consensus  | 
37  |  |   //   instance creates the ConsensusRound and calls StartReplicaOperation().  | 
38  |  |   //   This will trigger the Prepare(). At the same time replica consensus  | 
39  |  |   //   instance immediately stores the ReplicateMsg in the Log. Once the replicate  | 
40  |  |   //   message is stored in stable storage an ACK is sent to the leader (i.e. the  | 
41  |  |   //   replica Consensus instance does not wait for Prepare() to finish).  | 
42  |  |   virtual CHECKED_STATUS StartReplicaOperation(  | 
43  |  |       const ConsensusRoundPtr& context, HybridTime propagated_safe_time) = 0;  | 
44  |  |  | 
45  |  |   virtual void SetPropagatedSafeTime(HybridTime ht) = 0;  | 
46  |  |  | 
47  |  |   virtual bool ShouldApplyWrite() = 0;  | 
48  |  |  | 
49  |  |   // Performs steps to prepare request for peer.  | 
50  |  |   // For instance it could enqueue some operations to the Raft.  | 
51  |  |   //  | 
52  |  |   // Returns the current safe time, so we can send it from leaders to followers.  | 
53  |  |   virtual Result<HybridTime> PreparePeerRequest() = 0;  | 
54  |  |  | 
55  |  |   // This is called every time majority-replicated watermarks (OpId / leader leases) change. This is  | 
56  |  |   // used for updating the "propagated safe time" value in MvccManager and unblocking readers  | 
57  |  |   // waiting for it to advance.  | 
58  |  |   virtual void MajorityReplicated() = 0;  | 
59  |  |  | 
60  |  |   // This is called every time the Raft config was changed and replicated.  | 
61  |  |   // This is used to notify the higher layer about the config change. Currently it's  | 
62  |  |   // needed to update the internal flag in the MvccManager to return a correct safe  | 
63  |  |   // time value for a read/write operation in case of RF==1 mode.  | 
64  |  |   virtual void ChangeConfigReplicated(const RaftConfigPB& config) = 0;  | 
65  |  |  | 
66  |  |   // See DB::GetCurrentVersionNumSSTFiles  | 
67  |  |   virtual uint64_t NumSSTFiles() = 0;  | 
68  |  |  | 
69  |  |   // Register listener that will be invoked when number of SST files changed.  | 
70  |  |   // Listener could be set only once and then reset.  | 
71  |  |   virtual void ListenNumSSTFilesChanged(std::function<void()> listener) = 0;  | 
72  |  |  | 
73  |  |   // Checks whether operation with provided op id and type could be added to the log.  | 
74  |  |   virtual CHECKED_STATUS CheckOperationAllowed(  | 
75  |  |       const OpId& op_id, consensus::OperationType op_type) = 0;  | 
76  |  |  | 
77  | 74.1k  |   virtual ~ConsensusContext() = default;  | 
78  |  | };  | 
79  |  |  | 
80  |  | } // namespace consensus  | 
81  |  | } // namespace yb  | 
82  |  |  | 
83  |  | #endif // YB_CONSENSUS_CONSENSUS_CONTEXT_H  |