diff --git a/be/src/olap/olap_common.h b/be/src/olap/olap_common.h index 06adc65719556b7..b831e92bbeb2cd2 100644 --- a/be/src/olap/olap_common.h +++ b/be/src/olap/olap_common.h @@ -399,6 +399,7 @@ using ColumnId = uint32_t; using UniqueIdSet = std::set; // Column unique Id -> column id map using UniqueIdToColumnIdMap = std::map; +int64_t unique_rowset_id_next_high(); // 8 bit rowset id version // 56 bit, inc number from 1 @@ -418,10 +419,7 @@ struct RowsetId { rowset_id_str.data() + rowset_id_str.length(), high); if (ec != std::errc {}) [[unlikely]] { LOG(WARNING) << "failed to init rowset id: " << rowset_id_str; - high = []() { - std::mt19937_64 rg(std::random_device {}()); - return std::uniform_int_distribution()(rg); - }(); + high = unique_rowset_id_next_high(); } init(1, high, 0, 0); } else { diff --git a/be/src/olap/rowset/rowset_id_generator.h b/be/src/olap/rowset/rowset_id_generator.h index 43be640ffc61814..985156a4459f5a9 100644 --- a/be/src/olap/rowset/rowset_id_generator.h +++ b/be/src/olap/rowset/rowset_id_generator.h @@ -31,6 +31,7 @@ class RowsetIdGenerator { // generate and return the next global unique rowset id virtual RowsetId next_id() = 0; + virtual int64_t next_high() = 0; }; // RowsetIdGenerator } // namespace doris diff --git a/be/src/olap/rowset/unique_rowset_id_generator.cpp b/be/src/olap/rowset/unique_rowset_id_generator.cpp index 0ac7f63837a0993..ad7b29524ae4306 100644 --- a/be/src/olap/rowset/unique_rowset_id_generator.cpp +++ b/be/src/olap/rowset/unique_rowset_id_generator.cpp @@ -17,8 +17,17 @@ #include "olap/rowset/unique_rowset_id_generator.h" +#include + +#include "olap/storage_engine.h" +#include "runtime/exec_env.h" + namespace doris { +int64_t unique_rowset_id_next_high() { + return ExecEnv::GetInstance()->storage_engine().next_rowset_id_high(); +} + UniqueRowsetIdGenerator::UniqueRowsetIdGenerator(const UniqueId& backend_uid) : _backend_uid(backend_uid), _inc_id(1) {} @@ -31,4 +40,8 @@ RowsetId UniqueRowsetIdGenerator::next_id() { return rowset_id; } +int64_t UniqueRowsetIdGenerator::next_high() { + return _inc_id.fetch_add(1, std::memory_order_relaxed); +} + } // 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 2bbf65b47d114e9..f1c742dbef6b333 100644 --- a/be/src/olap/rowset/unique_rowset_id_generator.h +++ b/be/src/olap/rowset/unique_rowset_id_generator.h @@ -30,6 +30,7 @@ class UniqueRowsetIdGenerator : public RowsetIdGenerator { ~UniqueRowsetIdGenerator() override; RowsetId next_id() override; + int64_t next_high() override; private: const UniqueId _backend_uid; diff --git a/be/src/olap/storage_engine.cpp b/be/src/olap/storage_engine.cpp index e00b5b595e20dc4..70ebe2e553c885f 100644 --- a/be/src/olap/storage_engine.cpp +++ b/be/src/olap/storage_engine.cpp @@ -111,6 +111,10 @@ RowsetId BaseStorageEngine::next_rowset_id() { return _rowset_id_generator->next_id(); } +int64_t BaseStorageEngine::next_rowset_id_high() { + return _rowset_id_generator->next_high(); +} + StorageEngine& BaseStorageEngine::to_local() { CHECK_EQ(_type, Type::LOCAL); return *static_cast(this); diff --git a/be/src/olap/storage_engine.h b/be/src/olap/storage_engine.h index 421c0eb352d7128..4f3bbe9e302ca84 100644 --- a/be/src/olap/storage_engine.h +++ b/be/src/olap/storage_engine.h @@ -121,6 +121,7 @@ class BaseStorageEngine { int32_t effective_cluster_id() const { return _effective_cluster_id; } RowsetId next_rowset_id(); + int64_t next_rowset_id_high(); MemTableFlushExecutor* memtable_flush_executor() { return _memtable_flush_executor.get(); } CalcDeleteBitmapExecutor* calc_delete_bitmap_executor() {