Skip to content

Commit

Permalink
style: translate ch-comments to en-comments and apply clang-format part2
Browse files Browse the repository at this point in the history
Signed-off-by: koko2pp <[email protected]>
  • Loading branch information
koko2pp committed Nov 28, 2023
1 parent 6762823 commit fbd5372
Show file tree
Hide file tree
Showing 51 changed files with 3,690 additions and 4,598 deletions.
7 changes: 4 additions & 3 deletions curvefs_python/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

import os


def exec_cmd(cmd):
ret = os.system(cmd)
if ret == 0:
print cmd + " exec success"
else :
else:
print cmd + " exec fail, ret = " + str(ret)


Expand All @@ -37,10 +38,10 @@ def exec_cmd(cmd):
exec_cmd(cmd)
cmd = "curve list --user k8s --dirname /k8s"
exec_cmd(cmd)
# 不是root,失败
# Not root, failed
cmd = "curve list --user k8s --dirname /"
exec_cmd(cmd)
# root没有传入密码,失败
# Root did not pass in password, failed
cmd = "curve list --user root --dirname /"
exec_cmd(cmd)
cmd = "curve list --user root --dirname / --password root_password"
Expand Down
12 changes: 7 additions & 5 deletions nebd/src/common/timeutility.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
#include <stdint.h>
#include <sys/time.h>
#include <sys/types.h>

#include <ctime>
#include <string>
#include <vector>
#include <ctime>

namespace nebd {
namespace common {
Expand All @@ -53,7 +54,8 @@ class TimeUtility {
return tm.tv_sec;
}

// 时间戳转成标准时间输出在standard里面,时间戳单位为秒
// Convert the timestamp to standard time and output it in standard, with
// the timestamp unit in seconds
static inline void TimeStampToStandard(time_t timeStamp,
std::string* standard) {
char now[64];
Expand All @@ -64,7 +66,7 @@ class TimeUtility {
}
};

} // namespace common
} // namespace nebd
} // namespace common
} // namespace nebd

#endif // NEBD_SRC_COMMON_TIMEUTILITY_H_
#endif // NEBD_SRC_COMMON_TIMEUTILITY_H_
6 changes: 3 additions & 3 deletions nebd/src/part2/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#ifndef NEBD_SRC_PART2_UTIL_H_
#define NEBD_SRC_PART2_UTIL_H_

#include <string>
#include <mutex> // NOLINT
#include <ostream>
#include <string>

#include "nebd/src/part2/define.h"

Expand All @@ -51,9 +51,9 @@ class FdAllocator {
FdAllocator() : fd_(0) {}
~FdAllocator() {}

// fd的有效值范围为[1, INT_MAX]
// The valid range of values for fd is [1, INT_MAX]
int GetNext();
// 初始化fd的值
// Initialize the value of fd
void InitFd(int fd);

private:
Expand Down
36 changes: 17 additions & 19 deletions nebd/test/common/test_name_lock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

#include <gtest/gtest.h>

#include <random>
#include <thread> // NOLINT

Expand All @@ -32,29 +33,27 @@ namespace common {
TEST(TestNameLock, TestNameLockBasic) {
NameLock lock1, lock2, lock3;

// lock测试
// Lock test
lock1.Lock("str1");
// 同锁不同str可lock不死锁
// Same lock but different strs can lock without deadlock
lock1.Lock("str2");
// 不同锁同str可lock不死锁
// Different locks with the same str can lock without deadlock
lock2.Lock("str1");



// 同锁同str TryLock失败
// Same lock with str TryLock failed
ASSERT_FALSE(lock1.TryLock("str1"));
// 同锁不同str TryLock成功
// Same lock different str TryLock successful
ASSERT_TRUE(lock1.TryLock("str3"));
// 不同锁同str TryLock成功
// Different locks with str TryLock succeeded
ASSERT_TRUE(lock3.TryLock("str1"));

// unlock测试
// Unlock test
lock1.Unlock("str1");
lock1.Unlock("str2");
lock1.Unlock("str3");
lock2.Unlock("str1");
lock3.Unlock("str1");
// 未锁unlock ok
// Unlock OK
lock2.Unlock("str2");
}

Expand All @@ -64,12 +63,13 @@ TEST(TestNameLock, TestNameLockGuardBasic) {
NameLockGuard guard1(lock1, "str1");
NameLockGuard guard2(lock1, "str2");
NameLockGuard guard3(lock2, "str1");
// 作用域内加锁成功,不可再加锁
// Successfully locked within the scope, unable to lock again
ASSERT_FALSE(lock1.TryLock("str1"));
ASSERT_FALSE(lock1.TryLock("str2"));
ASSERT_FALSE(lock2.TryLock("str1"));
}
// 作用域外自动解锁,可再加锁
// Automatically unlocking outside the scope, with the option to add locks
// again
ASSERT_TRUE(lock1.TryLock("str1"));
ASSERT_TRUE(lock1.TryLock("str2"));
ASSERT_TRUE(lock2.TryLock("str1"));
Expand All @@ -80,27 +80,25 @@ TEST(TestNameLock, TestNameLockGuardBasic) {

TEST(TestNameLock, TestNameLockConcurrent) {
NameLock lock1;
auto worker = [&] (const std::string &str) {
auto worker = [&](const std::string& str) {
for (int i = 0; i < 10000; i++) {
NameLockGuard guard(lock1, str);
}
};

std::vector<std::thread> threadpool;
for (auto &t : threadpool) {
for (auto& t : threadpool) {
std::string str1 = "aaaa";
std::string str2 = "bbbb";
std::srand(std::time(nullptr));
std::string rstr = (std::rand() / 2) ? str1 : str2;
t = std::thread(worker, rstr);
}

for (auto &t : threadpool) {
for (auto& t : threadpool) {
t.join();
}
}



} // namespace common
} // namespace nebd
} // namespace common
} // namespace nebd
2 changes: 1 addition & 1 deletion proto/topology.proto
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ message CreateLogicalPoolRequest {
required LogicalPoolType type = 4;
required bytes redundanceAndPlaceMentPolicy = 5; //json body
required bytes userPolicy = 6; //json body
optional uint32 scatterWidth = 7; //生成copyset依据的scatterWidth平均值
optional uint32 scatterWidth = 7; // Generate copyset based on the average scatterWidth value
optional AllocateStatus status = 8;
}

Expand Down
54 changes: 25 additions & 29 deletions src/chunkserver/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,37 @@ namespace curve {
namespace chunkserver {

/**
* Cli就是配置变更相关接口的封装,方便使用,避免直接操作RPC
* Cli is the encapsulation of configuration change related interfaces, which is
* convenient to use and avoids direct RPC operations
*/

// 获取leader
butil::Status GetLeader(const LogicPoolID &logicPoolId,
const CopysetID &copysetId,
const Configuration &conf,
PeerId *leaderId);
// Get the leader
butil::Status GetLeader(const LogicPoolID& logicPoolId,
const CopysetID& copysetId, const Configuration& conf,
PeerId* leaderId);

// 增加一个peer
butil::Status AddPeer(const LogicPoolID &logicPoolId,
const CopysetID &copysetId,
const Configuration &conf,
const PeerId &peer_id,
const braft::cli::CliOptions &options);
// Add a peer
butil::Status AddPeer(const LogicPoolID& logicPoolId,
const CopysetID& copysetId, const Configuration& conf,
const PeerId& peer_id,
const braft::cli::CliOptions& options);

// 移除一个peer
butil::Status RemovePeer(const LogicPoolID &logicPoolId,
const CopysetID &copysetId,
const Configuration &conf,
const PeerId &peer_id,
const braft::cli::CliOptions &options);
// Remove a peer
butil::Status RemovePeer(const LogicPoolID& logicPoolId,
const CopysetID& copysetId, const Configuration& conf,
const PeerId& peer_id,
const braft::cli::CliOptions& options);

// 转移leader
butil::Status TransferLeader(const LogicPoolID &logicPoolId,
const CopysetID &copysetId,
const Configuration &conf,
const PeerId &peer,
const braft::cli::CliOptions &options);
// Transfer leader
butil::Status TransferLeader(const LogicPoolID& logicPoolId,
const CopysetID& copysetId,
const Configuration& conf, const PeerId& peer,
const braft::cli::CliOptions& options);

// 触发快照
butil::Status Snapshot(const LogicPoolID &logicPoolId,
const CopysetID &copysetId,
const PeerId &peer,
const braft::cli::CliOptions &options);
// Trigger snapshot
butil::Status Snapshot(const LogicPoolID& logicPoolId,
const CopysetID& copysetId, const PeerId& peer,
const braft::cli::CliOptions& options);

} // namespace chunkserver
} // namespace curve
Expand Down
Loading

0 comments on commit fbd5372

Please sign in to comment.