Skip to content

Commit

Permalink
style:Make the code standard according to clang-tidy
Browse files Browse the repository at this point in the history
Signed-off-by: Hao Lee <1838249551@qq.com>
  • Loading branch information
ForestLH committed May 18, 2023
1 parent 8bb85f1 commit 8827ff5
Show file tree
Hide file tree
Showing 249 changed files with 5,584 additions and 5,411 deletions.
292 changes: 146 additions & 146 deletions include/pika_admin.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions include/pika_auxiliary_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
class PikaAuxiliaryThread : public net::Thread {
public:
PikaAuxiliaryThread() { set_thread_name("AuxiliaryThread"); }
virtual ~PikaAuxiliaryThread();
~PikaAuxiliaryThread() override;
pstd::Mutex mu_;
pstd::CondVar cv_;

private:
virtual void* ThreadMain();
void* ThreadMain() override;
};

#endif
43 changes: 20 additions & 23 deletions include/pika_binlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@

#include "include/pika_define.h"

using pstd::Slice;
using pstd::Status;

std::string NewFileName(const std::string name, const uint32_t current);
std::string NewFileName(const std::string& name, uint32_t current);

class Version {
public:
Version(pstd::RWFile* save);
~Version();

Status Init();
pstd::Status Init();

// RWLock should be held when access members.
Status StableSave();
pstd::Status StableSave();

uint32_t pro_num_ = 0;
uint64_t pro_offset_ = 0;
Expand All @@ -38,34 +36,33 @@ class Version {

void debug() {
std::shared_lock l(rwlock_);
printf("Current pro_num %u pro_offset %lu\n", pro_num_, pro_offset_);
printf("Current pro_num %u pro_offset %llu\n", pro_num_, pro_offset_);
}
// No copying allowed;
Version(const Version&) = delete;
void operator=(const Version&) = delete;

private:
pstd::RWFile* save_ = nullptr;

// No copying allowed;
Version(const Version&);
void operator=(const Version&);
};

class Binlog {
public:
Binlog(const std::string& Binlog_path, const int file_size = 100 * 1024 * 1024);
Binlog(std::string Binlog_path, int file_size = 100 * 1024 * 1024);
~Binlog();

void Lock() { mutex_.lock(); }
void Unlock() { mutex_.unlock(); }

Status Put(const std::string& item);
pstd::Status Put(const std::string& item);

Status GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint32_t* term = nullptr, uint64_t* logic_id = nullptr);
pstd::Status GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint32_t* term = nullptr, uint64_t* logic_id = nullptr);
/*
* Set Producer pro_num and pro_offset with lock
*/
Status SetProducerStatus(uint32_t filenum, uint64_t pro_offset, uint32_t term = 0, uint64_t index = 0);
pstd::Status SetProducerStatus(uint32_t pro_num, uint64_t pro_offset, uint32_t term = 0, uint64_t index = 0);
// Need to hold Lock();
Status Truncate(uint32_t pro_num, uint64_t pro_offset, uint64_t index);
pstd::Status Truncate(uint32_t pro_num, uint64_t pro_offset, uint64_t index);

uint64_t file_size() { return file_size_; }

Expand All @@ -87,18 +84,22 @@ class Binlog {

void Close();

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

private:
Status Put(const char* item, int len);
static Status AppendPadding(pstd::WritableFile* file, uint64_t* len);
pstd::Status Put(const char* item, int len);
static pstd::Status AppendPadding(pstd::WritableFile* file, uint64_t* len);
// pstd::WritableFile *queue() { return queue_; }

void InitLogFile();
Status EmitPhysicalRecord(RecordType t, const char* ptr, size_t n, int* temp_pro_offset);
pstd::Status EmitPhysicalRecord(RecordType t, const char* ptr, size_t n, int* temp_pro_offset);

/*
* Produce
*/
Status Produce(const Slice& item, int* pro_offset);
pstd::Status Produce(const pstd::Slice& item, int* pro_offset);

std::atomic<bool> opened_;

Expand All @@ -123,10 +124,6 @@ class Binlog {
std::atomic<bool> binlog_io_error_;
// Not use
// int32_t retry_;

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

#endif
12 changes: 5 additions & 7 deletions include/pika_binlog_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,22 @@

#include "include/pika_binlog.h"

using pstd::Slice;
using pstd::Status;

class PikaBinlogReader {
public:
PikaBinlogReader(uint32_t cur_filenum, uint64_t cur_offset);
PikaBinlogReader();
~PikaBinlogReader();
Status Get(std::string* scratch, uint32_t* filenum, uint64_t* offset);
int Seek(std::shared_ptr<Binlog> logger, uint32_t filenum, uint64_t offset);
pstd::Status Get(std::string* scratch, uint32_t* filenum, uint64_t* offset);
int Seek(const std::shared_ptr<Binlog>& logger, uint32_t filenum, uint64_t offset);
bool ReadToTheEnd();
void GetReaderStatus(uint32_t* cur_filenum, uint64_t* cur_offset);

private:
bool GetNext(uint64_t* size);
unsigned int ReadPhysicalRecord(pstd::Slice* redult, uint32_t* filenum, uint64_t* offset);
unsigned int ReadPhysicalRecord(pstd::Slice* result, uint32_t* filenum, uint64_t* offset);
// Returns scratch binflog and corresponding offset
Status Consume(std::string* scratch, uint32_t* filenum, uint64_t* offset);
pstd::Status Consume(std::string* scratch, uint32_t* filenum, uint64_t* offset);

std::shared_mutex rwlock_;
uint32_t cur_filenum_ = 0;
Expand All @@ -44,7 +42,7 @@ class PikaBinlogReader {
pstd::SequentialFile* queue_ = nullptr;

char* const backing_store_;
Slice buffer_;
pstd::Slice buffer_;
};

#endif // PIKA_BINLOG_READER_H_
6 changes: 3 additions & 3 deletions include/pika_binlog_transverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define PIKA_BINLOG_TRANSVERTER_H_

#include <glog/logging.h>
#include <stdint.h>
#include <cstdint>
#include <iostream>
#include <vector>

Expand All @@ -32,7 +32,7 @@ const int SPACE_STROE_PARAMETER_LENGTH = 5;

class BinlogItem {
public:
BinlogItem() : exec_time_(0), term_id_(0), logic_id_(0), filenum_(0), offset_(0), content_("") {}
BinlogItem() = default;

friend class PikaBinlogTransverter;

Expand Down Expand Up @@ -62,7 +62,7 @@ class BinlogItem {

class PikaBinlogTransverter {
public:
PikaBinlogTransverter(){};
PikaBinlogTransverter()= default;;
static std::string BinlogEncode(BinlogType type, uint32_t exec_time, uint32_t term_id, uint64_t logic_id,
uint32_t filenum, uint64_t offset, const std::string& content,
const std::vector<std::string>& extends);
Expand Down
68 changes: 34 additions & 34 deletions include/pika_bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,90 +17,90 @@
class BitGetCmd : public Cmd {
public:
BitGetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
virtual std::vector<std::string> current_key() const {
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new BitGetCmd(*this); }
void Do(std::shared_ptr<Partition> partition = nullptr) override;
void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys) override{};
void Merge() override{};
Cmd* Clone() override { return new BitGetCmd(*this); }

private:
std::string key_;
int64_t bit_offset_ = -1;
virtual void Clear() {
void Clear() override {
key_ = "";
bit_offset_ = -1;
}
virtual void DoInitial() override;
void DoInitial() override;
};

class BitSetCmd : public Cmd {
public:
BitSetCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
virtual std::vector<std::string> current_key() const {
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new BitSetCmd(*this); }
void Do(std::shared_ptr<Partition> partition = nullptr) override;
void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys) override{};
void Merge() override{};
Cmd* Clone() override { return new BitSetCmd(*this); }

private:
std::string key_;
int64_t bit_offset_;
int64_t on_;
virtual void Clear() {
void Clear() override {
key_ = "";
bit_offset_ = -1;
on_ = -1;
}
virtual void DoInitial() override;
void DoInitial() override;
};

class BitCountCmd : public Cmd {
public:
BitCountCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
virtual std::vector<std::string> current_key() const {
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new BitCountCmd(*this); }
void Do(std::shared_ptr<Partition> partition = nullptr) override;
void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys) override{};
void Merge() override{};
Cmd* Clone() override { return new BitCountCmd(*this); }

private:
std::string key_;
bool count_all_;
int64_t start_offset_;
int64_t end_offset_;
virtual void Clear() {
void Clear() override {
key_ = "";
count_all_ = false;
start_offset_ = -1;
end_offset_ = -1;
}
virtual void DoInitial() override;
void DoInitial() override;
};

class BitPosCmd : public Cmd {
public:
BitPosCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
virtual std::vector<std::string> current_key() const {
std::vector<std::string> current_key() const override {
std::vector<std::string> res;
res.push_back(key_);
return res;
}
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new BitPosCmd(*this); }
void Do(std::shared_ptr<Partition> partition = nullptr) override;
void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys) override{};
void Merge() override{};
Cmd* Clone() override { return new BitPosCmd(*this); }

private:
std::string key_;
Expand All @@ -109,34 +109,34 @@ class BitPosCmd : public Cmd {
int64_t bit_val_;
int64_t start_offset_;
int64_t end_offset_;
virtual void Clear() {
void Clear() override {
key_ = "";
pos_all_ = false;
endoffset_set_ = false;
bit_val_ = -1;
start_offset_ = -1;
end_offset_ = -1;
}
virtual void DoInitial() override;
void DoInitial() override;
};

class BitOpCmd : public Cmd {
public:
BitOpCmd(const std::string& name, int arity, uint16_t flag) : Cmd(name, arity, flag){};
virtual void Do(std::shared_ptr<Partition> partition = nullptr) override;
virtual void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys){};
virtual void Merge(){};
virtual Cmd* Clone() override { return new BitOpCmd(*this); }
void Do(std::shared_ptr<Partition> partition = nullptr) override;
void Split(std::shared_ptr<Partition> partition, const HintKeys& hint_keys) override{};
void Merge() override{};
Cmd* Clone() override { return new BitOpCmd(*this); }

private:
std::string dest_key_;
std::vector<std::string> src_keys_;
storage::BitOpType op_;
virtual void Clear() {
void Clear() override {
dest_key_ = "";
src_keys_.clear();
op_ = storage::kBitOpDefault;
}
virtual void DoInitial() override;
void DoInitial() override;
};
#endif
Loading

0 comments on commit 8827ff5

Please sign in to comment.