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

Unique ID: UUID #3453

Merged
merged 6 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
5 changes: 5 additions & 0 deletions src/common/id/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ nebula_add_library(
Snowflake.cpp
)

nebula_add_library(
uuid_obj OBJECT
UUID.cpp
)

nebula_add_subdirectory(test)
20 changes: 20 additions & 0 deletions src/common/id/UUID.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#include "common/id/UUID.h"

namespace nebula {

boost::uuids::uuid UUIDV4::getId() {
boost::uuids::uuid uuid = boost::uuids::random_generator()();
return uuid;
}

std::string UUIDV4::getIdStr() {
boost::uuids::uuid uuid = getId();
return boost::uuids::to_string(uuid);
}

} // namespace nebula
28 changes: 28 additions & 0 deletions src/common/id/UUID.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License.
*/

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

/*
* UUID v1: time-based and mac-based
* UUID v2: DCE security
* UUID v3: name-based MD5
* UUID v4: random
* UUID v5: name-based SHA-1
* boost implements uuid v4 and v5(is deprecated due to security concerns)
*/
namespace nebula {

// the probability to find a duplicate within version-4 UUIDs is one in a billion.
// the computed is in: https://en.wikipedia.org/wiki/Universally_unique_identifier
jackwener marked this conversation as resolved.
Show resolved Hide resolved
class UUIDV4 {
public:
static boost::uuids::uuid getId();

static std::string getIdStr();
};
} // namespace nebula