| 66 | void BatchSender::SetPrefixLogData(const std::string &prefix_logdata) { prefix_logdata_ = prefix_logdata; } |
| 67 | |
| 68 | Status BatchSender::Send() { |
| 69 | if (pending_entries_ == 0) { |
| 70 | return Status::OK(); |
| 71 | } |
| 72 | |
| 73 | // rate limit |
| 74 | if (bytes_per_sec_ > 0) { |
| 75 | auto single_burst = rate_limiter_->GetSingleBurstBytes(); |
| 76 | auto left = static_cast<int64_t>(write_batch_.GetDataSize()); |
| 77 | while (left > 0) { |
| 78 | auto request_size = std::min(left, single_burst); |
| 79 | rate_limiter_->Request(request_size, rocksdb::Env::IOPriority::IO_HIGH, nullptr); |
| 80 | left -= request_size; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | auto s = sendApplyBatchCmd(dst_fd_, write_batch_); |
| 85 | if (!s.IsOK()) { |
| 86 | return s.Prefixed("failed to send APPLYBATCH command"); |
| 87 | } |
| 88 | |
| 89 | sent_bytes_ += write_batch_.GetDataSize(); |
| 90 | sent_batches_num_++; |
| 91 | pending_entries_ = 0; |
| 92 | write_batch_.Clear(); |
| 93 | return Status::OK(); |
| 94 | } |
| 95 | |
| 96 | Status BatchSender::sendApplyBatchCmd(int fd, const rocksdb::WriteBatch &write_batch) { |
| 97 | if (fd <= 0) { |
no test coverage detected