@@ -25,36 +25,35 @@ namespace DB
2525template <class ExchangeWriterPtr >
2626BroadcastOrPassThroughWriter<ExchangeWriterPtr>::BroadcastOrPassThroughWriter(
2727 ExchangeWriterPtr writer_,
28- Int64 batch_send_min_limit_,
28+ Int64 max_buffered_rows_,
29+ UInt64 max_buffered_bytes_,
2930 DAGContext & dag_context_,
3031 MPPDataPacketVersion data_codec_version_,
3132 tipb::CompressionMode compression_mode_,
3233 tipb::ExchangeType exchange_type_)
3334 : DAGResponseWriter(/* records_per_chunk=*/ -1 , dag_context_)
34- , batch_send_min_limit(batch_send_min_limit_)
3535 , writer(writer_)
3636 , exchange_type(exchange_type_)
3737 , data_codec_version(data_codec_version_)
3838 , compression_method(ToInternalCompressionMethod(compression_mode_))
3939{
40- rows_in_blocks = 0 ;
4140 RUNTIME_CHECK (dag_context.encode_type == tipb::EncodeType::TypeCHBlock);
4241 RUNTIME_CHECK (exchange_type == tipb::ExchangeType::Broadcast || exchange_type == tipb::ExchangeType::PassThrough);
4342
4443 switch (data_codec_version)
4544 {
4645 case MPPDataPacketV0:
47- if (batch_send_min_limit <= 0 )
48- batch_send_min_limit = 1 ;
46+ if (max_buffered_rows_ <= 0 )
47+ max_buffered_rows_ = 1 ;
4948 break ;
5049 case MPPDataPacketV1:
5150 default :
5251 {
5352 // make `batch_send_min_limit` always GT 0
54- if (batch_send_min_limit <= 0 )
53+ if (max_buffered_rows_ <= 0 )
5554 {
5655 // set upper limit if not specified
57- batch_send_min_limit = 8 * 1024 /* 8K */ ;
56+ max_buffered_rows_ = 8 * 1024 /* 8K */ ;
5857 }
5958 for (const auto & field_type : dag_context.result_field_types )
6059 {
@@ -63,13 +62,15 @@ BroadcastOrPassThroughWriter<ExchangeWriterPtr>::BroadcastOrPassThroughWriter(
6362 break ;
6463 }
6564 }
65+ max_buffered_rows = static_cast <UInt64>(max_buffered_rows_);
66+ max_buffered_bytes = max_buffered_bytes_;
6667}
6768
6869template <class ExchangeWriterPtr >
6970WriteResult BroadcastOrPassThroughWriter<ExchangeWriterPtr>::flush()
7071{
7172 has_pending_flush = false ;
72- if (rows_in_blocks > 0 )
73+ if (buffered_rows > 0 )
7374 {
7475 auto wait_res = waitForWritable ();
7576 if (wait_res == WaitResult::Ready)
@@ -102,11 +103,12 @@ WriteResult BroadcastOrPassThroughWriter<ExchangeWriterPtr>::write(const Block &
102103 size_t rows = block.rows ();
103104 if (rows > 0 )
104105 {
105- rows_in_blocks += rows;
106+ buffered_rows += rows;
107+ buffered_bytes += block.allocatedBytes ();
106108 blocks.push_back (block);
107109 }
108110
109- if (static_cast <Int64>(rows_in_blocks) >= batch_send_min_limit )
111+ if (needFlush () )
110112 {
111113 return flush ();
112114 }
@@ -130,7 +132,8 @@ void BroadcastOrPassThroughWriter<ExchangeWriterPtr>::writeBlocks()
130132 else
131133 writer->passThroughWrite (blocks, data_codec_version, compression_method);
132134 blocks.clear ();
133- rows_in_blocks = 0 ;
135+ buffered_rows = 0 ;
136+ buffered_bytes = 0 ;
134137}
135138
136139template class BroadcastOrPassThroughWriter <SyncMPPTunnelSetWriterPtr>;
0 commit comments