Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick](branch-2.0) Pick "[Fix](Rowset Id) Use a randomly generated rowset ID to handle memory write failures (#42949) #46102

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions be/src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions be/src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions be/src/olap/olap_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <gen_cpp/Types_types.h>
#include <netinet/in.h>

#include <charconv>
#include <cstdint>
#include <functional>
#include <list>
Expand All @@ -32,6 +33,7 @@
#include <unordered_map>
#include <unordered_set>

#include "common/config.h"
#include "io/io_common.h"
#include "olap/olap_define.h"
#include "util/hash_util.hpp"
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions be/test/olap/rowset/rowset_meta_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <gmock/gmock-matchers.h>
#include <gtest/gtest-message.h>
#include <gtest/gtest-test-part.h>
#include <gtest/gtest.h>

#include <filesystem>
#include <fstream>
Expand Down Expand Up @@ -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
Loading