Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add clang-tidy for pika #1515

Merged
merged 38 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b871a44
feature:add clang-tidy for pika
ForestLH May 14, 2023
79db0eb
feature:WIP modified clang-tidy file
ForestLH May 16, 2023
8bb85f1
feature:disable compile command clang-tidy check
ForestLH May 16, 2023
8827ff5
style:Make the code standard according to clang-tidy
ForestLH May 16, 2023
78e327d
merge upstream unstable
AlexStocks May 23, 2023
09558b9
delete double std::move
AlexStocks May 23, 2023
6200048
auto* -> auto
AlexStocks May 23, 2023
6bad717
using noncopyable
AlexStocks May 23, 2023
0f19c14
add space for override{}
AlexStocks May 23, 2023
341e190
add spaces
AlexStocks May 24, 2023
54cef5b
delete != 0
AlexStocks May 24, 2023
ff42430
format if-return
AlexStocks May 24, 2023
68b70a8
clear inheritage
AlexStocks May 24, 2023
487cb0f
format codes
AlexStocks May 24, 2023
9b9ca7c
format codes
AlexStocks May 24, 2023
569c68a
delete == 0
AlexStocks May 24, 2023
168277d
fix:fix build error
ForestLH May 25, 2023
b508696
style:disable check bool implicit convert in clang-tidy
ForestLH May 25, 2023
93b7a0d
Merge pull request #1 from AlexStocks/lihao-clang
ForestLH May 25, 2023
9f902dd
style:update code style
ForestLH May 25, 2023
d27094a
delete '!= nullptr'
AlexStocks May 25, 2023
02e17e5
format if/while
AlexStocks May 25, 2023
deaa4bb
Merge pull request #2 from ForestLH/style/clang
ForestLH May 25, 2023
f6a68d7
Merge pull request #3 from AlexStocks/lihao-clang
ForestLH May 25, 2023
5c1e24f
fix ci failure
AlexStocks May 25, 2023
9d4e024
Merge pull request #4 from AlexStocks/lihao-clang
ForestLH May 25, 2023
e919de2
fix:build ci error
ForestLH May 26, 2023
e8d9171
style:The judgment statement should not be an assignment
ForestLH May 26, 2023
de1594b
style:format codes
ForestLH May 26, 2023
6bc870c
Merge pull request #5 from ForestLH/style/clang
ForestLH May 26, 2023
3624335
style:format codes
ForestLH May 26, 2023
cb7238a
Merge pull request #6 from ForestLH/style/clang
ForestLH May 26, 2023
735fa02
format codes
AlexStocks May 26, 2023
b508399
merge upstream unstable
AlexStocks May 26, 2023
810f799
Merge branch 'unstable' into lihao-clang
AlexStocks May 26, 2023
62d8635
Merge pull request #7 from AlexStocks/lihao-clang
ForestLH May 26, 2023
008f567
format codes
AlexStocks May 26, 2023
7a2b3bd
Merge pull request #8 from AlexStocks/lihao-clang
ForestLH May 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
using noncopyable
  • Loading branch information
AlexStocks committed May 23, 2023
commit 6bad717b7e43c1c90b2182f20b0030e75e63ba75
6 changes: 1 addition & 5 deletions include/pika_binlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Version final : public pstd::noncopyable {
std::shared_ptr<pstd::RWFile> save_;
};

class Binlog {
class Binlog : public pstd::noncopyable {
public:
Binlog(std::string Binlog_path, int file_size = 100 * 1024 * 1024);
~Binlog();
Expand Down Expand Up @@ -83,10 +83,6 @@ class Binlog {

void Close();

// No copying allowed
Binlog(const Binlog&) = delete;
void operator=(const Binlog&) = delete;

private:
pstd::Status Put(const char* item, int len);
static pstd::Status AppendPadding(pstd::WritableFile* file, uint64_t* len);
Expand Down
7 changes: 1 addition & 6 deletions include/pika_consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@

#include <utility>

#include <utility>

#include "include/pika_binlog_transverter.h"
#include "include/pika_client_conn.h"
#include "include/pika_define.h"
#include "include/pika_slave_node.h"
#include "include/pika_stable_log.h"
#include "pstd/include/env.h"

class Context {
class Context : public pstd::noncopyable {
public:
Context(std::string path);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该是建议用std::move吧。


Expand All @@ -38,9 +36,6 @@ class Context {
tmp_stream << " Applied window " << applied_win_.ToStringStatus();
return tmp_stream.str();
}
// No copying allowed;
Context(const Context&) = delete;
void operator=(const Context&) = delete;

private:
std::string path_;
Expand Down
9 changes: 2 additions & 7 deletions src/net/include/http_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "pstd/include/pstd_status.h"
#include "pstd/include/xdebug.h"
#include "pstd/include/pika_noncopyable.h"

#include "net/include/net_conn.h"
#include "net/include/net_define.h"
Expand Down Expand Up @@ -128,7 +129,7 @@ class HTTPResponse {
bool SerializeHeader();
};

class HTTPHandles {
class HTTPHandles : public pstd::noncopyable {
public:
// You need implement these handles.
/*
Expand Down Expand Up @@ -164,12 +165,6 @@ class HTTPHandles {
HTTPHandles() = default;
virtual ~HTTPHandles() = default;

/*
* No allowed copy and copy assign
*/
HTTPHandles(const HTTPHandles&) = delete;
void operator=(const HTTPHandles&) = delete;

protected:
/*
* Assigned in ServerHandle's CreateWorkerSpecificData
Expand Down
8 changes: 2 additions & 6 deletions src/net/include/net_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
#include "net/include/server_thread.h"
#include "net/src/net_multiplexer.h"
#include "pstd/include/testutil.h"
#include "pstd/include/pika_noncopyable.h"

namespace net {

class Thread;

class NetConn : public std::enable_shared_from_this<NetConn> {
class NetConn : public std::enable_shared_from_this<NetConn>, public pstd::noncopyable {
public:
NetConn(int fd, std::string ip_port, Thread* thread, NetMultiplexer* mpx = nullptr);
#ifdef __ENABLE_SSL
AlexStocks marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -93,11 +94,6 @@ class NetConn : public std::enable_shared_from_this<NetConn> {

bool security() { return ssl_ != nullptr; }
#endif
/*
* No allowed copy and copy assign operator
*/
NetConn(const NetConn&) = delete;
void operator=(const NetConn&) = delete;

private:
int fd_ = -1;
Expand Down
5 changes: 1 addition & 4 deletions src/net/include/net_pubsub.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace net {
class NetFiredEvent;
class NetConn;

class PubSubThread : public Thread {
class PubSubThread : public Thread, public pstd::noncopyable {
public:
PubSubThread();

Expand Down Expand Up @@ -72,9 +72,6 @@ class PubSubThread : public Thread {
void UpdateConnReadyState(int fd, const ReadyState& state);

bool IsReady(int fd);
// No copying allowed
PubSubThread(const PubSubThread&) = delete;
void operator=(const PubSubThread&) = delete;

private:
void RemoveConn(const std::shared_ptr<NetConn>& conn);
Expand Down
9 changes: 2 additions & 7 deletions src/net/include/net_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
#include <string>

#include "pstd/include/pstd_mutex.h"
#include "pstd/include/pika_noncopyable.h"

namespace net {

class Thread {
class Thread : public pstd::noncopyable {
public:
Thread();
virtual ~Thread();
Expand All @@ -35,12 +36,6 @@ class Thread {

void set_thread_name(const std::string& name) { thread_name_ = name; }

/*
* No allowed copy and copy assign
*/
Thread(const Thread&) = delete;
void operator=(const Thread&) = delete;

protected:
std::atomic<bool> should_stop_;

Expand Down
7 changes: 1 addition & 6 deletions src/net/include/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct TimeTask {
bool operator<(const TimeTask& task) const { return exec_time > task.exec_time; }
};

class ThreadPool {
class ThreadPool : public pstd::noncopyable {
public:
class Worker {
public:
Expand All @@ -41,11 +41,6 @@ class ThreadPool {

int start();
int stop();
/*
* No allowed copy and copy assign
*/
Worker(const Worker&) = delete;
void operator=(const Worker&) = delete;

private:
pthread_t thread_id_;
Expand Down
5 changes: 1 addition & 4 deletions src/net/src/dispatch_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class NetItem;
class NetFiredEvent;
class WorkerThread;

class DispatchThread : public ServerThread {
class DispatchThread : public ServerThread, public pstd::noncopyable {
public:
DispatchThread(int port, int work_num, ConnFactory* conn_factory, int cron_interval, int queue_limit,
const ServerHandle* handle);
Expand Down Expand Up @@ -54,9 +54,6 @@ class DispatchThread : public ServerThread {
void HandleNewConn(int connfd, const std::string& ip_port) override;

void SetQueueLimit(int queue_limit) override;
// No copying allowed
DispatchThread(const DispatchThread&) = delete;
void operator=(const DispatchThread&) = delete;

private:
/*
Expand Down
7 changes: 4 additions & 3 deletions src/net/src/pb_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
#include "net/include/net_define.h"
#include "pstd/include/pstd_status.h"
#include "pstd/include/xdebug.h"
#include "pstd/include/pika_noncopyable.h"


using pstd::Status;

namespace net {

// Default PBCli is block IO;
class PbCli : public NetCli {
class PbCli : public NetCli, public pstd::noncopyable {
public:
PbCli(const std::string& ip, int port);
~PbCli() override;
Expand All @@ -28,8 +31,6 @@ class PbCli : public NetCli {
// Read, parse and store the reply
Status Recv(void* msg_res) override;

PbCli(const PbCli&) = delete;
void operator=(const PbCli&) = delete;
private:
// BuildWbuf need to access rbuf_, wbuf_;
char* rbuf_;
Expand Down
7 changes: 2 additions & 5 deletions src/net/src/redis_cli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
#include <utility>
#include <vector>

#include "pstd/include/pika_noncopyable.h"
#include "net/include/net_cli.h"
#include "net/include/net_define.h"

using pstd::Status;

namespace net {

class RedisCli : public NetCli {
class RedisCli : public NetCli, public pstd::noncopyable {
public:
RedisCli();
~RedisCli() override;
Expand All @@ -33,10 +34,6 @@ class RedisCli : public NetCli {
// Read, parse and store the reply
Status Recv(void* trival = nullptr) override;

// No copyable
RedisCli(const RedisCli&) = delete;
void operator=(const RedisCli&) = delete;

private:
RedisCmdArgsType argv_; // The parsed result

Expand Down
11 changes: 3 additions & 8 deletions src/net/src/server_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
#include <iostream>
#include <string>

#include "pstd/include/pika_noncopyable.h"

namespace net {

class ServerSocket {
class ServerSocket : public pstd::noncopyable {
public:
explicit ServerSocket(int port, bool is_block = false);

Expand Down Expand Up @@ -49,13 +51,6 @@ class ServerSocket {

void set_sockfd(int sockfd) { sockfd_ = sockfd; }

/*
* No allowed copy and copy assign operator
*/

ServerSocket(const ServerSocket&) = delete;
void operator=(const ServerSocket&) = delete;

private:
int SetNonBlock();
/*
Expand Down
15 changes: 7 additions & 8 deletions src/pika_client_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ PikaClientConn::PikaClientConn(int fd, const std::string& ip_port, net::Thread*
const net::HandleType& handle_type, int max_conn_rbuf_size)
: RedisConn(fd, ip_port, thread, mpx, handle_type, max_conn_rbuf_size),
server_thread_(reinterpret_cast<net::ServerThread*>(thread)),
current_table_(g_pika_conf->default_table())
{
autoh_stat_.Init();
current_table_(g_pika_conf->default_table()) {
auth_stat_.Init();
}

std::shared_ptr<Cmd> PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const std::string& opt,
Expand All @@ -43,9 +42,9 @@ std::shared_ptr<Cmd> PikaClientConn::DoCmd(const PikaCmdArgsType& argv, const st
c_ptr->SetConn(std::dynamic_pointer_cast<PikaClientConn>(shared_from_this()));
c_ptr->SetResp(resp_ptr);

// Check autohed
// Check authed
// AuthCmd will set stat_
if (!autoh_stat_.IsAuthed(c_ptr)) {
if (!auth_stat_.IsAuthed(c_ptr)) {
c_ptr->res().SetRes(CmdRes::kErrOther, "NOAUTH Authentication required.");
return c_ptr;
}
Expand Down Expand Up @@ -283,7 +282,7 @@ void PikaClientConn::ExecRedisCmd(const PikaCmdArgsType& argv, const std::shared

// Initial permission status
void PikaClientConn::AuthStat::Init() {
// Check autoh required
// Check auth required
stat_ = g_pika_conf->userpass().empty() ? kLimitAuthed : kNoAuthed;
if (stat_ == kLimitAuthed && g_pika_conf->requirepass().empty()) {
stat_ = kAdminAuthed;
Expand All @@ -308,15 +307,15 @@ bool PikaClientConn::AuthStat::IsAuthed(const std::shared_ptr<Cmd>& cmd_ptr) {
}
break;
default:
LOG(WARNING) << "Invalid autoh stat : " << static_cast<unsigned>(stat_);
LOG(WARNING) << "Invalid auth stat : " << static_cast<unsigned>(stat_);
return false;
}
return true;
}

// Update permission status
bool PikaClientConn::AuthStat::ChecknUpdate(const std::string& message) {
// Situations to change autoh status
// Situations to change auth status
if (message == "USER") {
stat_ = kLimitAuthed;
} else if (message == "ROOT") {
Expand Down
6 changes: 3 additions & 3 deletions src/pika_repl_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ Status PikaReplClient::SendMetaSync() {
node->set_ip(local_ip);
node->set_port(g_pika_server->port());

std::string masterautoh = g_pika_conf->masterautoh();
if (!masterautoh.empty()) {
meta_sync->set_autoh(masterautoh);
std::string masterauth = g_pika_conf->masterauth();
if (!masterauth.empty()) {
meta_sync->set_auth(masterauth);
}

std::string to_send;
Expand Down
6 changes: 3 additions & 3 deletions src/pika_repl_server_conn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ void PikaReplServerConn::HandleMetaSyncRequest(void* arg) {

InnerMessage::InnerRequest::MetaSync meta_sync_request = req->meta_sync();
const InnerMessage::Node& node = meta_sync_request.node();
std::string masterautoh = meta_sync_request.has_autoh() ? meta_sync_request.autoh() : "";
std::string masterauth = meta_sync_request.has_auth() ? meta_sync_request.auth() : "";

InnerMessage::InnerResponse response;
response.set_type(InnerMessage::kMetaSync);
if (!g_pika_conf->requirepass().empty() && g_pika_conf->requirepass() != masterautoh) {
if (!g_pika_conf->requirepass().empty() && g_pika_conf->requirepass() != masterauth) {
response.set_code(InnerMessage::kError);
response.set_reply("Auth with master error, Invalid masterautoh");
response.set_reply("Auth with master error, Invalid masterauth");
} else {
LOG(INFO) << "Receive MetaSync, Slave ip: " << node.ip() << ", Slave port:" << node.port();
std::vector<TableStruct> table_structs = g_pika_conf->table_structs();
Expand Down
Loading