Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 12709200D36 for ; Sun, 22 Oct 2017 17:15:52 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 10F16160BF1; Sun, 22 Oct 2017 15:15:52 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 77F5D160BEF for ; Sun, 22 Oct 2017 17:15:49 +0200 (CEST) Received: (qmail 77795 invoked by uid 500); 22 Oct 2017 15:15:48 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 77181 invoked by uid 99); 22 Oct 2017 15:15:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 22 Oct 2017 15:15:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2B0C9E0117; Sun, 22 Oct 2017 15:15:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: git-site-role@apache.org To: commits@hbase.apache.org Date: Sun, 22 Oct 2017 15:15:52 -0000 Message-Id: <8035d97f50284f159b90c0e2ce7506ba@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [09/51] [partial] hbase-site git commit: Published site at . archived-at: Sun, 22 Oct 2017 15:15:52 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/4f94a4c5/devapidocs/src-html/org/apache/hadoop/hbase/master/MasterCoprocessorHost.MasterEnvironment.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/master/MasterCoprocessorHost.MasterEnvironment.html b/devapidocs/src-html/org/apache/hadoop/hbase/master/MasterCoprocessorHost.MasterEnvironment.html index 7daa331..e6ad6d4 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/master/MasterCoprocessorHost.MasterEnvironment.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/master/MasterCoprocessorHost.MasterEnvironment.html @@ -40,1715 +40,1749 @@ 032import org.apache.hadoop.hbase.ServerName; 033import org.apache.hadoop.hbase.TableName; 034import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; -035import org.apache.hadoop.hbase.client.MasterSwitchType; -036import org.apache.hadoop.hbase.client.Mutation; -037import org.apache.hadoop.hbase.client.RegionInfo; -038import org.apache.hadoop.hbase.client.SnapshotDescription; -039import org.apache.hadoop.hbase.client.TableDescriptor; -040import org.apache.hadoop.hbase.coprocessor.BaseEnvironment; -041import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; -042import org.apache.hadoop.hbase.coprocessor.CoprocessorService; -043import org.apache.hadoop.hbase.coprocessor.CoprocessorServiceBackwardCompatiblity; -044import org.apache.hadoop.hbase.coprocessor.MasterCoprocessor; -045import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment; -046import org.apache.hadoop.hbase.coprocessor.MasterObserver; -047import org.apache.hadoop.hbase.coprocessor.MetricsCoprocessor; -048import org.apache.hadoop.hbase.coprocessor.ObserverContext; -049import org.apache.hadoop.hbase.master.locking.LockProcedure; -050import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; -051import org.apache.hadoop.hbase.metrics.MetricRegistry; -052import org.apache.hadoop.hbase.net.Address; -053import org.apache.hadoop.hbase.procedure2.LockType; -054import org.apache.hadoop.hbase.procedure2.LockedResource; -055import org.apache.hadoop.hbase.procedure2.Procedure; -056import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; -057import org.apache.hadoop.hbase.quotas.GlobalQuotaSettings; -058import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; -059import org.apache.hadoop.hbase.security.User; -060import org.apache.yetus.audience.InterfaceAudience; -061 -062/** -063 * Provides the coprocessor framework and environment for master oriented -064 * operations. {@link HMaster} interacts with the loaded coprocessors -065 * through this class. -066 */ -067@InterfaceAudience.Private -068public class MasterCoprocessorHost -069 extends CoprocessorHost<MasterCoprocessor, MasterCoprocessorEnvironment> { -070 -071 private static final Log LOG = LogFactory.getLog(MasterCoprocessorHost.class); -072 -073 /** -074 * Coprocessor environment extension providing access to master related -075 * services. -076 */ -077 private static class MasterEnvironment extends BaseEnvironment<MasterCoprocessor> -078 implements MasterCoprocessorEnvironment { -079 private final MasterServices masterServices; -080 private final boolean supportGroupCPs; -081 private final MetricRegistry metricRegistry; -082 -083 public MasterEnvironment(final MasterCoprocessor impl, final int priority, final int seq, -084 final Configuration conf, final MasterServices services) { -085 super(impl, priority, seq, conf); -086 this.masterServices = services; -087 supportGroupCPs = !useLegacyMethod(impl.getClass(), -088 "preBalanceRSGroup", ObserverContext.class, String.class); -089 this.metricRegistry = -090 MetricsCoprocessor.createRegistryForMasterCoprocessor(impl.getClass().getName()); -091 } -092 -093 @Override -094 public MasterServices getMasterServices() { -095 return masterServices; +035import org.apache.hadoop.hbase.client.Connection; +036import org.apache.hadoop.hbase.client.MasterSwitchType; +037import org.apache.hadoop.hbase.client.Mutation; +038import org.apache.hadoop.hbase.client.RegionInfo; +039import org.apache.hadoop.hbase.client.SnapshotDescription; +040import org.apache.hadoop.hbase.client.TableDescriptor; +041import org.apache.hadoop.hbase.coprocessor.BaseEnvironment; +042import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; +043import org.apache.hadoop.hbase.coprocessor.CoprocessorService; +044import org.apache.hadoop.hbase.coprocessor.CoprocessorServiceBackwardCompatiblity; +045import org.apache.hadoop.hbase.coprocessor.CoreCoprocessor; +046import org.apache.hadoop.hbase.coprocessor.HasMasterServices; +047import org.apache.hadoop.hbase.coprocessor.MasterCoprocessor; +048import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment; +049import org.apache.hadoop.hbase.coprocessor.MasterObserver; +050import org.apache.hadoop.hbase.coprocessor.MetricsCoprocessor; +051import org.apache.hadoop.hbase.coprocessor.ObserverContext; +052import org.apache.hadoop.hbase.master.locking.LockProcedure; +053import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; +054import org.apache.hadoop.hbase.metrics.MetricRegistry; +055import org.apache.hadoop.hbase.net.Address; +056import org.apache.hadoop.hbase.procedure2.LockType; +057import org.apache.hadoop.hbase.procedure2.LockedResource; +058import org.apache.hadoop.hbase.procedure2.Procedure; +059import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; +060import org.apache.hadoop.hbase.quotas.GlobalQuotaSettings; +061import org.apache.hadoop.hbase.replication.ReplicationPeerConfig; +062import org.apache.hadoop.hbase.security.User; +063import org.apache.yetus.audience.InterfaceAudience; +064 +065/** +066 * Provides the coprocessor framework and environment for master oriented +067 * operations. {@link HMaster} interacts with the loaded coprocessors +068 * through this class. +069 */ +070@InterfaceAudience.Private +071public class MasterCoprocessorHost +072 extends CoprocessorHost<MasterCoprocessor, MasterCoprocessorEnvironment> { +073 +074 private static final Log LOG = LogFactory.getLog(MasterCoprocessorHost.class); +075 +076 /** +077 * Coprocessor environment extension providing access to master related +078 * services. +079 */ +080 private static class MasterEnvironment extends BaseEnvironment<MasterCoprocessor> +081 implements MasterCoprocessorEnvironment { +082 private final Connection connection; +083 private final ServerName serverName; +084 private final boolean supportGroupCPs; +085 private final MetricRegistry metricRegistry; +086 +087 public MasterEnvironment(final MasterCoprocessor impl, final int priority, final int seq, +088 final Configuration conf, final MasterServices services) { +089 super(impl, priority, seq, conf); +090 this.connection = services.getConnection(); +091 this.serverName = services.getServerName(); +092 supportGroupCPs = !useLegacyMethod(impl.getClass(), +093 "preBalanceRSGroup", ObserverContext.class, String.class); +094 this.metricRegistry = +095 MetricsCoprocessor.createRegistryForMasterCoprocessor(impl.getClass().getName()); 096 } 097 098 @Override -099 public MetricRegistry getMetricRegistryForMaster() { -100 return metricRegistry; +099 public ServerName getServerName() { +100 return this.serverName; 101 } 102 103 @Override -104 public void shutdown() { -105 super.shutdown(); -106 MetricsCoprocessor.removeRegistry(this.metricRegistry); -107 } -108 } -109 -110 private MasterServices masterServices; -111 -112 public MasterCoprocessorHost(final MasterServices services, final Configuration conf) { -113 super(services); -114 this.conf = conf; -115 this.masterServices = services; -116 // Log the state of coprocessor loading here; should appear only once or -117 // twice in the daemon log, depending on HBase version, because there is -118 // only one MasterCoprocessorHost instance in the master process -119 boolean coprocessorsEnabled = conf.getBoolean(COPROCESSORS_ENABLED_CONF_KEY, -120 DEFAULT_COPROCESSORS_ENABLED); -121 LOG.info("System coprocessor loading is " + (coprocessorsEnabled ? "enabled" : "disabled")); -122 loadSystemCoprocessors(conf, MASTER_COPROCESSOR_CONF_KEY); -123 } -124 -125 -126 -127 @Override -128 public MasterEnvironment createEnvironment(final MasterCoprocessor instance, final int priority, -129 final int seq, final Configuration conf) { -130 // If coprocessor exposes any services, register them. -131 for (Service service : instance.getServices()) { -132 masterServices.registerService(service); -133 } -134 return new MasterEnvironment(instance, priority, seq, conf, masterServices); -135 } -136 -137 @Override -138 public MasterCoprocessor checkAndGetInstance(Class<?> implClass) -139 throws InstantiationException, IllegalAccessException { -140 if (MasterCoprocessor.class.isAssignableFrom(implClass)) { -141 return (MasterCoprocessor)implClass.newInstance(); -142 } else if (CoprocessorService.class.isAssignableFrom(implClass)) { -143 // For backward compatibility with old CoprocessorService impl which don't extend -144 // MasterCoprocessor. -145 return new CoprocessorServiceBackwardCompatiblity.MasterCoprocessorService( -146 (CoprocessorService)implClass.newInstance()); -147 } else { -148 LOG.error(implClass.getName() + " is not of type MasterCoprocessor. Check the " -149 + "configuration " + CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY); -150 return null; -151 } -152 } -153 -154 private ObserverGetter<MasterCoprocessor, MasterObserver> masterObserverGetter = -155 MasterCoprocessor::getMasterObserver; -156 -157 abstract class MasterObserverOperation extends -158 ObserverOperationWithoutResult<MasterObserver> { -159 public MasterObserverOperation(){ -160 super(masterObserverGetter); -161 } -162 -163 public MasterObserverOperation(User user) { -164 super(masterObserverGetter, user); -165 } -166 } -167 -168 -169 ////////////////////////////////////////////////////////////////////////////////////////////////// -170 // MasterObserver operations -171 ////////////////////////////////////////////////////////////////////////////////////////////////// -172 -173 -174 public boolean preCreateNamespace(final NamespaceDescriptor ns) throws IOException { -175 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -176 @Override -177 public void call(MasterObserver observer) throws IOException { -178 observer.preCreateNamespace(this, ns); -179 } -180 }); -181 } -182 -183 public void postCreateNamespace(final NamespaceDescriptor ns) throws IOException { -184 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -185 @Override -186 public void call(MasterObserver observer) throws IOException { -187 observer.postCreateNamespace(this, ns); -188 } -189 }); -190 } -191 -192 public boolean preDeleteNamespace(final String namespaceName) throws IOException { -193 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -194 @Override -195 public void call(MasterObserver observer) throws IOException { -196 observer.preDeleteNamespace(this, namespaceName); -197 } -198 }); -199 } -200 -201 public void postDeleteNamespace(final String namespaceName) throws IOException { -202 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -203 @Override -204 public void call(MasterObserver observer) throws IOException { -205 observer.postDeleteNamespace(this, namespaceName); -206 } -207 }); -208 } -209 -210 public boolean preModifyNamespace(final NamespaceDescriptor ns) throws IOException { -211 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -212 @Override -213 public void call(MasterObserver observer) throws IOException { -214 observer.preModifyNamespace(this, ns); -215 } -216 }); -217 } -218 -219 public void postModifyNamespace(final NamespaceDescriptor ns) throws IOException { -220 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -221 @Override -222 public void call(MasterObserver observer) throws IOException { -223 observer.postModifyNamespace(this, ns); -224 } -225 }); -226 } -227 -228 public void preGetNamespaceDescriptor(final String namespaceName) -229 throws IOException { -230 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -231 @Override -232 public void call(MasterObserver observer) throws IOException { -233 observer.preGetNamespaceDescriptor(this, namespaceName); -234 } -235 }); -236 } -237 -238 public void postGetNamespaceDescriptor(final NamespaceDescriptor ns) -239 throws IOException { -240 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -241 @Override -242 public void call(MasterObserver observer) throws IOException { -243 observer.postGetNamespaceDescriptor(this, ns); -244 } -245 }); -246 } -247 -248 public boolean preListNamespaceDescriptors(final List<NamespaceDescriptor> descriptors) -249 throws IOException { -250 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -251 @Override -252 public void call(MasterObserver observer) throws IOException { -253 observer.preListNamespaceDescriptors(this, descriptors); -254 } -255 }); -256 } -257 -258 public void postListNamespaceDescriptors(final List<NamespaceDescriptor> descriptors) -259 throws IOException { -260 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -261 @Override -262 public void call(MasterObserver observer) throws IOException { -263 observer.postListNamespaceDescriptors(this, descriptors); -264 } -265 }); -266 } -267 -268 /* Implementation of hooks for invoking MasterObservers */ -269 -270 public void preCreateTable(final TableDescriptor htd, final RegionInfo[] regions) -271 throws IOException { -272 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -273 @Override -274 public void call(MasterObserver observer) throws IOException { -275 observer.preCreateTable(this, htd, regions); -276 } -277 }); -278 } -279 -280 public void postCreateTable(final TableDescriptor htd, final RegionInfo[] regions) -281 throws IOException { -282 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -283 @Override -284 public void call(MasterObserver observer) throws IOException { -285 observer.postCreateTable(this, htd, regions); -286 } -287 }); -288 } -289 -290 public void preCreateTableAction(final TableDescriptor htd, final RegionInfo[] regions, -291 final User user) throws IOException { -292 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { -293 @Override -294 public void call(MasterObserver observer) throws IOException { -295 observer.preCreateTableAction(this, htd, regions); -296 } -297 }); -298 } -299 -300 public void postCompletedCreateTableAction( -301 final TableDescriptor htd, final RegionInfo[] regions, final User user) throws IOException { -302 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { -303 @Override -304 public void call(MasterObserver observer) throws IOException { -305 observer.postCompletedCreateTableAction(this, htd, regions); -306 } -307 }); -308 } -309 -310 public void preDeleteTable(final TableName tableName) throws IOException { -311 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -312 @Override -313 public void call(MasterObserver observer) throws IOException { -314 observer.preDeleteTable(this, tableName); -315 } -316 }); -317 } -318 -319 public void postDeleteTable(final TableName tableName) throws IOException { -320 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -321 @Override -322 public void call(MasterObserver observer) throws IOException { -323 observer.postDeleteTable(this, tableName); -324 } -325 }); -326 } -327 -328 public void preDeleteTableAction(final TableName tableName, final User user) throws IOException { -329 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { -330 @Override -331 public void call(MasterObserver observer) throws IOException { -332 observer.preDeleteTableAction(this, tableName); -333 } -334 }); -335 } -336 -337 public void postCompletedDeleteTableAction(final TableName tableName, final User user) -338 throws IOException { -339 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { -340 @Override -341 public void call(MasterObserver observer) throws IOException { -342 observer.postCompletedDeleteTableAction(this, tableName); -343 } -344 }); -345 } -346 -347 public void preTruncateTable(final TableName tableName) throws IOException { -348 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -349 @Override -350 public void call(MasterObserver observer) throws IOException { -351 observer.preTruncateTable(this, tableName); -352 } -353 }); -354 } -355 -356 public void postTruncateTable(final TableName tableName) throws IOException { -357 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -358 @Override -359 public void call(MasterObserver observer) throws IOException { -360 observer.postTruncateTable(this, tableName); -361 } -362 }); -363 } -364 -365 public void preTruncateTableAction(final TableName tableName, final User user) -366 throws IOException { -367 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { -368 @Override -369 public void call(MasterObserver observer) throws IOException { -370 observer.preTruncateTableAction(this, tableName); -371 } -372 }); -373 } -374 -375 public void postCompletedTruncateTableAction(final TableName tableName, final User user) -376 throws IOException { -377 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { -378 @Override -379 public void call(MasterObserver observer) throws IOException { -380 observer.postCompletedTruncateTableAction(this, tableName); -381 } -382 }); -383 } -384 -385 public void preModifyTable(final TableName tableName, final TableDescriptor htd) -386 throws IOException { -387 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -388 @Override -389 public void call(MasterObserver observer) throws IOException { -390 observer.preModifyTable(this, tableName, htd); -391 } -392 }); -393 } -394 -395 public void postModifyTable(final TableName tableName, final TableDescriptor htd) -396 throws IOException { -397 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -398 @Override -399 public void call(MasterObserver observer) throws IOException { -400 observer.postModifyTable(this, tableName, htd); -401 } -402 }); -403 } -404 -405 public void preModifyTableAction(final TableName tableName, final TableDescriptor htd, -406 final User user) throws IOException { -407 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { -408 @Override -409 public void call(MasterObserver observer) throws IOException { -410 observer.preModifyTableAction(this, tableName, htd); -411 } -412 }); -413 } -414 -415 public void postCompletedModifyTableAction(final TableName tableName, final TableDescriptor htd, -416 final User user) throws IOException { -417 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { -418 @Override -419 public void call(MasterObserver observer) throws IOException { -420 observer.postCompletedModifyTableAction(this, tableName, htd); -421 } -422 }); -423 } -424 -425 public boolean preAddColumn(final TableName tableName, final ColumnFamilyDescriptor columnFamily) -426 throws IOException { -427 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -428 @Override -429 public void call(MasterObserver observer) throws IOException { -430 observer.preAddColumnFamily(this, tableName, columnFamily); -431 } -432 }); -433 } -434 -435 public void postAddColumn(final TableName tableName, final ColumnFamilyDescriptor columnFamily) -436 throws IOException { -437 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -438 @Override -439 public void call(MasterObserver observer) throws IOException { -440 observer.postAddColumnFamily(this, tableName, columnFamily); -441 } -442 }); -443 } -444 -445 public boolean preAddColumnFamilyAction( -446 final TableName tableName, -447 final ColumnFamilyDescriptor columnFamily, -448 final User user) -449 throws IOException { -450 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { -451 @Override -452 public void call(MasterObserver observer) throws IOException { -453 observer.preAddColumnFamilyAction(this, tableName, columnFamily); -454 } -455 }); -456 } -457 -458 public void postCompletedAddColumnFamilyAction( -459 final TableName tableName, -460 final ColumnFamilyDescriptor columnFamily, -461 final User user) -462 throws IOException { -463 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { -464 @Override -465 public void call(MasterObserver observer) throws IOException { -466 observer.postCompletedAddColumnFamilyAction(this, tableName, columnFamily); -467 } -468 }); -469 } -470 -471 public boolean preModifyColumn(final TableName tableName, -472 final ColumnFamilyDescriptor columnFamily) throws IOException { -473 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -474 @Override -475 public void call(MasterObserver observer) throws IOException { -476 observer.preModifyColumnFamily(this, tableName, columnFamily); -477 } -478 }); -479 } -480 -481 public void postModifyColumn(final TableName tableName, final ColumnFamilyDescriptor columnFamily) -482 throws IOException { -483 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { -484 @Override -485 public void call(MasterObserver observer) throws IOException { -486 observer.postModifyColumnFamily(this, tableName, columnFamily); -487 } -488 }); -489 } -490 -491 public boolean preModifyColumnFamilyAction( -492 final TableName tableName, -493 final ColumnFamilyDescriptor columnFamily, -494 final User user) throws IOException { -495 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { -496 @Override -497 public void call(MasterObserver observer) throws IOException { -498 observer.preModifyColumnFamilyAction(this, tableName, columnFamily); -499 } -500 }); -501 } -502 -503 public void postCompletedModifyColumnFamilyAction( -504 final TableName tableName, -505 final ColumnFamilyDescriptor columnFamily, -506 final User user) throws IOException { -507 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { +104 public Connection getConnection() { +105 return this.connection; +106 } +107 +108 @Override +109 public MetricRegistry getMetricRegistryForMaster() { +110 return metricRegistry; +111 } +112 +113 @Override +114 public void shutdown() { +115 super.shutdown(); +116 MetricsCoprocessor.removeRegistry(this.metricRegistry); +117 } +118 } +119 +120 /** +121 * Special version of MasterEnvironment that exposes MasterServices for Core Coprocessors only. +122 * Temporary hack until Core Coprocessors are integrated into Core. +123 */ +124 private static class MasterEnvironmentForCoreCoprocessors extends MasterEnvironment +125 implements HasMasterServices { +126 private final MasterServices masterServices; +127 +128 public MasterEnvironmentForCoreCoprocessors(final MasterCoprocessor impl, final int priority, +129 final int seq, final Configuration conf, final MasterServices services) { +130 super(impl, priority, seq, conf, services); +131 this.masterServices = services; +132 } +133 +134 /** +135 * @return An instance of MasterServices, an object NOT for general user-space Coprocessor +136 * consumption. +137 */ +138 public MasterServices getMasterServices() { +139 return this.masterServices; +140 } +141 } +142 +143 private MasterServices masterServices; +144 +145 public MasterCoprocessorHost(final MasterServices services, final Configuration conf) { +146 super(services); +147 this.conf = conf; +148 this.masterServices = services; +149 // Log the state of coprocessor loading here; should appear only once or +150 // twice in the daemon log, depending on HBase version, because there is +151 // only one MasterCoprocessorHost instance in the master process +152 boolean coprocessorsEnabled = conf.getBoolean(COPROCESSORS_ENABLED_CONF_KEY, +153 DEFAULT_COPROCESSORS_ENABLED); +154 LOG.info("System coprocessor loading is " + (coprocessorsEnabled ? "enabled" : "disabled")); +155 loadSystemCoprocessors(conf, MASTER_COPROCESSOR_CONF_KEY); +156 } +157 +158 @Override +159 public MasterEnvironment createEnvironment(final MasterCoprocessor instance, final int priority, +160 final int seq, final Configuration conf) { +161 // If coprocessor exposes any services, register them. +162 for (Service service : instance.getServices()) { +163 masterServices.registerService(service); +164 } +165 // If a CoreCoprocessor, return a 'richer' environment, one laden with MasterServices. +166 return instance.getClass().isAnnotationPresent(CoreCoprocessor.class)? +167 new MasterEnvironmentForCoreCoprocessors(instance, priority, seq, conf, masterServices): +168 new MasterEnvironment(instance, priority, seq, conf, masterServices); +169 } +170 +171 @Override +172 public MasterCoprocessor checkAndGetInstance(Class<?> implClass) +173 throws InstantiationException, IllegalAccessException { +174 if (MasterCoprocessor.class.isAssignableFrom(implClass)) { +175 return (MasterCoprocessor)implClass.newInstance(); +176 } else if (CoprocessorService.class.isAssignableFrom(implClass)) { +177 // For backward compatibility with old CoprocessorService impl which don't extend +178 // MasterCoprocessor. +179 return new CoprocessorServiceBackwardCompatiblity.MasterCoprocessorService( +180 (CoprocessorService)implClass.newInstance()); +181 } else { +182 LOG.error(implClass.getName() + " is not of type MasterCoprocessor. Check the " +183 + "configuration " + CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY); +184 return null; +185 } +186 } +187 +188 private ObserverGetter<MasterCoprocessor, MasterObserver> masterObserverGetter = +189 MasterCoprocessor::getMasterObserver; +190 +191 abstract class MasterObserverOperation extends +192 ObserverOperationWithoutResult<MasterObserver> { +193 public MasterObserverOperation(){ +194 super(masterObserverGetter); +195 } +196 +197 public MasterObserverOperation(User user) { +198 super(masterObserverGetter, user); +199 } +200 } +201 +202 +203 ////////////////////////////////////////////////////////////////////////////////////////////////// +204 // MasterObserver operations +205 ////////////////////////////////////////////////////////////////////////////////////////////////// +206 +207 +208 public boolean preCreateNamespace(final NamespaceDescriptor ns) throws IOException { +209 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +210 @Override +211 public void call(MasterObserver observer) throws IOException { +212 observer.preCreateNamespace(this, ns); +213 } +214 }); +215 } +216 +217 public void postCreateNamespace(final NamespaceDescriptor ns) throws IOException { +218 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +219 @Override +220 public void call(MasterObserver observer) throws IOException { +221 observer.postCreateNamespace(this, ns); +222 } +223 }); +224 } +225 +226 public boolean preDeleteNamespace(final String namespaceName) throws IOException { +227 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +228 @Override +229 public void call(MasterObserver observer) throws IOException { +230 observer.preDeleteNamespace(this, namespaceName); +231 } +232 }); +233 } +234 +235 public void postDeleteNamespace(final String namespaceName) throws IOException { +236 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +237 @Override +238 public void call(MasterObserver observer) throws IOException { +239 observer.postDeleteNamespace(this, namespaceName); +240 } +241 }); +242 } +243 +244 public boolean preModifyNamespace(final NamespaceDescriptor ns) throws IOException { +245 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +246 @Override +247 public void call(MasterObserver observer) throws IOException { +248 observer.preModifyNamespace(this, ns); +249 } +250 }); +251 } +252 +253 public void postModifyNamespace(final NamespaceDescriptor ns) throws IOException { +254 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +255 @Override +256 public void call(MasterObserver observer) throws IOException { +257 observer.postModifyNamespace(this, ns); +258 } +259 }); +260 } +261 +262 public void preGetNamespaceDescriptor(final String namespaceName) +263 throws IOException { +264 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +265 @Override +266 public void call(MasterObserver observer) throws IOException { +267 observer.preGetNamespaceDescriptor(this, namespaceName); +268 } +269 }); +270 } +271 +272 public void postGetNamespaceDescriptor(final NamespaceDescriptor ns) +273 throws IOException { +274 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +275 @Override +276 public void call(MasterObserver observer) throws IOException { +277 observer.postGetNamespaceDescriptor(this, ns); +278 } +279 }); +280 } +281 +282 public boolean preListNamespaceDescriptors(final List<NamespaceDescriptor> descriptors) +283 throws IOException { +284 return execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +285 @Override +286 public void call(MasterObserver observer) throws IOException { +287 observer.preListNamespaceDescriptors(this, descriptors); +288 } +289 }); +290 } +291 +292 public void postListNamespaceDescriptors(final List<NamespaceDescriptor> descriptors) +293 throws IOException { +294 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +295 @Override +296 public void call(MasterObserver observer) throws IOException { +297 observer.postListNamespaceDescriptors(this, descriptors); +298 } +299 }); +300 } +301 +302 /* Implementation of hooks for invoking MasterObservers */ +303 +304 public void preCreateTable(final TableDescriptor htd, final RegionInfo[] regions) +305 throws IOException { +306 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +307 @Override +308 public void call(MasterObserver observer) throws IOException { +309 observer.preCreateTable(this, htd, regions); +310 } +311 }); +312 } +313 +314 public void postCreateTable(final TableDescriptor htd, final RegionInfo[] regions) +315 throws IOException { +316 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +317 @Override +318 public void call(MasterObserver observer) throws IOException { +319 observer.postCreateTable(this, htd, regions); +320 } +321 }); +322 } +323 +324 public void preCreateTableAction(final TableDescriptor htd, final RegionInfo[] regions, +325 final User user) throws IOException { +326 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { +327 @Override +328 public void call(MasterObserver observer) throws IOException { +329 observer.preCreateTableAction(this, htd, regions); +330 } +331 }); +332 } +333 +334 public void postCompletedCreateTableAction( +335 final TableDescriptor htd, final RegionInfo[] regions, final User user) throws IOException { +336 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { +337 @Override +338 public void call(MasterObserver observer) throws IOException { +339 observer.postCompletedCreateTableAction(this, htd, regions); +340 } +341 }); +342 } +343 +344 public void preDeleteTable(final TableName tableName) throws IOException { +345 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +346 @Override +347 public void call(MasterObserver observer) throws IOException { +348 observer.preDeleteTable(this, tableName); +349 } +350 }); +351 } +352 +353 public void postDeleteTable(final TableName tableName) throws IOException { +354 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +355 @Override +356 public void call(MasterObserver observer) throws IOException { +357 observer.postDeleteTable(this, tableName); +358 } +359 }); +360 } +361 +362 public void preDeleteTableAction(final TableName tableName, final User user) throws IOException { +363 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { +364 @Override +365 public void call(MasterObserver observer) throws IOException { +366 observer.preDeleteTableAction(this, tableName); +367 } +368 }); +369 } +370 +371 public void postCompletedDeleteTableAction(final TableName tableName, final User user) +372 throws IOException { +373 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { +374 @Override +375 public void call(MasterObserver observer) throws IOException { +376 observer.postCompletedDeleteTableAction(this, tableName); +377 } +378 }); +379 } +380 +381 public void preTruncateTable(final TableName tableName) throws IOException { +382 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +383 @Override +384 public void call(MasterObserver observer) throws IOException { +385 observer.preTruncateTable(this, tableName); +386 } +387 }); +388 } +389 +390 public void postTruncateTable(final TableName tableName) throws IOException { +391 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +392 @Override +393 public void call(MasterObserver observer) throws IOException { +394 observer.postTruncateTable(this, tableName); +395 } +396 }); +397 } +398 +399 public void preTruncateTableAction(final TableName tableName, final User user) +400 throws IOException { +401 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { +402 @Override +403 public void call(MasterObserver observer) throws IOException { +404 observer.preTruncateTableAction(this, tableName); +405 } +406 }); +407 } +408 +409 public void postCompletedTruncateTableAction(final TableName tableName, final User user) +410 throws IOException { +411 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { +412 @Override +413 public void call(MasterObserver observer) throws IOException { +414 observer.postCompletedTruncateTableAction(this, tableName); +415 } +416 }); +417 } +418 +419 public void preModifyTable(final TableName tableName, final TableDescriptor htd) +420 throws IOException { +421 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +422 @Override +423 public void call(MasterObserver observer) throws IOException { +424 observer.preModifyTable(this, tableName, htd); +425 } +426 }); +427 } +428 +429 public void postModifyTable(final TableName tableName, final TableDescriptor htd) +430 throws IOException { +431 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation() { +432 @Override +433 public void call(MasterObserver observer) throws IOException { +434 observer.postModifyTable(this, tableName, htd); +435 } +436 }); +437 } +438 +439 public void preModifyTableAction(final TableName tableName, final TableDescriptor htd, +440 final User user) throws IOException { +441 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { +442 @Override +443 public void call(MasterObserver observer) throws IOException { +444 observer.preModifyTableAction(this, tableName, htd); +445 } +446 }); +447 } +448 +449 public void postCompletedModifyTableAction(final TableName tableName, final TableDescriptor htd, +450 final User user) throws IOException { +451 execOperation(coprocEnvironments.isEmpty() ? null : new MasterObserverOperation(user) { +