-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add rowset id generator to FE and BE #1678
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
Changes from all commits
d5d8758
ee2f33e
1af363d
77da432
2f00d2a
00a9c4f
f12dab0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |||||||||
| #include <list> | ||||||||||
| #include <map> | ||||||||||
| #include <memory> | ||||||||||
| #include <ostream> | ||||||||||
| #include <sstream> | ||||||||||
| #include <string> | ||||||||||
| #include <typeinfo> | ||||||||||
|
|
@@ -35,8 +36,12 @@ | |||||||||
| #include "util/hash_util.hpp" | ||||||||||
| #include "util/uid_util.h" | ||||||||||
|
|
||||||||||
| #define LOW_56_BITS 0x00ffffffffffffff | ||||||||||
|
|
||||||||||
| namespace doris { | ||||||||||
|
|
||||||||||
| static const int64_t MAX_ROWSET_ID = 1L << 56; | ||||||||||
|
|
||||||||||
| typedef int32_t SchemaHash; | ||||||||||
| typedef int64_t VersionHash; | ||||||||||
| typedef __int128 int128_t; | ||||||||||
|
|
@@ -241,7 +246,84 @@ typedef std::set<uint32_t> UniqueIdSet; | |||||||||
| // Column unique Id -> column id map | ||||||||||
| typedef std::map<ColumnId, ColumnId> UniqueIdToColumnIdMap; | ||||||||||
|
|
||||||||||
| typedef int64_t RowsetId; | ||||||||||
| // 128 bit backend uid, it is a uuid bit, id version | ||||||||||
| // 8 bit rowset id version | ||||||||||
| // 56 bit, inc number from 0 | ||||||||||
| struct RowsetId { | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can RowsetId support ++ operator?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can directly use protobuf to do serialize and deserialize?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is useless using ++ , because it will need to get a rowsetidgenerator object. |
||||||||||
| int8_t version = 0; | ||||||||||
yiguolei marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| int64_t hi = 0; | ||||||||||
| int64_t mi = 0; | ||||||||||
| int64_t lo = 0; | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uint64_t?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UniqueId generator using int64_t so that I use int64_t here |
||||||||||
|
|
||||||||||
| void init(const std::string& rowset_id_str) { | ||||||||||
| // for new rowsetid its a 48 hex string | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| // if the len < 48, then it is an old format rowset id | ||||||||||
| if (rowset_id_str.length() < 48) { | ||||||||||
| int64_t low = std::stol(rowset_id_str, nullptr, 10); | ||||||||||
| init(1, 0, 0, low); | ||||||||||
| } else { | ||||||||||
| int64_t high = 0; | ||||||||||
| int64_t middle = 0; | ||||||||||
| int64_t low = 0; | ||||||||||
| from_hex(&high, rowset_id_str.substr(0, 16)); | ||||||||||
| from_hex(&middle, rowset_id_str.substr(16, 16)); | ||||||||||
| from_hex(&low, rowset_id_str.substr(32, 16)); | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| init(low >> 56, high, middle, low & LOW_56_BITS); | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // to compatiable with old version | ||||||||||
| void init(int64_t rowset_id) { | ||||||||||
| init(1, 0, 0, rowset_id); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| void init(int64_t id_version, int64_t high, int64_t middle, int64_t low) { | ||||||||||
| version = id_version; | ||||||||||
| if (low >= MAX_ROWSET_ID) { | ||||||||||
| LOG(FATAL) << "low is too large:" << low; | ||||||||||
| } | ||||||||||
| hi = high; | ||||||||||
| mi = middle; | ||||||||||
| lo = (id_version << 56) + (low & LOW_56_BITS); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| std::string to_string() const { | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need to_string and serialize and deserialize api
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to_string is ok, because it is a string value in pb. |
||||||||||
| if (version < 2) { | ||||||||||
| return std::to_string(lo & LOW_56_BITS); | ||||||||||
| } else { | ||||||||||
| char buf[48]; | ||||||||||
| to_hex(hi, buf); | ||||||||||
| to_hex(mi, buf + 16); | ||||||||||
| to_hex(lo, buf + 32); | ||||||||||
| return {buf, 48}; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // std::unordered_map need this api | ||||||||||
| bool operator==(const RowsetId& rhs) const { | ||||||||||
| return lo == rhs.lo && hi == rhs.hi && mi == rhs.mi ; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| bool operator!=(const RowsetId& rhs) const { | ||||||||||
| return lo != rhs.lo || hi != rhs.hi || mi != rhs.mi ; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| bool operator<(const RowsetId& rhs) const { | ||||||||||
| if (hi != rhs.hi) { | ||||||||||
| return hi < rhs.hi; | ||||||||||
| } else if (mi != rhs.mi) { | ||||||||||
| return mi < rhs.mi; | ||||||||||
| } else { | ||||||||||
| return lo < rhs.lo; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| friend std::ostream& operator<<(std::ostream& out, const RowsetId& rowset_id) { | ||||||||||
| out << rowset_id.to_string(); | ||||||||||
| return out; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| }; | ||||||||||
|
|
||||||||||
| } // namespace doris | ||||||||||
|
|
||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ static constexpr uint32_t OLAP_COMPACTION_DEFAULT_CANDIDATE_SIZE = 10; | |
| // the max length supported for string type | ||
| static const uint16_t OLAP_STRING_MAX_LENGTH = 65535; | ||
|
|
||
| static const int32_t PREFERRED_SNAPSHOT_VERSION = 2; | ||
| static const int32_t PREFERRED_SNAPSHOT_VERSION = 3; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add some comment to explain the version 1 , 2, and 3?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
|
||
| // the max bytes for stored string length | ||
| using StringOffsetType = uint32_t; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some comment here to describe the version meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done