You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by "PragmaTwice (via GitHub)" <gi...@apache.org> on 2023/03/09 04:44:03 UTC

[GitHub] [incubator-kvrocks] PragmaTwice commented on a diff in pull request #1302: Add CreateThread to avoid manual try-catch

PragmaTwice commented on code in PR #1302:
URL: https://github.com/apache/incubator-kvrocks/pull/1302#discussion_r1130424163


##########
src/commands/cmd_replication.cc:
##########
@@ -271,48 +273,52 @@ class CommandFetchFile : public Commander {
     conn->NeedNotFreeBufferEvent();  // Feed-replica-file thread will close the replica bufferevent
     conn->EnableFlag(Redis::Connection::kCloseAsync);
 
-    std::thread t = std::thread([svr, repl_fd, ip, files, bev = conn->GetBufferEvent()]() {
-      Util::ThreadSetName("feed-repl-file");
-      auto exit = MakeScopeExit([bev] { bufferevent_free(bev); });
-      svr->IncrFetchFileThread();
-
-      for (const auto &file : files) {
-        if (svr->IsStopped()) break;
-
-        uint64_t file_size = 0, max_replication_bytes = 0;
-        if (svr->GetConfig()->max_replication_mb > 0) {
-          max_replication_bytes = (svr->GetConfig()->max_replication_mb * MiB) / svr->GetFetchFileThreadNum();
-        }
-        auto start = std::chrono::high_resolution_clock::now();
-        auto fd = UniqueFD(Engine::Storage::ReplDataManager::OpenDataFile(svr->storage_, file, &file_size));
-        if (!fd) break;
-
-        // Send file size and content
-        if (Util::SockSend(repl_fd, std::to_string(file_size) + CRLF).IsOK() &&
-            Util::SockSendFile(repl_fd, *fd, file_size).IsOK()) {
-          LOG(INFO) << "[replication] Succeed sending file " << file << " to " << ip;
-        } else {
-          LOG(WARNING) << "[replication] Fail to send file " << file << " to " << ip << ", error: " << strerror(errno);
-          break;
-        }
-        fd.Close();
-
-        // Sleep if the speed of sending file is more than replication speed limit
-        auto end = std::chrono::high_resolution_clock::now();
-        uint64_t duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
-        auto shortest = static_cast<uint64_t>(static_cast<double>(file_size) /
-                                              static_cast<double>(max_replication_bytes) * (1000 * 1000));
-        if (max_replication_bytes > 0 && duration < shortest) {
-          LOG(INFO) << "[replication] Need to sleep " << (shortest - duration) / 1000
-                    << " ms since of sending files too quickly";
-          usleep(shortest - duration);
-        }
-      }
-      auto now = static_cast<time_t>(Util::GetTimeStamp());
-      svr->storage_->SetCheckpointAccessTime(now);
-      svr->DecrFetchFileThread();
-    });
-    t.detach();
+    std::thread t =

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org