diff --git a/be/src/common/config.cpp b/be/src/common/config.cpp index 486717d9bf33a2..fc86856a644d2a 100644 --- a/be/src/common/config.cpp +++ b/be/src/common/config.cpp @@ -1191,6 +1191,7 @@ DEFINE_mInt64(tablet_meta_serialize_size_limit, "1610612736"); // 1717986918 = 2GB * 0.8 DEFINE_Validator(tablet_meta_serialize_size_limit, [](const int64_t config) -> bool { return config < 1717986918; }); +DEFINE_Bool(force_regenerate_rowsetid_on_start_error, "false"); // clang-format off #ifdef BE_TEST diff --git a/be/src/common/config.h b/be/src/common/config.h index 51f02afee2f712..5f6e48c772fc44 100644 --- a/be/src/common/config.h +++ b/be/src/common/config.h @@ -1239,6 +1239,7 @@ DECLARE_Int32(partition_disk_index_lru_size); DECLARE_mBool(ignore_schema_change_check); DECLARE_mInt64(tablet_meta_serialize_size_limit); +DECLARE_Bool(force_regenerate_rowsetid_on_start_error); #ifdef BE_TEST // test s3 diff --git a/be/src/olap/olap_common.h b/be/src/olap/olap_common.h index 811e77590f98b8..33e81e3b7a1bcc 100644 --- a/be/src/olap/olap_common.h +++ b/be/src/olap/olap_common.h @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -32,6 +33,7 @@ #include #include +#include "common/config.h" #include "io/io_common.h" #include "olap/olap_define.h" #include "util/hash_util.hpp" @@ -394,8 +396,18 @@ struct RowsetId { 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 high = std::stol(rowset_id_str, nullptr, 10); + if (rowset_id_str.length() < 48) [[unlikely]] { + int64_t high; + auto [_, ec] = std::from_chars(rowset_id_str.data(), + rowset_id_str.data() + rowset_id_str.length(), high); + if (ec != std::errc {}) [[unlikely]] { + if (config::force_regenerate_rowsetid_on_start_error) { + LOG(WARNING) << "failed to init rowset id: " << rowset_id_str; + high = MAX_ROWSET_ID - 1; + } else { + LOG(FATAL) << "failed to init rowset id: " << rowset_id_str; + } + } init(1, high, 0, 0); } else { int64_t high = 0; diff --git a/be/test/olap/rowset/rowset_meta_test.cpp b/be/test/olap/rowset/rowset_meta_test.cpp index a65c3b4b5fbc9a..66ceaa02714799 100644 --- a/be/test/olap/rowset/rowset_meta_test.cpp +++ b/be/test/olap/rowset/rowset_meta_test.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -112,4 +113,13 @@ TEST_F(RowsetMetaTest, TestInitWithInvalidData) { EXPECT_FALSE(rowset_meta.init("invalid pb meta data")); } +TEST_F(RowsetMetaTest, TestRowsetIdInit) { + RowsetId id {}; + config::force_regenerate_rowsetid_on_start_error = true; + std::string rowset_id_str = "test"; + id.init(rowset_id_str); + // 0x100000000000000 - 0x01 + EXPECT_EQ(id.to_string(), "72057594037927935"); +} + } // namespace doris