yashmayya commented on code in PR #19353: URL: https://github.com/apache/pinot/pull/19353#discussion_r3866366745
########## pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/operator/exchange/SpoolBroadcastExchange.java: ########## @@ -0,0 +1,92 @@ +/** + * 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. + */ +package org.apache.pinot.query.runtime.operator.exchange; + +import java.util.List; +import java.util.function.Function; +import org.apache.pinot.common.utils.DataSchema.ColumnDataType; +import org.apache.pinot.query.mailbox.SendingMailbox; +import org.apache.pinot.query.runtime.blocks.BlockSplitter; +import org.apache.pinot.query.runtime.blocks.MseBlock; +import org.apache.pinot.query.runtime.blocks.RowHeapDataBlock; + + +/// Broadcasts blocks to the per-receiver-stage exchanges of a multi-send (spool) node. +/// +/// Unlike [BroadcastExchange], which routes the very same block instance to every destination, this exchange gives +/// every destination except the first its own [copy][RowHeapDataBlock#copy()] of blocks that carry mutable cells, +/// i.e. aggregation intermediate results in [OBJECT][ColumnDataType#OBJECT] columns of on-heap blocks. Local +/// (same-JVM) mailboxes deliver on-heap blocks by reference, so without the copies multiple receiver stages would +/// observe the same mutable intermediate result objects and corrupt them by mutating them when merging them or +/// extracting final results. +/// +/// Within a single receiver stage the rows of one copy are still shared: the inner per-stage exchange either routes +/// each row to exactly one worker (hash/singleton distribution), or broadcasts rows that downstream operators never +/// mutate. Aggregation intermediate results only travel on the hash/singleton edge between the partial and the final +/// aggregation, never on broadcast edges, so only the fan-out across receiver stages needs the copies. +class SpoolBroadcastExchange extends BroadcastExchange { + + SpoolBroadcastExchange(List<SendingMailbox> sendingMailboxes, BlockSplitter splitter, + Function<List<SendingMailbox>, Integer> statsIndexChooser) { + super(sendingMailboxes, splitter, statsIndexChooser); + } + + @Override + protected void route(List<SendingMailbox> destinations, MseBlock.Data block) { + int numDestinations = destinations.size(); + if (numDestinations == 1 || !mayContainMutableCells(block)) { Review Comment: Hm that's a good point, I'll restructure this to remove the spool broadcast exchange and fold it into the regular one. I disagree with the second suggestion of fixing the aggregation function merge mutation contract because as said it'll have a big perf impact. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
