org.apache.hadoop.hbase.procedure
Class Subprocedure

java.lang.Object
  extended by org.apache.hadoop.hbase.procedure.Subprocedure
All Implemented Interfaces:
Callable<Void>
Direct Known Subclasses:
FlushSnapshotSubprocedure, Subprocedure.SubprocedureImpl

public abstract class Subprocedure
extends Object
implements Callable<Void>

Distributed procedure member's Subprocedure. A procedure is sarted on a ProcedureCoordinator which communicates with ProcedureMembers who create and start its part of the Procedure. This sub part is called a Subprocedure Users should subclass this and implement acquireBarrier() (get local barrier for this member), insideBarrier() (execute while globally barriered and release barrier) and cleanup(Exception) (release state associated with subprocedure.) When submitted to a ProcedureMemeber, the call method is executed in a separate thread. Latches are use too block its progress and trigger continuations when barrier conditions are met. Exception that makes it out of calls to acquireBarrier() or insideBarrier() gets converted into ForeignException, which will get propagated to the ProcedureCoordinator. There is a category of procedure (ex: online-snapshots), and a user-specified instance-specific barrierName. (ex: snapshot121126).


Nested Class Summary
static class Subprocedure.SubprocedureImpl
          Empty Subprocedure for testing.
 
Field Summary
protected  TimeoutExceptionInjector executionTimeoutTimer
           
protected  ForeignExceptionDispatcher monitor
          monitor to check for errors
protected  ProcedureMemberRpcs rpcs
           
protected  long wakeFrequency
          frequency to check for errors (ms)
 
Constructor Summary
Subprocedure(ProcedureMember member, String procName, ForeignExceptionDispatcher monitor, long wakeFrequency, long timeout)
           
 
Method Summary
abstract  void acquireBarrier()
          The implementation of this method should gather and hold required resources (locks, disk space, etc) to satisfy the Procedures barrier condition.
 Void call()
          Execute the Subprocedure acquireBarrier() and insideBarrier() methods while keeping some state for other threads to access.
 void cancel(String msg, Throwable cause)
          Method to cancel the Subprocedure by injecting an exception from and external source.
abstract  void cleanup(Exception e)
          Users should override this method.
 String getMemberName()
           
 String getName()
           
abstract  void insideBarrier()
          The implementation of this method should act with the assumption that the barrier condition has been satisfied.
 void receiveReachedGlobalBarrier()
          Callback for the member rpcs to call when the global barrier has been reached.
 void waitForLocallyCompleted()
          Waits until the entire procedure has globally completed, or has been aborted.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

monitor

protected final ForeignExceptionDispatcher monitor
monitor to check for errors


wakeFrequency

protected final long wakeFrequency
frequency to check for errors (ms)


executionTimeoutTimer

protected final TimeoutExceptionInjector executionTimeoutTimer

rpcs

protected final ProcedureMemberRpcs rpcs
Constructor Detail

Subprocedure

public Subprocedure(ProcedureMember member,
                    String procName,
                    ForeignExceptionDispatcher monitor,
                    long wakeFrequency,
                    long timeout)
Parameters:
member - reference to the member managing this subprocedure
procName - name of the procedure this subprocedure is associated with
monitor - notified if there is an error in the subprocedure
wakeFrequency - time in millis to wake to check if there is an error via the monitor (in milliseconds).
timeout - time in millis that will trigger a subprocedure abort if it has not completed
Method Detail

getName

public String getName()

getMemberName

public String getMemberName()

call

public final Void call()
Execute the Subprocedure acquireBarrier() and insideBarrier() methods while keeping some state for other threads to access. This would normally be executed by the ProcedureMemeber when a acquire message comes from the coordinator. Rpcs are used to spend message back to the coordinator after different phases are executed. Any exceptions caught during the execution (except for InterrupedException) get converted and propagated to coordinator via ProcedureMemberRpcs.sendMemberAborted( Subprocedure, ForeignException).

Specified by:
call in interface Callable<Void>

acquireBarrier

public abstract void acquireBarrier()
                             throws ForeignException
The implementation of this method should gather and hold required resources (locks, disk space, etc) to satisfy the Procedures barrier condition. For example, this would be where to make all the regions on a RS on the quiescent for an procedure that required all regions to be globally quiesed. Users should override this method. If a quiescent is not required, this is overkill but can still be used to execute a procedure on all members and to propagate any exceptions.

Throws:
ForeignException

insideBarrier

public abstract void insideBarrier()
                            throws ForeignException
The implementation of this method should act with the assumption that the barrier condition has been satisfied. Continuing the previous example, a condition could be that all RS's globally have been quiesced, and procedures that require this precondition could be implemented here. Users should override this method. If quiescense is not required, this can be a no-op

Throws:
ForeignException

cleanup

public abstract void cleanup(Exception e)
Users should override this method. This implementation of this method should rollback and cleanup any temporary or partially completed state that the acquireBarrier() may have created.

Parameters:
e -

cancel

public void cancel(String msg,
                   Throwable cause)
Method to cancel the Subprocedure by injecting an exception from and external source.

Parameters:
cause -

receiveReachedGlobalBarrier

public void receiveReachedGlobalBarrier()
Callback for the member rpcs to call when the global barrier has been reached. This unblocks the main subprocedure exectuion thread so that the Subprocedure's insideBarrier() method can be run.


waitForLocallyCompleted

public void waitForLocallyCompleted()
                             throws ForeignException,
                                    InterruptedException
Waits until the entire procedure has globally completed, or has been aborted.

Throws:
ForeignException
InterruptedException


Copyright © 2007–2016 The Apache Software Foundation. All rights reserved.