Loading...
Searching...
No Matches
response_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
27
28namespace resdb {
29
31 public:
32 ResponseManager(const ResDBConfig& config,
33 ReplicaCommunicator* replica_communicator,
34 SystemInfo* system_info, SignatureVerifier* verifier);
35
37
38 int AddContextList(std::vector<std::unique_ptr<Context>> context,
39 uint64_t id);
40 std::vector<std::unique_ptr<Context>> FetchContextList(uint64_t id);
41
42 int NewUserRequest(std::unique_ptr<Context> context,
43 std::unique_ptr<Request> user_request);
44
45 int ProcessResponseMsg(std::unique_ptr<Context> context,
46 std::unique_ptr<Request> request);
47
48 private:
49 // Add response messages which will be sent back to the caller
50 // if there are f+1 same messages.
51 CollectorResultCode AddResponseMsg(
52 const SignatureInfo& signature, std::unique_ptr<Request> request,
53 std::function<void(const Request&,
55 call_back);
56 void SendResponseToClient(const BatchUserResponse& batch_response);
57
58 struct QueueItem {
59 std::unique_ptr<Context> context;
60 std::unique_ptr<Request> user_request;
61 };
62 bool MayConsensusChangeStatus(int type, int received_count,
63 std::atomic<TransactionStatue>* status);
64 int DoBatch(const std::vector<std::unique_ptr<QueueItem>>& batch_req);
65 int BatchProposeMsg();
66 int GetPrimary();
67
68 private:
69 ResDBConfig config_;
70 ReplicaCommunicator* replica_communicator_;
71 std::unique_ptr<LockFreeCollectorPool> collector_pool_, context_pool_;
72 LockFreeQueue<QueueItem> batch_queue_;
73 std::thread user_req_thread_;
74 std::atomic<bool> stop_;
75 uint64_t local_id_ = 0;
76 Stats* global_stats_;
77 SystemInfo* system_info_;
78 std::atomic<int> send_num_;
79 SignatureVerifier* verifier_;
80};
81
82} // namespace resdb
std::vector< std::unique_ptr< Context > > FetchContextList(uint64_t id)
int ProcessResponseMsg(std::unique_ptr< Context > context, std::unique_ptr< Request > request)
int AddContextList(std::vector< std::unique_ptr< Context > > context, uint64_t id)
int NewUserRequest(std::unique_ptr< Context > context, std::unique_ptr< Request > user_request)
std::list< std::unique_ptr< RequestInfo > > CollectorDataType