@Override public MasterEnvironment createEnvironment(final MasterCoprocessor instance, final int priority, final int seq, final Configuration conf) { // If coprocessor exposes any services, register them. for (Service service : instance.getServices()) { masterServices.registerService(service); } // If a CoreCoprocessor, return a 'richer' environment, one laden with MasterServices. return instance.getClass().isAnnotationPresent(CoreCoprocessor.class)? new MasterEnvironmentForCoreCoprocessors(instance, priority, seq, conf, masterServices): new MasterEnvironment(instance, priority, seq, conf, masterServices); }
private boolean execOperation(final CoprocessorOperation ctx) throws IOException { if (ctx == null) return false; boolean bypass = false; List<MasterEnvironment> envs = coprocessors.get(); for (int i = 0; i < envs.size(); i++) { MasterEnvironment env = envs.get(i); if (env.getInstance() instanceof MasterObserver) { ctx.prepare(env); Thread currentThread = Thread.currentThread(); ClassLoader cl = currentThread.getContextClassLoader(); try { currentThread.setContextClassLoader(env.getClassLoader()); ctx.call((MasterObserver)env.getInstance(), ctx); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } finally { currentThread.setContextClassLoader(cl); } bypass |= ctx.shouldBypass(); if (ctx.shouldComplete()) { break; } } ctx.postEnvCall(env); } return bypass; } }
protected synchronized void startExpiredTimestampCalculator(MasterEnvironment ctx) throws IOException { if (themisExpiredTsCalculator != null) { return; } LOG.info("try to start thread to compute the expired timestamp for themis table"); this.zk = ((MasterEnvironment)ctx).getMasterServices().getZooKeeper(); themisExpiredTsZNodePath = getThemisExpiredTsZNodePath(this.zk); connection = HConnectionManager.createConnection(ctx.getConfiguration()); lockCleaner = new ServerLockCleaner(connection, new ThemisCoprocessorClient(connection)); String expiredTsCalculatePeriodStr = ctx.getConfiguration() .get(THEMIS_EXPIRED_TIMESTAMP_CALCULATE_PERIOD_KEY); if (expiredTsCalculatePeriodStr == null) { expiredTsCalculatePeriod = TransactionTTL.readTransactionTTL / 1000; } else { expiredTsCalculatePeriod = Integer.parseInt(expiredTsCalculatePeriodStr); } themisExpiredTsCalculator = new ExpiredTimestampCalculator(expiredTsCalculatePeriod * 1000, ctx.getMasterServices()); Threads.setDaemonThreadRunning(themisExpiredTsCalculator.getThread()); LOG.info("successfully start thread to compute the expired timestamp for themis table, timestampType=" + TransactionTTL.timestampType + ", calculatorPeriod=" + expiredTsCalculatePeriod + ", zkPath=" + themisExpiredTsZNodePath); }
boolean preUnassign(final HRegionInfo regionInfo, final boolean force) throws IOException { boolean bypass = false; ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).preUnassign( ctx, regionInfo, force); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } bypass |= ctx.shouldBypass(); if (ctx.shouldComplete()) { break; } } } return bypass; }
boolean preModifyColumn(byte [] tableName, HColumnDescriptor descriptor) throws IOException { boolean bypass = false; ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).preModifyColumn( ctx, tableName, descriptor); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } bypass |= ctx.shouldBypass(); if (ctx.shouldComplete()) { break; } } } return bypass; }
boolean preMove(final HRegionInfo region, final ServerName srcServer, final ServerName destServer) throws IOException { boolean bypass = false; ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).preMove( ctx, region, srcServer, destServer); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } bypass |= ctx.shouldBypass(); if (ctx.shouldComplete()) { break; } } } return bypass; }
boolean preBalance() throws IOException { boolean bypass = false; ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).preBalance(ctx); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } bypass |= ctx.shouldBypass(); if (ctx.shouldComplete()) { break; } } } return bypass; }
boolean preAssign(final HRegionInfo regionInfo) throws IOException { boolean bypass = false; ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver) env.getInstance()).preAssign(ctx, regionInfo); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } bypass |= ctx.shouldBypass(); if (ctx.shouldComplete()) { break; } } } return bypass; }
boolean preDeleteColumn(final byte [] tableName, final byte [] c) throws IOException { boolean bypass = false; ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).preDeleteColumn(ctx, tableName, c); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } bypass |= ctx.shouldBypass(); if (ctx.shouldComplete()) { break; } } } return bypass; }
boolean preAddColumn(byte [] tableName, HColumnDescriptor column) throws IOException { boolean bypass = false; ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).preAddColumn(ctx, tableName, column); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } bypass |= ctx.shouldBypass(); if (ctx.shouldComplete()) { break; } } } return bypass; }
boolean preBalanceSwitch(final boolean b) throws IOException { boolean balance = b; ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { balance = ((MasterObserver)env.getInstance()).preBalanceSwitch( ctx, balance); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; } } } return balance; }
void postUnassign(final HRegionInfo regionInfo, final boolean force) throws IOException { ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).postUnassign( ctx, regionInfo, force); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; } } } }
void postModifyTable(final byte[] tableName, HTableDescriptor htd) throws IOException { ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).postModifyTable(ctx, tableName, htd); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; } } } }
void preModifyTable(final byte[] tableName, HTableDescriptor htd) throws IOException { ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).preModifyTable(ctx, tableName, htd); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; } } } }
void postModifyColumn(byte [] tableName, HColumnDescriptor descriptor) throws IOException { ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).postModifyColumn( ctx, tableName, descriptor); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; } } } }
void postAddColumn(byte [] tableName, HColumnDescriptor column) throws IOException { ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).postAddColumn(ctx, tableName, column); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; } } } }
public void preSnapshot(final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor) throws IOException { ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).preSnapshot(ctx, snapshot, hTableDescriptor); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; } } } }
void postCreateTable(HTableDescriptor htd, HRegionInfo[] regions) throws IOException { ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).postCreateTable(ctx, htd, regions); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; } } } }
void preCreateTable(HTableDescriptor htd, HRegionInfo[] regions) throws IOException { ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).preCreateTable(ctx, htd, regions); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; } } } }
void postDeleteColumn(final byte [] tableName, final byte [] c) throws IOException { ObserverContext<MasterCoprocessorEnvironment> ctx = null; for (MasterEnvironment env: coprocessors) { if (env.getInstance() instanceof MasterObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); try { ((MasterObserver)env.getInstance()).postDeleteColumn(ctx, tableName, c); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } if (ctx.shouldComplete()) { break; } } } }