/** * Split a region on the region server. * * @param controller the RPC controller * @param request the request * @throws ServiceException */ @Override @QosPriority(priority=HConstants.HIGH_QOS) public SplitRegionResponse splitRegion(final RpcController controller, final SplitRegionRequest request) throws ServiceException { try { checkOpen(); requestCount.increment(); HRegion region = getRegion(request.getRegion()); region.startRegionOperation(Operation.SPLIT_REGION); LOG.info("Splitting " + region.getRegionNameAsString()); region.flushcache(); byte[] splitPoint = null; if (request.hasSplitPoint()) { splitPoint = request.getSplitPoint().toByteArray(); } region.forceSplit(splitPoint); compactSplitThread.requestSplit(region, region.checkSplit()); return SplitRegionResponse.newBuilder().build(); } catch (IOException ie) { throw new ServiceException(ie); } }
/** * Merge regions on the region server. * * @param controller the RPC controller * @param request the request * @return merge regions response * @throws ServiceException */ @Override @QosPriority(priority = HConstants.HIGH_QOS) public MergeRegionsResponse mergeRegions(final RpcController controller, final MergeRegionsRequest request) throws ServiceException { try { checkOpen(); requestCount.increment(); HRegion regionA = getRegion(request.getRegionA()); HRegion regionB = getRegion(request.getRegionB()); boolean forcible = request.getForcible(); regionA.startRegionOperation(Operation.MERGE_REGION); regionB.startRegionOperation(Operation.MERGE_REGION); LOG.info("Receiving merging request for " + regionA + ", " + regionB + ",forcible=" + forcible); regionA.flushcache(); regionB.flushcache(); compactSplitThread.requestRegionsMerge(regionA, regionB, forcible); return MergeRegionsResponse.newBuilder().build(); } catch (IOException ie) { throw new ServiceException(ie); } }
public void postStartRegionOperation(final Operation op) throws IOException { ObserverContext<RegionCoprocessorEnvironment> ctx = null; for (RegionEnvironment env : coprocessors) { if (env.getInstance() instanceof RegionObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); Thread currentThread = Thread.currentThread(); ClassLoader cl = currentThread.getContextClassLoader(); try { currentThread.setContextClassLoader(env.getClassLoader()); ((RegionObserver) env.getInstance()).postStartRegionOperation(ctx, op); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } finally { currentThread.setContextClassLoader(cl); } if (ctx.shouldComplete()) { break; } } } }
public void postCloseRegionOperation(final Operation op) throws IOException { ObserverContext<RegionCoprocessorEnvironment> ctx = null; for (RegionEnvironment env : coprocessors) { if (env.getInstance() instanceof RegionObserver) { ctx = ObserverContext.createAndPrepare(env, ctx); Thread currentThread = Thread.currentThread(); ClassLoader cl = currentThread.getContextClassLoader(); try { currentThread.setContextClassLoader(env.getClassLoader()); ((RegionObserver) env.getInstance()).postCloseRegionOperation(ctx, op); } catch (Throwable e) { handleCoprocessorThrowable(env, e); } finally { currentThread.setContextClassLoader(cl); } if (ctx.shouldComplete()) { break; } } } }
@Override public void postStartRegionOperation(ObserverContext<RegionCoprocessorEnvironment> e, Operation op) throws IOException { if (op.equals(Operation.BATCH_MUTATE)) { HRegionServer rs = (HRegionServer) e.getEnvironment().getRegionServerServices(); HRegion userRegion = e.getEnvironment().getRegion(); HTableDescriptor userTableDesc = userRegion.getTableDesc(); String tableName = userTableDesc.getNameAsString(); if (isNotIndexedTableDescriptor(userTableDesc)) { return; } if (!isValidIndexMutation(userTableDesc)) { return; } acquireLockOnIndexRegion(tableName, userRegion, rs, op); } }
/** * Merge regions on the region server. * * @param controller the RPC controller * @param request the request * @return merge regions response * @throws ServiceException */ @Override @QosPriority(priority = HConstants.HIGH_QOS) public MergeRegionsResponse mergeRegions(final RpcController controller, final MergeRegionsRequest request) throws ServiceException { try { checkOpen(); requestCount.increment(); HRegion regionA = getRegion(request.getRegionA()); HRegion regionB = getRegion(request.getRegionB()); boolean forcible = request.getForcible(); regionA.startRegionOperation(Operation.MERGE_REGION); regionB.startRegionOperation(Operation.MERGE_REGION); LOG.info("Receiving merging request for " + regionA + ", " + regionB + ",forcible=" + forcible); regionA.flushcache(); regionB.flushcache(); regionServer.compactSplitThread.requestRegionsMerge(regionA, regionB, forcible); return MergeRegionsResponse.newBuilder().build(); } catch (IOException ie) { throw new ServiceException(ie); } }
/** * Split a region on the region server. * * @param controller the RPC controller * @param request the request * @throws ServiceException */ @Override @QosPriority(priority = HConstants.ADMIN_QOS) public SplitRegionResponse splitRegion(final RpcController controller, final SplitRegionRequest request) throws ServiceException { try { checkOpen(); requestCount.increment(); HRegion region = getRegion(request.getRegion()); region.startRegionOperation(Operation.SPLIT_REGION); LOG.info("Splitting " + region.getRegionNameAsString()); long startTime = EnvironmentEdgeManager.currentTime(); HRegion.FlushResult flushResult = region.flushcache(); if (flushResult.isFlushSucceeded()) { long endTime = EnvironmentEdgeManager.currentTime(); regionServer.metricsRegionServer.updateFlushTime(endTime - startTime); } byte[] splitPoint = null; if (request.hasSplitPoint()) { splitPoint = request.getSplitPoint().toByteArray(); } region.forceSplit(splitPoint); regionServer.compactSplitThread.requestSplit(region, region.checkSplit()); return SplitRegionResponse.newBuilder().build(); } catch (IOException ie) { throw new ServiceException(ie); } }
public void postStartRegionOperation(final Operation op) throws IOException { execOperation(coprocessors.isEmpty() ? null : new RegionOperation() { @Override public void call(RegionObserver oserver, ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException { oserver.postStartRegionOperation(ctx, op); } }); }
public void postCloseRegionOperation(final Operation op) throws IOException { execOperation(coprocessors.isEmpty() ? null : new RegionOperation() { @Override public void call(RegionObserver oserver, ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException { oserver.postCloseRegionOperation(ctx, op); } }); }
@Override public void postCloseRegionOperation(final ObserverContext<RegionCoprocessorEnvironment> ctx, Operation op) throws IOException { if (ctPostStartRegionOperation.get() > 0) { ctPostCloseRegionOperation.incrementAndGet(); } }
@Override public void postCloseRegionOperation(ObserverContext<RegionCoprocessorEnvironment> ctx, Operation op) throws IOException { if (op.equals(Operation.BATCH_MUTATE)) { HRegionServer rs = (HRegionServer) ctx.getEnvironment().getRegionServerServices(); HRegion userRegion = ctx.getEnvironment().getRegion(); HTableDescriptor userTableDesc = userRegion.getTableDesc(); String tableName = userTableDesc.getNameAsString(); if (isNotIndexedTableDescriptor(userTableDesc)) { return; } if (!isValidIndexMutation(userTableDesc)) { // Ideally need not release any lock because in the preStartRegionOperationHook we would not // have // acquired // any lock on the index region return; } HRegion indexRegion = getIndexTableRegion(tableName, userRegion, rs); // This check for isClosed and isClosing is needed because we should not unlock // when the index region lock would have already been released before throwing NSRE // TODO : What is the scenario that i may get an IllegalMonitorStateException if (!indexRegion.isClosed() || !indexRegion.isClosing()) { indexRegion.closeRegionOperation(); } } }
/** * Split a region on the region server. * * @param controller the RPC controller * @param request the request * @throws ServiceException */ @Override @QosPriority(priority=HConstants.HIGH_QOS) public SplitRegionResponse splitRegion(final RpcController controller, final SplitRegionRequest request) throws ServiceException { // Shen Li: add a reuseFile field to request try { checkOpen(); requestCount.increment(); HRegion region = getRegion(request.getRegion()); boolean reuseFile = request.getReuseFile(); // TODO: should not ask client to provide dest hostnames // do it in SplitRequest region.startRegionOperation(Operation.SPLIT_REGION); LOG.info("Shen Li: Splitting " + region.getRegionNameAsString()); region.flushcache(); byte[] splitPoint = null; if (request.hasSplitPoint()) { splitPoint = request.getSplitPoint().toByteArray(); } region.forceSplit(splitPoint); regionServer.compactSplitThread .requestSplit(region, region.checkSplit(), reuseFile); return SplitRegionResponse.newBuilder().build(); } catch (IOException ie) { throw new ServiceException(ie); } }
@Override public void postStartRegionOperation(final ObserverContext<RegionCoprocessorEnvironment> ctx, Operation op) throws IOException { }
@Override public void postCloseRegionOperation(final ObserverContext<RegionCoprocessorEnvironment> ctx, Operation op) throws IOException { }
/** * Compact a region on the region server. * * @param controller the RPC controller * @param request the request * @throws ServiceException */ @Override @QosPriority(priority = HConstants.ADMIN_QOS) public CompactRegionResponse compactRegion(final RpcController controller, final CompactRegionRequest request) throws ServiceException { try { checkOpen(); requestCount.increment(); HRegion region = getRegion(request.getRegion()); region.startRegionOperation(Operation.COMPACT_REGION); LOG.info("Compacting " + region.getRegionNameAsString()); boolean major = false; byte[] family = null; Store store = null; if (request.hasFamily()) { family = request.getFamily().toByteArray(); store = region.getStore(family); if (store == null) { throw new ServiceException(new IOException("column family " + Bytes.toString(family) + " does not exist in region " + region.getRegionNameAsString())); } } if (request.hasMajor()) { major = request.getMajor(); } if (major) { if (family != null) { store.triggerMajorCompaction(); } else { region.triggerMajorCompaction(); } } String familyLogMsg = (family != null) ? " for column family: " + Bytes.toString(family) : ""; if (LOG.isTraceEnabled()) { LOG.trace("User-triggered compaction requested for region " + region.getRegionNameAsString() + familyLogMsg); } String log = "User-triggered " + (major ? "major " : "") + "compaction" + familyLogMsg; if (family != null) { regionServer.compactSplitThread.requestCompaction(region, store, log, Store.PRIORITY_USER, null); } else { regionServer.compactSplitThread.requestCompaction(region, log, Store.PRIORITY_USER, null); } return CompactRegionResponse.newBuilder().build(); } catch (IOException ie) { throw new ServiceException(ie); } }
@Override public void postStartRegionOperation(final ObserverContext<RegionCoprocessorEnvironment> ctx, Operation op) throws IOException { ctPostStartRegionOperation.incrementAndGet(); }
/** * Compact a region on the region server. * * @param controller the RPC controller * @param request the request * @throws ServiceException */ @Override @QosPriority(priority=HConstants.HIGH_QOS) public CompactRegionResponse compactRegion(final RpcController controller, final CompactRegionRequest request) throws ServiceException { try { checkOpen(); requestCount.increment(); HRegion region = getRegion(request.getRegion()); region.startRegionOperation(Operation.COMPACT_REGION); LOG.info("Compacting " + region.getRegionNameAsString()); boolean major = false; byte [] family = null; Store store = null; if (request.hasFamily()) { family = request.getFamily().toByteArray(); store = region.getStore(family); if (store == null) { throw new ServiceException(new IOException("column family " + Bytes.toString(family) + " does not exist in region " + region.getRegionNameAsString())); } } if (request.hasMajor()) { major = request.getMajor(); } if (major) { if (family != null) { store.triggerMajorCompaction(); } else { region.triggerMajorCompaction(); } } String familyLogMsg = (family != null)?" for column family: " + Bytes.toString(family):""; LOG.trace("User-triggered compaction requested for region " + region.getRegionNameAsString() + familyLogMsg); String log = "User-triggered " + (major ? "major " : "") + "compaction" + familyLogMsg; if(family != null) { compactSplitThread.requestCompaction(region, store, log, Store.PRIORITY_USER, null); } else { compactSplitThread.requestCompaction(region, log, Store.PRIORITY_USER, null); } return CompactRegionResponse.newBuilder().build(); } catch (IOException ie) { throw new ServiceException(ie); } }
private void acquireLockOnIndexRegion(String tableName, HRegion userRegion, HRegionServer rs, Operation op) throws IOException { HRegion indexRegion = getIndexTableRegion(tableName, userRegion, rs); indexRegion.checkResources(); indexRegion.startRegionOperation(op); }
/** * Compact a region on the region server. * * @param controller the RPC controller * @param request the request * @throws ServiceException */ @Override @QosPriority(priority=HConstants.HIGH_QOS) public CompactRegionResponse compactRegion(final RpcController controller, final CompactRegionRequest request) throws ServiceException { try { checkOpen(); requestCount.increment(); HRegion region = getRegion(request.getRegion()); region.startRegionOperation(Operation.COMPACT_REGION); LOG.info("Compacting " + region.getRegionNameAsString()); boolean major = false; byte [] family = null; Store store = null; if (request.hasFamily()) { family = request.getFamily().toByteArray(); store = region.getStore(family); if (store == null) { throw new ServiceException(new IOException("column family " + Bytes.toString(family) + " does not exist in region " + region.getRegionNameAsString())); } } if (request.hasMajor()) { major = request.getMajor(); } if (major) { if (family != null) { store.triggerMajorCompaction(); } else { region.triggerMajorCompaction(); } } String familyLogMsg = (family != null)?" for column family: " + Bytes.toString(family):""; if (LOG.isTraceEnabled()) { LOG.trace("User-triggered compaction requested for region " + region.getRegionNameAsString() + familyLogMsg); } String log = "User-triggered " + (major ? "major " : "") + "compaction" + familyLogMsg; if(family != null) { regionServer.compactSplitThread.requestCompaction(region, store, log, Store.PRIORITY_USER, null); } else { regionServer.compactSplitThread.requestCompaction(region, log, Store.PRIORITY_USER, null); } return CompactRegionResponse.newBuilder().build(); } catch (IOException ie) { throw new ServiceException(ie); } }
/** * This will be called for region operations where read lock is acquired in * {@link HRegion#startRegionOperation()}. * @param ctx * @param operation The operation is about to be taken on the region * @throws IOException */ void postStartRegionOperation(final ObserverContext<RegionCoprocessorEnvironment> ctx, Operation operation) throws IOException;
/** * Called after releasing read lock in {@link HRegion#closeRegionOperation(Operation)}. * @param ctx * @param operation * @throws IOException */ void postCloseRegionOperation(final ObserverContext<RegionCoprocessorEnvironment> ctx, Operation operation) throws IOException;