org.apache.hadoop.hbase.catalog
Class CatalogTracker

java.lang.Object
  extended by org.apache.hadoop.hbase.catalog.CatalogTracker

public class CatalogTracker
extends Object

Tracks the availability of the catalog tables -ROOT- and .META.. This class is "read-only" in that the locations of the catalog tables cannot be explicitly set. Instead, ZooKeeper is used to learn of the availability and location of -ROOT-. -ROOT- is used to learn of the location of .META. If not available in -ROOT-, ZooKeeper is used to monitor for a new location of .META..

Call start() to start up operation. Call stop()} to interrupt waits and close up shop.


Field Summary
static byte[] META_REGION
           
static byte[] ROOT_REGION
           
 
Constructor Summary
CatalogTracker(HConnection connection)
          Constructs a catalog tracker.
CatalogTracker(ZooKeeperWatcher zk, HConnection connection, Abortable abortable)
          Constructs the catalog tracker.
CatalogTracker(ZooKeeperWatcher zk, HConnection connection, Abortable abortable, int defaultTimeout)
          Constructs the catalog tracker.
 
Method Summary
 HConnection getConnection()
           
 HServerAddress getMetaLocation()
           
 HServerAddress getRootLocation()
          Gets the current location for -ROOT- or null if location is not currently available.
 void start()
          Starts the catalog tracker.
 void stop()
          Stop working.
 boolean verifyMetaRegionLocation(long timeout)
          Verify .META. is deployed and accessible.
 boolean verifyRootRegionLocation(long timeout)
          Verify -ROOT- is deployed and accessible.
 void waitForMeta()
          Waits indefinitely for availability of .META..
 HServerAddress waitForMeta(long timeout)
          Gets the current location for .META. if available and waits for up to the specified timeout if not immediately available.
 HRegionInterface waitForMetaServerConnection(long timeout)
          Gets a connection to the server hosting meta, as reported by ZooKeeper, waiting up to the specified timeout for availability.
 HRegionInterface waitForMetaServerConnectionDefault()
          Gets a connection to the server hosting meta, as reported by ZooKeeper, waiting up to the specified timeout for availability.
 void waitForRoot()
          Waits indefinitely for availability of -ROOT-.
 HRegionInterface waitForRootServerConnection(long timeout)
          Gets a connection to the server hosting root, as reported by ZooKeeper, waiting up to the specified timeout for availability.
 HRegionInterface waitForRootServerConnectionDefault()
          Gets a connection to the server hosting root, as reported by ZooKeeper, waiting for the default timeout specified on instantiation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_REGION

public static final byte[] ROOT_REGION

META_REGION

public static final byte[] META_REGION
Constructor Detail

CatalogTracker

public CatalogTracker(HConnection connection)
               throws IOException
Constructs a catalog tracker. Find current state of catalog tables and begin active tracking by executing start() post construction. Does not timeout.

Parameters:
connection - Server connection; if problem, this connections Abortable.abort(String, Throwable) will be called.
Throws:
IOException

CatalogTracker

public CatalogTracker(ZooKeeperWatcher zk,
                      HConnection connection,
                      Abortable abortable)
               throws IOException
Constructs the catalog tracker. Find current state of catalog tables and begin active tracking by executing start() post construction. Does not timeout.

Parameters:
zk -
connection - server connection
abortable - if fatal exception
Throws:
IOException

CatalogTracker

public CatalogTracker(ZooKeeperWatcher zk,
                      HConnection connection,
                      Abortable abortable,
                      int defaultTimeout)
               throws IOException
Constructs the catalog tracker. Find current state of catalog tables and begin active tracking by executing start() post construction.

Parameters:
zk -
connection - server connection
abortable - if fatal exception
defaultTimeout - Timeout to use. Pass zero for no timeout (Object.wait(long) when passed a 0 waits for ever).
Throws:
IOException
Method Detail

start

public void start()
           throws IOException,
                  InterruptedException
Starts the catalog tracker. Determines current availability of catalog tables and ensures all further transitions of either region are tracked.

Throws:
IOException
InterruptedException

stop

public void stop()
Stop working. Interrupts any ongoing waits.


getRootLocation

public HServerAddress getRootLocation()
                               throws InterruptedException
Gets the current location for -ROOT- or null if location is not currently available.

Returns:
location of root, null if not available
Throws:
InterruptedException

getMetaLocation

public HServerAddress getMetaLocation()
Returns:
Location of meta or null if not yet available.

waitForRoot

public void waitForRoot()
                 throws InterruptedException
Waits indefinitely for availability of -ROOT-. Used during cluster startup.

Throws:
InterruptedException - if interrupted while waiting

waitForRootServerConnection

public HRegionInterface waitForRootServerConnection(long timeout)
                                             throws InterruptedException,
                                                    NotAllMetaRegionsOnlineException,
                                                    IOException
Gets a connection to the server hosting root, as reported by ZooKeeper, waiting up to the specified timeout for availability.

Returns:
connection to server hosting root
Throws:
InterruptedException
NotAllMetaRegionsOnlineException - if timed out waiting
IOException
See Also:
for additional information

waitForRootServerConnectionDefault

public HRegionInterface waitForRootServerConnectionDefault()
                                                    throws NotAllMetaRegionsOnlineException,
                                                           IOException
Gets a connection to the server hosting root, as reported by ZooKeeper, waiting for the default timeout specified on instantiation.

Returns:
connection to server hosting root
Throws:
NotAllMetaRegionsOnlineException - if timed out waiting
IOException
See Also:
for additional information

waitForMeta

public void waitForMeta()
                 throws InterruptedException
Waits indefinitely for availability of .META.. Used during cluster startup.

Throws:
InterruptedException - if interrupted while waiting

waitForMeta

public HServerAddress waitForMeta(long timeout)
                           throws InterruptedException,
                                  IOException,
                                  NotAllMetaRegionsOnlineException
Gets the current location for .META. if available and waits for up to the specified timeout if not immediately available. Throws an exception if timed out waiting. This method differs from waitForMeta() in that it will go ahead and verify the location gotten from ZooKeeper by trying to use returned connection.

Parameters:
timeout - maximum time to wait for meta availability, in milliseconds
Returns:
location of meta
Throws:
InterruptedException - if interrupted while waiting
IOException - unexpected exception connecting to meta server
NotAllMetaRegionsOnlineException - if meta not available before timeout

waitForMetaServerConnection

public HRegionInterface waitForMetaServerConnection(long timeout)
                                             throws InterruptedException,
                                                    NotAllMetaRegionsOnlineException,
                                                    IOException
Gets a connection to the server hosting meta, as reported by ZooKeeper, waiting up to the specified timeout for availability.

Returns:
connection to server hosting meta
Throws:
InterruptedException
NotAllMetaRegionsOnlineException - if timed out waiting
IOException
See Also:
for additional information

waitForMetaServerConnectionDefault

public HRegionInterface waitForMetaServerConnectionDefault()
                                                    throws NotAllMetaRegionsOnlineException,
                                                           IOException
Gets a connection to the server hosting meta, as reported by ZooKeeper, waiting up to the specified timeout for availability.

Returns:
connection to server hosting meta
Throws:
NotAllMetaRegionsOnlineException - if timed out or interrupted
IOException
See Also:
for additional information

verifyRootRegionLocation

public boolean verifyRootRegionLocation(long timeout)
                                 throws InterruptedException,
                                        IOException
Verify -ROOT- is deployed and accessible.

Parameters:
timeout - How long to wait on zk for root address (passed through to the internal call to waitForRootServerConnection(long).
Returns:
True if the -ROOT- location is healthy.
Throws:
IOException
InterruptedException

verifyMetaRegionLocation

public boolean verifyMetaRegionLocation(long timeout)
                                 throws InterruptedException,
                                        IOException
Verify .META. is deployed and accessible.

Parameters:
timeout - How long to wait on zk for .META. address (passed through to the internal call to waitForMetaServerConnection(long).
Returns:
True if the .META. location is healthy.
Throws:
IOException - Some unexpected IOE.
InterruptedException

getConnection

public HConnection getConnection()


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.