Class FSHLog.SafePointZigZagLatch

java.lang.Object
org.apache.hadoop.hbase.regionserver.wal.FSHLog.SafePointZigZagLatch
Enclosing class:
FSHLog

static class FSHLog.SafePointZigZagLatch extends Object
This class is used coordinating two threads holding one thread at a 'safe point' while the orchestrating thread does some work that requires the first thread paused: e.g. holding the WAL writer while its WAL is swapped out from under it by another thread.

Thread A signals Thread B to hold when it gets to a 'safe point'. Thread A wait until Thread B gets there. When the 'safe point' has been attained, Thread B signals Thread A. Thread B then holds at the 'safe point'. Thread A on notification that Thread B is paused, goes ahead and does the work it needs to do while Thread B is holding. When Thread A is done, it flags B and then Thread A and Thread B continue along on their merry way. Pause and signalling 'zigzags' between the two participating threads. We use two latches -- one the inverse of the other -- pausing and signaling when states are achieved.

To start up the drama, Thread A creates an instance of this class each time it would do this zigzag dance and passes it to Thread B (these classes use Latches so it is one shot only). Thread B notices the new instance (via reading a volatile reference or how ever) and it starts to work toward the 'safe point'. Thread A calls waitSafePoint(SyncFuture) when it cannot proceed until the Thread B 'safe point' is attained. Thread A will be held inside in waitSafePoint(SyncFuture) until Thread B reaches the 'safe point'. Once there, Thread B frees Thread A by calling safePointAttained(). Thread A now knows Thread B is at the 'safe point' and that it is holding there (When Thread B calls safePointAttained() it blocks here until Thread A calls releaseSafePoint()). Thread A proceeds to do what it needs to do while Thread B is paused. When finished, it lets Thread B lose by calling releaseSafePoint() and away go both Threads again.