org.apache.hadoop.hbase.master.snapshot
Class SnapshotManager

java.lang.Object
  extended by org.apache.hadoop.hbase.master.snapshot.SnapshotManager
All Implemented Interfaces:
Stoppable

@InterfaceAudience.Private
@InterfaceStability.Unstable
public class SnapshotManager
extends Object
implements Stoppable

This class manages the procedure of taking and restoring snapshots. There is only one SnapshotManager for the master.

The class provides methods for monitoring in-progress snapshot actions.

Note: Currently there can only be one snapshot being taken at a time over the cluster. This is a simplification in the current implementation.


Field Summary
static String HBASE_SNAPSHOT_ENABLED
          Enable or disable snapshot support
static String ONLINE_SNAPSHOT_CONTROLLER_DESCRIPTION
          Name of the operation to use in the controller
 
Constructor Summary
SnapshotManager(MasterServices master, MetricsMaster metricsMaster)
          Construct a snapshot manager.
SnapshotManager(MasterServices master, MetricsMaster metricsMaster, ProcedureCoordinator coordinator, ExecutorService pool)
          Fully specify all necessary components of a snapshot manager.
 
Method Summary
 void checkSnapshotSupport()
          Throws an exception if snapshot operations (take a snapshot, restore, clone) are not supported.
 void deleteSnapshot(HBaseProtos.SnapshotDescription snapshot)
          Delete the specified snapshot
 List<HBaseProtos.SnapshotDescription> getCompletedSnapshots()
          Gets the list of all completed snapshots.
 boolean isRestoreDone(HBaseProtos.SnapshotDescription snapshot)
          Returns the status of a restore operation.
 boolean isSnapshotDone(HBaseProtos.SnapshotDescription expected)
          Check if the specified snapshot is done
 boolean isStopped()
           
 void restoreSnapshot(HBaseProtos.SnapshotDescription reqSnapshot)
          Restore the specified snapshot
 void setSnapshotHandlerForTesting(TableName tableName, SnapshotSentinel handler)
          Set the handler for the current snapshot
 void stop(String why)
          Stop this service.
 void takeSnapshot(HBaseProtos.SnapshotDescription snapshot)
          Take a snapshot based on the enabled/disabled state of the table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HBASE_SNAPSHOT_ENABLED

public static final String HBASE_SNAPSHOT_ENABLED
Enable or disable snapshot support

See Also:
Constant Field Values

ONLINE_SNAPSHOT_CONTROLLER_DESCRIPTION

public static final String ONLINE_SNAPSHOT_CONTROLLER_DESCRIPTION
Name of the operation to use in the controller

See Also:
Constant Field Values
Constructor Detail

SnapshotManager

public SnapshotManager(MasterServices master,
                       MetricsMaster metricsMaster)
                throws org.apache.zookeeper.KeeperException,
                       IOException,
                       UnsupportedOperationException
Construct a snapshot manager.

Parameters:
master -
Throws:
org.apache.zookeeper.KeeperException
IOException
UnsupportedOperationException

SnapshotManager

public SnapshotManager(MasterServices master,
                       MetricsMaster metricsMaster,
                       ProcedureCoordinator coordinator,
                       ExecutorService pool)
                throws IOException,
                       UnsupportedOperationException
Fully specify all necessary components of a snapshot manager. Exposed for testing.

Parameters:
master - services for the master where the manager is running
coordinator - procedure coordinator instance. exposed for testing.
pool - HBase ExecutorServcie instance, exposed for testing.
Throws:
IOException
UnsupportedOperationException
Method Detail

getCompletedSnapshots

public List<HBaseProtos.SnapshotDescription> getCompletedSnapshots()
                                                            throws IOException
Gets the list of all completed snapshots.

Returns:
list of SnapshotDescriptions
Throws:
IOException - File system exception

deleteSnapshot

public void deleteSnapshot(HBaseProtos.SnapshotDescription snapshot)
                    throws SnapshotDoesNotExistException,
                           IOException
Delete the specified snapshot

Parameters:
snapshot -
Throws:
SnapshotDoesNotExistException - If the specified snapshot does not exist.
IOException - For filesystem IOExceptions

isSnapshotDone

public boolean isSnapshotDone(HBaseProtos.SnapshotDescription expected)
                       throws IOException
Check if the specified snapshot is done

Parameters:
expected -
Returns:
true if snapshot is ready to be restored, false if it is still being taken.
Throws:
IOException - IOException if error from HDFS or RPC
UnknownSnapshotException - if snapshot is invalid or does not exist.

takeSnapshot

public void takeSnapshot(HBaseProtos.SnapshotDescription snapshot)
                  throws IOException
Take a snapshot based on the enabled/disabled state of the table.

Parameters:
snapshot -
Throws:
HBaseSnapshotException - when a snapshot specific exception occurs.
IOException - when some sort of generic IO exception occurs.

setSnapshotHandlerForTesting

public void setSnapshotHandlerForTesting(TableName tableName,
                                         SnapshotSentinel handler)
Set the handler for the current snapshot

Exposed for TESTING

Parameters:
tableName -
handler - handler the master should use TODO get rid of this if possible, repackaging, modify tests.

restoreSnapshot

public void restoreSnapshot(HBaseProtos.SnapshotDescription reqSnapshot)
                     throws IOException
Restore the specified snapshot

Parameters:
reqSnapshot -
Throws:
IOException

isRestoreDone

public boolean isRestoreDone(HBaseProtos.SnapshotDescription snapshot)
                      throws IOException
Returns the status of a restore operation. If the in-progress restore is failed throws the exception that caused the failure.

Parameters:
snapshot -
Returns:
false if in progress, true if restore is completed or not requested.
Throws:
IOException - if there was a failure during the restore

stop

public void stop(String why)
Description copied from interface: Stoppable
Stop this service.

Specified by:
stop in interface Stoppable
Parameters:
why - Why we're stopping.

isStopped

public boolean isStopped()
Specified by:
isStopped in interface Stoppable
Returns:
True if Stoppable.stop(String) has been closed.

checkSnapshotSupport

public void checkSnapshotSupport()
                          throws UnsupportedOperationException
Throws an exception if snapshot operations (take a snapshot, restore, clone) are not supported. Called at the beginning of snapshot() and restoreSnapshot() methods.

Throws:
UnsupportedOperationException - if snapshot are not supported


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