You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by "Tadimeti, Veera" <ve...@epsilon.com> on 2017/07/06 14:14:04 UTC
scope of RegionCoprocessorEnvironment sharedData
hi,
I have few questions regarding scope of RegionCoprocessorEnvironment sharedData.
* Is sharedData map is shared accross all instances simultaneously ?
o I am putting a variable in sharedData in preScannerOpen() based on scan attribute,
o check that variable exists in postScannerNext() then apply logic,
o remove the variable postScannerClose().
o If data is in multiple regions, when one coprocessor removes variable in postScannerClose(), will the variable is NULL for another region coprocessor in postScannerNext() ?
* Is sharedData map is shared across all the client request operations ?
If a variable is set in sharedData for one client operation(say SCAN), will the variable is available for another client operation(new SCAN) ?
* Will the variables be garbage collected even if we dont implement (removed variables in sharedData) postScannerClose() method
Please find below the logic that I am using currently
CODE:
public RegionScanner preScannerOpen(ObserverContext<RegionCoprocessorEnvironment> e, Scan scan, RegionScanner s) throws IOException {
byte[] useGetInPostScannerNext = scan.getAttribute(USE_GET_OPERATION_IN_POST_SCANNER_NEXT);
String useGetInPostScannerNextStr = Bytes.toString(useGetInPostScannerNext);
if (Boolean.parseBoolean(useGetInPostScannerNextStr)) {
e.getEnvironment().getSharedData().put(USE_GET_OPERATION_IN_POST_SCANNER_NEXT, useGetInPostScannerNextStr);
}
return super.preScannerOpen(e, scan, s);
}
@Override
public boolean postScannerNext(final ObserverContext<RegionCoprocessorEnvironment> e,
final InternalScanner s, final List<Result> results, final int limit,
final boolean hasMore) throws IOException {
try {
if (canUseGetOperation(e)) {
//logic goes here
}
} catch (Exception ex) {
logger.error("Exception in postScannerNext ", ex);
throw new IOException(ex);
}
return hasMore;
}
@Override
public void postScannerClose(ObserverContext<RegionCoprocessorEnvironment> e, InternalScanner s) throws IOException {
if (canUseGetOperation(e)) {
e.getEnvironment().getSharedData().remove(USE_GET_OPERATION_IN_POST_SCANNER_NEXT);
}
super.postScannerClose(e, s);
}
private boolean canUseGetOperation(final ObserverContext<RegionCoprocessorEnvironment> e) {
String useGetOperationInPostScannerNext = (String) e.getEnvironment().getSharedData().get(USE_GET_OPERATION_IN_POST_SCANNER_NEXT);
return Boolean.parseBoolean(useGetOperationInPostScannerNext);
}
Thanks & Regards,
Veera Tadimeti