Loading...
Searching...
No Matches
message_manager.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <stdint.h>
23
24#include <map>
25#include <memory>
26#include <queue>
27#include <set>
28
38#include "platform/proto/checkpoint_info.pb.h"
39#include "platform/proto/resdb.pb.h"
41
42namespace resdb {
43
45 public:
46 MessageManager(const ResDBConfig& config,
47 std::unique_ptr<TransactionManager> transaction_manager,
48 CheckPointManager* checkpoint_manager,
49 SystemInfo* system_info);
51
52 absl::StatusOr<uint64_t> AssignNextSeq();
53
54 int64_t GetCurrentPrimary() const;
56 void SetNextSeq(uint64_t seq);
57 int64_t GetNextSeq();
58
59 // Add commit messages and return the number of messages have been received.
60 // The commit messages only include post(pre-prepare), prepare and commit
61 // messages. Messages are handled by state (PREPARE,COMMIT,READY_EXECUTE).
62
63 // If there are enough messages and the state is changed after adding the
64 // message, return 1, otherwise return 0. Return -2 if the request is not
65 // valid.
66 CollectorResultCode AddConsensusMsg(const SignatureInfo& signature,
67 std::unique_ptr<Request> request);
68
69 // Obtain the request that has been executed from Executor.
70 // The messages that have been executed from Executor will save inside
71 // Message Manager. Consensus Service can obtain the message then send back
72 // to the client proxy.
73 std::unique_ptr<BatchUserResponse> GetResponseMsg();
74
75 // Get committed messages with 2f+1 proof in [min_seq, max_seq].
76 RequestSet GetRequestSet(uint64_t min_seq, uint64_t max_seq);
77
78 // Get the transactions that have been execuited.
79 Request* GetRequest(uint64_t seq);
80
81 // Get the proof info containing the request and signatures
82 // if the request has been prepared, having received 2f+1
83 // pre-prepare messages.
84 std::vector<RequestInfo> GetPreparedProof(uint64_t seq);
86
87 // ============= System information ========
88 // Obtain the current replica list.
89 std::vector<ReplicaInfo> GetReplicas();
90
91 uint64_t GetCurrentView() const;
92
93 // Replica State
94 int GetReplicaState(ReplicaState* state);
95 std::unique_ptr<Context> FetchClientContext(uint64_t seq);
96
98
99 void SetLastCommittedTime(uint64_t proxy_id);
100
101 uint64_t GetLastCommittedTime(uint64_t proxy_id);
102
103 bool IsPreapared(uint64_t seq);
104
105 uint64_t GetHighestPreparedSeq();
106
107 void SetHighestPreparedSeq(uint64_t seq);
108
110
111 void SendResponse(std::unique_ptr<Request> request);
112
114
115 private:
116 bool IsValidMsg(const Request& request);
117
118 bool MayConsensusChangeStatus(int type, int received_count,
119 std::atomic<TransactionStatue>* status,
120 bool force);
121
122 private:
123 ResDBConfig config_;
124 uint64_t next_seq_ = 1;
125
127 ChainState* txn_db_;
128 SystemInfo* system_info_;
129 CheckPointManager* checkpoint_manager_;
130 std::map<uint64_t, std::vector<std::unique_ptr<RequestInfo>>>
131 committed_proof_;
132 std::map<uint64_t, Request> committed_data_;
133
134 std::mutex data_mutex_, seq_mutex_;
135 std::unique_ptr<TransactionExecutor> transaction_executor_;
136 std::unique_ptr<LockFreeCollectorPool> collector_pool_;
137
138 Stats* global_stats_;
139
140 std::mutex lct_lock_;
141 std::map<uint64_t, uint64_t> last_committed_time_;
142};
143
144} // namespace resdb
void SetLastCommittedTime(uint64_t proxy_id)
void SetDuplicateManager(DuplicateManager *manager)
Request * GetRequest(uint64_t seq)
absl::StatusOr< uint64_t > AssignNextSeq()
TransactionStatue GetTransactionState(uint64_t seq)
uint64_t GetMinExecutCandidateSeq()
std::vector< ReplicaInfo > GetReplicas()
void SendResponse(std::unique_ptr< Request > request)
uint64_t GetCurrentView() const
uint64_t GetLastCommittedTime(uint64_t proxy_id)
void SetHighestPreparedSeq(uint64_t seq)
int GetReplicaState(ReplicaState *state)
CollectorResultCode AddConsensusMsg(const SignatureInfo &signature, std::unique_ptr< Request > request)
std::vector< RequestInfo > GetPreparedProof(uint64_t seq)
bool IsPreapared(uint64_t seq)
int64_t GetCurrentPrimary() const
std::unique_ptr< BatchUserResponse > GetResponseMsg()
void SetNextSeq(uint64_t seq)
std::unique_ptr< Context > FetchClientContext(uint64_t seq)
RequestSet GetRequestSet(uint64_t min_seq, uint64_t max_seq)
LockFreeCollectorPool * GetCollectorPool()