This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 8503efdde32 [Fix](tablet-meta) limit the data size of tablet meta
(#39455) (#39967)
8503efdde32 is described below
commit 8503efdde320898fe3cbbd6b2bea455d6d9eb699
Author: Luwei <[email protected]>
AuthorDate: Mon Sep 9 15:14:18 2024 +0800
[Fix](tablet-meta) limit the data size of tablet meta (#39455) (#39967)
pick master #39455
---
be/src/common/config.cpp | 7 +++++++
be/src/common/config.h | 2 ++
be/src/olap/delta_writer.cpp | 10 ++++++++++
be/src/olap/push_handler.cpp | 11 +++++++++++
be/src/olap/schema_change.cpp | 1 +
be/src/olap/tablet.h | 11 +++++++++++
be/src/olap/tablet_meta.cpp | 21 +++++++++++++++++++++
be/src/olap/tablet_meta.h | 9 +++++++++
8 files changed, 72 insertions(+)
diff --git a/be/src/common/config.cpp b/be/src/common/config.cpp
index ae89127c722..e93f40d7ffa 100644
--- a/be/src/common/config.cpp
+++ b/be/src/common/config.cpp
@@ -1181,6 +1181,13 @@ DEFINE_Int32(partition_disk_index_lru_size, "10000");
DEFINE_mBool(ignore_schema_change_check, "false");
+// Tablet meta size limit after serialization, 1.5GB
+DEFINE_mInt64(tablet_meta_serialize_size_limit, "1610612736");
+// Protobuf supports a maximum of 2GB, so the size of the tablet meta after
serialization must be less than 2GB
+// 1717986918 = 2GB * 0.8
+DEFINE_Validator(tablet_meta_serialize_size_limit,
+ [](const int64_t config) -> bool { return config <
1717986918; });
+
// clang-format off
#ifdef BE_TEST
// test s3
diff --git a/be/src/common/config.h b/be/src/common/config.h
index df050c52a83..daf054a7369 100644
--- a/be/src/common/config.h
+++ b/be/src/common/config.h
@@ -1234,6 +1234,8 @@ DECLARE_Int32(partition_disk_index_lru_size);
DECLARE_mBool(ignore_schema_change_check);
+DECLARE_mInt64(tablet_meta_serialize_size_limit);
+
#ifdef BE_TEST
// test s3
DECLARE_String(test_s3_resource);
diff --git a/be/src/olap/delta_writer.cpp b/be/src/olap/delta_writer.cpp
index b9eb8bdf6c1..d19d1a8d2b6 100644
--- a/be/src/olap/delta_writer.cpp
+++ b/be/src/olap/delta_writer.cpp
@@ -188,6 +188,16 @@ Status DeltaWriter::init() {
}
}
+ int version_count = _tablet->version_count() +
_tablet->stale_version_count();
+ if (_tablet->avg_rs_meta_serialize_size() * version_count >
+ config::tablet_meta_serialize_size_limit) {
+ return Status::Error<TOO_MANY_VERSION>(
+ "failed to init rowset builder. meta serialize size : {},
exceed limit: {}, "
+ "tablet: {}",
+ _tablet->avg_rs_meta_serialize_size() * version_count,
+ config::tablet_meta_serialize_size_limit,
_tablet->tablet_id());
+ }
+
{
std::shared_lock base_migration_rlock(_tablet->get_migration_lock(),
std::defer_lock);
if (!base_migration_rlock.try_lock_for(
diff --git a/be/src/olap/push_handler.cpp b/be/src/olap/push_handler.cpp
index 4ac74326a38..51cfd4856d2 100644
--- a/be/src/olap/push_handler.cpp
+++ b/be/src/olap/push_handler.cpp
@@ -164,6 +164,17 @@ Status
PushHandler::_do_streaming_ingestion(TabletSharedPtr tablet, const TPushR
"failed to push data. version count: {}, exceed limit: {},
tablet: {}",
tablet->version_count(), config::max_tablet_version_num,
tablet->full_name());
}
+
+ int version_count = tablet->version_count() +
tablet->stale_version_count();
+ if (tablet->avg_rs_meta_serialize_size() * version_count >
+ config::tablet_meta_serialize_size_limit) {
+ return Status::Error<TOO_MANY_VERSION>(
+ "failed to init rowset builder. meta serialize size : {},
exceed limit: {}, "
+ "tablet: {}",
+ tablet->avg_rs_meta_serialize_size() * version_count,
+ config::tablet_meta_serialize_size_limit, tablet->tablet_id());
+ }
+
auto tablet_schema = std::make_shared<TabletSchema>();
tablet_schema->copy_from(*tablet->tablet_schema());
if (!request.columns_desc.empty() && request.columns_desc[0].col_unique_id
>= 0) {
diff --git a/be/src/olap/schema_change.cpp b/be/src/olap/schema_change.cpp
index 31d3f0a32c8..65867b7f7ae 100644
--- a/be/src/olap/schema_change.cpp
+++ b/be/src/olap/schema_change.cpp
@@ -853,6 +853,7 @@ Status
SchemaChangeHandler::_do_process_alter_tablet_v2(const TAlterTabletReqV2&
}
std::vector<RowsetSharedPtr> empty_vec;
new_tablet->modify_rowsets(empty_vec, rowsets_to_delete);
+ new_tablet->delete_rowsets(rowsets_to_delete, false);
// inherit cumulative_layer_point from base_tablet
// check if new_tablet.ce_point > base_tablet.ce_point?
new_tablet->set_cumulative_layer_point(-1);
diff --git a/be/src/olap/tablet.h b/be/src/olap/tablet.h
index 1fbc8254910..54d841b6bdd 100644
--- a/be/src/olap/tablet.h
+++ b/be/src/olap/tablet.h
@@ -128,6 +128,7 @@ public:
size_t num_rows();
int version_count() const;
bool exceed_version_limit(int32_t limit) const;
+ int stale_version_count() const;
uint64_t segment_count() const;
Version max_version() const;
Version max_version_unlocked() const;
@@ -147,6 +148,7 @@ public:
double bloom_filter_fpp() const;
size_t next_unique_id() const;
size_t row_size() const;
+ int64_t avg_rs_meta_serialize_size() const;
// operation in rowsets
Status add_rowset(RowsetSharedPtr rowset);
@@ -828,6 +830,11 @@ inline int Tablet::version_count() const {
return _tablet_meta->version_count();
}
+inline int Tablet::stale_version_count() const {
+ std::shared_lock rdlock(_meta_lock);
+ return _tablet_meta->stale_version_count();
+}
+
inline Version Tablet::max_version() const {
std::shared_lock rdlock(_meta_lock);
return _tablet_meta->max_version();
@@ -894,4 +901,8 @@ inline size_t Tablet::row_size() const {
return _schema->row_size();
}
+inline int64_t Tablet::avg_rs_meta_serialize_size() const {
+ return _tablet_meta->avg_rs_meta_serialize_size();
+}
+
} // namespace doris
diff --git a/be/src/olap/tablet_meta.cpp b/be/src/olap/tablet_meta.cpp
index 0d9eb5316f1..a5324c9a6ed 100644
--- a/be/src/olap/tablet_meta.cpp
+++ b/be/src/olap/tablet_meta.cpp
@@ -26,10 +26,12 @@
#include <json2pb/pb_to_json.h>
#include <time.h>
+#include <cstdint>
#include <set>
#include <utility>
#include "common/config.h"
+#include "gutil/integral_types.h"
#include "io/fs/file_reader_writer_fwd.h"
#include "io/fs/file_writer.h"
#include "olap/data_dir.h"
@@ -490,6 +492,25 @@ Status TabletMeta::serialize(string* meta_binary) {
<< partition_id << " new=" <<
tablet_meta_pb.DebugString();
});
bool serialize_success = tablet_meta_pb.SerializeToString(meta_binary);
+ if (!_rs_metas.empty() || !_stale_rs_metas.empty()) {
+ _avg_rs_meta_serialize_size =
+ meta_binary->length() / (_rs_metas.size() +
_stale_rs_metas.size());
+ if (meta_binary->length() > config::tablet_meta_serialize_size_limit ||
+ !serialize_success) {
+ int64_t origin_meta_size = meta_binary->length();
+ int64_t stale_rowsets_num = tablet_meta_pb.stale_rs_metas().size();
+ tablet_meta_pb.clear_stale_rs_metas();
+ meta_binary->clear();
+ serialize_success = tablet_meta_pb.SerializeToString(meta_binary);
+ LOG(WARNING) << "tablet meta serialization size exceeds limit: "
+ << config::tablet_meta_serialize_size_limit
+ << " clean up stale rowsets, tablet id: " <<
tablet_id()
+ << " stale rowset num: " << stale_rowsets_num
+ << " serialization size before clean " <<
origin_meta_size
+ << " serialization size after clean " <<
meta_binary->length();
+ }
+ }
+
if (!serialize_success) {
LOG(FATAL) << "failed to serialize meta " << full_name();
}
diff --git a/be/src/olap/tablet_meta.h b/be/src/olap/tablet_meta.h
index ed8faca6941..a79cdd27296 100644
--- a/be/src/olap/tablet_meta.h
+++ b/be/src/olap/tablet_meta.h
@@ -162,6 +162,7 @@ public:
// Remote disk space occupied by tablet.
size_t tablet_remote_size() const;
size_t version_count() const;
+ size_t stale_version_count() const;
Version max_version() const;
TabletState tablet_state() const;
@@ -268,6 +269,8 @@ public:
return _time_series_compaction_level_threshold;
}
+ int64_t avg_rs_meta_serialize_size() const { return
_avg_rs_meta_serialize_size; }
+
private:
Status _save_meta(DataDir* data_dir);
@@ -322,6 +325,8 @@ private:
int64_t _time_series_compaction_empty_rowsets_threshold = 0;
int64_t _time_series_compaction_level_threshold = 0;
+ int64_t _avg_rs_meta_serialize_size = 0;
+
mutable std::shared_mutex _meta_lock;
};
@@ -605,6 +610,10 @@ inline size_t TabletMeta::version_count() const {
return _rs_metas.size();
}
+inline size_t TabletMeta::stale_version_count() const {
+ return _rs_metas.size();
+}
+
inline TabletState TabletMeta::tablet_state() const {
return _tablet_state;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]