kotman12 commented on PR #5301:
URL: https://github.com/apache/solr/pull/5301#issuecomment-6752208095

   ## Setup (same in both cases)
   
   ```
   ZooKeeper sends, in this order:
      B-Connected (seq 5)    B-Disconnected (seq 6)    B-Expired (seq 7)
   
   Where each event runs:
      B-Connected, B-Disconnected -> thread pool (may finish in any order)
      B-Expired                   -> the single Expired thread
   
   The Expired thread is already busy recovering from A's expiry:
      it created B and is stuck in:  while (!connected) wait();
   ```
   
   In both cases the pool happens to finish B-Disconnected before B-Connected.
   
   ## Before Houston's change: no sequence check
   
   ```
   time  pool thread            connected   Expired thread
   ----  ---------------------  ---------   --------------------------------
    t1                            false     waiting for connected...
    t2   apply B-Disconnected     false     wakes, still false, waits again
    t3   apply B-Connected        TRUE  <-- late, but applied anyway
    t4                            true      wakes, sees true -> EXITS the wait
    t5                                      finishes recovery, thread is free
    t6                                      runs B-Expired
    t7                                      -> starts a new session C, recovers
   ```
   
   Applying B-Connected late is technically wrong, since B isn't connected at 
t3. But it flips the flag, the waiter
   exits, the thread frees up, and B-Expired then gets processed. The bad state 
is brief and the system recovers.
   
   ## After Houston's change: stale events are ignored
   
   ```
   time  pool thread            connected   Expired thread
   ----  ---------------------  ---------   --------------------------------
    t1                            false     waiting for connected...
    t2   apply B-Disconnected     false     wakes, still false, waits again
    t3   B-Connected arrives:     false     (nothing changes)
         seq 5 < 6, "stale"
         -> IGNORED
    t4                            false     still waiting...
    t5                                      still waiting...
    ...
    B-Expired is queued here:
         [ Expired thread: busy waiting ] <- [ B-Expired waiting for this 
thread ]
                       ^                                  |
                       +------ never released -------------------+
   ```
   
   Ignoring B-Connected is correct, since B really is disconnected. But that 
late `Connected` was the only thing that
   ever released the waiter. The one event that could say "give up, B is dead" 
is B-Expired, and it needs the very
   thread that's stuck.


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

Reply via email to