mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
celldb in-memory mode (--celldb-in-memory option)
This commit is contained in:
parent
420029b056
commit
1723562748
48 changed files with 1966 additions and 201 deletions
|
@ -27,6 +27,8 @@
|
|||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/HashMap.h"
|
||||
#include "td/utils/HashSet.h"
|
||||
#include "td/utils/Time.h"
|
||||
#include "td/utils/Timer.h"
|
||||
#include "td/utils/port/FileFd.h"
|
||||
|
||||
namespace vm {
|
||||
|
@ -199,6 +201,43 @@ struct CellSerializationInfo {
|
|||
td::Result<Ref<DataCell>> create_data_cell(td::Slice data, td::Span<Ref<Cell>> refs) const;
|
||||
};
|
||||
|
||||
class BagOfCellsLogger {
|
||||
public:
|
||||
BagOfCellsLogger() = default;
|
||||
explicit BagOfCellsLogger(td::CancellationToken cancellation_token)
|
||||
: cancellation_token_(std::move(cancellation_token)) {
|
||||
}
|
||||
|
||||
void start_stage(std::string stage) {
|
||||
log_speed_at_ = td::Timestamp::in(LOG_SPEED_PERIOD);
|
||||
processed_cells_ = 0;
|
||||
timer_ = {};
|
||||
stage_ = std::move(stage);
|
||||
}
|
||||
void finish_stage(td::Slice desc) {
|
||||
LOG(ERROR) << "serializer: " << stage_ << " took " << timer_.elapsed() << "s, " << desc;
|
||||
}
|
||||
td::Status on_cell_processed() {
|
||||
++processed_cells_;
|
||||
if (processed_cells_ % 1000 == 0) {
|
||||
TRY_STATUS(cancellation_token_.check());
|
||||
}
|
||||
if (log_speed_at_.is_in_past()) {
|
||||
log_speed_at_ += LOG_SPEED_PERIOD;
|
||||
LOG(WARNING) << "serializer: " << stage_ << " " << (double)processed_cells_ / LOG_SPEED_PERIOD << " cells/s";
|
||||
processed_cells_ = 0;
|
||||
}
|
||||
return td::Status::OK();
|
||||
}
|
||||
|
||||
private:
|
||||
std::string stage_;
|
||||
td::Timer timer_;
|
||||
td::CancellationToken cancellation_token_;
|
||||
td::Timestamp log_speed_at_;
|
||||
size_t processed_cells_ = 0;
|
||||
static constexpr double LOG_SPEED_PERIOD = 120.0;
|
||||
};
|
||||
class BagOfCells {
|
||||
public:
|
||||
enum { hash_bytes = vm::Cell::hash_bytes, default_max_roots = 16384 };
|
||||
|
@ -283,6 +322,7 @@ class BagOfCells {
|
|||
const unsigned char* index_ptr{nullptr};
|
||||
const unsigned char* data_ptr{nullptr};
|
||||
std::vector<unsigned long long> custom_index;
|
||||
BagOfCellsLogger* logger_ptr_{nullptr};
|
||||
|
||||
public:
|
||||
void clear();
|
||||
|
@ -292,14 +332,17 @@ class BagOfCells {
|
|||
int add_root(td::Ref<vm::Cell> add_root);
|
||||
td::Status import_cells() TD_WARN_UNUSED_RESULT;
|
||||
BagOfCells() = default;
|
||||
void set_logger(BagOfCellsLogger* logger_ptr) {
|
||||
logger_ptr_ = logger_ptr;
|
||||
}
|
||||
std::size_t estimate_serialized_size(int mode = 0);
|
||||
BagOfCells& serialize(int mode = 0);
|
||||
std::string serialize_to_string(int mode = 0);
|
||||
td::Status serialize(int mode = 0);
|
||||
td::string serialize_to_string(int mode = 0);
|
||||
td::Result<td::BufferSlice> serialize_to_slice(int mode = 0);
|
||||
std::size_t serialize_to(unsigned char* buffer, std::size_t buff_size, int mode = 0);
|
||||
td::Result<std::size_t> serialize_to(unsigned char* buffer, std::size_t buff_size, int mode = 0);
|
||||
td::Status serialize_to_file(td::FileFd& fd, int mode = 0);
|
||||
template<typename WriterT>
|
||||
std::size_t serialize_to_impl(WriterT& writer, int mode = 0);
|
||||
template <typename WriterT>
|
||||
td::Result<std::size_t> serialize_to_impl(WriterT& writer, int mode = 0);
|
||||
std::string extract_string() const;
|
||||
|
||||
td::Result<long long> deserialize(const td::Slice& data, int max_roots = default_max_roots);
|
||||
|
@ -345,6 +388,8 @@ td::Result<std::vector<Ref<Cell>>> std_boc_deserialize_multi(td::Slice data,
|
|||
int max_roots = BagOfCells::default_max_roots);
|
||||
td::Result<td::BufferSlice> std_boc_serialize_multi(std::vector<Ref<Cell>> root, int mode = 0);
|
||||
|
||||
td::Status std_boc_serialize_to_file(Ref<Cell> root, td::FileFd& fd, int mode = 0,
|
||||
td::CancellationToken cancellation_token = {});
|
||||
td::Status std_boc_serialize_to_file_large(std::shared_ptr<CellDbReader> reader, Cell::Hash root_hash, td::FileFd& fd,
|
||||
int mode = 0, td::CancellationToken cancellation_token = {});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue