Loading...
Searching...
No Matches
performance_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 <semaphore.h>
23
24#include <future>
25#include <queue>
26
32
33namespace resdb {
34
36 public:
37 PerformanceClientTimeout(std::string hash_, uint64_t time_);
39 bool operator<(const PerformanceClientTimeout& other) const;
40
41 std::string hash;
42 uint64_t timeout_time;
43};
44
46 public:
47 PerformanceManager(const ResDBConfig& config,
48 ReplicaCommunicator* replica_communicator,
49 SystemInfo* system_info, SignatureVerifier* verifier);
50
52
53 int StartEval();
54
55 int ProcessResponseMsg(std::unique_ptr<Context> context,
56 std::unique_ptr<Request> request);
57 void SetDataFunc(std::function<std::string()> func);
58
59 private:
60 // Add response messages which will be sent back to the caller
61 // if there are f+1 same messages.
62 CollectorResultCode AddResponseMsg(
63 const SignatureInfo& signature, std::unique_ptr<Request> request,
64 std::function<void(const Request&,
66 call_back);
67 void SendResponseToClient(const BatchUserResponse& batch_response);
68
69 struct QueueItem {
70 std::unique_ptr<Context> context;
71 std::unique_ptr<Request> user_request;
72 };
73 bool MayConsensusChangeStatus(int type, int received_count,
74 std::atomic<TransactionStatue>* status);
75 int DoBatch(const std::vector<std::unique_ptr<QueueItem>>& batch_req);
76 int BatchProposeMsg();
77 int GetPrimary();
78 std::unique_ptr<Request> GenerateUserRequest();
79
80 void AddWaitingResponseRequest(std::unique_ptr<Request> request);
81 void RemoveWaitingResponseRequest(std::string hash);
82 bool CheckTimeOut(std::string hash);
83 void ResponseTimer(std::string hash);
84 void MonitoringClientTimeOut();
85 std::unique_ptr<Request> GetTimeOutRequest(std::string hash);
86
87 private:
88 ResDBConfig config_;
89 ReplicaCommunicator* replica_communicator_;
90 std::unique_ptr<LockFreeCollectorPool> collector_pool_, context_pool_;
91 LockFreeQueue<QueueItem> batch_queue_;
92 std::thread user_req_thread_[16];
93 std::atomic<bool> stop_;
94 uint64_t local_id_ = 0;
95 Stats* global_stats_;
96 std::vector<int> send_num_;
97 std::mutex mutex_;
98 std::atomic<int> total_num_;
99 SystemInfo* system_info_;
100 SignatureVerifier* verifier_;
101 SignatureInfo sig_;
102 std::function<std::string()> data_func_;
103 std::future<bool> eval_ready_future_;
104 std::promise<bool> eval_ready_promise_;
105 std::atomic<bool> eval_started_;
106 std::atomic<int> fail_num_;
107
108 std::thread checking_timeout_thread_;
109 std::map<std::string, std::unique_ptr<Request>> waiting_response_batches_;
110 std::priority_queue<PerformanceClientTimeout> client_timeout_min_heap_;
111 std::mutex pm_lock_;
112 uint64_t timeout_length_;
113 sem_t request_sent_signal_;
114 uint64_t highest_seq_;
115 uint64_t highest_seq_primary_id_;
116};
117
118} // namespace resdb
bool operator<(const PerformanceClientTimeout &other) const
int ProcessResponseMsg(std::unique_ptr< Context > context, std::unique_ptr< Request > request)
void SetDataFunc(std::function< std::string()> func)
std::list< std::unique_ptr< RequestInfo > > CollectorDataType