Loading...
Searching...
No Matches
checkpoint_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
32#include "platform/proto/checkpoint_info.pb.h"
33#include "platform/proto/resdb.pb.h"
34
35namespace resdb {
36
38 public:
39 CheckPointManager(const ResDBConfig& config,
40 ReplicaCommunicator* replica_communicator,
41 SignatureVerifier* verifier);
42 virtual ~CheckPointManager();
43
45 uint64_t GetMaxTxnSeq();
46
47 void AddCommitData(std::unique_ptr<Request> request);
48 int ProcessCheckPoint(std::unique_ptr<Context> context,
49 std::unique_ptr<Request> request);
50
51 uint64_t GetStableCheckpoint() override;
52 StableCheckPoint GetStableCheckpointWithVotes();
53 bool IsValidCheckpointProof(const StableCheckPoint& stable_ckpt);
54
55 void SetTimeoutHandler(std::function<void()> timeout_handler);
57 int64_t current_stable_checkpoint) {}
58
59 void Stop();
60
61 void TimeoutHandler();
62
63 void WaitSignal();
64 std::unique_ptr<std::pair<uint64_t, std::string>> PopStableSeqHash();
65
66 void SetExecutor(TransactionExecutor* executor) { executor_ = executor; }
67
68 uint64_t GetHighestPreparedSeq();
69
70 void SetHighestPreparedSeq(uint64_t seq);
71
72 sem_t* CommitableSeqSignal();
73
74 uint64_t GetCommittableSeq();
75
76 private:
77 void UpdateCheckPointStatus();
78 void UpdateStableCheckPointStatus();
79 void BroadcastCheckPoint(uint64_t seq, const std::string& hash,
80 const std::vector<std::string>& stable_hashs,
81 const std::vector<uint64_t>& stable_seqs);
82
83 void Notify();
84 bool Wait();
85
86 protected:
89 std::unique_ptr<ChainState> txn_db_;
92 std::atomic<bool> stop_;
93 std::map<std::pair<uint64_t, std::string>, std::set<uint32_t>> sender_ckpt_;
94 std::map<std::pair<uint64_t, std::string>, std::vector<SignatureInfo>>
96 std::map<std::pair<uint64_t, std::string>, std::vector<std::string>>
98 std::atomic<uint64_t> current_stable_seq_;
99 std::mutex mutex_;
101 std::mutex cv_mutex_;
102 std::condition_variable cv_;
103 std::function<void()> timeout_handler_;
104 StableCheckPoint stable_ckpt_;
105 int new_data_ = 0;
107 std::condition_variable signal_;
109 std::mutex lt_mutex_;
110 uint64_t last_seq_ = 0;
112 std::atomic<uint64_t> highest_prepared_seq_;
113 uint64_t committable_seq_ = 0;
116};
117
118} // namespace resdb
void SetTimeoutHandler(std::function< void()> timeout_handler)
std::map< std::pair< uint64_t, std::string >, std::set< uint32_t > > sender_ckpt_
SignatureVerifier * verifier_
bool IsValidCheckpointProof(const StableCheckPoint &stable_ckpt)
std::unique_ptr< ChainState > txn_db_
LockFreeQueue< std::pair< uint64_t, std::string > > stable_hash_queue_
ReplicaCommunicator * replica_communicator_
virtual void UpdateStableCheckPointCallback(int64_t current_stable_checkpoint)
std::condition_variable cv_
std::map< std::pair< uint64_t, std::string >, std::vector< SignatureInfo > > sign_ckpt_
std::atomic< uint64_t > highest_prepared_seq_
TransactionExecutor * executor_
std::unique_ptr< std::pair< uint64_t, std::string > > PopStableSeqHash()
std::function< void()> timeout_handler_
int ProcessCheckPoint(std::unique_ptr< Context > context, std::unique_ptr< Request > request)
uint64_t GetStableCheckpoint() override
StableCheckPoint GetStableCheckpointWithVotes()
std::atomic< bool > stop_
void SetExecutor(TransactionExecutor *executor)
std::atomic< uint64_t > current_stable_seq_
void AddCommitData(std::unique_ptr< Request > request)
void SetHighestPreparedSeq(uint64_t seq)
std::map< std::pair< uint64_t, std::string >, std::vector< std::string > > hash_ckpt_
std::condition_variable signal_
LockFreeQueue< Request > data_queue_