Skip to content

Commit 6debbc3

Browse files
authored
[cherry-pick](branch-2.0) Pick "[Fix](Rowset Id) Use a randomly generated rowset ID to handle memory write failures (#42949) (#46102)
1 parent 342bcee commit 6debbc3

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

be/src/common/config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,7 @@ DEFINE_mInt64(tablet_meta_serialize_size_limit, "1610612736");
11911191
// 1717986918 = 2GB * 0.8
11921192
DEFINE_Validator(tablet_meta_serialize_size_limit,
11931193
[](const int64_t config) -> bool { return config < 1717986918; });
1194+
DEFINE_Bool(force_regenerate_rowsetid_on_start_error, "false");
11941195

11951196
// clang-format off
11961197
#ifdef BE_TEST

be/src/common/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,7 @@ DECLARE_Int32(partition_disk_index_lru_size);
12391239
DECLARE_mBool(ignore_schema_change_check);
12401240

12411241
DECLARE_mInt64(tablet_meta_serialize_size_limit);
1242+
DECLARE_Bool(force_regenerate_rowsetid_on_start_error);
12421243

12431244
#ifdef BE_TEST
12441245
// test s3

be/src/olap/olap_common.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <gen_cpp/Types_types.h>
2121
#include <netinet/in.h>
2222

23+
#include <charconv>
2324
#include <cstdint>
2425
#include <functional>
2526
#include <list>
@@ -32,6 +33,7 @@
3233
#include <unordered_map>
3334
#include <unordered_set>
3435

36+
#include "common/config.h"
3537
#include "io/io_common.h"
3638
#include "olap/olap_define.h"
3739
#include "util/hash_util.hpp"
@@ -402,8 +404,18 @@ struct RowsetId {
402404
void init(const std::string& rowset_id_str) {
403405
// for new rowsetid its a 48 hex string
404406
// if the len < 48, then it is an old format rowset id
405-
if (rowset_id_str.length() < 48) {
406-
int64_t high = std::stol(rowset_id_str, nullptr, 10);
407+
if (rowset_id_str.length() < 48) [[unlikely]] {
408+
int64_t high;
409+
auto [_, ec] = std::from_chars(rowset_id_str.data(),
410+
rowset_id_str.data() + rowset_id_str.length(), high);
411+
if (ec != std::errc {}) [[unlikely]] {
412+
if (config::force_regenerate_rowsetid_on_start_error) {
413+
LOG(WARNING) << "failed to init rowset id: " << rowset_id_str;
414+
high = MAX_ROWSET_ID - 1;
415+
} else {
416+
LOG(FATAL) << "failed to init rowset id: " << rowset_id_str;
417+
}
418+
}
407419
init(1, high, 0, 0);
408420
} else {
409421
int64_t high = 0;

be/test/olap/rowset/rowset_meta_test.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <gmock/gmock-matchers.h>
2222
#include <gtest/gtest-message.h>
2323
#include <gtest/gtest-test-part.h>
24+
#include <gtest/gtest.h>
2425

2526
#include <filesystem>
2627
#include <fstream>
@@ -112,4 +113,13 @@ TEST_F(RowsetMetaTest, TestInitWithInvalidData) {
112113
EXPECT_FALSE(rowset_meta.init("invalid pb meta data"));
113114
}
114115

116+
TEST_F(RowsetMetaTest, TestRowsetIdInit) {
117+
RowsetId id {};
118+
config::force_regenerate_rowsetid_on_start_error = true;
119+
std::string rowset_id_str = "test";
120+
id.init(rowset_id_str);
121+
// 0x100000000000000 - 0x01
122+
EXPECT_EQ(id.to_string(), "72057594037927935");
123+
}
124+
115125
} // namespace doris

0 commit comments

Comments
 (0)