Skip to content

Commit

Permalink
fix: comment
Browse files Browse the repository at this point in the history
  • Loading branch information
longfar-ncy committed Oct 21, 2024
1 parent f1a1048 commit f9287eb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
9 changes: 6 additions & 3 deletions pproxy/task_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <memory>
#include <queue>
#include <string>
#include <type_traits>

#include "pstd/thread_pool.h"

class Task {
public:
Expand Down Expand Up @@ -46,8 +49,8 @@ class TaskManager {

template <class F, class... Args>
auto Push(F&& function, Args&&... args) //
-> std::future<typename std::result_of<F(Args...)>::type> {
using ReturnType = typename std::result_of<F(Args...)>::type;
-> std::future<std::invoke_result_t<F, Args...>> {
using ReturnType = std::invoke_result_t<F, Args...>;

auto task = std::make_shared<std::packaged_task<ReturnType()>>( //
std::bind(std::forward<F>(function), std::forward<Args>(args)...));
Expand All @@ -72,7 +75,7 @@ class TaskManager {
void processTasks();

private:
std::shared_ptr<::Threadpool> threadpool_;
std::shared_ptr<Threadpool> threadpool_;
std::queue<Task> tasks_;
std::mutex mutex_;
size_t maxWorkers_;
Expand Down
18 changes: 9 additions & 9 deletions src/cmd_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,22 @@ void InfoCmd::InfoRaft(PClient* client, std::string& message) {
return client->SetRes(CmdRes::kWrongNum, client->CmdName());
}

praft_ = PSTORE.GetBackend(client->GetCurrentDB())->GetPRaft();
assert(praft_);
if (!praft_->IsInitialized()) {
auto praft = PSTORE.GetBackend(client->GetCurrentDB())->GetPRaft();
assert(praft);
if (!praft->IsInitialized()) {
return client->SetRes(CmdRes::kErrOther, "Don't already cluster member");
}

auto node_status = praft_->GetNodeStatus();
auto node_status = praft->GetNodeStatus();
if (node_status.state == braft::State::STATE_END) {
message += "-ERR Node is not initialized.\r\n";
return;
}

std::stringstream tmp_stream;
tmp_stream << "raft_group_id:" << praft_->GetGroupID() << "\r\n";
tmp_stream << "raft_node_id:" << praft_->GetNodeID() << "\r\n";
tmp_stream << "raft_peer_id:" << praft_->GetPeerID() << "\r\n";
tmp_stream << "raft_group_id:" << praft->GetGroupID() << "\r\n";
tmp_stream << "raft_node_id:" << praft->GetNodeID() << "\r\n";
tmp_stream << "raft_peer_id:" << praft->GetPeerID() << "\r\n";
if (braft::is_active_state(node_status.state)) {
tmp_stream << "raft_state:up\r\n";
} else {
Expand All @@ -290,9 +290,9 @@ void InfoCmd::InfoRaft(PClient* client, std::string& message) {
tmp_stream << "raft_leader_id:" << node_status.leader_id.to_string() << "\r\n";
tmp_stream << "raft_current_term:" << std::to_string(node_status.term) << "\r\n";

if (praft_->IsLeader()) {
if (praft->IsLeader()) {
std::vector<braft::PeerId> peers;
auto status = praft_->GetListPeers(&peers);
auto status = praft->GetListPeers(&peers);
if (!status.ok()) {
tmp_stream.str("-ERR ");
tmp_stream << status.error_str() << "\r\n";
Expand Down
5 changes: 1 addition & 4 deletions src/cmd_admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,12 @@ class InfoCmd : public BaseCmd {
void InfoServer(std::string& info);
void InfoStats(std::string& info);
void InfoCPU(std::string& info);
void InfoRaft(PClient* client, std::string& info);
void InfoRaft(PClient* client, std::string& message);
void InfoData(std::string& info);
void InfoCommandStats(PClient* client, std::string& info);
std::string FormatCommandStatLine(const CommandStatistics& stats);
double MethodofTotalTimeCalculation(const uint64_t time_consuming);
double MethodofCommandStatistics(const uint64_t time_consuming, const uint64_t frequency);

private:
PRaft* praft_ = nullptr;
};

class CmdDebug : public BaseCmdGroup {
Expand Down
9 changes: 2 additions & 7 deletions src/praft/praft.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,6 @@ void PRaft::SendNodeRequest(PClient* client) {
auto cluster_cmd_type = cluster_cmd_ctx_.GetClusterCmdType();
switch (cluster_cmd_type) {
case ClusterCmdType::kJoin: {
// SendNodeInfoRequest(client, "DATA");
// SendNodeInfoRequest(client, "DATA");
SendNodeAddRequest(client);
} break;
case ClusterCmdType::kRemove:
Expand Down Expand Up @@ -448,7 +446,6 @@ int PRaft::ProcessClusterJoinCmdResponse(PClient* client, const char* start, int
ERROR("Joined Raft cluster fail, str: {}", reply);
join_client->SetRes(CmdRes::kErrOther, reply);
join_client->SendPacket();
// join_client->Clear();
// If the join fails, clear clusterContext and set it again by using the join command
cluster_cmd_ctx_.Clear();
}
Expand All @@ -473,7 +470,6 @@ int PRaft::ProcessClusterRemoveCmdResponse(PClient* client, const char* start, i

remove_client->SetRes(CmdRes::kOK);
remove_client->SendPacket();
// remove_client->Clear();
} else if (reply.find(NOT_LEADER) != std::string::npos) {
auto remove_client = cluster_cmd_ctx_.GetClient();
remove_client->Clear();
Expand All @@ -482,7 +478,6 @@ int PRaft::ProcessClusterRemoveCmdResponse(PClient* client, const char* start, i
ERROR("Removed Raft cluster fail, str: {}", reply);
remove_client->SetRes(CmdRes::kErrOther, reply);
remove_client->SendPacket();
// remove_client->Clear();
}

// If the remove fails, clear clusterContext and set it again by using the join command
Expand All @@ -493,7 +488,7 @@ int PRaft::ProcessClusterRemoveCmdResponse(PClient* client, const char* start, i

butil::Status PRaft::AddPeer(const std::string& peer) {
if (!node_) {
ERROR_LOG_AND_STATUS("Node is not initialized");
return ERROR_LOG_AND_STATUS("Node is not initialized");
}

braft::SynchronizedClosure done;
Expand All @@ -510,7 +505,7 @@ butil::Status PRaft::AddPeer(const std::string& peer) {

butil::Status PRaft::AddPeer(const std::string& endpoint, int index) {
if (!node_) {
ERROR_LOG_AND_STATUS("Node is not initialized");
return ERROR_LOG_AND_STATUS("Node is not initialized");
}

braft::SynchronizedClosure done;
Expand Down

0 comments on commit f9287eb

Please sign in to comment.