@InterfaceAudience.Private public class WriteHeavyIncrementObserver extends Object implements RegionCoprocessor, RegionObserver
We will convert increment to put, and do aggregating when get. And of course the return value of increment is useless then.
Notice that this is only an example so we do not handle most corner cases, for example, you must provide a qualifier when doing a get.
Coprocessor.State
RegionObserver.MutationType
Modifier and Type | Field and Description |
---|---|
private org.apache.commons.lang3.mutable.MutableLong[] |
lastTimestamps |
private int |
mask |
PRIORITY_HIGHEST, PRIORITY_LOWEST, PRIORITY_SYSTEM, PRIORITY_USER, VERSION
Constructor and Description |
---|
WriteHeavyIncrementObserver() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getBulkLoadObserver, getEndpointObserver
getServices, start, stop
postAppend, postBatchMutate, postBatchMutateIndispensably, postBulkLoadHFile, postCheckAndDelete, postCheckAndPut, postClose, postCloseRegionOperation, postCommitStoreFile, postCompact, postCompactSelection, postDelete, postExists, postFlush, postFlush, postGetOp, postIncrement, postInstantiateDeleteTracker, postMemStoreCompaction, postMutationBeforeWAL, postOpen, postPut, postReplayWALs, postScannerClose, postScannerFilterRow, postScannerNext, postScannerOpen, postStartRegionOperation, postStoreFileReaderOpen, postWALRestore, preAppend, preAppendAfterRowLock, preBatchMutate, preBulkLoadHFile, preCheckAndDelete, preCheckAndDeleteAfterRowLock, preCheckAndPut, preCheckAndPutAfterRowLock, preClose, preCommitStoreFile, preCompactSelection, preDelete, preExists, preFlush, preIncrementAfterRowLock, preMemStoreCompaction, preOpen, prePrepareTimeStampForDeleteVersion, prePut, preReplayWALs, preScannerClose, preScannerNext, preScannerOpen, preStoreFileReaderOpen, preWALRestore
private final int mask
private final org.apache.commons.lang3.mutable.MutableLong[] lastTimestamps
public WriteHeavyIncrementObserver()
public Optional<RegionObserver> getRegionObserver()
getRegionObserver
in interface RegionCoprocessor
public void preFlushScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Store store, ScanOptions options, FlushLifeCycleTracker tracker) throws IOException
RegionObserver
options
to change max
versions and TTL for the scanner being opened.preFlushScannerOpen
in interface RegionObserver
c
- the environment provided by the region serverstore
- the store where flush is being requestedoptions
- used to change max versions and TTL for the scanner being openedIOException
private Cell createCell(byte[] row, byte[] family, byte[] qualifier, long ts, long value)
private InternalScanner wrap(byte[] family, InternalScanner scanner)
public InternalScanner preFlush(ObserverContext<RegionCoprocessorEnvironment> c, Store store, InternalScanner scanner, FlushLifeCycleTracker tracker) throws IOException
RegionObserver
preFlush
in interface RegionObserver
c
- the environment provided by the region serverstore
- the store where flush is being requestedscanner
- the scanner over existing data used in the memstoretracker
- tracker used to track the life cycle of a flushnull
unless the implementation
is writing new store files on its own.IOException
public void preCompactScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Store store, ScanType scanType, ScanOptions options, CompactionLifeCycleTracker tracker, CompactionRequest request) throws IOException
RegionObserver
options
to change max
versions and TTL for the scanner being opened.preCompactScannerOpen
in interface RegionObserver
c
- the environment provided by the region serverstore
- the store being compactedscanType
- type of Scanoptions
- used to change max versions and TTL for the scanner being openedtracker
- tracker used to track the life cycle of a compactionrequest
- the requested compactionIOException
public InternalScanner preCompact(ObserverContext<RegionCoprocessorEnvironment> c, Store store, InternalScanner scanner, ScanType scanType, CompactionLifeCycleTracker tracker, CompactionRequest request) throws IOException
RegionObserver
StoreFile
s selected for compaction into a new
StoreFile
.
To override or modify the compaction process, implementing classes can wrap the provided
InternalScanner
with a custom implementation that is returned from this method. The
custom scanner can then inspect Cell
s from the wrapped scanner,
applying its own policy to what gets written.
preCompact
in interface RegionObserver
c
- the environment provided by the region serverstore
- the store being compactedscanner
- the scanner over existing data used in the store file rewritingscanType
- type of Scantracker
- tracker used to track the life cycle of a compactionrequest
- the requested compactionnull
unless the
implementation is writing new store files on its own.IOException
public void preMemStoreCompactionCompactScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c, Store store, ScanOptions options) throws IOException
RegionObserver
options
to change max versions and TTL for the scanner being opened. Notice that this method will only
be called when you use eager
mode. For basic
mode we will not drop any cells
thus we do not open a store scanner.preMemStoreCompactionCompactScannerOpen
in interface RegionObserver
c
- the environment provided by the region serverstore
- the store where in memory compaction is being requestedoptions
- used to change max versions and TTL for the scanner being openedIOException
public InternalScanner preMemStoreCompactionCompact(ObserverContext<RegionCoprocessorEnvironment> c, Store store, InternalScanner scanner) throws IOException
RegionObserver
eager
mode. For basic
mode we will not drop any cells thus there is no
InternalScanner
.preMemStoreCompactionCompact
in interface RegionObserver
c
- the environment provided by the region serverstore
- the store where in memory compaction is being executedscanner
- the scanner over existing data used in the memstore segments being compactIOException
public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> c, Get get, List<Cell> result) throws IOException
RegionObserver
Call CoprocessorEnvironment#bypass to skip default actions. If 'bypass' is set, we skip out on calling any subsequent chained coprocessors.
preGetOp
in interface RegionObserver
c
- the environment provided by the region serverget
- the Get requestresult
- The result to return to the client if default processing
is bypassed. Can be modified. Will not be used if default processing
is not bypassed.IOException
private long getUniqueTimestamp(byte[] row)
public Result preIncrement(ObserverContext<RegionCoprocessorEnvironment> c, Increment increment) throws IOException
RegionObserver
Call CoprocessorEnvironment#bypass to skip default actions. If 'bypass' is set, we skip out on calling any subsequent chained coprocessors.
Note: Do not retain references to any Cells in 'increment' beyond the life of this invocation. If need a Cell reference for later use, copy the cell and use that.
preIncrement
in interface RegionObserver
c
- the environment provided by the region serverincrement
- increment objectIOException
public void preStoreScannerOpen(ObserverContext<RegionCoprocessorEnvironment> ctx, Store store, ScanOptions options) throws IOException
RegionObserver
This hook is called when a "user" scanner is opened. Use preFlushScannerOpen
and
preCompactScannerOpen
to inject flush/compaction.
Notice that, this method is used to change the inherent max versions and TTL for a Store. For
example, you can change the max versions option for a Scan
object to 10 in
preScannerOpen
, but if the max versions config on the Store is 1, then you still can
only read 1 version. You need also to inject here to change the max versions to 10 if you want
to get more versions.
preStoreScannerOpen
in interface RegionObserver
ctx
- the environment provided by the region serverstore
- the store which we want to get scanner fromoptions
- used to change max versions and TTL for the scanner being openedIOException
RegionObserver.preFlushScannerOpen(ObserverContext, Store, ScanOptions, FlushLifeCycleTracker)
,
RegionObserver.preCompactScannerOpen(ObserverContext, Store, ScanType, ScanOptions,
CompactionLifeCycleTracker, CompactionRequest)
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.