Skip to content

Commit cdf118b

Browse files
authored
chore: avoid creating window message again (#2670)
Signed-off-by: Yashash H L <yashashhl25@gmail.com>
1 parent 53a87ee commit cdf118b

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

rust/numaflow-core/src/reduce/reducer/aligned/reducer.rs

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,27 +226,27 @@ impl AlignedReduceActor {
226226
/// Runs the actor, listening for messages and multiplexing them to the reduce tasks.
227227
async fn run(mut self) {
228228
while let Some(msg) = self.receiver.recv().await {
229-
self.handle_window_message(msg.window, msg.operation).await;
229+
self.handle_window_message(msg).await;
230230
}
231231
self.wait_for_all_tasks().await;
232232
}
233233

234234
/// Handle a window message based on its operation type
235-
async fn handle_window_message(&mut self, window: Window, operation: WindowOperation) {
236-
let window_id = window.pnf_slot();
237-
match operation {
238-
WindowOperation::Open(msg) => self.window_open(window, window_id, msg).await,
239-
WindowOperation::Append(msg) => self.window_append(window, window_id, msg).await,
240-
WindowOperation::Close => self.window_close(window_id).await,
235+
async fn handle_window_message(&mut self, window_msg: AlignedWindowMessage) {
236+
match &window_msg.operation {
237+
WindowOperation::Open(_) => self.window_open(window_msg).await,
238+
WindowOperation::Append(_) => self.window_append(window_msg).await,
239+
WindowOperation::Close => self.window_close(window_msg).await,
241240
}
242241
}
243242

244243
/// Creates a new reduce task for the window and sends the initial Open command with the
245244
/// first message.
246-
async fn window_open(&mut self, window: Window, window_id: Bytes, msg: Message) {
245+
async fn window_open(&mut self, window_msg: AlignedWindowMessage) {
247246
// Create a new channel for this window's messages
248247
let (message_tx, message_rx) = mpsc::channel(100);
249248
let message_stream = ReceiverStream::new(message_rx);
249+
let window = window_msg.window.clone();
250250

251251
// Create a ReduceTask
252252
let reduce_task = ReduceTask::new(
@@ -258,20 +258,14 @@ impl AlignedReduceActor {
258258
self.window_manager.clone(),
259259
);
260260

261-
// Create the initial window message
262-
let window_msg = AlignedWindowMessage {
263-
operation: WindowOperation::Open(msg),
264-
window: window.clone(),
265-
};
266-
267261
// start the reduce task and store the handle and the sender so that we can send messages
268262
// and wait for it to complete.
269263
let task_handle = reduce_task
270264
.start(message_stream, self.cln_token.clone())
271265
.await;
272266

273267
self.active_streams.insert(
274-
window_id,
268+
window.pnf_slot(),
275269
ActiveStream {
276270
message_tx: message_tx.clone(),
277271
task_handle,
@@ -283,24 +277,21 @@ impl AlignedReduceActor {
283277
}
284278

285279
/// sends the message to the reduce task for the window.
286-
async fn window_append(&mut self, window: Window, window_id: Bytes, msg: Message) {
280+
async fn window_append(&mut self, window_msg: AlignedWindowMessage) {
281+
let window = window_msg.window.clone();
282+
let window_id = window.pnf_slot();
283+
287284
// Get the existing stream or log error if not found create a new one.
288285
let Some(active_stream) = self.active_streams.get(&window_id) else {
289286
// windows may not be found during replay, because the windower doesn't send the open
290287
// message for the active windows that got replayed, hence we create a new one.
291288
// this happens because of out-of-order messages and we have to ensure that the (t+1)th
292289
// message is sent to the window that could be created by (t)th message iff (t+1)th message
293290
// belongs to that window created by (t)th message.
294-
self.window_open(window, window_id, msg).await;
291+
self.window_open(window_msg).await;
295292
return;
296293
};
297294

298-
// Create the append window message
299-
let window_msg = AlignedWindowMessage {
300-
operation: WindowOperation::Append(msg),
301-
window,
302-
};
303-
304295
// Send the append message
305296
active_stream
306297
.message_tx
@@ -310,7 +301,9 @@ impl AlignedReduceActor {
310301
}
311302

312303
/// Closes the reduce task for the window.
313-
async fn window_close(&mut self, window_id: Bytes) {
304+
async fn window_close(&mut self, window_msg: AlignedWindowMessage) {
305+
let window_id = window_msg.window.pnf_slot();
306+
314307
// Get the existing stream or log error if not found
315308
let Some(active_stream) = self.active_streams.remove(&window_id) else {
316309
error!("No active stream found for window {:?}", window_id);

rust/numaflow-core/src/shared/create_components.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use numaflow_pb::clients::source::source_client::SourceClient;
3838
use numaflow_pb::clients::sourcetransformer::source_transform_client::SourceTransformClient;
3939
use numaflow_sqs::sink::SqsSinkBuilder;
4040
use tokio_util::sync::CancellationToken;
41-
use tracing::info;
4241

4342
/// Creates a sink writer based on the configuration
4443
pub(crate) async fn create_sink_writer(

0 commit comments

Comments
 (0)