mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
"getcollatoroptionsjson" command in validator console (#1059)
* "getcollatoroptionsjson" command in validator console * Improve state serializer Use previous persistent state to speed up reading
This commit is contained in:
parent
00cd053dbc
commit
b9e89d4c66
23 changed files with 353 additions and 80 deletions
|
@ -68,9 +68,14 @@ Result<T> read_file_impl(CSlice path, int64 size, int64 offset) {
|
|||
return Status::Error("Failed to read file: invalid size");
|
||||
}
|
||||
auto content = create_empty<T>(narrow_cast<size_t>(size));
|
||||
TRY_RESULT(got_size, from_file.pread(as_mutable_slice(content), offset));
|
||||
if (got_size != static_cast<size_t>(size)) {
|
||||
return Status::Error("Failed to read file");
|
||||
MutableSlice slice = as_mutable_slice(content);
|
||||
while (!slice.empty()) {
|
||||
TRY_RESULT(got_size, from_file.pread(slice, offset));
|
||||
if (got_size == 0) {
|
||||
return Status::Error("Failed to read file");
|
||||
}
|
||||
offset += got_size;
|
||||
slice.remove_prefix(got_size);
|
||||
}
|
||||
from_file.close();
|
||||
return std::move(content);
|
||||
|
@ -103,9 +108,15 @@ Status write_file(CSlice to, Slice data, WriteFileOptions options) {
|
|||
TRY_STATUS(to_file.lock(FileFd::LockFlags::Write, to.str(), 10));
|
||||
TRY_STATUS(to_file.truncate_to_current_position(0));
|
||||
}
|
||||
TRY_RESULT(written, to_file.write(data));
|
||||
if (written != size) {
|
||||
return Status::Error(PSLICE() << "Failed to write file: written " << written << " bytes instead of " << size);
|
||||
size_t total_written = 0;
|
||||
while (!data.empty()) {
|
||||
TRY_RESULT(written, to_file.write(data));
|
||||
if (written == 0) {
|
||||
return Status::Error(PSLICE() << "Failed to write file: written " << total_written << " bytes instead of "
|
||||
<< size);
|
||||
}
|
||||
total_written += written;
|
||||
data.remove_prefix(written);
|
||||
}
|
||||
if (options.need_sync) {
|
||||
TRY_STATUS(to_file.sync());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue