Skip to content

Commit

Permalink
fix the file
Browse files Browse the repository at this point in the history
  • Loading branch information
koko2pp committed Nov 27, 2023
1 parent 3da138c commit 917684b
Showing 1 changed file with 48 additions and 52 deletions.
100 changes: 48 additions & 52 deletions src/kvstorageclient/etcd_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@
#define SRC_KVSTORAGECLIENT_ETCD_CLIENT_H_

#include <libetcdclient.h>

#include <string>
#include <utility>
#include <vector>
#include <utility>

namespace curve {
namespace kvstorage {
Expand All @@ -44,7 +43,7 @@ class KVStorageClient {
*
* @return error code EtcdErrCode
*/
virtual int Put(const std::string& key, const std::string& value) = 0;
virtual int Put(const std::string &key, const std::string &value) = 0;

/**
* @brief PutRewithRevision store key-value
Expand All @@ -55,9 +54,8 @@ class KVStorageClient {
*
* @return error code EtcdErrCode
*/
virtual int PutRewithRevision(const std::string& key,
const std::string& value,
int64_t* revision) = 0;
virtual int PutRewithRevision(const std::string &key,
const std::string &value, int64_t *revision) = 0;

/**
* @brief Get Get the value of the specified key
Expand All @@ -67,7 +65,7 @@ class KVStorageClient {
*
* @return error code
*/
virtual int Get(const std::string& key, std::string* out) = 0;
virtual int Get(const std::string &key, std::string *out) = 0;

/**
* @brief List Get all the values ​​between [startKey, endKey)
Expand All @@ -78,16 +76,15 @@ class KVStorageClient {
*
* @return error code
*/
virtual int List(const std::string& startKey, const std::string& endKey,
std::vector<std::string>* values) = 0;
virtual int List(const std::string &startKey, const std::string &endKey,
std::vector<std::string> *values) = 0;

/**
* @brief List all the key and values between [startKey, endKey)
*
* @param[in] startKey
* @param[in] endKey
* @param[out] out store key/value pairs that key is between [startKey,
* endKey)
* @param[out] out store key/value pairs that key is between [startKey, endKey)
*
* @return error code
*/
Expand All @@ -101,7 +98,7 @@ class KVStorageClient {
*
* @return error code
*/
virtual int Delete(const std::string& key) = 0;
virtual int Delete(const std::string &key) = 0;

/**
* @brief DeleteRewithRevision Delete the value of the specified key
Expand All @@ -111,18 +108,17 @@ class KVStorageClient {
*
* @return error code
*/
virtual int DeleteRewithRevision(const std::string& key,
int64_t* revision) = 0;
virtual int DeleteRewithRevision(
const std::string &key, int64_t *revision) = 0;

/*
* @brief TxnN Operate transactions in the order of ops[0] ops[1] ...,
* currently 2 and 3 operations are supported //NOLINT
*
* @param[in] ops Operation set
*
* @return error code
*/
virtual int TxnN(const std::vector<Operation>& ops) = 0;
* @brief TxnN Operate transactions in the order of ops[0] ops[1] ..., currently 2 and 3 operations are supported //NOLINT
*
* @param[in] ops Operation set
*
* @return error code
*/
virtual int TxnN(const std::vector<Operation> &ops) = 0;

/**
* @brief CompareAndSwap Transaction, to achieve CAS
Expand All @@ -133,15 +129,17 @@ class KVStorageClient {
*
* @return error code
*/
virtual int CompareAndSwap(const std::string& key, const std::string& preV,
const std::string& target) = 0;
virtual int CompareAndSwap(const std::string &key, const std::string &preV,
const std::string &target) = 0;
};

// encapsulate the c header file of etcd generated by go compilation
class EtcdClientImp : public KVStorageClient {
public:
EtcdClientImp() {}
~EtcdClientImp() { CloseClient(); }
~EtcdClientImp() {
CloseClient();
}

/**
* @brief Init init the etcdclient, a global var in go
Expand All @@ -156,30 +154,30 @@ class EtcdClientImp : public KVStorageClient {

void CloseClient();

int Put(const std::string& key, const std::string& value) override;
int Put(const std::string &key, const std::string &value) override;

int PutRewithRevision(const std::string& key, const std::string& value,
int64_t* revision) override;
int PutRewithRevision(const std::string &key, const std::string &value,
int64_t *revision) override;

int Get(const std::string& key, std::string* out) override;
int Get(const std::string &key, std::string *out) override;

int List(const std::string& startKey, const std::string& endKey,
std::vector<std::string>* values) override;
int List(const std::string &startKey,
const std::string &endKey, std::vector<std::string> *values) override;

int List(const std::string& startKey, const std::string& endKey,
std::vector<std::pair<std::string, std::string>>* out) override;
std::vector<std::pair<std::string, std::string> >* out) override;

int Delete(const std::string& key) override;
int Delete(const std::string &key) override;

int DeleteRewithRevision(const std::string& key,
int64_t* revision) override;
int DeleteRewithRevision(
const std::string &key, int64_t *revision) override;

int TxnN(const std::vector<Operation>& ops) override;
int TxnN(const std::vector<Operation> &ops) override;

int CompareAndSwap(const std::string& key, const std::string& preV,
const std::string& target) override;
int CompareAndSwap(const std::string &key, const std::string &preV,
const std::string &target) override;

virtual int GetCurrentRevision(int64_t* revision);
virtual int GetCurrentRevision(int64_t *revision);

/**
* @brief ListWithLimitAndRevision
Expand All @@ -193,11 +191,9 @@ class EtcdClientImp : public KVStorageClient {
* @param[out] values the value vector of all the key-value pairs
* @param[out] lastKey the last key of the vector
*/
virtual int ListWithLimitAndRevision(const std::string& startKey,
const std::string& endKey,
int64_t limit, int64_t revision,
std::vector<std::string>* values,
std::string* lastKey);
virtual int ListWithLimitAndRevision(const std::string &startKey,
const std::string &endKey, int64_t limit, int64_t revision,
std::vector<std::string> *values, std::string *lastKey);

/**
* @brief CampaignLeader Leader campaign through etcd, return directly if
Expand All @@ -213,14 +209,14 @@ class EtcdClientImp : public KVStorageClient {
* leader when the session expired after
* client offline.
* @param[in] electionTimeoutMs the timeout,0 will block always
* @param[out] leaderOid leader's objectId,recorded in objectManager
* @param[out] leaderOid leader的objectId,recorded in objectManager
*
* @return EtcdErrCode::EtcdCampaignLeaderSuccess success,others fail
*/
virtual int CampaignLeader(const std::string& pfx,
const std::string& leaderName,
uint32_t sessionInterSec,
uint32_t electionTimeoutMs, uint64_t* leaderOid);
virtual int CampaignLeader(
const std::string &pfx, const std::string &leaderName,
uint32_t sessionInterSec, uint32_t electionTimeoutMs,
uint64_t *leaderOid);

/**
* @brief LeaderObserve
Expand All @@ -232,8 +228,8 @@ class EtcdClientImp : public KVStorageClient {
*
* @return if returned, the session between mds and etcd expired
*/
virtual int LeaderObserve(uint64_t leaderOid,
const std::string& leaderName);
virtual int LeaderObserve(
uint64_t leaderOid, const std::string &leaderName);

/**
* @brief LeaderResign the leader resigns initiatively, the other peers
Expand All @@ -245,7 +241,7 @@ class EtcdClientImp : public KVStorageClient {
* @return EtcdErrCode::EtcdLeaderResiginSuccess resign seccess
* EtcdErrCode::EtcdLeaderResiginErr resign fail
*/
virtual int LeaderResign(uint64_t leaderOid, uint64_t timeoutMs);
virtual int LeaderResign(uint64_t leaderOid, uint64_t timeoutMs);

// for test
void SetTimeout(int time);
Expand Down

0 comments on commit 917684b

Please sign in to comment.