下面列出了怎么用org.apache.hadoop.hbase.CoprocessorEnvironment的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void start(CoprocessorEnvironment env) throws IOException {
observer = new ExampleRegionObserverMeta();
if (env instanceof RegionCoprocessorEnvironment
&& ((RegionCoprocessorEnvironment) env).getRegionInfo().getTable() != null
&& ((RegionCoprocessorEnvironment) env).getRegionInfo().getTable()
.equals(TableName.META_TABLE_NAME)) {
RegionCoprocessorEnvironment regionCoprocessorEnv = (RegionCoprocessorEnvironment) env;
registry = regionCoprocessorEnv.getMetricRegistryForRegionServer();
LossyCounting.LossyCountingListener<String> listener = key -> {
registry.remove(key);
metrics.remove(key);
};
final Configuration conf = regionCoprocessorEnv.getConfiguration();
clientMetricsLossyCounting = new LossyCounting<>("clientMetaMetrics", conf, listener);
regionMetricsLossyCounting = new LossyCounting<>("regionMetaMetrics", conf, listener);
// only be active mode when this region holds meta table.
active = true;
}
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
LOG.info("Starting compactor coprocessor");
commitTableConf = new HBaseCommitTableConfig();
String commitTableName = env.getConfiguration().get(COMMIT_TABLE_NAME_KEY);
if (commitTableName != null) {
commitTableConf.setTableName(commitTableName);
}
connection = RegionConnectionFactory
.getConnection(RegionConnectionFactory.ConnectionType.COMPACTION_CONNECTION, (RegionCoprocessorEnvironment) env);
commitTableClient = new HBaseCommitTable(connection, commitTableConf).getClient();
retainNonTransactionallyDeletedCells =
env.getConfiguration().getBoolean(HBASE_RETAIN_NON_TRANSACTIONALLY_DELETED_CELLS_KEY,
HBASE_RETAIN_NON_TRANSACTIONALLY_DELETED_CELLS_DEFAULT);
LOG.info("Compactor coprocessor started");
}
@Override
public void start(CoprocessorEnvironment ctx) throws IOException {
this.conf = ctx.getConfiguration();
this.quotasEnabled = QuotaUtil.isQuotaEnabled(conf);
if (!(ctx instanceof MasterCoprocessorEnvironment)) {
throw new CoprocessorException("Must be loaded on master.");
}
// if running on master
MasterCoprocessorEnvironment mEnv = (MasterCoprocessorEnvironment) ctx;
if (mEnv instanceof HasMasterServices) {
this.masterServices = ((HasMasterServices) mEnv).getMasterServices();
} else {
throw new CoprocessorException("Must be loaded on a master having master services.");
}
}
@Override
public void start(CoprocessorEnvironment environment) {
// make sure we are on a region server
if (!(environment instanceof RegionCoprocessorEnvironment)) {
throw new IllegalArgumentException(
"Constraints only act on regions - started in an environment that was not a region");
}
RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) environment;
TableDescriptor desc = env.getRegion().getTableDescriptor();
// load all the constraints from the HTD
try {
this.constraints = Constraints.getConstraints(desc, classloader);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
if (LOG.isInfoEnabled()) {
LOG.info("Finished loading " + constraints.size()
+ " user Constraints on table: " + desc.getTableName());
}
}
@Override
public void start(CoprocessorEnvironment e) throws IOException {
try {
region = (HRegion) ((RegionCoprocessorEnvironment) e).getRegion();
String[] name = region.getTableDescriptor().getTableName().getNameAsString().split(":");
if (name.length == 2) {
namespace = name[0];
tableName = name[1];
}
else {
tableName = name[0];
}
regionName = region.getRegionInfo().getEncodedName();
conf = HConfiguration.unwrapDelegate();
rootDir = FSUtils.getRootDir(conf);
fs = FSUtils.getCurrentFileSystem(conf);
backupDir = new Path(rootDir, BackupRestoreConstants.BACKUP_DIR + "/data/splice/" + tableName + "/" + regionName);
preparing = new AtomicBoolean(false);
isCompacting = new AtomicBoolean(false);
isSplitting = new AtomicBoolean(false);
} catch (Throwable t) {
throw CoprocessorUtils.getIOException(t);
}
}
@Override
public void start(final CoprocessorEnvironment env) throws IOException {
if (env instanceof RegionCoprocessorEnvironment) {
this.env = (RegionCoprocessorEnvironment) env;
} else {
throw new CoprocessorException("Must be loaded on a table region!");
}
}
@Override
public void start(CoprocessorEnvironment e) {
sharedData = ((RegionCoprocessorEnvironment)e).getSharedData();
// using new String here, so that there will be new object on each invocation
sharedData.putIfAbsent("test1", new Object());
startCalled = true;
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
// sleep a little bit to compensate time clock skew when SYSTEM.CATALOG moves
// among region servers because we relies on server time of RS which is hosting
// SYSTEM.CATALOG
Configuration config = env.getConfiguration();
long sleepTime = config.getLong(QueryServices.CLOCK_SKEW_INTERVAL_ATTRIB,
QueryServicesOptions.DEFAULT_CLOCK_SKEW_INTERVAL);
try {
if(sleepTime > 0) {
Thread.sleep(sleepTime);
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
enableRebuildIndex =
config.getBoolean(
QueryServices.INDEX_FAILURE_HANDLING_REBUILD_ATTRIB,
QueryServicesOptions.DEFAULT_INDEX_FAILURE_HANDLING_REBUILD);
rebuildIndexTimeInterval =
config.getLong(
QueryServices.INDEX_FAILURE_HANDLING_REBUILD_INTERVAL_ATTRIB,
QueryServicesOptions.DEFAULT_INDEX_FAILURE_HANDLING_REBUILD_INTERVAL);
initialRebuildTaskDelay =
config.getLong(
QueryServices.INDEX_REBUILD_TASK_INITIAL_DELAY,
QueryServicesOptions.DEFAULT_INDEX_REBUILD_TASK_INITIAL_DELAY);
}
@Override
public void start(CoprocessorEnvironment e) throws IOException {
if (e instanceof RegionCoprocessorEnvironment) {
RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) e;
this.cacheSupplier = getTransactionStateCacheSupplier(env);
this.cache = cacheSupplier.get();
HTableDescriptor tableDesc = env.getRegion().getTableDesc();
for (HColumnDescriptor columnDesc : tableDesc.getFamilies()) {
String columnTTL = columnDesc.getValue(TxConstants.PROPERTY_TTL);
long ttl = 0;
if (columnTTL != null) {
try {
ttl = Long.parseLong(columnTTL);
LOG.info("Family " + columnDesc.getNameAsString() + " has TTL of " + columnTTL);
} catch (NumberFormatException nfe) {
LOG.warn("Invalid TTL value configured for column family " + columnDesc.getNameAsString() +
", value = " + columnTTL);
}
}
ttlByFamily.put(columnDesc.getName(), ttl);
}
this.allowEmptyValues = getAllowEmptyValues(env, tableDesc);
this.txMaxLifetimeMillis = getTxMaxLifetimeMillis(env);
this.readNonTxnData = Boolean.valueOf(tableDesc.getValue(TxConstants.READ_NON_TX_DATA));
if (readNonTxnData) {
LOG.info("Reading pre-existing data enabled for table " + tableDesc.getNameAsString());
}
initializePruneState(env);
}
}
@Override
public void start(CoprocessorEnvironment e) throws IOException {
// Can't use ClientKeyValueBuilder on server-side because the memstore expects to
// be able to get a single backing buffer for a KeyValue.
this.kvBuilder = GenericKeyValueBuilder.INSTANCE;
/*
* We need to create a copy of region's configuration since we don't want any side effect of
* setting the RpcControllerFactory.
*/
upsertSelectConfig = PropertiesUtil.cloneConfig(e.getConfiguration());
/*
* Till PHOENIX-3995 is fixed, we need to use the
* InterRegionServerIndexRpcControllerFactory. Although this would cause remote RPCs to use
* index handlers on the destination region servers, it is better than using the regular
* priority handlers which could result in a deadlock.
*/
upsertSelectConfig.setClass(RpcControllerFactory.CUSTOM_CONTROLLER_CONF_KEY,
InterRegionServerIndexRpcControllerFactory.class, RpcControllerFactory.class);
compactionConfig = ServerUtil.getCompactionConfig(e.getConfiguration());
// For retries of index write failures, use the same # of retries as the rebuilder
indexWriteConfig = PropertiesUtil.cloneConfig(e.getConfiguration());
indexWriteConfig.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
e.getConfiguration().getInt(QueryServices.INDEX_REBUILD_RPC_RETRIES_COUNTER,
QueryServicesOptions.DEFAULT_INDEX_REBUILD_RPC_RETRIES_COUNTER));
indexWriteProps = new ReadOnlyProps(indexWriteConfig.iterator());
}
@Override
public void start(CoprocessorEnvironment e) throws IOException {
try {
SpliceLogUtils.trace(LOG, "starting %s", SIObserver.class);
RegionCoprocessorEnvironment rce = (RegionCoprocessorEnvironment) e;
TableName tableName = rce.getRegion().getTableDescriptor().getTableName();
doesTableNeedSI(tableName);
HBaseSIEnvironment env = HBaseSIEnvironment.loadEnvironment(new SystemClock(), ZkUtils.getRecoverableZooKeeper());
SIDriver driver = env.getSIDriver();
if (tableEnvMatch) {
try{
conglomId=Long.parseLong(tableName.getQualifierAsString());
}catch(NumberFormatException nfe){
SpliceLogUtils.warn(LOG,"Unable to parse conglomerate id for table %s",tableName);
conglomId=-1;
}
operationStatusFactory = driver.getOperationStatusLib();
//noinspection unchecked
txnOperationFactory = new SimpleTxnOperationFactory(driver.getExceptionFactory(), HOperationFactory.INSTANCE);
//noinspection unchecked
Partition regionPartition = new RegionPartition((HRegion) rce.getRegion());
region = new TxnRegion(regionPartition,
driver.getRollForward(),
driver.getReadResolver(regionPartition),
driver.getTxnSupplier(),
driver.getTransactor(),
driver.getOperationFactory()
);
Tracer.traceRegion(region.getTableName(), rce.getRegion());
}
ZKWatcher zk = ((RegionServerServices)((RegionCoprocessorEnvironment)e).getOnlineRegions()).getZooKeeper();
this.authManager = TableAuthManager.getOrCreate(zk, e.getConfiguration());
this.authTokenEnabled = driver.getConfiguration().getAuthenticationTokenEnabled();
} catch (Throwable t) {
throw CoprocessorUtils.getIOException(t);
}
}
@Override
public void start(CoprocessorEnvironment e) throws IOException {
if (e instanceof RegionCoprocessorEnvironment) {
RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) e;
this.cacheSupplier = getTransactionStateCacheSupplier(env);
this.cache = cacheSupplier.get();
HTableDescriptor tableDesc = env.getRegion().getTableDesc();
for (HColumnDescriptor columnDesc : tableDesc.getFamilies()) {
String columnTTL = columnDesc.getValue(TxConstants.PROPERTY_TTL);
long ttl = 0;
if (columnTTL != null) {
try {
ttl = Long.parseLong(columnTTL);
LOG.info("Family " + columnDesc.getNameAsString() + " has TTL of " + columnTTL);
} catch (NumberFormatException nfe) {
LOG.warn("Invalid TTL value configured for column family " + columnDesc.getNameAsString() +
", value = " + columnTTL);
}
}
ttlByFamily.put(columnDesc.getName(), ttl);
}
this.allowEmptyValues = getAllowEmptyValues(env, tableDesc);
this.txMaxLifetimeMillis = getTxMaxLifetimeMillis(env);
this.readNonTxnData = Boolean.valueOf(tableDesc.getValue(TxConstants.READ_NON_TX_DATA));
if (readNonTxnData) {
LOG.info("Reading pre-existing data enabled for table " + tableDesc.getNameAsString());
}
initializePruneState(env);
}
}
@Override
public void stop(CoprocessorEnvironment e) throws IOException {
if (this.stopped) {
return;
}
if (this.disabled) {
return;
}
this.stopped = true;
String msg = "Indexer is being stopped";
this.builder.stop(msg);
this.writer.stop(msg);
this.recoveryWriter.stop(msg);
}
@Override
public void start(CoprocessorEnvironment e) throws IOException {
if (e instanceof RegionCoprocessorEnvironment) {
RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) e;
this.cacheSupplier = getTransactionStateCacheSupplier(env);
this.cache = cacheSupplier.get();
HTableDescriptor tableDesc = env.getRegion().getTableDesc();
for (HColumnDescriptor columnDesc : tableDesc.getFamilies()) {
String columnTTL = columnDesc.getValue(TxConstants.PROPERTY_TTL);
long ttl = 0;
if (columnTTL != null) {
try {
ttl = Long.parseLong(columnTTL);
LOG.info("Family " + columnDesc.getNameAsString() + " has TTL of " + columnTTL);
} catch (NumberFormatException nfe) {
LOG.warn("Invalid TTL value configured for column family " + columnDesc.getNameAsString() +
", value = " + columnTTL);
}
}
ttlByFamily.put(columnDesc.getName(), ttl);
}
this.allowEmptyValues = getAllowEmptyValues(env, tableDesc);
this.txMaxLifetimeMillis = getTxMaxLifetimeMillis(env);
this.readNonTxnData = Boolean.valueOf(tableDesc.getValue(TxConstants.READ_NON_TX_DATA));
if (readNonTxnData) {
LOG.info("Reading pre-existing data enabled for table " + tableDesc.getNameAsString());
}
initializePruneState(env);
}
}
@Override
public void stop(CoprocessorEnvironment e) throws IOException {
try {
resetPruneState();
} finally {
if (cacheSupplier != null) {
cacheSupplier.release();
}
}
}
@Override
public void start(CoprocessorEnvironment e) throws IOException {
if (e instanceof RegionCoprocessorEnvironment) {
RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) e;
this.cacheSupplier = getTransactionStateCacheSupplier(env);
this.cache = cacheSupplier.get();
HTableDescriptor tableDesc = env.getRegion().getTableDesc();
for (HColumnDescriptor columnDesc : tableDesc.getFamilies()) {
String columnTTL = columnDesc.getValue(TxConstants.PROPERTY_TTL);
long ttl = 0;
if (columnTTL != null) {
try {
ttl = Long.parseLong(columnTTL);
LOG.info("Family " + columnDesc.getNameAsString() + " has TTL of " + columnTTL);
} catch (NumberFormatException nfe) {
LOG.warn("Invalid TTL value configured for column family " + columnDesc.getNameAsString() +
", value = " + columnTTL);
}
}
ttlByFamily.put(columnDesc.getName(), ttl);
}
this.allowEmptyValues = getAllowEmptyValues(env, tableDesc);
this.txMaxLifetimeMillis = getTxMaxLifetimeMillis(env);
this.readNonTxnData = Boolean.valueOf(tableDesc.getValue(TxConstants.READ_NON_TX_DATA));
if (readNonTxnData) {
LOG.info("Reading pre-existing data enabled for table " + tableDesc.getNameAsString());
}
initializePruneState(env);
}
}
@Override
public void stop(CoprocessorEnvironment e) throws IOException {
try {
resetPruneState();
} finally {
if (cacheSupplier != null) {
cacheSupplier.release();
}
}
}
@Override
public void start(CoprocessorEnvironment e) throws IOException {
if (e instanceof RegionCoprocessorEnvironment) {
RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) e;
this.cacheSupplier = getTransactionStateCacheSupplier(env);
this.cache = cacheSupplier.get();
HTableDescriptor tableDesc = env.getRegion().getTableDesc();
for (HColumnDescriptor columnDesc : tableDesc.getFamilies()) {
String columnTTL = columnDesc.getValue(TxConstants.PROPERTY_TTL);
long ttl = 0;
if (columnTTL != null) {
try {
ttl = Long.parseLong(columnTTL);
LOG.info("Family " + columnDesc.getNameAsString() + " has TTL of " + columnTTL);
} catch (NumberFormatException nfe) {
LOG.warn("Invalid TTL value configured for column family " + columnDesc.getNameAsString() +
", value = " + columnTTL);
}
}
ttlByFamily.put(columnDesc.getName(), ttl);
}
this.allowEmptyValues = getAllowEmptyValues(env, tableDesc);
this.txMaxLifetimeMillis = getTxMaxLifetimeMillis(env);
this.readNonTxnData = Boolean.valueOf(tableDesc.getValue(TxConstants.READ_NON_TX_DATA));
if (readNonTxnData) {
LOG.info("Reading pre-existing data enabled for table " + tableDesc.getNameAsString());
}
initializePruneState(env);
}
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
RegionCoprocessorEnvironment renv = (RegionCoprocessorEnvironment) env;
try {
this.cache = ((ZKDataHolder) renv.getSharedData().computeIfAbsent(ZKKEY, k -> {
String ensemble = renv.getConfiguration().get(ZK_ENSEMBLE_KEY);
int sessionTimeout =
renv.getConfiguration().getInt(ZK_SESSION_TIMEOUT_KEY, ZK_SESSION_TIMEOUT_DEFAULT);
return new ZKDataHolder(ensemble, sessionTimeout);
})).acquire();
} catch (Exception e) {
throw new IOException(e);
}
}
@Override
public void start(CoprocessorEnvironment e) throws IOException {
synchronized (SolrRegionObserver.class) {
_startCount++;
if (_startCount > 1) { //�Ѿ���ʼ�����
return;
}
}
init(e);
}
@Override
public void stop(CoprocessorEnvironment e) throws IOException {
synchronized (SolrRegionObserver.class) {
_startCount--;
if (_startCount > 0) { //��������
return;
}
}
this.destroy(e);
}
@Override
public void stop(CoprocessorEnvironment env) {
super.stop(env);
if (callSuperTwice) {
super.stop(env);
}
}
/**
* Logs the start of the observer and runs the SpliceDriver if needed...
*/
@SuppressFBWarnings(value="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification="intentional")
@Override
public void start(CoprocessorEnvironment e) throws IOException{
try {
isHbaseJVM= true;
lifecycleManager = startEngine(e);
SpliceClient.isRegionServer = true;
} catch (Throwable t) {
throw CoprocessorUtils.getIOException(t);
}
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
if (env instanceof RegionCoprocessorEnvironment) {
this.env = (RegionCoprocessorEnvironment) env;
} else {
throw new CoprocessorException("Must be loaded on a table region!");
}
}
@Override
public void start(CoprocessorEnvironment env) throws IOException{
try {
RegionCoprocessorEnvironment rce=(RegionCoprocessorEnvironment)env;
HRegion region=(HRegion)rce.getRegion();
HBaseSIEnvironment siEnv = HBaseSIEnvironment.loadEnvironment(new SystemClock(), ZkUtils.getRecoverableZooKeeper());
SConfiguration configuration=siEnv.configuration();
TableType table= EnvUtils.getTableType(configuration,rce);
if(table.equals(TableType.TRANSACTION_TABLE)){
TransactionResolver resolver=resolverRef.get();
SIDriver driver=siEnv.getSIDriver();
assert driver!=null:"SIDriver Cannot be null";
long txnKeepAliveTimeout = configuration.getTransactionTimeout();
@SuppressWarnings("unchecked") TxnPartition regionStore=new RegionTxnStore(region,
driver.getTxnSupplier(),
resolver,
txnKeepAliveTimeout,
new SystemClock());
TimestampSource timestampSource=driver.getTimestampSource();
int txnLockStrips = configuration.getTransactionLockStripes();
lifecycleStore = new StripedTxnLifecycleStore(txnLockStrips,regionStore,
new RegionServerControl(region, (RegionServerServices)rce.getOnlineRegions()),timestampSource);
isTxnTable=true;
}
} catch (Throwable t) {
throw CoprocessorUtils.getIOException(t);
}
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
if (env instanceof RegionCoprocessorEnvironment) {
this.env = (RegionCoprocessorEnvironment) env;
} else {
throw new CoprocessorException("Must be loaded on a table region!");
}
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
if (env instanceof RegionCoprocessorEnvironment) {
this.env = (RegionCoprocessorEnvironment) env;
} else {
throw new CoprocessorException("Must be loaded on a table region!");
}
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
Configuration conf = env.getConfiguration();
this.accessCheckEnabled = conf.getBoolean(QueryServices.PHOENIX_ACLS_ENABLED,
QueryServicesOptions.DEFAULT_PHOENIX_ACLS_ENABLED);
if (!this.accessCheckEnabled) {
LOGGER.warn(
"PhoenixAccessController has been loaded with authorization checks disabled.");
}
this.execPermissionsCheckEnabled = conf.getBoolean(AccessControlConstants.EXEC_PERMISSION_CHECKS_KEY,
AccessControlConstants.DEFAULT_EXEC_PERMISSION_CHECKS);
if (env instanceof PhoenixMetaDataControllerEnvironment) {
this.env = (PhoenixMetaDataControllerEnvironment)env;
} else {
throw new IllegalArgumentException(
"Not a valid environment, should be loaded by PhoenixMetaDataControllerEnvironment");
}
ZKWatcher zk = null;
RegionCoprocessorEnvironment regionEnv = this.env.getRegionCoprocessorEnvironment();
if (regionEnv instanceof HasRegionServerServices) {
zk = ((HasRegionServerServices) regionEnv).getRegionServerServices().getZooKeeper();
}
accessChecker = new AccessChecker(env.getConfiguration(), zk);
// set the user-provider.
this.userProvider = UserProvider.instantiate(env.getConfiguration());
// init superusers and add the server principal (if using security)
// or process owner as default super user.
Superusers.initialize(env.getConfiguration());
}
@Override
public void start(CoprocessorEnvironment env) throws IOException {
if (env instanceof RegionCoprocessorEnvironment) {
this.env = (RegionCoprocessorEnvironment) env;
} else {
throw new CoprocessorException("Must be loaded on a table region!");
}
}
@Override
public void stop(CoprocessorEnvironment e) throws IOException {
if (this.stopped) {
return;
}
if (this.disabled) {
super.stop(e);
return;
}
this.stopped = true;
String msg = "Indexer is being stopped";
this.builder.stop(msg);
this.writer.stop(msg);
this.recoveryWriter.stop(msg);
}