Skip to content

Commit f5d350f

Browse files
authored
Merge branch 'master' into varbinary_order_by
2 parents 03d900d + c1eec85 commit f5d350f

File tree

1,024 files changed

+27950
-18175
lines changed

Some content is hidden

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

1,024 files changed

+27950
-18175
lines changed

be/benchmark/benchmark_bits.hpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
#include <benchmark/benchmark.h>
19+
20+
#include "util/simd/bits.h"
21+
22+
namespace doris {} // namespace doris
23+
24+
static void BM_Bits_CountZeroNum(benchmark::State& state) {
25+
const auto n = static_cast<size_t>(state.range(0));
26+
std::vector<int8_t> data(n, 0);
27+
28+
for (auto _ : state) {
29+
auto r = doris::simd::count_zero_num<size_t>(data.data(), data.size());
30+
benchmark::DoNotOptimize(r);
31+
}
32+
33+
state.SetBytesProcessed(state.iterations() * n);
34+
}
35+
36+
static void BM_Bits_CountZeroNumNullMap(benchmark::State& state) {
37+
const auto n = static_cast<size_t>(state.range(0));
38+
std::vector<int8_t> data(n, 0);
39+
std::vector<uint8_t> null_map(n, 0);
40+
41+
for (auto _ : state) {
42+
auto r = doris::simd::count_zero_num<size_t>(data.data(), null_map.data(), data.size());
43+
benchmark::DoNotOptimize(r);
44+
}
45+
46+
state.SetBytesProcessed(state.iterations() * n);
47+
}
48+
49+
BENCHMARK(BM_Bits_CountZeroNum)
50+
->Unit(benchmark::kNanosecond)
51+
->Arg(16) // 16 bytes
52+
->Arg(32) // 32 bytes
53+
->Arg(64) // 64 bytes
54+
->Arg(256) // 256 bytes
55+
->Arg(1024) // 1KB
56+
->Repetitions(5)
57+
->DisplayAggregatesOnly();
58+
59+
BENCHMARK(BM_Bits_CountZeroNumNullMap)
60+
->Unit(benchmark::kNanosecond)
61+
->Arg(16) // 16 bytes
62+
->Arg(32) // 32 bytes
63+
->Arg(64) // 64 bytes
64+
->Arg(256) // 256 bytes
65+
->Arg(1024) // 1KB
66+
->Repetitions(5)
67+
->DisplayAggregatesOnly();

be/benchmark/benchmark_main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <benchmark/benchmark.h>
1919

2020
#include "benchmark_bit_pack.hpp"
21+
#include "benchmark_bits.hpp"
2122
#include "benchmark_block_bloom_filter.hpp"
2223
#include "benchmark_fastunion.hpp"
2324
#include "benchmark_hll_merge.hpp"

be/cmake/thirdparty.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ add_thirdparty(curl)
6868
add_thirdparty(lz4)
6969
add_thirdparty(thrift)
7070
add_thirdparty(thriftnb)
71+
add_thirdparty(crc32c)
7172

7273
add_thirdparty(libevent_core LIBNAME "lib/libevent_core.a")
7374
add_thirdparty(libevent_openssl LIBNAME "lib/libevent_openssl.a")

be/src/cloud/cloud_base_compaction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ Status CloudBaseCompaction::pick_rowsets_to_compact() {
226226
<< ", num_cumulative_rowsets=" << _input_rowsets.size() - 1
227227
<< ", base_compaction_num_cumulative_rowsets="
228228
<< config::base_compaction_min_rowset_num;
229+
apply_txn_size_truncation_and_log("CloudBaseCompaction");
229230
return Status::OK();
230231
}
231232

@@ -251,6 +252,7 @@ Status CloudBaseCompaction::pick_rowsets_to_compact() {
251252
<< ", base_size=" << base_size
252253
<< ", cumulative_base_ratio=" << cumulative_base_ratio
253254
<< ", policy_ratio=" << base_cumulative_delta_ratio;
255+
apply_txn_size_truncation_and_log("CloudBaseCompaction");
254256
return Status::OK();
255257
}
256258

@@ -263,6 +265,7 @@ Status CloudBaseCompaction::pick_rowsets_to_compact() {
263265
<< ", interval_since_last_base_compaction="
264266
<< interval_since_last_base_compaction
265267
<< ", interval_threshold=" << interval_threshold;
268+
apply_txn_size_truncation_and_log("CloudBaseCompaction");
266269
return Status::OK();
267270
}
268271

be/src/cloud/cloud_cumulative_compaction.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ Status CloudCumulativeCompaction::modify_rowsets() {
375375
if (_input_rowsets.size() == 1) {
376376
DCHECK_EQ(_output_rowset->version(), _input_rowsets[0]->version());
377377
// MUST NOT move input rowset to stale path
378-
cloud_tablet()->add_rowsets({_output_rowset}, true, wrlock);
378+
cloud_tablet()->add_rowsets({_output_rowset}, true, wrlock, true);
379379
} else {
380380
cloud_tablet()->delete_rowsets(_input_rowsets, wrlock);
381381
cloud_tablet()->add_rowsets({_output_rowset}, false, wrlock);
@@ -532,6 +532,8 @@ Status CloudCumulativeCompaction::pick_rowsets_to_compact() {
532532
return Status::Error<CUMULATIVE_NO_SUITABLE_VERSION>(
533533
"no suitable versions: only one rowset and not overlapping");
534534
}
535+
536+
apply_txn_size_truncation_and_log("CloudCumulativeCompaction");
535537
return Status::OK();
536538
}
537539

be/src/cloud/cloud_index_change_compaction.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ Status CloudIndexChangeCompaction::prepare_compact() {
6969

7070
_input_rowsets.push_back(input_rowset);
7171

72+
// Apply transaction size truncation (usually only 1 rowset for index change)
73+
int64_t kept_size = 0;
74+
int64_t truncated_size = 0;
75+
cloud::truncate_rowsets_by_txn_size(_input_rowsets, kept_size, truncated_size);
76+
7277
for (auto& rs : _input_rowsets) {
7378
_input_row_num += rs->num_rows();
7479
_input_segments += rs->num_segments();
@@ -473,4 +478,4 @@ Status CloudIndexChangeCompaction::garbage_collection() {
473478
return st;
474479
}
475480

476-
} // namespace doris
481+
} // namespace doris

be/src/cloud/cloud_schema_change_job.cpp

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "cloud/cloud_schema_change_job.h"
1919

20+
#include <gen_cpp/Types_types.h>
2021
#include <gen_cpp/cloud.pb.h>
2122

2223
#include <algorithm>
@@ -32,6 +33,7 @@
3233
#include "olap/delete_handler.h"
3334
#include "olap/olap_define.h"
3435
#include "olap/rowset/beta_rowset.h"
36+
#include "olap/rowset/rowset.h"
3537
#include "olap/rowset/rowset_factory.h"
3638
#include "olap/rowset/segment_v2/inverted_index_desc.h"
3739
#include "olap/storage_engine.h"
@@ -217,6 +219,20 @@ Status CloudSchemaChangeJob::process_alter_tablet(const TAlterTabletReqV2& reque
217219

218220
SchemaChangeParams sc_params;
219221

222+
// cache schema change output to file cache
223+
std::vector<RowsetSharedPtr> rowsets;
224+
rowsets.resize(rs_splits.size());
225+
std::transform(rs_splits.begin(), rs_splits.end(), rowsets.begin(),
226+
[](RowSetSplits& split) { return split.rs_reader->rowset(); });
227+
sc_params.output_to_file_cache = _should_cache_sc_output(rowsets);
228+
if (request.__isset.query_globals && request.__isset.query_options) {
229+
sc_params.runtime_state =
230+
std::make_shared<RuntimeState>(request.query_options, request.query_globals);
231+
} else {
232+
// for old version request compatibility
233+
sc_params.runtime_state = std::make_shared<RuntimeState>();
234+
}
235+
220236
RETURN_IF_ERROR(DescriptorTbl::create(&sc_params.pool, request.desc_tbl, &sc_params.desc_tbl));
221237
sc_params.ref_rowset_readers.reserve(rs_splits.size());
222238
for (RowSetSplits& split : rs_splits) {
@@ -269,7 +285,8 @@ Status CloudSchemaChangeJob::_convert_historical_rowsets(const SchemaChangeParam
269285

270286
// Add filter information in change, and filter column information will be set in _parse_request
271287
// And filter some data every time the row block changes
272-
BlockChanger changer(_new_tablet->tablet_schema(), *sc_params.desc_tbl);
288+
BlockChanger changer(_new_tablet->tablet_schema(), *sc_params.desc_tbl,
289+
sc_params.runtime_state);
273290

274291
bool sc_sorting = false;
275292
bool sc_directly = false;
@@ -309,6 +326,8 @@ Status CloudSchemaChangeJob::_convert_historical_rowsets(const SchemaChangeParam
309326
context.tablet_schema = _new_tablet->tablet_schema();
310327
context.newest_write_timestamp = rs_reader->newest_write_timestamp();
311328
context.storage_resource = _cloud_storage_engine.get_storage_resource(sc_params.vault_id);
329+
context.write_file_cache = sc_params.output_to_file_cache;
330+
context.tablet = _new_tablet;
312331
if (!context.storage_resource) {
313332
return Status::InternalError("vault id not found, maybe not sync, vault id {}",
314333
sc_params.vault_id);
@@ -467,7 +486,7 @@ Status CloudSchemaChangeJob::_convert_historical_rowsets(const SchemaChangeParam
467486
// during double write phase by `CloudMetaMgr::sync_tablet_rowsets` in another thread
468487
std::unique_lock lock {_new_tablet->get_sync_meta_lock()};
469488
std::unique_lock wlock(_new_tablet->get_header_lock());
470-
_new_tablet->add_rowsets(std::move(_output_rowsets), true, wlock);
489+
_new_tablet->add_rowsets(std::move(_output_rowsets), true, wlock, false);
471490
_new_tablet->set_cumulative_layer_point(_output_cumulative_point);
472491
_new_tablet->reset_approximate_stats(stats.num_rowsets(), stats.num_segments(),
473492
stats.num_rows(), stats.data_size());
@@ -503,7 +522,7 @@ Status CloudSchemaChangeJob::_process_delete_bitmap(int64_t alter_version,
503522
std::make_shared<CloudTablet>(_cloud_storage_engine, tmp_meta);
504523
{
505524
std::unique_lock wlock(tmp_tablet->get_header_lock());
506-
tmp_tablet->add_rowsets(_output_rowsets, true, wlock);
525+
tmp_tablet->add_rowsets(_output_rowsets, true, wlock, false);
507526
// Set alter version to let the tmp_tablet can fill hole rowset greater than alter_version
508527
tmp_tablet->set_alter_version(alter_version);
509528
}
@@ -521,7 +540,7 @@ Status CloudSchemaChangeJob::_process_delete_bitmap(int64_t alter_version,
521540
DBUG_BLOCK);
522541
{
523542
std::unique_lock wlock(tmp_tablet->get_header_lock());
524-
tmp_tablet->add_rowsets(_output_rowsets, true, wlock);
543+
tmp_tablet->add_rowsets(_output_rowsets, true, wlock, false);
525544
}
526545
for (auto rowset : ret.rowsets) {
527546
RETURN_IF_ERROR(CloudTablet::update_delete_bitmap_without_lock(tmp_tablet, rowset));
@@ -544,7 +563,7 @@ Status CloudSchemaChangeJob::_process_delete_bitmap(int64_t alter_version,
544563
{max_version + 1, new_max_version}, CaptureRowsetOps {}));
545564
{
546565
std::unique_lock wlock(tmp_tablet->get_header_lock());
547-
tmp_tablet->add_rowsets(_output_rowsets, true, wlock);
566+
tmp_tablet->add_rowsets(_output_rowsets, true, wlock, false);
548567
}
549568
for (auto rowset : ret.rowsets) {
550569
RETURN_IF_ERROR(CloudTablet::update_delete_bitmap_without_lock(tmp_tablet, rowset));
@@ -595,4 +614,34 @@ void CloudSchemaChangeJob::clean_up_on_failure() {
595614
}
596615
}
597616

617+
bool CloudSchemaChangeJob::_should_cache_sc_output(
618+
const std::vector<RowsetSharedPtr>& input_rowsets) {
619+
int64_t total_size = 0;
620+
int64_t cached_index_size = 0;
621+
int64_t cached_data_size = 0;
622+
623+
for (const auto& rs : input_rowsets) {
624+
const RowsetMetaSharedPtr& rs_meta = rs->rowset_meta();
625+
total_size += rs_meta->total_disk_size();
626+
cached_index_size += rs->approximate_cache_index_size();
627+
cached_data_size += rs->approximate_cached_data_size();
628+
}
629+
630+
double input_hit_rate = static_cast<double>(cached_index_size + cached_data_size) / total_size;
631+
632+
LOG(INFO) << "CloudSchemaChangeJob check cache sc output strategy. "
633+
<< "job_id=" << _job_id << ", input_rowsets_count=" << input_rowsets.size()
634+
<< ", total_size=" << total_size << ", cached_index_size=" << cached_index_size
635+
<< ", cached_data_size=" << cached_data_size << ", input_hit_rate=" << input_hit_rate
636+
<< ", min_hit_ratio_threshold="
637+
<< config::file_cache_keep_schema_change_output_min_hit_ratio << ", should_cache="
638+
<< (input_hit_rate > config::file_cache_keep_schema_change_output_min_hit_ratio);
639+
640+
if (input_hit_rate > config::file_cache_keep_schema_change_output_min_hit_ratio) {
641+
return true;
642+
}
643+
644+
return false;
645+
}
646+
598647
} // namespace doris

be/src/cloud/cloud_schema_change_job.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ class CloudSchemaChangeJob {
3939
void clean_up_on_failure();
4040

4141
private:
42+
bool _should_cache_sc_output(const std::vector<RowsetSharedPtr>& input_rowsets);
43+
4244
Status _convert_historical_rowsets(const SchemaChangeParams& sc_params,
4345
cloud::TabletJobInfoPB& job);
4446

4547
Status _process_delete_bitmap(int64_t alter_version, int64_t start_calc_delete_bitmap_version,
4648
int64_t initiator, const std::string& vault_id);
4749

48-
private:
4950
CloudStorageEngine& _cloud_storage_engine;
5051
std::shared_ptr<CloudTablet> _base_tablet;
5152
std::shared_ptr<CloudTablet> _new_tablet;

be/src/cloud/cloud_tablet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ void CloudTablet::add_rowsets(std::vector<RowsetSharedPtr> to_add, bool version_
387387

388388
auto add_rowsets_directly = [=, this](std::vector<RowsetSharedPtr>& rowsets) {
389389
for (auto& rs : rowsets) {
390-
if (version_overlap || warmup_delta_data) {
390+
if (warmup_delta_data) {
391391
#ifndef BE_TEST
392392
bool warm_up_state_updated = false;
393393
// Warmup rowset data in background

be/src/cloud/config.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ DEFINE_mInt32(check_auto_compaction_interval_seconds, "5");
5656
DEFINE_mInt32(max_base_compaction_task_num_per_disk, "2");
5757
DEFINE_mBool(prioritize_query_perf_in_compaction, "false");
5858
DEFINE_mInt32(compaction_max_rowset_count, "10000");
59+
DEFINE_mInt64(compaction_txn_max_size_bytes, "7340032"); // 7MB
5960

6061
DEFINE_mInt32(refresh_s3_info_interval_s, "60");
6162
DEFINE_mInt32(vacuum_stale_rowsets_interval_s, "300");

0 commit comments

Comments
 (0)