Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
nebula-bots committed Aug 12, 2021
1 parent e52d837 commit 735e4e4
Show file tree
Hide file tree
Showing 1,395 changed files with 178,745 additions and 188,304 deletions.
12 changes: 10 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# Copyright (c) 2020 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License,
# attached with Common Clause Condition 1.0, found in the LICENSES directory.
#
# This is the output of clang-format-9.0 --style=google --dump-config,
# except for changes mentioned below.
# We have locked the version of clang-format in order to avoid inconsistencies
# in the format caused by developers using different clang-format versions.
---
Language: Cpp
# BasedOnStyle: Google
Expand Down Expand Up @@ -50,7 +59,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
ColumnLimit: 100
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Expand Down Expand Up @@ -154,4 +163,3 @@ StatementMacros:
TabWidth: 8
UseTab: Never
...

7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ add_custom_target(
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)


add_custom_target(
clang-format
COMMAND "find" "src/" "-type" "f" "\\(" "-iname" "\\*.h" "-o" "-iname" "\\*.cpp" "\\)" "-exec" "clang-format" "-i" "{}" "\\;"
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)

if (ENABLE_NATIVE)
message(STATUS "ENABLE_NATIVE is ${ENABLE_NATIVE}")
add_compile_options(-fPIC)
Expand Down
76 changes: 37 additions & 39 deletions src/clients/meta/FileBasedClusterIdMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,56 @@
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/

#include "common/base/Base.h"
#include "clients/meta/FileBasedClusterIdMan.h"

#include "common/base/Base.h"

namespace nebula {
namespace meta {

// static
bool FileBasedClusterIdMan::persistInFile(ClusterID clusterId,
const std::string& filename) {
auto dirname = fs::FileUtils::dirname(filename.c_str());
if (!fs::FileUtils::makeDir(dirname)) {
LOG(ERROR) << "Failed mkdir " << dirname;
return false;
}
if (fs::FileUtils::remove(filename.c_str())) {
LOG(INFO) << "Remove the existed file " << filename;
}
int fd = ::open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) {
LOG(ERROR) << "Open file error, file " << filename << ", error " << strerror(errno);
return false;
}
int bytes = ::write(fd, reinterpret_cast<const char*>(&clusterId), sizeof(ClusterID));
if (bytes != sizeof(clusterId)) {
LOG(ERROR) << "Write clusterId failed!";
::close(fd);
return false;
}
LOG(INFO) << "Persiste clusterId " << clusterId << " succeeded!";
bool FileBasedClusterIdMan::persistInFile(ClusterID clusterId, const std::string& filename) {
auto dirname = fs::FileUtils::dirname(filename.c_str());
if (!fs::FileUtils::makeDir(dirname)) {
LOG(ERROR) << "Failed mkdir " << dirname;
return false;
}
if (fs::FileUtils::remove(filename.c_str())) {
LOG(INFO) << "Remove the existed file " << filename;
}
int fd = ::open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) {
LOG(ERROR) << "Open file error, file " << filename << ", error " << strerror(errno);
return false;
}
int bytes = ::write(fd, reinterpret_cast<const char*>(&clusterId), sizeof(ClusterID));
if (bytes != sizeof(clusterId)) {
LOG(ERROR) << "Write clusterId failed!";
::close(fd);
return true;
return false;
}
LOG(INFO) << "Persiste clusterId " << clusterId << " succeeded!";
::close(fd);
return true;
}


// static
ClusterID FileBasedClusterIdMan::getClusterIdFromFile(const std::string& filename) {
int fd = ::open(filename.c_str(), O_RDONLY);
if (fd < 0) {
LOG(WARNING) << "Open file failed, error " << strerror(errno);
return 0;
}
ClusterID clusterId = 0;
int len = ::read(fd, reinterpret_cast<char*>(&clusterId), sizeof(ClusterID));
if (len != sizeof(ClusterID)) {
LOG(ERROR) << "Get clusterId failed!";
::close(fd);
return 0;
}
LOG(INFO) << "Get clusterId: " << clusterId;
int fd = ::open(filename.c_str(), O_RDONLY);
if (fd < 0) {
LOG(WARNING) << "Open file failed, error " << strerror(errno);
return 0;
}
ClusterID clusterId = 0;
int len = ::read(fd, reinterpret_cast<char*>(&clusterId), sizeof(ClusterID));
if (len != sizeof(ClusterID)) {
LOG(ERROR) << "Get clusterId failed!";
::close(fd);
return clusterId;
return 0;
}
LOG(INFO) << "Get clusterId: " << clusterId;
::close(fd);
return clusterId;
}

} // namespace meta
Expand Down
7 changes: 3 additions & 4 deletions src/clients/meta/FileBasedClusterIdMan.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@
#include "common/fs/FileUtils.h"
#include "common/meta/ClusterIdManBase.h"


namespace nebula {
namespace meta {

/**
* This class manages clusterId used for meta server and storage server.
* */
class FileBasedClusterIdMan : public ClusterIdManBase {
public:
static bool persistInFile(ClusterID clusterId, const std::string& filename);
public:
static bool persistInFile(ClusterID clusterId, const std::string& filename);

static ClusterID getClusterIdFromFile(const std::string& filename);
static ClusterID getClusterIdFromFile(const std::string& filename);
};

} // namespace meta
Expand Down
Loading

0 comments on commit 735e4e4

Please sign in to comment.