org.apache.hadoop.hbase.regionserver
Class RegionMergeTransaction

java.lang.Object
  extended by org.apache.hadoop.hbase.regionserver.RegionMergeTransaction

@InterfaceAudience.Private
public class RegionMergeTransaction
extends Object

Executes region merge as a "transaction". It is similar with SplitTransaction. Call prepare(RegionServerServices) to setup the transaction, execute(Server, RegionServerServices) to run the transaction and rollback(Server, RegionServerServices) to cleanup if execute fails.

Here is an example of how you would use this class:

  RegionMergeTransaction mt = new RegionMergeTransaction(this.conf, parent, midKey)
  if (!mt.prepare(services)) return;
  try {
    mt.execute(server, services);
  } catch (IOException ioe) {
    try {
      mt.rollback(server, services);
      return;
    } catch (RuntimeException e) {
      myAbortable.abort("Failed merge, abort");
    }
  }
 

This class is not thread safe. Caller needs ensure merge is run by one thread only.


Constructor Summary
RegionMergeTransaction(HRegion a, HRegion b, boolean forcible)
          Constructor
RegionMergeTransaction(HRegion a, HRegion b, boolean forcible, long masterSystemTime)
          Constructor
 
Method Summary
 Put addLocation(Put p, ServerName sn, long openSeqNum)
           
static void createNodeMerging(ZooKeeperWatcher zkw, HRegionInfo region, ServerName serverName, HRegionInfo a, HRegionInfo b)
          Creates a new ephemeral node in the PENDING_MERGE state for the merged region.
 HRegion execute(Server server, RegionServerServices services)
          Run the transaction.
static HRegionInfo getMergedRegionInfo(HRegionInfo a, HRegionInfo b)
          Get merged region info through the specified two regions
 boolean prepare(RegionServerServices services)
          Does checks on merge inputs.
 void prepareMutationsForMerge(HRegionInfo mergedRegion, HRegionInfo regionA, HRegionInfo regionB, ServerName serverName, List<Mutation> mutations)
           
 boolean rollback(Server server, RegionServerServices services)
           
 HRegion stepsAfterPONR(Server server, RegionServerServices services, HRegion mergedRegion)
           
 HRegion stepsBeforePONR(Server server, RegionServerServices services, boolean testing)
           
static int transitionMergingNode(ZooKeeperWatcher zkw, HRegionInfo merged, HRegionInfo a, HRegionInfo b, ServerName serverName, int znodeVersion, EventType beginState, EventType endState)
          Transitions an existing ephemeral node for the specified region which is currently in the begin state to be in the end state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegionMergeTransaction

public RegionMergeTransaction(HRegion a,
                              HRegion b,
                              boolean forcible)
Constructor

Parameters:
a - region a to merge
b - region b to merge
forcible - if false, we will only merge adjacent regions

RegionMergeTransaction

public RegionMergeTransaction(HRegion a,
                              HRegion b,
                              boolean forcible,
                              long masterSystemTime)
Constructor

Parameters:
a - region a to merge
b - region b to merge
forcible - if false, we will only merge adjacent regions
masterSystemTime - the time at the master side
Method Detail

prepare

public boolean prepare(RegionServerServices services)
Does checks on merge inputs.

Parameters:
services -
Returns:
true if the regions are mergeable else false if they are not (e.g. its already closed, etc.).

execute

public HRegion execute(Server server,
                       RegionServerServices services)
                throws IOException
Run the transaction.

Parameters:
server - Hosting server instance. Can be null when testing (won't try and update in zk if a null server)
services - Used to online/offline regions.
Returns:
merged region
Throws:
IOException - If thrown, transaction failed. Call rollback(Server, RegionServerServices)
IOException
See Also:
rollback(Server, RegionServerServices)

stepsAfterPONR

public HRegion stepsAfterPONR(Server server,
                              RegionServerServices services,
                              HRegion mergedRegion)
                       throws IOException
Throws:
IOException

prepareMutationsForMerge

public void prepareMutationsForMerge(HRegionInfo mergedRegion,
                                     HRegionInfo regionA,
                                     HRegionInfo regionB,
                                     ServerName serverName,
                                     List<Mutation> mutations)
                              throws IOException
Throws:
IOException

addLocation

public Put addLocation(Put p,
                       ServerName sn,
                       long openSeqNum)

stepsBeforePONR

public HRegion stepsBeforePONR(Server server,
                               RegionServerServices services,
                               boolean testing)
                        throws IOException
Throws:
IOException

getMergedRegionInfo

public static HRegionInfo getMergedRegionInfo(HRegionInfo a,
                                              HRegionInfo b)
Get merged region info through the specified two regions

Parameters:
a - merging region A
b - merging region B
Returns:
the merged region info

rollback

public boolean rollback(Server server,
                        RegionServerServices services)
                 throws IOException
Parameters:
server - Hosting server instance (May be null when testing).
services - Services of regionserver, used to online regions.
Returns:
True if we successfully rolled back, false if we got to the point of no return and so now need to abort the server to minimize damage.
Throws:
IOException - If thrown, rollback failed. Take drastic action.

createNodeMerging

public static void createNodeMerging(ZooKeeperWatcher zkw,
                                     HRegionInfo region,
                                     ServerName serverName,
                                     HRegionInfo a,
                                     HRegionInfo b)
                              throws org.apache.zookeeper.KeeperException,
                                     IOException
Creates a new ephemeral node in the PENDING_MERGE state for the merged region. Create it ephemeral in case regionserver dies mid-merge.

Does not transition nodes from other states. If a node already exists for this region, a KeeperException.NodeExistsException will be thrown.

Parameters:
zkw - zk reference
region - region to be created as offline
serverName - server event originates from
Throws:
org.apache.zookeeper.KeeperException
IOException

transitionMergingNode

public static int transitionMergingNode(ZooKeeperWatcher zkw,
                                        HRegionInfo merged,
                                        HRegionInfo a,
                                        HRegionInfo b,
                                        ServerName serverName,
                                        int znodeVersion,
                                        EventType beginState,
                                        EventType endState)
                                 throws org.apache.zookeeper.KeeperException,
                                        IOException
Transitions an existing ephemeral node for the specified region which is currently in the begin state to be in the end state. Master cleans up the final MERGE znode when it reads it (or if we crash, zk will clean it up).

Does not transition nodes from other states. If for some reason the node could not be transitioned, the method returns -1. If the transition is successful, the version of the node after transition is returned.

This method can fail and return false for three different reasons:

Does not set any watches.

This method should only be used by a RegionServer when merging two regions.

Parameters:
zkw - zk reference
merged - region to be transitioned to opened
a - merging region A
b - merging region B
serverName - server event originates from
znodeVersion - expected version of data before modification
beginState - the expected current state the znode should be
endState - the state to be transition to
Returns:
version of node after transition, -1 if unsuccessful transition
Throws:
org.apache.zookeeper.KeeperException - if unexpected zookeeper exception
IOException


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