-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor](shuffle) Unify all hash-partition based shuffling
- Loading branch information
Showing
10 changed files
with
520 additions
and
310 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#include "writer.h" | ||
|
||
#include "pipeline/exec/exchange_sink_operator.h" | ||
#include "vec/core/block.h" | ||
|
||
namespace doris::pipeline { | ||
#include "common/compile_check_begin.h" | ||
template <typename ChannelPtrType> | ||
void Writer::_handle_eof_channel(RuntimeState* state, ChannelPtrType channel, Status st) const { | ||
channel->set_receiver_eof(st); | ||
// Chanel will not send RPC to the downstream when eof, so close chanel by OK status. | ||
static_cast<void>(channel->close(state)); | ||
} | ||
|
||
Status Writer::write(ExchangeSinkLocalState* local_state, RuntimeState* state, | ||
vectorized::Block* block, bool eos) const { | ||
auto rows = block->rows(); | ||
{ | ||
SCOPED_TIMER(local_state->split_block_hash_compute_timer()); | ||
RETURN_IF_ERROR(local_state->partitioner()->do_partitioning(state, block)); | ||
} | ||
int64_t old_channel_mem_usage = 0; | ||
for (const auto& channel : local_state->channels) { | ||
old_channel_mem_usage += channel->mem_usage(); | ||
} | ||
{ | ||
SCOPED_TIMER(local_state->distribute_rows_into_channels_timer()); | ||
const auto& channel_filed = local_state->partitioner()->get_channel_ids(); | ||
if (channel_filed.len == sizeof(uint32_t)) { | ||
RETURN_IF_ERROR(_channel_add_rows(state, local_state->channels, | ||
local_state->partitioner()->partition_count(), | ||
channel_filed.get<uint32_t>(), rows, block, eos)); | ||
} else { | ||
RETURN_IF_ERROR(_channel_add_rows(state, local_state->channels, | ||
local_state->partitioner()->partition_count(), | ||
channel_filed.get<int64_t>(), rows, block, eos)); | ||
} | ||
} | ||
int64_t new_channel_mem_usage = 0; | ||
for (const auto& channel : local_state->channels) { | ||
new_channel_mem_usage += channel->mem_usage(); | ||
} | ||
COUNTER_UPDATE(local_state->memory_used_counter(), | ||
new_channel_mem_usage - old_channel_mem_usage); | ||
return Status::OK(); | ||
} | ||
|
||
template <typename ChannelIdType> | ||
Status Writer::_channel_add_rows(RuntimeState* state, | ||
std::vector<std::shared_ptr<vectorized::Channel>>& channels, | ||
size_t partition_count, | ||
const ChannelIdType* __restrict channel_ids, size_t rows, | ||
vectorized::Block* block, bool eos) const { | ||
std::vector<uint32_t> partition_rows_histogram; | ||
auto row_idx = vectorized::PODArray<uint32_t>(rows); | ||
{ | ||
partition_rows_histogram.assign(partition_count + 2, 0); | ||
for (size_t i = 0; i < rows; ++i) { | ||
partition_rows_histogram[channel_ids[i] + 1]++; | ||
} | ||
for (size_t i = 1; i <= partition_count + 1; ++i) { | ||
partition_rows_histogram[i] += partition_rows_histogram[i - 1]; | ||
} | ||
for (int32_t i = cast_set<int32_t>(rows) - 1; i >= 0; --i) { | ||
row_idx[partition_rows_histogram[channel_ids[i] + 1] - 1] = i; | ||
partition_rows_histogram[channel_ids[i] + 1]--; | ||
} | ||
} | ||
#define HANDLE_CHANNEL_STATUS(state, channel, status) \ | ||
do { \ | ||
if (status.is<ErrorCode::END_OF_FILE>()) { \ | ||
_handle_eof_channel(state, channel, status); \ | ||
} else { \ | ||
RETURN_IF_ERROR(status); \ | ||
} \ | ||
} while (0) | ||
Status status = Status::OK(); | ||
for (size_t i = 0; i < partition_count; ++i) { | ||
uint32_t start = partition_rows_histogram[i + 1]; | ||
uint32_t size = partition_rows_histogram[i + 2] - start; | ||
if (!channels[i]->is_receiver_eof() && size > 0) { | ||
status = channels[i]->add_rows(block, row_idx.data(), start, size, false); | ||
HANDLE_CHANNEL_STATUS(state, channels[i], status); | ||
} | ||
} | ||
if (eos) { | ||
for (int i = 0; i < partition_count; ++i) { | ||
if (!channels[i]->is_receiver_eof()) { | ||
status = channels[i]->add_rows(block, row_idx.data(), 0, 0, true); | ||
HANDLE_CHANNEL_STATUS(state, channels[i], status); | ||
} | ||
} | ||
} | ||
return Status::OK(); | ||
} | ||
|
||
} // namespace doris::pipeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
#pragma once | ||
|
||
#include "vec/sink/vdata_stream_sender.h" | ||
|
||
namespace doris { | ||
class RuntimeState; | ||
class Status; | ||
namespace vectorized { | ||
class Block; | ||
class Channel; | ||
} // namespace vectorized | ||
namespace pipeline { | ||
|
||
#include "common/compile_check_begin.h" | ||
class ExchangeSinkLocalState; | ||
|
||
class Writer { | ||
public: | ||
Writer() = default; | ||
|
||
Status write(ExchangeSinkLocalState* local_state, RuntimeState* state, vectorized::Block* block, | ||
bool eos) const; | ||
|
||
private: | ||
template <typename ChannelIdType> | ||
Status _channel_add_rows(RuntimeState* state, | ||
std::vector<std::shared_ptr<vectorized::Channel>>& channels, | ||
size_t partition_count, const ChannelIdType* __restrict channel_ids, | ||
size_t rows, vectorized::Block* block, bool eos) const; | ||
|
||
template <typename ChannelPtrType> | ||
void _handle_eof_channel(RuntimeState* state, ChannelPtrType channel, Status st) const; | ||
}; | ||
#include "common/compile_check_end.h" | ||
} // namespace pipeline | ||
} // namespace doris |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.