org.apache.hadoop.hbase.coprocessor.example
Class ZooKeeperScanPolicyObserver

java.lang.Object
  extended by org.apache.hadoop.hbase.coprocessor.BaseRegionObserver
      extended by org.apache.hadoop.hbase.coprocessor.example.ZooKeeperScanPolicyObserver
All Implemented Interfaces:
Coprocessor, RegionObserver

public class ZooKeeperScanPolicyObserver
extends BaseRegionObserver

This is an example showing how a RegionObserver could configured via ZooKeeper in order to control a Region compaction, flush, and scan policy. This also demonstrated the use of shared RegionObserver state. See RegionCoprocessorEnvironment.getSharedData(). This would be useful for an incremental backup tool, which would indicate the last time of a successful backup via ZK and instruct HBase to not delete data that was inserted since (based on wall clock time). This implements org.apache.zookeeper.Watcher directly instead of using ZooKeeperWatcher, because RegionObservers come and go and currently listeners registered with ZooKeeperWatcher cannot be removed.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.Coprocessor
Coprocessor.State
 
Field Summary
static String node
           
static String zkkey
           
 
Fields inherited from interface org.apache.hadoop.hbase.Coprocessor
PRIORITY_HIGHEST, PRIORITY_LOWEST, PRIORITY_SYSTEM, PRIORITY_USER, VERSION
 
Constructor Summary
ZooKeeperScanPolicyObserver()
           
 
Method Summary
protected  ScanInfo getScanInfo(Store store, RegionCoprocessorEnvironment e)
           
 InternalScanner preCompactScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Store store, List<? extends KeyValueScanner> scanners, ScanType scanType, long earliestPutTs, InternalScanner s)
          Called prior to writing the StoreFiles selected for compaction into a new StoreFile and prior to creating the scanner used to read the input files.
 InternalScanner preFlushScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Store store, KeyValueScanner memstoreScanner, InternalScanner s)
          Called before a memstore is flushed to disk and prior to creating the scanner to read from the memstore.
 KeyValueScanner preStoreScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Store store, Scan scan, NavigableSet<byte[]> targetCols, KeyValueScanner s)
          Called before a store opens a new scanner.
 void start(CoprocessorEnvironment e)
           
 void stop(CoprocessorEnvironment e)
           
 
Methods inherited from class org.apache.hadoop.hbase.coprocessor.BaseRegionObserver
postAppend, postBatchMutate, postBulkLoadHFile, postCheckAndDelete, postCheckAndPut, postClose, postCompact, postCompact, postCompactSelection, postCompactSelection, postCompleteSplit, postDelete, postExists, postFlush, postFlush, postGet, postGetClosestRowBefore, postIncrement, postIncrementColumnValue, postOpen, postPut, postRollBackSplit, postScannerClose, postScannerFilterRow, postScannerNext, postScannerOpen, postSplit, postWALRestore, preAppend, preBatchMutate, preBulkLoadHFile, preCheckAndDelete, preCheckAndPut, preClose, preCompact, preCompact, preCompactScannerOpen, preCompactSelection, preCompactSelection, preDelete, preExists, preFlush, preFlush, preGet, preGetClosestRowBefore, preIncrement, preIncrementColumnValue, preOpen, prePut, preRollBackSplit, preScannerClose, preScannerNext, preScannerOpen, preSplit, preSplit, preWALRestore
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

node

public static final String node
See Also:
Constant Field Values

zkkey

public static final String zkkey
See Also:
Constant Field Values
Constructor Detail

ZooKeeperScanPolicyObserver

public ZooKeeperScanPolicyObserver()
Method Detail

start

public void start(CoprocessorEnvironment e)
           throws IOException
Specified by:
start in interface Coprocessor
Overrides:
start in class BaseRegionObserver
Throws:
IOException

stop

public void stop(CoprocessorEnvironment e)
          throws IOException
Specified by:
stop in interface Coprocessor
Overrides:
stop in class BaseRegionObserver
Throws:
IOException

getScanInfo

protected ScanInfo getScanInfo(Store store,
                               RegionCoprocessorEnvironment e)

preFlushScannerOpen

public InternalScanner preFlushScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c,
                                           Store store,
                                           KeyValueScanner memstoreScanner,
                                           InternalScanner s)
                                    throws IOException
Description copied from interface: RegionObserver
Called before a memstore is flushed to disk and prior to creating the scanner to read from the memstore. To override or modify how a memstore is flushed, implementing classes can return a new scanner to provide the KeyValues to be stored into the new StoreFile or null to perform the default processing. Calling ObserverContext.bypass() has no effect in this hook.

Specified by:
preFlushScannerOpen in interface RegionObserver
Overrides:
preFlushScannerOpen in class BaseRegionObserver
Parameters:
c - the environment provided by the region server
store - the store being flushed
memstoreScanner - the scanner for the memstore that is flushed
s - the base scanner, if not null, from previous RegionObserver in the chain
Returns:
the scanner to use during the flush. null if the default implementation is to be used.
Throws:
IOException - if an error occurred on the coprocessor

preCompactScannerOpen

public InternalScanner preCompactScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c,
                                             Store store,
                                             List<? extends KeyValueScanner> scanners,
                                             ScanType scanType,
                                             long earliestPutTs,
                                             InternalScanner s)
                                      throws IOException
Description copied from interface: RegionObserver
Called prior to writing the StoreFiles selected for compaction into a new StoreFile and prior to creating the scanner used to read the input files. To override or modify the compaction process, implementing classes can return a new scanner to provide the KeyValues to be stored into the new StoreFile or null to perform the default processing. Calling ObserverContext.bypass() has no effect in this hook.

Specified by:
preCompactScannerOpen in interface RegionObserver
Overrides:
preCompactScannerOpen in class BaseRegionObserver
Parameters:
c - the environment provided by the region server
store - the store being compacted
scanners - the list StoreFileScanners to be read from
scanType - the ScanType indicating whether this is a major or minor compaction
earliestPutTs - timestamp of the earliest put that was found in any of the involved store files
s - the base scanner, if not null, from previous RegionObserver in the chain
Returns:
the scanner to use during compaction. null if the default implementation is to be used.
Throws:
IOException - if an error occurred on the coprocessor

preStoreScannerOpen

public KeyValueScanner preStoreScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c,
                                           Store store,
                                           Scan scan,
                                           NavigableSet<byte[]> targetCols,
                                           KeyValueScanner s)
                                    throws IOException
Description copied from interface: RegionObserver
Called before a store opens a new scanner. This hook is called when a "user" scanner is opened.

See RegionObserver.preFlushScannerOpen(ObserverContext, Store, KeyValueScanner, InternalScanner) and RegionObserver.preCompactScannerOpen(ObserverContext, Store, List, ScanType, long, InternalScanner) to override scanners created for flushes or compactions, resp.

Call CoprocessorEnvironment#complete to skip any subsequent chained coprocessors. Calling ObserverContext.bypass() has no effect in this hook.

Specified by:
preStoreScannerOpen in interface RegionObserver
Overrides:
preStoreScannerOpen in class BaseRegionObserver
Parameters:
c - the environment provided by the region server
store - the store being scanned
scan - the Scan specification
targetCols - columns to be used in the scanner
s - the base scanner, if not null, from previous RegionObserver in the chain
Returns:
a KeyValueScanner instance to use or null to use the default implementation
Throws:
IOException - if an error occurred on the coprocessor


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