yiguolei commented on a change in pull request #1678: Add rowset id generator 
to FE and BE
URL: https://github.com/apache/incubator-doris/pull/1678#discussion_r318514906
 
 

 ##########
 File path: be/src/olap/olap_common.h
 ##########
 @@ -241,7 +246,83 @@ typedef std::set<uint32_t> UniqueIdSet;
 // Column unique Id -> column id map
 typedef std::map<ColumnId, ColumnId> UniqueIdToColumnIdMap;
 
-typedef int64_t RowsetId;
+// 8 bit, id version
+// 120 bit, backend random number generated by uuid
+// 64 bit, inc number from 0
+struct RowsetId {
+    int8_t version = 0;
+    int64_t hi = 0;
+    int64_t mi = 0;
+    int64_t lo = 0;
+
+    void init(const std::string& rowset_id_str) {
+        // for new rowsetid its a 48 hex string
+        // 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));
+            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 {
 
 Review comment:
   to_string is ok, because it is a string value in pb.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to