@@ -172,16 +172,20 @@ Status MergeTreeWriter::WriteSortedReadersToFiles(
172172 }
173173 }
174174
175+ // 2. prepare loser tree sort merge reader
175176 auto sort_merge_reader = std::make_unique<SortMergeReaderWithLoserTree>(
176177 std::move (readers), key_comparator_, user_defined_seq_comparator_, merge_function_wrapper_);
177178 raw_readers_guard.Release ();
179+ // 3. project key value to arrow array
178180 auto create_consumer = [target_schema = write_schema_, pool = pool_]()
179181 -> Result<std::unique_ptr<RowToArrowArrayConverter<KeyValue, KeyValueBatch>>> {
180182 return KeyValueMetaProjectionConsumer::Create (target_schema, pool);
181183 };
184+ // consumer batch size is WriteBatchSize
182185 auto async_key_value_producer_consumer =
183186 std::make_unique<AsyncKeyValueProducerAndConsumer<KeyValue, KeyValueBatch>>(
184- std::move (sort_merge_reader), create_consumer, options_.GetWriteBatchSize (), 1 , pool_);
187+ std::move (sort_merge_reader), create_consumer, options_.GetWriteBatchSize (),
188+ /* projection_thread_num=*/ 1 , pool_);
185189 ScopeGuard async_readers_guard ([&]() -> void { async_key_value_producer_consumer->Close (); });
186190 std::unique_ptr<RollingFileWriter<KeyValueBatch, std::shared_ptr<DataFileMeta>>> rolling_writer;
187191 PAIMON_ASSIGN_OR_RAISE (rolling_writer, CreateRollingRowWriter ());
@@ -309,6 +313,7 @@ Status MergeTreeWriter::FlushWriteBuffer(bool wait_for_latest_compaction,
309313 wait_for_latest_compaction = true ;
310314 }
311315 auto cleanup_guard = ScopeGuard ([&]() { write_buffer_->Clear (); });
316+ // 1. flush write buffer to get sorted readers
312317 PAIMON_ASSIGN_OR_RAISE (std::vector<std::unique_ptr<KeyValueRecordReader>> readers,
313318 write_buffer_->CreateReaders ());
314319 PAIMON_RETURN_NOT_OK (WriteSortedReadersToFiles (std::move (readers)));
0 commit comments