-
Notifications
You must be signed in to change notification settings - Fork 0
/
glog_metainfo.h
74 lines (47 loc) · 1.38 KB
/
glog_metainfo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <map>
#include <set>
#include <string>
#include <functional>
#include <mutex>
#include <memory>
#include <cassert>
#include <stdint.h>
#include "glog_comm.h"
namespace paxos {
class Paxos;
};
namespace glog {
class AsyncWorker;
class SetRequest;
using PaxosLogCreater =
std::function<std::unique_ptr<paxos::Paxos>(uint64_t logid)>;
extern uint64_t METAINFO_LOGID;
class GlogMetaInfo {
public:
GlogMetaInfo(ReadCBType readcb, PaxosLogCreater plog_creater);
~GlogMetaInfo();
std::tuple<std::unique_ptr<glog::SetRequest>, uint64_t>
PackMetaInfoEntry(const std::string& logname);
uint64_t QueryLogId(const std::string& logname);
paxos::Paxos& GetMetaInfoLog() {
assert(nullptr != meta_log_);
return *meta_log_;
}
paxos::Paxos* GetPaxosLog(uint64_t logid);
int ApplyLogEntry(uint64_t apply_index);
std::set<uint64_t> GetAllLogId();
private:
ReadCBType readcb_;
PaxosLogCreater plog_creater_;
std::unique_ptr<paxos::Paxos> meta_log_;
// protected by meta_log_mutex_;
std::mutex meta_log_mutex_;
uint64_t meta_apply_index_ = 0;
uint64_t max_assigned_logid_ = 0;
std::map<std::string, uint64_t> state_;
std::map<uint64_t, std::unique_ptr<paxos::Paxos>> map_plog_;
// end of protected
std::unique_ptr<AsyncWorker> async_worker_;
};
} // namespace glog