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

branch-2.1: [Optimize](TabletMeta) Reuse TabletSchema in TabletMeta #46572 #46687

Merged
merged 1 commit into from
Jan 9, 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
18 changes: 17 additions & 1 deletion be/src/olap/tablet_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <time.h>

#include <cstdint>
#include <memory>
#include <set>
#include <utility>

Expand All @@ -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"
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions be/src/olap/tablet_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class TabletMeta : public MetadataAdder<TabletMeta> {
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,
Expand Down Expand Up @@ -301,6 +302,7 @@ class TabletMeta : public MetadataAdder<TabletMeta> {
// 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.
Expand Down
Loading