forked from ton-blockchain/ton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive-db.hpp
97 lines (75 loc) · 2.94 KB
/
archive-db.hpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include "td/actor/actor.h"
#include "td/utils/buffer.h"
#include "ton/ton-types.h"
#include "td/utils/port/FileFd.h"
#include "package.hpp"
#include "filedb.hpp"
#include "validator/interfaces/block-handle.h"
#include <map>
#include <list>
namespace ton {
namespace validator {
class PackageWriter : public td::actor::Actor {
public:
PackageWriter(std::shared_ptr<Package> package) : package_(std::move(package)) {
}
void append(std::string filename, td::BufferSlice data, td::Promise<std::pair<td::uint64, td::uint64>> promise);
private:
std::shared_ptr<Package> package_;
};
class ArchiveFile : public td::actor::Actor {
public:
ArchiveFile(std::string path, UnixTime ts) : path_(std::move(path)), ts_(ts) {
}
void start_up() override;
void write(FileDb::RefId ref_id, td::BufferSlice data, td::Promise<td::Unit> promise);
void write_handle(BlockHandle handle, td::Promise<td::Unit> promise);
void read(FileDb::RefId ref_id, td::Promise<td::BufferSlice> promise);
void read_handle(BlockIdExt block_id, td::Promise<BlockHandle> promise);
private:
void completed_write(FileDb::RefId ref_id, td::uint64 offset, td::uint64 new_size, td::Promise<td::Unit> promise);
std::shared_ptr<Package> package_;
std::shared_ptr<td::KeyValue> index_;
td::actor::ActorOwn<PackageWriter> writer_;
std::string path_;
UnixTime ts_;
};
class ArchiveManager : public td::actor::Actor {
public:
ArchiveManager(std::string db_root);
void write(UnixTime ts, bool key_block, FileDb::RefId ref_id, td::BufferSlice data, td::Promise<td::Unit> promise);
void write_handle(BlockHandle handle, td::Promise<td::Unit> promise);
void read(UnixTime ts, bool key_block, FileDb::RefId ref_id, td::Promise<td::BufferSlice> promise);
void read_handle(BlockIdExt block_id, td::Promise<BlockHandle> promise);
void start_up() override;
private:
void read_handle_cont(BlockIdExt block_id, td::Promise<BlockHandle> promise);
struct FileDescription {
struct Desc {
BlockSeqno seqno;
LogicalTime lt;
};
FileDescription(UnixTime unix_time, bool key_block) : unix_time(unix_time), key_block(key_block) {
}
auto file_actor_id() const {
return file.get();
}
UnixTime unix_time;
bool key_block;
std::map<ShardIdFull, Desc> first_blocks;
td::actor::ActorOwn<ArchiveFile> file;
};
void load_package(UnixTime ts, bool key_block);
UnixTime convert_ts(UnixTime ts, bool key_block);
FileDescription *get_file(UnixTime ts, bool key_block, bool force = true);
FileDescription *add_file(UnixTime ts, bool key_block);
void update_desc(FileDescription &desc, ShardIdFull shard, BlockSeqno seqno, LogicalTime lt);
FileDescription *get_file_by_seqno(ShardIdFull shard, BlockSeqno seqno, bool key_block);
std::string db_root_;
std::map<UnixTime, FileDescription> files_;
std::map<UnixTime, FileDescription> key_files_;
std::shared_ptr<td::KeyValue> index_;
};
} // namespace validator
} // namespace ton