org.apache.hadoop.hbase.coprocessor.example
Class ZooKeeperScanPolicyObserver
java.lang.Object
org.apache.hadoop.hbase.coprocessor.BaseRegionObserver
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.
Method Summary |
protected Store.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 StoreFile s 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, postDelete, postExists, postFlush, postFlush, postGet, postGetClosestRowBefore, postIncrement, postIncrementColumnValue, postLockRow, postOpen, postPut, postScannerClose, postScannerFilterRow, postScannerNext, postScannerOpen, postSplit, postUnlockRow, postWALRestore, preAppend, preBatchMutate, preBulkLoadHFile, preCheckAndDelete, preCheckAndPut, preClose, preCompact, preCompact, preCompactScannerOpen, preCompactSelection, preCompactSelection, preDelete, preExists, preFlush, preFlush, preGet, preGetClosestRowBefore, preIncrement, preIncrementColumnValue, preLockRow, preOpen, prePut, preScannerClose, preScannerNext, preScannerOpen, preSplit, preUnlockRow, preWALRestore |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
node
public static String node
zkkey
public static String zkkey
ZooKeeperScanPolicyObserver
public ZooKeeperScanPolicyObserver()
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 Store.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 serverstore
- the store being flushedmemstoreScanner
- the scanner for the memstore that is flusheds
- 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
StoreFile
s 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 serverstore
- the store being compactedscanners
- the list StoreFileScanner
s to be read fromearliestPutTs
- timestamp of the earliest put that was found in any of the involved store
filess
- 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 serverstore
- the store being scannedscan
- the Scan specificationtargetCols
- columns to be used in the scanners
- 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 © 2015 The Apache Software Foundation. All Rights Reserved.