This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 5e6669ff088 branch-2.1: [Optimize](TabletMeta) Reuse TabletSchema in
TabletMeta #46572 (#46687)
5e6669ff088 is described below
commit 5e6669ff088e09a53c9fec3168906685d8f4d514
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Jan 9 22:20:31 2025 +0800
branch-2.1: [Optimize](TabletMeta) Reuse TabletSchema in TabletMeta #46572
(#46687)
Cherry-picked from #46572
Co-authored-by: lihangyu <[email protected]>
---
be/src/olap/tablet_meta.cpp | 18 +++++++++++++++++-
be/src/olap/tablet_meta.h | 2 ++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/be/src/olap/tablet_meta.cpp b/be/src/olap/tablet_meta.cpp
index b7c1d0b041f..2454f271792 100644
--- a/be/src/olap/tablet_meta.cpp
+++ b/be/src/olap/tablet_meta.cpp
@@ -27,6 +27,7 @@
#include <time.h>
#include <cstdint>
+#include <memory>
#include <set>
#include <utility>
@@ -39,7 +40,9 @@
#include "olap/olap_define.h"
#include "olap/rowset/rowset.h"
#include "olap/rowset/rowset_meta_manager.h"
+#include "olap/tablet_fwd.h"
#include "olap/tablet_meta_manager.h"
+#include "olap/tablet_schema_cache.h"
#include "olap/utils.h"
#include "util/debug_points.h"
#include "util/mem_info.h"
@@ -80,6 +83,12 @@ TabletMetaSharedPtr TabletMeta::create(
request.inverted_index_storage_format,
request.time_series_compaction_level_threshold);
}
+TabletMeta::~TabletMeta() {
+ if (_handle) {
+ TabletSchemaCache::instance()->release(_handle);
+ }
+}
+
TabletMeta::TabletMeta()
: _tablet_uid(0, 0),
_schema(new TabletSchema),
@@ -595,7 +604,14 @@ void TabletMeta::init_from_pb(const TabletMetaPB&
tablet_meta_pb) {
}
// init _schema
- _schema->init_from_pb(tablet_meta_pb.schema());
+ TabletSchemaSPtr schema = std::make_shared<TabletSchema>();
+ schema->init_from_pb(tablet_meta_pb.schema());
+ if (_handle) {
+ TabletSchemaCache::instance()->release(_handle);
+ }
+ auto pair = TabletSchemaCache::instance()->insert(schema->to_key());
+ _handle = pair.first;
+ _schema = pair.second;
if (tablet_meta_pb.has_enable_unique_key_merge_on_write()) {
_enable_unique_key_merge_on_write =
tablet_meta_pb.enable_unique_key_merge_on_write();
diff --git a/be/src/olap/tablet_meta.h b/be/src/olap/tablet_meta.h
index 4a67f6b0f9d..b04e138a3b6 100644
--- a/be/src/olap/tablet_meta.h
+++ b/be/src/olap/tablet_meta.h
@@ -99,6 +99,7 @@ public:
const std::unordered_map<uint32_t, uint32_t>&
col_ordinal_to_unique_id);
TabletMeta();
+ ~TabletMeta() override;
TabletMeta(int64_t table_id, int64_t partition_id, int64_t tablet_id,
int64_t replica_id,
int32_t schema_hash, uint64_t shard_id, const TTabletSchema&
tablet_schema,
uint32_t next_unique_id,
@@ -301,6 +302,7 @@ private:
// the reference of _schema may use in tablet, so here need keep
// the lifetime of tablemeta and _schema is same with tablet
TabletSchemaSPtr _schema;
+ Cache::Handle* _handle = nullptr;
std::vector<RowsetMetaSharedPtr> _rs_metas;
// This variable _stale_rs_metas is used to record these rowsets‘ meta
which are be compacted.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]