You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2020/04/14 14:27:57 UTC

[incubator-doris] branch master updated: [rowset id] Reduce memory of UniqueRowsetIdGenerator (#3316)

This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 91438fc  [rowset id] Reduce memory of UniqueRowsetIdGenerator (#3316)
91438fc is described below

commit 91438fcb40b16b222b4a74f452b88d1a1baf6ed7
Author: HuangWei <hu...@xiaomi.com>
AuthorDate: Tue Apr 14 22:27:49 2020 +0800

    [rowset id] Reduce memory of UniqueRowsetIdGenerator (#3316)
---
 be/src/olap/olap_common.h                         |  7 -------
 be/src/olap/rowset/unique_rowset_id_generator.cpp | 15 +++++++++------
 be/src/olap/rowset/unique_rowset_id_generator.h   |  4 ++--
 3 files changed, 11 insertions(+), 15 deletions(-)

diff --git a/be/src/olap/olap_common.h b/be/src/olap/olap_common.h
index 8dd7723..311bd53 100644
--- a/be/src/olap/olap_common.h
+++ b/be/src/olap/olap_common.h
@@ -350,13 +350,6 @@ struct RowsetId {
     }
 };
 
-struct RowsetIdHash {
-    size_t operator()(const RowsetId& rowset_id) const {
-        // hi is an increasing number on a BE instance, we can use it as the hash value simply.
-        return rowset_id.hi;
-    }
-};
-
 }  // namespace doris
 
 #endif // DORIS_BE_SRC_OLAP_OLAP_COMMON_H
diff --git a/be/src/olap/rowset/unique_rowset_id_generator.cpp b/be/src/olap/rowset/unique_rowset_id_generator.cpp
index d03b43c..da9cfac 100644
--- a/be/src/olap/rowset/unique_rowset_id_generator.cpp
+++ b/be/src/olap/rowset/unique_rowset_id_generator.cpp
@@ -21,9 +21,8 @@
 
 namespace doris {
 
-UniqueRowsetIdGenerator::UniqueRowsetIdGenerator(const UniqueId& backend_uid) :
-    _backend_uid(backend_uid), _inc_id(0) {
-}
+UniqueRowsetIdGenerator::UniqueRowsetIdGenerator(const UniqueId& backend_uid)
+        : _backend_uid(backend_uid), _inc_id(0) {}
 
 // generate a unique rowset id and save it in a set to check whether it is valid in the future
 RowsetId UniqueRowsetIdGenerator::next_id() {
@@ -31,7 +30,7 @@ RowsetId UniqueRowsetIdGenerator::next_id() {
     rowset_id.init(_version, ++_inc_id, _backend_uid.hi, _backend_uid.lo);
     {
         std::lock_guard<SpinLock> l(_lock);
-        _valid_rowset_ids.insert(rowset_id);
+        _valid_rowset_id_hi.insert(rowset_id.hi);
     }
     return rowset_id;
 }
@@ -42,13 +41,17 @@ bool UniqueRowsetIdGenerator::id_in_use(const RowsetId& rowset_id) const {
     if (rowset_id.version < _version) {
         return true;
     }
+    if ((rowset_id.mi != _backend_uid.hi) || (rowset_id.lo != _backend_uid.lo)) {
+        return false;
+    }
+
     std::lock_guard<SpinLock> l(_lock);
-    return _valid_rowset_ids.count(rowset_id) == 1;
+    return _valid_rowset_id_hi.count(rowset_id.hi) == 1;
 }
 
 void UniqueRowsetIdGenerator::release_id(const RowsetId& rowset_id) {
     std::lock_guard<SpinLock> l(_lock);
-    _valid_rowset_ids.erase(rowset_id);
+    _valid_rowset_id_hi.erase(rowset_id.hi);
 }
 
 } // namespace doris
diff --git a/be/src/olap/rowset/unique_rowset_id_generator.h b/be/src/olap/rowset/unique_rowset_id_generator.h
index 2715438..4aee87b 100644
--- a/be/src/olap/rowset/unique_rowset_id_generator.h
+++ b/be/src/olap/rowset/unique_rowset_id_generator.h
@@ -24,7 +24,7 @@
 namespace doris {
 
 class UniqueRowsetIdGenerator : public RowsetIdGenerator {
-public:    
+public:
     UniqueRowsetIdGenerator(const UniqueId& backend_uid);
     ~UniqueRowsetIdGenerator() {}
 
@@ -39,7 +39,7 @@ private:
     const UniqueId _backend_uid;
     const int64_t _version = 2; // modify it when create new version id generator
     std::atomic<int64_t> _inc_id;
-    std::unordered_set<RowsetId, RowsetIdHash> _valid_rowset_ids;
+    std::unordered_set<int64_t> _valid_rowset_id_hi;
 
     DISALLOW_COPY_AND_ASSIGN(UniqueRowsetIdGenerator);
 }; // UniqueRowsetIdGenerator


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org