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

Open
wants to merge 2 commits into
base: branch-2.0
Choose a base branch
from
Open
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
18 changes: 16 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 @@ -381,6 +383,8 @@ using ColumnId = uint32_t;
using UniqueIdSet = std::set<uint32_t>;
// Column unique Id -> column id map
using UniqueIdToColumnIdMap = std::map<ColumnId, ColumnId>;
struct RowsetId;
RowsetId next_rowset_id();

// 8 bit rowset id version
// 56 bit, inc number from 1
Expand All @@ -394,8 +398,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
6 changes: 6 additions & 0 deletions be/src/olap/rowset/unique_rowset_id_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <memory>
#include <mutex>

#include "olap/storage_engine.h"
#include "runtime/exec_env.h"
#include "util/doris_metrics.h"
#include "util/metrics.h"
#include "util/spinlock.h"
Expand All @@ -29,6 +31,10 @@ namespace doris {

DEFINE_GAUGE_METRIC_PROTOTYPE_2ARG(rowset_count_generated_and_in_use, MetricUnit::ROWSETS);

RowsetId next_rowset_id() {
return ExecEnv::GetInstance()->storage_engine()->next_rowset_id();
}

UniqueRowsetIdGenerator::UniqueRowsetIdGenerator(const UniqueId& backend_uid)
: _backend_uid(backend_uid), _inc_id(0) {
REGISTER_HOOK_METRIC(rowset_count_generated_and_in_use, [this]() {
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