chaoyli commented on a change in pull request #563: Modify schema change to use rowset URL: https://github.com/apache/incubator-doris/pull/563#discussion_r250466836
########## File path: be/src/olap/schema_change.cpp ########## @@ -1115,121 +1057,109 @@ bool SchemaChangeWithSorting::process(ColumnData* olap_data, SegmentGroup* new_s } bool SchemaChangeWithSorting::_internal_sorting(const vector<RowBlock*>& row_block_arr, - const Version& temp_delta_versions, - SegmentGroup** temp_segment_group) { - ColumnDataWriter* writer = NULL; + const Version& version, + const VersionHash version_hash, + RowsetSharedPtr* rowset) { uint64_t merged_rows = 0; RowBlockMerger merger(_tablet); - (*temp_segment_group) = - new(nothrow) SegmentGroup(_tablet->tablet_id(), - 0, - _tablet->tablet_schema(), - _tablet->num_key_fields(), - _tablet->num_short_key_fields(), - _tablet->num_rows_per_row_block(), - _tablet->rowset_path_prefix(), - temp_delta_versions, - rand(), - false, - 0, 0); - if (NULL == (*temp_segment_group)) { - OLAP_LOG_WARNING("failed to malloc SegmentGroup. [size=%ld]", sizeof(SegmentGroup)); - goto INTERNAL_SORTING_ERR; + RowsetBuilderContextBuilderSharedPtr context_builder(new RowsetBuilderContextBuilder()); + RowsetId rowset_id = 0; + OLAPStatus status = RowsetIdGenerator::instance()->get_next_id(_tablet->data_dir(), &rowset_id); + if (status == OLAP_SUCCESS) { + LOG(WARNING) << "get next rowset id failed"; + return false; } - - VLOG(3) << "init writer. tablet=" << _tablet->full_name() - << ", block_row_size=" << _tablet->num_rows_per_row_block(); - writer = ColumnDataWriter::create(*temp_segment_group, false, - _tablet->compress_kind(), _tablet->bloom_filter_fpp()); - if (NULL == writer) { - OLAP_LOG_WARNING("failed to create writer."); - goto INTERNAL_SORTING_ERR; + context_builder->set_rowset_id(rowset_id) + .set_tablet_id(_tablet->tablet_id()) + .set_partition_id(_tablet->partition_id()) + .set_tablet_schema_hash(_tablet->schema_hash()) + .set_rowset_type(ALPHA_ROWSET) + .set_rowset_path_prefix(_tablet->tablet_path()) + .set_tablet_schema(_tablet->tablet_schema()) + .set_num_key_fields(_tablet->num_key_fields()) + .set_num_short_key_fields(_tablet->num_short_key_fields()) + .set_num_rows_per_row_block(_tablet->num_rows_per_row_block()) + .set_compress_kind(_tablet->compress_kind()) + .set_bloom_filter_fpp(_tablet->bloom_filter_fpp()) + .set_rowset_state(VISIBLE) + .set_version(version) + .set_version_hash(version_hash); + + RowsetBuilderContext context = context_builder->build(); + RowsetBuilderSharedPtr rowset_builder(new AlphaRowsetBuilder()); + if (rowset_builder == nullptr) { + LOG(WARNING) << "new rowset builder failed"; + return false; } + VLOG(3) << "init rowset builder. tablet=" << _tablet->full_name() + << ", block_row_size=" << _tablet->num_rows_per_row_block(); + rowset_builder->init(context); - if (!merger.merge(row_block_arr, writer, &merged_rows)) { - OLAP_LOG_WARNING("failed to merge row blocks."); + if (!merger.merge(row_block_arr, rowset_builder, &merged_rows)) { + LOG(WARNING) << "failed to merge row blocks."; goto INTERNAL_SORTING_ERR; } add_merged_rows(merged_rows); - if (OLAP_SUCCESS != (*temp_segment_group)->load()) { - OLAP_LOG_WARNING("failed to reload olap index."); + *rowset = rowset_builder->build(); + + if (OLAP_SUCCESS != (*rowset)->init()) { + LOG(WARNING) << "failed to reload olap index."; goto INTERNAL_SORTING_ERR; } - SAFE_DELETE(writer); return true; INTERNAL_SORTING_ERR: - SAFE_DELETE(writer); - - (*temp_segment_group)->delete_all_files(); - SAFE_DELETE(*temp_segment_group); + rowset_builder->release(); return false; } bool SchemaChangeWithSorting::_external_sorting( - vector<SegmentGroup*>& src_segment_groups, - SegmentGroup* dest_segment_group, + vector<RowsetSharedPtr>& src_rowsets, + RowsetBuilderSharedPtr rowset_builder, TabletSharedPtr tablet) { - Merger merger(_tablet, dest_segment_group, READER_ALTER_TABLE); + Merger merger(_tablet, rowset_builder, READER_ALTER_TABLE); uint64_t merged_rows = 0; uint64_t filted_rows = 0; vector<RowsetReaderSharedPtr> rs_readers; - for (vector<SegmentGroup*>::iterator it = src_segment_groups.begin(); - it != src_segment_groups.end(); ++it) { - ColumnData* olap_data = ColumnData::create(*it); - if (NULL == olap_data) { - OLAP_LOG_WARNING("fail to create ColumnData."); + for (vector<RowsetSharedPtr>::iterator it = src_rowsets.begin(); + it != src_rowsets.end(); ++it) { + RowsetReaderSharedPtr rowset_reader = (*it)->create_reader(); + if (rowset_reader == nullptr) { + LOG(WARNING) << "fail to create rowset reader."; goto EXTERNAL_SORTING_ERR; } - - rs_readers.push_back(olap_data); - - if (OLAP_SUCCESS != olap_data->init()) { - OLAP_LOG_WARNING("fail to initial olap data. [version='%d-%d' tablet='%s']", - (*it)->version().first, - (*it)->version().second, - tablet->full_name().c_str()); + OLAPStatus status = rowset_reader->init(nullptr); Review comment: init(nullptr) is OK? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@doris.apache.org For additional commands, e-mail: dev-h...@doris.apache.org