rjvkr2021 opened a new pull request, #3844:
URL: https://github.com/apache/celeborn/pull/3844

   <!--
   Thanks for sending a pull request!  Here are some tips for you:
     - Make sure the PR title start w/ a JIRA ticket, e.g. '[CELEBORN-XXXX] 
Your PR title ...'.
     - Be sure to keep the PR description updated to reflect all changes.
     - Please write your PR title to summarize what this PR proposes.
     - If possible, provide a concise example to reproduce the issue for a 
faster review.
   -->
   
   ### What changes were proposed in this pull request?
   
   This PR fixes a race causing `DataPusher` to accept data during termination 
and drop it.
   
   ### Why are the changes needed?
   
   #### Background
   
   When a task wants to push shuffle data to a Celeborn worker, it does not 
push the
   data directly. Instead, the data is copied into a reusable buffer and 
enqueued
   for asynchronous processing.
   
   The producer returns successfully after the buffer is accepted by the queue. 
A
   background thread later dequeues the buffer, pushes its data to the worker, 
and
   returns the buffer to the reusable buffer pool.
   
   #### Race
   
   The race occurs when the background thread is being terminated. In the 
original
   implementation, termination waits for the reusable buffer pool (`idleQueue`)
   to become full and then sets `terminated=true`.
   
   The check and the state change are not an atomic admission barrier. After the
   buffer-pool check succeeds but before `terminated` is set, a producer can
   borrow a reusable buffer, copy data into it, enqueue it successfully, and
   return from `addTask()`.
   
   The background thread can then observe `terminated`, stop without processing
   the newly enqueued buffer, and termination can clear the queue.
   
   #### Impact
   
   The producer has reported success even though the data was never pushed to 
the
   worker. This causes silent data loss.
   
   #### Fix
   
   Task admission and background thread termination must be ordered through an 
explicit lifecycle:
   
   ```text
   RUNNING -> CLOSING -> TERMINATED
   ```
   
   When termination begins, the pusher transitions to `CLOSING` before waiting 
for
   existing work to finish. New calls to `addTask()` are rejected in `CLOSING`,
   while producers admitted in `RUNNING` are allowed to complete. After all
   admitted producers and queued tasks have been drained, the pusher transitions
   to `TERMINATED`.
   
   This guarantees that every successful `addTask()` corresponds to work 
admitted
   before termination and therefore handled before termination completes.
   
   ### Does this PR resolve a correctness bug?
   
   No
   
   ### Does this PR introduce _any_ user-facing change?
   
   No
   
   
   ### How was this patch tested?
   
   Added following unit tests:
   1. testDataPusherRejectsTasksWhileClosing
   2. testDataPusherDrainsTaskAdmittedBeforeTermination
   


-- 
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]

Reply via email to