Skip to content

Commit d615a31

Browse files
committed
modify raw ptr to sptr
1 parent 13f8178 commit d615a31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+232
-198
lines changed

be/src/exec/olap_scanner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Status OlapScanner::prepare(
8383
LOG(WARNING) << ss.str();
8484
return Status::InternalError(ss.str());
8585
}
86-
_tablet_schema = *_tablet->tablet_schema();
86+
_tablet_schema.copy_from(*_tablet->tablet_schema());
8787
if (!_parent->_olap_scan_node.columns_desc.empty() &&
8888
_parent->_olap_scan_node.columns_desc[0].col_unique_id >= 0) {
8989
_tablet_schema.clear_columns();

be/src/olap/base_tablet.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ extern MetricPrototype METRIC_query_scan_count;
3131

3232
BaseTablet::BaseTablet(TabletMetaSharedPtr tablet_meta, DataDir* data_dir)
3333
: _state(tablet_meta->tablet_state()), _tablet_meta(tablet_meta), _data_dir(data_dir) {
34-
TabletSchemaPB tablet_meta_pb;
35-
_tablet_meta->tablet_schema().to_schema_pb(&tablet_meta_pb);
36-
_schema = TabletSchemaCache::instance()->insert(tablet_meta_pb.SerializeAsString());
34+
_schema = TabletSchemaCache::instance()->insert(_tablet_meta->tablet_schema().to_key());
3735
_gen_tablet_path();
3836

3937
std::stringstream ss;
@@ -74,7 +72,7 @@ bool BaseTablet::set_tablet_schema_into_rowset_meta() {
7472
bool flag = false;
7573
for (RowsetMetaSharedPtr rowset_meta : _tablet_meta->all_mutable_rs_metas()) {
7674
if (!rowset_meta->tablet_schema()) {
77-
rowset_meta->set_tablet_schema(_schema.get());
75+
rowset_meta->set_tablet_schema(_schema);
7876
flag = true;
7977
}
8078
}

be/src/olap/compaction.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ Status Compaction::do_compaction_impl(int64_t permits) {
157157
TabletSchemaSPtr cur_tablet_schema =
158158
_tablet->rowset_meta_with_max_schema_version(rowset_metas)->tablet_schema();
159159

160-
RETURN_NOT_OK(construct_output_rowset_writer(cur_tablet_schema.get()));
160+
RETURN_NOT_OK(construct_output_rowset_writer(cur_tablet_schema));
161161
RETURN_NOT_OK(construct_input_rowset_readers());
162162
TRACE("prepare finished");
163163

@@ -238,7 +238,7 @@ Status Compaction::do_compaction_impl(int64_t permits) {
238238
return Status::OK();
239239
}
240240

241-
Status Compaction::construct_output_rowset_writer(const TabletSchema* schema) {
241+
Status Compaction::construct_output_rowset_writer(TabletSchemaSPtr schema) {
242242
return _tablet->create_rowset_writer(_output_version, VISIBLE, NONOVERLAPPING, schema,
243243
_oldest_write_timestamp, _newest_write_timestamp,
244244
&_output_rs_writer);

be/src/olap/compaction.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Compaction {
6565
Status modify_rowsets();
6666
void gc_output_rowset();
6767

68-
Status construct_output_rowset_writer(const TabletSchema* schema);
68+
Status construct_output_rowset_writer(TabletSchemaSPtr schema);
6969
Status construct_input_rowset_readers();
7070

7171
Status check_version_continuity(const std::vector<RowsetSharedPtr>& rowsets);

be/src/olap/data_dir.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,9 @@ Status DataDir::load() {
476476
if (rowset_meta->rowset_state() == RowsetStatePB::COMMITTED &&
477477
rowset_meta->tablet_uid() == tablet->tablet_uid()) {
478478
if (!rowset_meta->tablet_schema()) {
479-
rowset_meta->set_tablet_schema(tablet->tablet_schema().get());
480-
RowsetMetaPB rowset_meta_pb = rowset_meta->get_rowset_pb();
481-
tablet->tablet_schema()->to_schema_pb(rowset_meta_pb.mutable_tablet_schema());
479+
rowset_meta->set_tablet_schema(tablet->tablet_schema());
482480
RowsetMetaManager::save(_meta, rowset_meta->tablet_uid(), rowset_meta->rowset_id(),
483-
rowset_meta_pb);
481+
rowset_meta->get_rowset_pb());
484482
}
485483
Status commit_txn_status = _txn_manager->commit_txn(
486484
_meta, rowset_meta->partition_id(), rowset_meta->txn_id(),
@@ -501,11 +499,9 @@ Status DataDir::load() {
501499
} else if (rowset_meta->rowset_state() == RowsetStatePB::VISIBLE &&
502500
rowset_meta->tablet_uid() == tablet->tablet_uid()) {
503501
if (!rowset_meta->tablet_schema()) {
504-
rowset_meta->set_tablet_schema(tablet->tablet_schema().get());
505-
RowsetMetaPB rowset_meta_pb = rowset_meta->get_rowset_pb();
506-
tablet->tablet_schema()->to_schema_pb(rowset_meta_pb.mutable_tablet_schema());
502+
rowset_meta->set_tablet_schema(tablet->tablet_schema());
507503
RowsetMetaManager::save(_meta, rowset_meta->tablet_uid(), rowset_meta->rowset_id(),
508-
rowset_meta_pb);
504+
rowset_meta->get_rowset_pb());
509505
}
510506
Status publish_status = tablet->add_rowset(rowset);
511507
if (!publish_status &&

be/src/olap/delta_writer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Status DeltaWriter::init() {
127127
*_tablet->tablet_schema());
128128

129129
RETURN_NOT_OK(_tablet->create_rowset_writer(_req.txn_id, _req.load_id, PREPARED, OVERLAPPING,
130-
_tablet_schema.get(), &_rowset_writer));
130+
_tablet_schema, &_rowset_writer));
131131
_schema.reset(new Schema(*_tablet_schema));
132132
_reset_mem_table();
133133

@@ -381,7 +381,7 @@ int64_t DeltaWriter::partition_id() const {
381381
void DeltaWriter::_build_current_tablet_schema(int64_t index_id,
382382
const POlapTableSchemaParam& ptable_schema_param,
383383
const TabletSchema& ori_tablet_schema) {
384-
*_tablet_schema = ori_tablet_schema;
384+
_tablet_schema->copy_from(ori_tablet_schema);
385385
//new tablet schame if new table
386386
if (ptable_schema_param.indexes_size() > 0 &&
387387
ptable_schema_param.indexes(0).columns_desc_size() != 0 &&

be/src/olap/delta_writer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class DeltaWriter {
128128
// tablet schema owned by delta writer, all write will use this tablet schema
129129
// it's build from tablet_schema(stored when create tablet) and OlapTableSchema
130130
// every request will have it's own tablet schema so simple schema change can work
131-
std::unique_ptr<TabletSchema> _tablet_schema;
131+
TabletSchemaSPtr _tablet_schema;
132132
bool _delta_written_success;
133133

134134
StorageEngine* _storage_engine;

be/src/olap/push_handler.cpp

+13-11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "olap/schema_change.h"
3232
#include "olap/storage_engine.h"
3333
#include "olap/tablet.h"
34+
#include "olap/tablet_schema.h"
3435
#include "runtime/exec_env.h"
3536

3637
namespace doris {
@@ -115,7 +116,8 @@ Status PushHandler::_do_streaming_ingestion(TabletSharedPtr tablet, const TPushR
115116
}
116117

117118
DeletePredicatePB del_pred;
118-
auto tablet_schema = *tablet_var.tablet->tablet_schema();
119+
TabletSchema tablet_schema;
120+
tablet_schema.copy_from(*tablet_var.tablet->tablet_schema());
119121
if (!request.columns_desc.empty() && request.columns_desc[0].col_unique_id >= 0) {
120122
tablet_schema.clear_columns();
121123
for (const auto& column_desc : request.columns_desc) {
@@ -141,25 +143,25 @@ Status PushHandler::_do_streaming_ingestion(TabletSharedPtr tablet, const TPushR
141143
<< ". tablet: " << tablet_vars->at(0).tablet->full_name();
142144
return Status::OLAPInternalError(OLAP_ERR_TOO_MANY_VERSION);
143145
}
144-
145-
auto tablet_schema = *tablet_vars->at(0).tablet->tablet_schema();
146+
auto tablet_schema = std::make_shared<TabletSchema>();
147+
tablet_schema->copy_from(*tablet_vars->at(0).tablet->tablet_schema());
146148
if (!request.columns_desc.empty() && request.columns_desc[0].col_unique_id >= 0) {
147-
tablet_schema.clear_columns();
149+
tablet_schema->clear_columns();
148150
for (const auto& column_desc : request.columns_desc) {
149-
tablet_schema.append_column(TabletColumn(column_desc));
151+
tablet_schema->append_column(TabletColumn(column_desc));
150152
}
151153
}
152154

153155
// writes
154156
if (push_type == PUSH_NORMAL_V2) {
155157
res = _convert_v2(tablet_vars->at(0).tablet, tablet_vars->at(1).tablet,
156158
&(tablet_vars->at(0).rowset_to_add), &(tablet_vars->at(1).rowset_to_add),
157-
&tablet_schema);
159+
tablet_schema);
158160

159161
} else {
160162
res = _convert(tablet_vars->at(0).tablet, tablet_vars->at(1).tablet,
161163
&(tablet_vars->at(0).rowset_to_add), &(tablet_vars->at(1).rowset_to_add),
162-
&tablet_schema);
164+
tablet_schema);
163165
}
164166
if (!res.ok()) {
165167
LOG(WARNING) << "fail to convert tmp file when realtime push. res=" << res
@@ -219,7 +221,7 @@ void PushHandler::_get_tablet_infos(const std::vector<TabletVars>& tablet_vars,
219221

220222
Status PushHandler::_convert_v2(TabletSharedPtr cur_tablet, TabletSharedPtr new_tablet,
221223
RowsetSharedPtr* cur_rowset, RowsetSharedPtr* new_rowset,
222-
const TabletSchema* tablet_schema) {
224+
TabletSchemaSPtr tablet_schema) {
223225
Status res = Status::OK();
224226
uint32_t num_rows = 0;
225227
PUniqueId load_id;
@@ -344,7 +346,7 @@ Status PushHandler::_convert_v2(TabletSharedPtr cur_tablet, TabletSharedPtr new_
344346

345347
Status PushHandler::_convert(TabletSharedPtr cur_tablet, TabletSharedPtr new_tablet,
346348
RowsetSharedPtr* cur_rowset, RowsetSharedPtr* new_rowset,
347-
const TabletSchema* tablet_schema) {
349+
TabletSchemaSPtr tablet_schema) {
348350
Status res = Status::OK();
349351
RowCursor row;
350352
BinaryFile raw_file;
@@ -515,7 +517,7 @@ IBinaryReader* IBinaryReader::create(bool need_decompress) {
515517

516518
BinaryReader::BinaryReader() : _row_buf(nullptr), _row_buf_size(0) {}
517519

518-
Status BinaryReader::init(const TabletSchema* tablet_schema, BinaryFile* file) {
520+
Status BinaryReader::init(TabletSchemaSPtr tablet_schema, BinaryFile* file) {
519521
Status res = Status::OK();
520522

521523
do {
@@ -657,7 +659,7 @@ LzoBinaryReader::LzoBinaryReader()
657659
_row_num(0),
658660
_next_row_start(0) {}
659661

660-
Status LzoBinaryReader::init(const TabletSchema* tablet_schema, BinaryFile* file) {
662+
Status LzoBinaryReader::init(TabletSchemaSPtr tablet_schema, BinaryFile* file) {
661663
Status res = Status::OK();
662664

663665
do {

be/src/olap/push_handler.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "olap/olap_common.h"
3131
#include "olap/row_cursor.h"
3232
#include "olap/rowset/rowset.h"
33+
#include "olap/tablet_schema.h"
3334

3435
namespace doris {
3536

@@ -61,12 +62,12 @@ class PushHandler {
6162
private:
6263
Status _convert_v2(TabletSharedPtr cur_tablet, TabletSharedPtr new_tablet_vec,
6364
RowsetSharedPtr* cur_rowset, RowsetSharedPtr* new_rowset,
64-
const TabletSchema* tablet_schema);
65+
TabletSchemaSPtr tablet_schema);
6566
// Convert local data file to internal formatted delta,
6667
// return new delta's SegmentGroup
6768
Status _convert(TabletSharedPtr cur_tablet, TabletSharedPtr new_tablet_vec,
6869
RowsetSharedPtr* cur_rowset, RowsetSharedPtr* new_rowset,
69-
const TabletSchema* tablet_schema);
70+
TabletSchemaSPtr tablet_schema);
7071

7172
// Only for debug
7273
std::string _debug_version_list(const Versions& versions) const;
@@ -114,7 +115,7 @@ class IBinaryReader {
114115
static IBinaryReader* create(bool need_decompress);
115116
virtual ~IBinaryReader() = default;
116117

117-
virtual Status init(const TabletSchema* tablet_schema, BinaryFile* file) = 0;
118+
virtual Status init(TabletSchemaSPtr tablet_schema, BinaryFile* file) = 0;
118119
virtual Status finalize() = 0;
119120

120121
virtual Status next(RowCursor* row) = 0;
@@ -133,7 +134,7 @@ class IBinaryReader {
133134
_ready(false) {}
134135

135136
BinaryFile* _file;
136-
const TabletSchema* _tablet_schema;
137+
TabletSchemaSPtr _tablet_schema;
137138
size_t _content_len;
138139
size_t _curr;
139140
uint32_t _adler_checksum;
@@ -146,7 +147,7 @@ class BinaryReader : public IBinaryReader {
146147
explicit BinaryReader();
147148
~BinaryReader() override { finalize(); }
148149

149-
Status init(const TabletSchema* tablet_schema, BinaryFile* file) override;
150+
Status init(TabletSchemaSPtr tablet_schema, BinaryFile* file) override;
150151
Status finalize() override;
151152

152153
Status next(RowCursor* row) override;
@@ -163,7 +164,7 @@ class LzoBinaryReader : public IBinaryReader {
163164
explicit LzoBinaryReader();
164165
~LzoBinaryReader() override { finalize(); }
165166

166-
Status init(const TabletSchema* tablet_schema, BinaryFile* file) override;
167+
Status init(TabletSchemaSPtr tablet_schema, BinaryFile* file) override;
167168
Status finalize() override;
168169

169170
Status next(RowCursor* row) override;

be/src/olap/rowset/beta_rowset.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "io/fs/s3_file_system.h"
2929
#include "olap/olap_define.h"
3030
#include "olap/rowset/beta_rowset_reader.h"
31+
#include "olap/tablet_schema.h"
3132
#include "olap/utils.h"
3233
#include "util/doris_metrics.h"
3334

@@ -53,7 +54,7 @@ std::string BetaRowset::remote_segment_path(int64_t tablet_id, const RowsetId& r
5354
segment_id);
5455
}
5556

56-
BetaRowset::BetaRowset(const TabletSchema* schema, const std::string& tablet_path,
57+
BetaRowset::BetaRowset(TabletSchemaSPtr schema, const std::string& tablet_path,
5758
RowsetMetaSharedPtr rowset_meta)
5859
: Rowset(schema, tablet_path, std::move(rowset_meta)) {}
5960

be/src/olap/rowset/beta_rowset.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class BetaRowset : public Rowset {
7373
Status load_segments(std::vector<segment_v2::SegmentSharedPtr>* segments);
7474

7575
protected:
76-
BetaRowset(const TabletSchema* schema, const std::string& tablet_path,
76+
BetaRowset(TabletSchemaSPtr schema, const std::string& tablet_path,
7777
RowsetMetaSharedPtr rowset_meta);
7878

7979
// init segment groups

be/src/olap/rowset/rowset.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
#include "olap/rowset/rowset.h"
1919

20+
#include "olap/tablet_schema.h"
21+
#include "olap/tablet_schema_cache.h"
2022
#include "util/time.h"
2123

2224
namespace doris {
2325

24-
Rowset::Rowset(const TabletSchema* schema, const std::string& tablet_path,
26+
Rowset::Rowset(TabletSchemaSPtr schema, const std::string& tablet_path,
2527
RowsetMetaSharedPtr rowset_meta)
2628
: _tablet_path(tablet_path), _rowset_meta(std::move(rowset_meta)), _refs_by_reader(0) {
2729
_is_pending = !_rowset_meta->has_version();
@@ -32,7 +34,7 @@ Rowset::Rowset(const TabletSchema* schema, const std::string& tablet_path,
3234
_is_cumulative = version.first != version.second;
3335
}
3436
// build schema from RowsetMeta.tablet_schema or Tablet.tablet_schema
35-
_schema = _rowset_meta->tablet_schema() ? _rowset_meta->tablet_schema().get() : schema;
37+
_schema = _rowset_meta->tablet_schema() ? _rowset_meta->tablet_schema() : schema;
3638
}
3739

3840
Status Rowset::load(bool use_cache) {

be/src/olap/rowset/rowset.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class Rowset : public std::enable_shared_from_this<Rowset> {
138138

139139
// publish rowset to make it visible to read
140140
void make_visible(Version version);
141-
const TabletSchema* tablet_schema() { return _schema; }
141+
TabletSchemaSPtr tablet_schema() { return _schema; }
142142

143143
// helper class to access RowsetMeta
144144
int64_t start_version() const { return rowset_meta()->version().first; }
@@ -158,7 +158,7 @@ class Rowset : public std::enable_shared_from_this<Rowset> {
158158
bool delete_flag() const { return rowset_meta()->delete_flag(); }
159159
int64_t num_segments() const { return rowset_meta()->num_segments(); }
160160
void to_rowset_pb(RowsetMetaPB* rs_meta) const { return rowset_meta()->to_rowset_pb(rs_meta); }
161-
const RowsetMetaPB& get_rowset_pb() const { return rowset_meta()->get_rowset_pb(); }
161+
RowsetMetaPB get_rowset_pb() const { return rowset_meta()->get_rowset_pb(); }
162162
int64_t oldest_write_timestamp() const { return rowset_meta()->oldest_write_timestamp(); }
163163
int64_t newest_write_timestamp() const { return rowset_meta()->newest_write_timestamp(); }
164164
KeysType keys_type() { return _schema->keys_type(); }
@@ -269,7 +269,7 @@ class Rowset : public std::enable_shared_from_this<Rowset> {
269269

270270
DISALLOW_COPY_AND_ASSIGN(Rowset);
271271
// this is non-public because all clients should use RowsetFactory to obtain pointer to initialized Rowset
272-
Rowset(const TabletSchema* schema, const std::string& tablet_path,
272+
Rowset(TabletSchemaSPtr schema, const std::string& tablet_path,
273273
RowsetMetaSharedPtr rowset_meta);
274274

275275
// this is non-public because all clients should use RowsetFactory to obtain pointer to initialized Rowset
@@ -284,7 +284,7 @@ class Rowset : public std::enable_shared_from_this<Rowset> {
284284
// allow subclass to add custom logic when rowset is being published
285285
virtual void make_visible_extra(Version version) {}
286286

287-
const TabletSchema* _schema;
287+
TabletSchemaSPtr _schema;
288288
std::string _tablet_path;
289289
RowsetMetaSharedPtr _rowset_meta;
290290
// init in constructor

be/src/olap/rowset/rowset_factory.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
namespace doris {
2828

29-
Status RowsetFactory::create_rowset(const TabletSchema* schema, const std::string& tablet_path,
29+
Status RowsetFactory::create_rowset(TabletSchemaSPtr schema, const std::string& tablet_path,
3030
RowsetMetaSharedPtr rowset_meta, RowsetSharedPtr* rowset) {
3131
if (rowset_meta->rowset_type() == ALPHA_ROWSET) {
3232
return Status::OLAPInternalError(OLAP_ERR_ROWSET_INVALID);

be/src/olap/rowset/rowset_factory.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RowsetFactory {
3131
public:
3232
// return OLAP_SUCCESS and set inited rowset in `*rowset`.
3333
// return others if failed to create or init rowset.
34-
static Status create_rowset(const TabletSchema* schema, const std::string& tablet_path,
34+
static Status create_rowset(TabletSchemaSPtr schema, const std::string& tablet_path,
3535
RowsetMetaSharedPtr rowset_meta, RowsetSharedPtr* rowset);
3636

3737
// create and init rowset writer.

be/src/olap/rowset/rowset_meta.h

+10-7
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,13 @@ class RowsetMeta {
258258
}
259259
}
260260

261-
// warning!don't use tablet_schema in rowset_meta_pb
262-
const RowsetMetaPB& get_rowset_pb() { return _rowset_meta_pb; }
261+
RowsetMetaPB get_rowset_pb() {
262+
RowsetMetaPB rowset_meta_pb = _rowset_meta_pb;
263+
if (_schema) {
264+
_schema->to_schema_pb(rowset_meta_pb.mutable_tablet_schema());
265+
}
266+
return rowset_meta_pb;
267+
}
263268

264269
bool is_singleton_delta() const {
265270
return has_version() && _rowset_meta_pb.start_version() == _rowset_meta_pb.end_version();
@@ -336,11 +341,9 @@ class RowsetMeta {
336341
int64_t oldest_write_timestamp() const { return _rowset_meta_pb.oldest_write_timestamp(); }
337342

338343
int64_t newest_write_timestamp() const { return _rowset_meta_pb.newest_write_timestamp(); }
339-
void set_tablet_schema(const TabletSchema* tablet_schema) {
340-
TabletSchemaPB ts_pb;
341-
tablet_schema->to_schema_pb(&ts_pb);
342-
CHECK(_schema == nullptr);
343-
_schema = TabletSchemaCache::instance()->insert(ts_pb.SerializeAsString());
344+
void set_tablet_schema(const TabletSchemaSPtr& tablet_schema) {
345+
DCHECK(_schema == nullptr);
346+
_schema = TabletSchemaCache::instance()->insert(tablet_schema->to_key());
344347
}
345348

346349
TabletSchemaSPtr tablet_schema() { return _schema; }

0 commit comments

Comments
 (0)