diff --git a/be/src/olap/tablet_meta.cpp b/be/src/olap/tablet_meta.cpp index b7c1d0b041f373..2454f271792ae9 100644 --- a/be/src/olap/tablet_meta.cpp +++ b/be/src/olap/tablet_meta.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -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(); + 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 4a67f6b0f9d939..b04e138a3b61b7 100644 --- a/be/src/olap/tablet_meta.h +++ b/be/src/olap/tablet_meta.h @@ -99,6 +99,7 @@ class TabletMeta : public MetadataAdder { const std::unordered_map& 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 @@ class TabletMeta : public MetadataAdder { // 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 _rs_metas; // This variable _stale_rs_metas is used to record these rowsets‘ meta which are be compacted.