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 BF69D200C88 for ; Fri, 2 Jun 2017 17:00:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BE694160BE7; Fri, 2 Jun 2017 15:00:10 +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 4EE93160BDD for ; Fri, 2 Jun 2017 17:00:08 +0200 (CEST) Received: (qmail 85050 invoked by uid 500); 2 Jun 2017 15:00:05 -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 83777 invoked by uid 99); 2 Jun 2017 15:00:04 -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; Fri, 02 Jun 2017 15:00:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 695EDDFF81; Fri, 2 Jun 2017 15:00:03 +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: Fri, 02 Jun 2017 15:00:14 -0000 Message-Id: In-Reply-To: <286a7c4d3f7c4d88b7ebfc3c326dec94@git.apache.org> References: <286a7c4d3f7c4d88b7ebfc3c326dec94@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [13/32] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd. archived-at: Fri, 02 Jun 2017 15:00:10 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/7e7efd3e/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.html b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.html index 8e8e860..e4a10f2 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/regionserver/HRegionServer.html @@ -2208,1514 +2208,1513 @@ 2200 ReportRegionStateTransitionResponse response = 2201 rss.reportRegionStateTransition(null, request); 2202 if (response.hasErrorMessage()) { -2203 LOG.info("Failed transition " + hris[0] -2204 + " to " + code + ": " + response.getErrorMessage()); +2203 LOG.info("TRANSITION FAILED " + request + ": " + response.getErrorMessage()); +2204 // NOTE: Return mid-method!!! 2205 return false; 2206 } 2207 // Log if we had to retry else don't log unless TRACE. We want to 2208 // know if were successful after an attempt showed in logs as failed. 2209 if (tries > 0 || LOG.isTraceEnabled()) { -2210 LOG.trace("TRANSITION REPORTED " + request); +2210 LOG.info("TRANSITION REPORTED " + request); 2211 } -2212 return true; -2213 } catch (ServiceException se) { -2214 IOException ioe = ProtobufUtil.getRemoteException(se); -2215 boolean pause = ioe instanceof ServerNotRunningYetException || -2216 ioe instanceof PleaseHoldException; -2217 if (pause) { -2218 // Do backoff else we flood the Master with requests. -2219 pauseTime = ConnectionUtils.getPauseTime(pauseTime, tries); -2220 } else { -2221 pauseTime = INIT_PAUSE_TIME_MS; // Reset. -2222 } -2223 LOG.info("Failed report of region transition " + -2224 TextFormat.shortDebugString(request) + "; retry (#" + tries + ")" + -2225 (pause? -2226 " after " + pauseTime + "ms delay (Master is coming online...).": -2227 " immediately."), -2228 ioe); -2229 if (pause) Threads.sleep(pauseTime); -2230 tries++; -2231 if (rssStub == rss) { -2232 rssStub = null; -2233 } -2234 } -2235 } -2236 if (LOG.isTraceEnabled()) { -2237 LOG.trace("TRANSITION NOT REPORTED " + request); -2238 } -2239 return false; -2240 } -2241 -2242 /** -2243 * Trigger a flush in the primary region replica if this region is a secondary replica. Does not -2244 * block this thread. See RegionReplicaFlushHandler for details. -2245 */ -2246 void triggerFlushInPrimaryRegion(final HRegion region) { -2247 if (ServerRegionReplicaUtil.isDefaultReplica(region.getRegionInfo())) { -2248 return; -2249 } -2250 if (!ServerRegionReplicaUtil.isRegionReplicaReplicationEnabled(region.conf) || -2251 !ServerRegionReplicaUtil.isRegionReplicaWaitForPrimaryFlushEnabled( -2252 region.conf)) { -2253 region.setReadsEnabled(true); -2254 return; -2255 } -2256 -2257 region.setReadsEnabled(false); // disable reads before marking the region as opened. -2258 // RegionReplicaFlushHandler might reset this. -2259 -2260 // submit it to be handled by one of the handlers so that we do not block OpenRegionHandler -2261 this.service.submit( -2262 new RegionReplicaFlushHandler(this, clusterConnection, -2263 rpcRetryingCallerFactory, rpcControllerFactory, operationTimeout, region)); -2264 } -2265 -2266 @Override -2267 public RpcServerInterface getRpcServer() { -2268 return rpcServices.rpcServer; -2269 } -2270 -2271 @VisibleForTesting -2272 public RSRpcServices getRSRpcServices() { -2273 return rpcServices; -2274 } -2275 -2276 /** -2277 * Cause the server to exit without closing the regions it is serving, the log -2278 * it is using and without notifying the master. Used unit testing and on -2279 * catastrophic events such as HDFS is yanked out from under hbase or we OOME. -2280 * -2281 * @param reason -2282 * the reason we are aborting -2283 * @param cause -2284 * the exception that caused the abort, or null -2285 */ -2286 @Override -2287 public void abort(String reason, Throwable cause) { -2288 String msg = "***** ABORTING region server " + this + ": " + reason + " *****"; -2289 if (cause != null) { -2290 LOG.fatal(msg, cause); -2291 } else { -2292 LOG.fatal(msg); -2293 } -2294 this.abortRequested = true; -2295 // HBASE-4014: show list of coprocessors that were loaded to help debug -2296 // regionserver crashes.Note that we're implicitly using -2297 // java.util.HashSet's toString() method to print the coprocessor names. -2298 LOG.fatal("RegionServer abort: loaded coprocessors are: " + -2299 CoprocessorHost.getLoadedCoprocessors()); -2300 // Try and dump metrics if abort -- might give clue as to how fatal came about.... -2301 try { -2302 LOG.info("Dump of metrics as JSON on abort: " + JSONBean.dumpRegionServerMetrics()); -2303 } catch (MalformedObjectNameException | IOException e) { -2304 LOG.warn("Failed dumping metrics", e); -2305 } -2306 -2307 // Do our best to report our abort to the master, but this may not work -2308 try { -2309 if (cause != null) { -2310 msg += "\nCause:\n" + StringUtils.stringifyException(cause); -2311 } -2312 // Report to the master but only if we have already registered with the master. -2313 if (rssStub != null && this.serverName != null) { -2314 ReportRSFatalErrorRequest.Builder builder = -2315 ReportRSFatalErrorRequest.newBuilder(); -2316 ServerName sn = -2317 ServerName.parseVersionedServerName(this.serverName.getVersionedBytes()); -2318 builder.setServer(ProtobufUtil.toServerName(sn)); -2319 builder.setErrorMessage(msg); -2320 rssStub.reportRSFatalError(null, builder.build()); -2321 } -2322 } catch (Throwable t) { -2323 LOG.warn("Unable to report fatal error to master", t); -2324 } -2325 stop(reason); -2326 } -2327 -2328 /** -2329 * @see HRegionServer#abort(String, Throwable) -2330 */ -2331 public void abort(String reason) { -2332 abort(reason, null); -2333 } -2334 -2335 @Override -2336 public boolean isAborted() { -2337 return this.abortRequested; -2338 } -2339 -2340 /* -2341 * Simulate a kill -9 of this server. Exits w/o closing regions or cleaninup -2342 * logs but it does close socket in case want to bring up server on old -2343 * hostname+port immediately. -2344 */ -2345 @VisibleForTesting -2346 protected void kill() { -2347 this.killed = true; -2348 abort("Simulated kill"); -2349 } -2350 -2351 /** -2352 * Called on stop/abort before closing the cluster connection and meta locator. -2353 */ -2354 protected void sendShutdownInterrupt() { -2355 } -2356 -2357 /** -2358 * Wait on all threads to finish. Presumption is that all closes and stops -2359 * have already been called. -2360 */ -2361 protected void stopServiceThreads() { -2362 // clean up the scheduled chores -2363 if (this.choreService != null) choreService.shutdown(); -2364 if (this.nonceManagerChore != null) nonceManagerChore.cancel(true); -2365 if (this.compactionChecker != null) compactionChecker.cancel(true); -2366 if (this.periodicFlusher != null) periodicFlusher.cancel(true); -2367 if (this.healthCheckChore != null) healthCheckChore.cancel(true); -2368 if (this.storefileRefresher != null) storefileRefresher.cancel(true); -2369 if (this.movedRegionsCleaner != null) movedRegionsCleaner.cancel(true); -2370 if (this.fsUtilizationChore != null) fsUtilizationChore.cancel(true); -2371 -2372 if (this.cacheFlusher != null) { -2373 this.cacheFlusher.join(); -2374 } -2375 -2376 if (this.spanReceiverHost != null) { -2377 this.spanReceiverHost.closeReceivers(); -2378 } -2379 if (this.walRoller != null) { -2380 this.walRoller.close(); -2381 } -2382 if (this.compactSplitThread != null) { -2383 this.compactSplitThread.join(); -2384 } -2385 if (this.service != null) this.service.shutdown(); -2386 if (this.replicationSourceHandler != null && -2387 this.replicationSourceHandler == this.replicationSinkHandler) { -2388 this.replicationSourceHandler.stopReplicationService(); -2389 } else { -2390 if (this.replicationSourceHandler != null) { -2391 this.replicationSourceHandler.stopReplicationService(); -2392 } -2393 if (this.replicationSinkHandler != null) { -2394 this.replicationSinkHandler.stopReplicationService(); -2395 } -2396 } -2397 } -2398 -2399 /** -2400 * @return Return the object that implements the replication -2401 * source service. -2402 */ -2403 @VisibleForTesting -2404 public ReplicationSourceService getReplicationSourceService() { -2405 return replicationSourceHandler; -2406 } -2407 -2408 /** -2409 * @return Return the object that implements the replication -2410 * sink service. -2411 */ -2412 ReplicationSinkService getReplicationSinkService() { -2413 return replicationSinkHandler; -2414 } -2415 -2416 /** -2417 * Get the current master from ZooKeeper and open the RPC connection to it. -2418 * To get a fresh connection, the current rssStub must be null. -2419 * Method will block until a master is available. You can break from this -2420 * block by requesting the server stop. -2421 * -2422 * @return master + port, or null if server has been stopped -2423 */ -2424 @VisibleForTesting -2425 protected synchronized ServerName createRegionServerStatusStub() { -2426 // Create RS stub without refreshing the master node from ZK, use cached data -2427 return createRegionServerStatusStub(false); -2428 } -2429 -2430 /** -2431 * Get the current master from ZooKeeper and open the RPC connection to it. To get a fresh -2432 * connection, the current rssStub must be null. Method will block until a master is available. -2433 * You can break from this block by requesting the server stop. -2434 * @param refresh If true then master address will be read from ZK, otherwise use cached data -2435 * @return master + port, or null if server has been stopped -2436 */ -2437 @VisibleForTesting -2438 protected synchronized ServerName createRegionServerStatusStub(boolean refresh) { -2439 if (rssStub != null) { -2440 return masterAddressTracker.getMasterAddress(); -2441 } -2442 ServerName sn = null; -2443 long previousLogTime = 0; -2444 RegionServerStatusService.BlockingInterface intRssStub = null; -2445 LockService.BlockingInterface intLockStub = null; -2446 boolean interrupted = false; -2447 try { -2448 while (keepLooping()) { -2449 sn = this.masterAddressTracker.getMasterAddress(refresh); -2450 if (sn == null) { -2451 if (!keepLooping()) { -2452 // give up with no connection. -2453 LOG.debug("No master found and cluster is stopped; bailing out"); -2454 return null; -2455 } -2456 if (System.currentTimeMillis() > (previousLogTime + 1000)) { -2457 LOG.debug("No master found; retry"); -2458 previousLogTime = System.currentTimeMillis(); -2459 } -2460 refresh = true; // let's try pull it from ZK directly -2461 if (sleep(200)) { -2462 interrupted = true; -2463 } -2464 continue; -2465 } -2466 -2467 // If we are on the active master, use the shortcut -2468 if (this instanceof HMaster && sn.equals(getServerName())) { -2469 intRssStub = ((HMaster)this).getMasterRpcServices(); -2470 intLockStub = ((HMaster)this).getMasterRpcServices(); -2471 break; -2472 } -2473 try { -2474 BlockingRpcChannel channel = -2475 this.rpcClient.createBlockingRpcChannel(sn, userProvider.getCurrent(), -2476 shortOperationTimeout); -2477 intRssStub = RegionServerStatusService.newBlockingStub(channel); -2478 intLockStub = LockService.newBlockingStub(channel); -2479 break; -2480 } catch (IOException e) { -2481 if (System.currentTimeMillis() > (previousLogTime + 1000)) { -2482 e = e instanceof RemoteException ? -2483 ((RemoteException)e).unwrapRemoteException() : e; -2484 if (e instanceof ServerNotRunningYetException) { -2485 LOG.info("Master isn't available yet, retrying"); -2486 } else { -2487 LOG.warn("Unable to connect to master. Retrying. Error was:", e); -2488 } -2489 previousLogTime = System.currentTimeMillis(); -2490 } -2491 if (sleep(200)) { -2492 interrupted = true; -2493 } -2494 } -2495 } -2496 } finally { -2497 if (interrupted) { -2498 Thread.currentThread().interrupt(); -2499 } -2500 } -2501 this.rssStub = intRssStub; -2502 this.lockStub = intLockStub; -2503 return sn; -2504 } -2505 -2506 /** -2507 * @return True if we should break loop because cluster is going down or -2508 * this server has been stopped or hdfs has gone bad. -2509 */ -2510 private boolean keepLooping() { -2511 return !this.stopped && isClusterUp(); -2512 } -2513 -2514 /* -2515 * Let the master know we're here Run initialization using parameters passed -2516 * us by the master. -2517 * @return A Map of key/value configurations we got from the Master else -2518 * null if we failed to register. -2519 * @throws IOException -2520 */ -2521 private RegionServerStartupResponse reportForDuty() throws IOException { -2522 ServerName masterServerName = createRegionServerStatusStub(true); -2523 if (masterServerName == null) return null; -2524 RegionServerStartupResponse result = null; -2525 try { -2526 rpcServices.requestCount.reset(); -2527 rpcServices.rpcGetRequestCount.reset(); -2528 rpcServices.rpcScanRequestCount.reset(); -2529 rpcServices.rpcMultiRequestCount.reset(); -2530 rpcServices.rpcMutateRequestCount.reset(); -2531 LOG.info("reportForDuty to master=" + masterServerName + " with port=" -2532 + rpcServices.isa.getPort() + ", startcode=" + this.startcode); -2533 long now = EnvironmentEdgeManager.currentTime(); -2534 int port = rpcServices.isa.getPort(); -2535 RegionServerStartupRequest.Builder request = RegionServerStartupRequest.newBuilder(); -2536 if (shouldUseThisHostnameInstead()) { -2537 request.setUseThisHostnameInstead(useThisHostnameInstead); -2538 } -2539 request.setPort(port); -2540 request.setServerStartCode(this.startcode); -2541 request.setServerCurrentTime(now); -2542 result = this.rssStub.regionServerStartup(null, request.build()); -2543 } catch (ServiceException se) { -2544 IOException ioe = ProtobufUtil.getRemoteException(se); -2545 if (ioe instanceof ClockOutOfSyncException) { -2546 LOG.fatal("Master rejected startup because clock is out of sync", ioe); -2547 // Re-throw IOE will cause RS to abort -2548 throw ioe; -2549 } else if (ioe instanceof ServerNotRunningYetException) { -2550 LOG.debug("Master is not running yet"); -2551 } else { -2552 LOG.warn("error telling master we are up", se); -2553 } -2554 rssStub = null; -2555 } -2556 return result; -2557 } -2558 -2559 @Override -2560 public RegionStoreSequenceIds getLastSequenceId(byte[] encodedRegionName) { -2561 try { -2562 GetLastFlushedSequenceIdRequest req = -2563 RequestConverter.buildGetLastFlushedSequenceIdRequest(encodedRegionName); -2564 RegionServerStatusService.BlockingInterface rss = rssStub; -2565 if (rss == null) { // Try to connect one more time -2566 createRegionServerStatusStub(); -2567 rss = rssStub; -2568 if (rss == null) { -2569 // Still no luck, we tried -2570 LOG.warn("Unable to connect to the master to check " + "the last flushed sequence id"); -2571 return RegionStoreSequenceIds.newBuilder().setLastFlushedSequenceId(HConstants.NO_SEQNUM) -2572 .build(); -2573 } -2574 } -2575 GetLastFlushedSequenceIdResponse resp = rss.getLastFlushedSequenceId(null, req); -2576 return RegionStoreSequenceIds.newBuilder() -2577 .setLastFlushedSequenceId(resp.getLastFlushedSequenceId()) -2578 .addAllStoreSequenceId(resp.getStoreLastFlushedSequenceIdList()).build(); -2579 } catch (ServiceException e) { -2580 LOG.warn("Unable to connect to the master to check the last flushed sequence id", e); -2581 return RegionStoreSequenceIds.newBuilder().setLastFlushedSequenceId(HConstants.NO_SEQNUM) -2582 .build(); -2583 } -2584 } -2585 -2586 /** -2587 * Closes all regions. Called on our way out. -2588 * Assumes that its not possible for new regions to be added to onlineRegions -2589 * while this method runs. -2590 */ -2591 protected void closeAllRegions(final boolean abort) { -2592 closeUserRegions(abort); -2593 closeMetaTableRegions(abort); -2594 } -2595 -2596 /** -2597 * Close meta region if we carry it -2598 * @param abort Whether we're running an abort. -2599 */ -2600 void closeMetaTableRegions(final boolean abort) { -2601 Region meta = null; -2602 this.lock.writeLock().lock(); -2603 try { -2604 for (Map.Entry<String, Region> e: onlineRegions.entrySet()) { -2605 HRegionInfo hri = e.getValue().getRegionInfo(); -2606 if (hri.isMetaRegion()) { -2607 meta = e.getValue(); -2608 } -2609 if (meta != null) break; -2610 } -2611 } finally { -2612 this.lock.writeLock().unlock(); -2613 } -2614 if (meta != null) closeRegionIgnoreErrors(meta.getRegionInfo(), abort); -2615 } -2616 -2617 /** -2618 * Schedule closes on all user regions. -2619 * Should be safe calling multiple times because it wont' close regions -2620 * that are already closed or that are closing. -2621 * @param abort Whether we're running an abort. -2622 */ -2623 void closeUserRegions(final boolean abort) { -2624 this.lock.writeLock().lock(); -2625 try { -2626 for (Map.Entry<String, Region> e: this.onlineRegions.entrySet()) { -2627 Region r = e.getValue(); -2628 if (!r.getRegionInfo().isMetaTable() && r.isAvailable()) { -2629 // Don't update zk with this close transition; pass false. -2630 closeRegionIgnoreErrors(r.getRegionInfo(), abort); -2631 } -2632 } -2633 } finally { -2634 this.lock.writeLock().unlock(); -2635 } -2636 } -2637 -2638 /** @return the info server */ -2639 public InfoServer getInfoServer() { -2640 return infoServer; -2641 } -2642 -2643 /** -2644 * @return true if a stop has been requested. -2645 */ -2646 @Override -2647 public boolean isStopped() { -2648 return this.stopped; -2649 } -2650 -2651 @Override -2652 public boolean isStopping() { -2653 return this.stopping; -2654 } -2655 -2656 @Override -2657 public Map<String, Region> getRecoveringRegions() { -2658 return this.recoveringRegions; -2659 } -2660 -2661 /** -2662 * -2663 * @return the configuration -2664 */ -2665 @Override -2666 public Configuration getConfiguration() { -2667 return conf; -2668 } -2669 -2670 /** @return the write lock for the server */ -2671 ReentrantReadWriteLock.WriteLock getWriteLock() { -2672 return lock.writeLock(); -2673 } -2674 -2675 public int getNumberOfOnlineRegions() { -2676 return this.onlineRegions.size(); -2677 } -2678 -2679 boolean isOnlineRegionsEmpty() { -2680 return this.onlineRegions.isEmpty(); -2681 } -2682 -2683 /** -2684 * For tests, web ui and metrics. -2685 * This method will only work if HRegionServer is in the same JVM as client; -2686 * HRegion cannot be serialized to cross an rpc. -2687 */ -2688 public Collection<Region> getOnlineRegionsLocalContext() { -2689 Collection<Region> regions = this.onlineRegions.values(); -2690 return Collections.unmodifiableCollection(regions); -2691 } -2692 -2693 @Override -2694 public void addToOnlineRegions(Region region) { -2695 this.onlineRegions.put(region.getRegionInfo().getEncodedName(), region); -2696 configurationManager.registerObserver(region); -2697 } -2698 -2699 /** -2700 * @return A new Map of online regions sorted by region size with the first entry being the -2701 * biggest. If two regions are the same size, then the last one found wins; i.e. this method -2702 * may NOT return all regions. -2703 */ -2704 SortedMap<Long, Region> getCopyOfOnlineRegionsSortedBySize() { -2705 // we'll sort the regions in reverse -2706 SortedMap<Long, Region> sortedRegions = new TreeMap<>( -2707 new Comparator<Long>() { -2708 @Override -2709 public int compare(Long a, Long b) { -2710 return -1 * a.compareTo(b); -2711 } -2712 }); -2713 // Copy over all regions. Regions are sorted by size with biggest first. -2714 for (Region region : this.onlineRegions.values()) { -2715 sortedRegions.put(region.getMemstoreSize(), region); -2716 } -2717 return sortedRegions; -2718 } -2719 -2720 /** -2721 * @return time stamp in millis of when this region server was started -2722 */ -2723 public long getStartcode() { -2724 return this.startcode; -2725 } -2726 -2727 /** @return reference to FlushRequester */ -2728 @Override -2729 public FlushRequester getFlushRequester() { -2730 return this.cacheFlusher; -2731 } -2732 -2733 /** -2734 * Get the top N most loaded regions this server is serving so we can tell the -2735 * master which regions it can reallocate if we're overloaded. TODO: actually -2736 * calculate which regions are most loaded. (Right now, we're just grabbing -2737 * the first N regions being served regardless of load.) -2738 */ -2739 protected HRegionInfo[] getMostLoadedRegions() { -2740 ArrayList<HRegionInfo> regions = new ArrayList<>(); -2741 for (Region r : onlineRegions.values()) { -2742 if (!r.isAvailable()) { -2743 continue; -2744 } -2745 if (regions.size() < numRegionsToReport) { -2746 regions.add(r.getRegionInfo()); -2747 } else { -2748 break; -2749 } -2750 } -2751 return regions.toArray(new HRegionInfo[regions.size()]); -2752 } -2753 -2754 @Override -2755 public Leases getLeases() { -2756 return leases; -2757 } -2758 -2759 /** -2760 * @return Return the rootDir. -2761 */ -2762 protected Path getRootDir() { -2763 return rootDir; -2764 } -2765 -2766 /** -2767 * @return Return the fs. -2768 */ -2769 @Override -2770 public FileSystem getFileSystem() { -2771 return fs; -2772 } -2773 -2774 /** -2775 * @return Return the walRootDir. -2776 */ -2777 protected Path getWALRootDir() { -2778 return walRootDir; -2779 } -2780 -2781 /** -2782 * @return Return the walFs. -2783 */ -2784 protected FileSystem getWALFileSystem() { -2785 return walFs; -2786 } -2787 -2788 @Override -2789 public String toString() { -2790 return getServerName().toString(); -2791 } -2792 -2793 /** -2794 * Interval at which threads should run -2795 * -2796 * @return the interval -2797 */ -2798 public int getThreadWakeFrequency() { -2799 return threadWakeFrequency; -2800 } -2801 -2802 @Override -2803 public ZooKeeperWatcher getZooKeeper() { -2804 return zooKeeper; -2805 } -2806 -2807 @Override -2808 public BaseCoordinatedStateManager getCoordinatedStateManager() { -2809 return csm; -2810 } -2811 -2812 @Override -2813 public ServerName getServerName() { -2814 return serverName; -2815 } -2816 -2817 @Override -2818 public CompactionRequestor getCompactionRequester() { -2819 return this.compactSplitThread; -2820 } -2821 -2822 public RegionServerCoprocessorHost getRegionServerCoprocessorHost(){ -2823 return this.rsHost; -2824 } -2825 -2826 @Override -2827 public ConcurrentMap<byte[], Boolean> getRegionsInTransitionInRS() { -2828 return this.regionsInTransitionInRS; -2829 } -2830 -2831 @Override -2832 public ExecutorService getExecutorService() { -2833 return service; -2834 } -2835 -2836 @Override -2837 public ChoreService getChoreService() { -2838 return choreService; -2839 } -2840 -2841 @Override -2842 public RegionServerRpcQuotaManager getRegionServerRpcQuotaManager() { -2843 return rsQuotaManager; -2844 } -2845 -2846 // -2847 // Main program and support routines -2848 // -2849 -2850 /** -2851 * Load the replication service objects, if any -2852 */ -2853 static private void createNewReplicationInstance(Configuration conf, -2854 HRegionServer server, FileSystem walFs, Path walDir, Path oldWALDir) throws IOException{ -2855 -2856 if ((server instanceof HMaster) && -2857 (!BaseLoadBalancer.userTablesOnMaster(conf))) { -2858 return; -2859 } -2860 -2861 // read in the name of the source replication class from the config file. -2862 String sourceClassname = conf.get(HConstants.REPLICATION_SOURCE_SERVICE_CLASSNAME, -2863 HConstants.REPLICATION_SERVICE_CLASSNAME_DEFAULT); -2864 -2865 // read in the name of the sink replication class from the config file. -2866 String sinkClassname = conf.get(HConstants.REPLICATION_SINK_SERVICE_CLASSNAME, -2867 HConstants.REPLICATION_SERVICE_CLASSNAME_DEFAULT); -2868 -2869 // If both the sink and the source class names are the same, then instantiate -2870 // only one object. -2871 if (sourceClassname.equals(sinkClassname)) { -2872 server.replicationSourceHandler = (ReplicationSourceService) -2873 newReplicationInstance(sourceClassname, -2874 conf, server, walFs, walDir, oldWALDir); -2875 server.replicationSinkHandler = (ReplicationSinkService) -2876 server.replicationSourceHandler; -2877 } else { -2878 server.replicationSourceHandler = (ReplicationSourceService) -2879 newReplicationInstance(sourceClassname, -2880 conf, server, walFs, walDir, oldWALDir); -2881 server.replicationSinkHandler = (ReplicationSinkService) -2882 newReplicationInstance(sinkClassname, -2883 conf, server, walFs, walDir, oldWALDir); -2884 } -2885 } -2886 -2887 static private ReplicationService newReplicationInstance(String classname, -2888 Configuration conf, HRegionServer server, FileSystem walFs, Path logDir, -2889 Path oldLogDir) throws IOException{ -2890 -2891 Class<?> clazz = null; -2892 try { -2893 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); -2894 clazz = Class.forName(classname, true, classLoader); -2895 } catch (java.lang.ClassNotFoundException nfe) { -2896 throw new IOException("Could not find class for " + classname); -2897 } -2898 -2899 // create an instance of the replication object. -2900 ReplicationService service = (ReplicationService) -2901 ReflectionUtils.newInstance(clazz, conf); -2902 service.initialize(server, walFs, logDir, oldLogDir); -2903 return service; -2904 } -2905 -2906 /** -2907 * Utility for constructing an instance of the passed HRegionServer class. -2908 * -2909 * @param regionServerClass -2910 * @param conf2 -2911 * @return HRegionServer instance. -2912 */ -2913 public static HRegionServer constructRegionServer( -2914 Class<? extends HRegionServer> regionServerClass, -2915 final Configuration conf2, CoordinatedStateManager cp) { -2916 try { -2917 Constructor<? extends HRegionServer> c = regionServerClass -2918 .getConstructor(Configuration.class, CoordinatedStateManager.class); -2919 return c.newInstance(conf2, cp); -2920 } catch (Exception e) { -2921 throw new RuntimeException("Failed construction of " + "Regionserver: " -2922 + regionServerClass.toString(), e); -2923 } -2924 } -2925 -2926 /** -2927 * @see org.apache.hadoop.hbase.regionserver.HRegionServerCommandLine -2928 */ -2929 public static void main(String[] args) throws Exception { -2930 LOG.info("STARTING service '" + HRegionServer.class.getSimpleName()); -2931 VersionInfo.logVersion(); -2932 Configuration conf = HBaseConfiguration.create(); -2933 @SuppressWarnings("unchecked") -2934 Class<? extends HRegionServer> regionServerClass = (Class<? extends HRegionServer>) conf -2935 .getClass(HConstants.REGION_SERVER_IMPL, HRegionServer.class); -2936 -2937 new HRegionServerCommandLine(regionServerClass).doMain(args); -2938 } -2939 -2940 /** -2941 * Gets the online regions of the specified table. -2942 * This method looks at the in-memory onlineRegions. It does not go to <code>hbase:meta</code>. -2943 * Only returns <em>online</em> regions. If a region on this table has been -2944 * closed during a disable, etc., it will not be included in the returned list. -2945 * So, the returned list may not necessarily be ALL regions in this table, its -2946 * all the ONLINE regions in the table. -2947 * @param tableName -2948 * @return Online regions from <code>tableName</code> -2949 */ -2950 @Override -2951 public List<Region> getOnlineRegions(TableName tableName) { -2952 List<Region> tableRegions = new ArrayList<>(); -2953 synchronized (this.onlineRegions) { -2954 for (Region region: this.onlineRegions.values()) { -2955 HRegionInfo regionInfo = region.getRegionInfo(); -2956 if(regionInfo.getTable().equals(tableName)) { -2957 tableRegions.add(region); -2958 } -2959 } -2960 } -2961 return tableRegions; -2962 } -2963 -2964 @Override -2965 public List<Region> getOnlineRegions() { -2966 List<Region> allRegions = new ArrayList<>(); -2967 synchronized (this.onlineRegions) { -2968 // Return a clone copy of the onlineRegions -2969 allRegions.addAll(onlineRegions.values()); -2970 } -2971 return allRegions; -2972 } -2973 /** -2974 * Gets the online tables in this RS. -2975 * This method looks at the in-memory onlineRegions. -2976 * @return all the online tables in this RS -2977 */ -2978 @Override -2979 public Set<TableName> getOnlineTables() { -2980 Set<TableName> tables = new HashSet<>(); -2981 synchronized (this.onlineRegions) { -2982 for (Region region: this.onlineRegions.values()) { -2983 tables.add(region.getTableDesc().getTableName()); -2984 } -2985 } -2986 return tables; -2987 } -2988 -2989 // used by org/apache/hbase/tmpl/regionserver/RSStatusTmpl.jamon (HBASE-4070). -2990 public String[] getRegionServerCoprocessors() { -2991 TreeSet<String> coprocessors = new TreeSet<>(); -2992 try { -2993 coprocessors.addAll(getWAL(null).getCoprocessorHost().getCoprocessors()); -2994 } catch (IOException exception) { -2995 LOG.warn("Exception attempting to fetch wal coprocessor information for the common wal; " + -2996 "skipping."); -2997 LOG.debug("Exception details for failure to fetch wal coprocessor information.", exception); -2998 } -2999 Collection<Region> regions = getOnlineRegionsLocalContext(); -3000 for (Region region: regions) { -3001 coprocessors.addAll(region.getCoprocessorHost().getCoprocessors()); -3002 try { -3003 coprocessors.addAll(getWAL(region.getRegionInfo()).getCoprocessorHost().getCoprocessors()); -3004 } catch (IOException exception) { -3005 LOG.warn("Exception attempting to fetch wal coprocessor information for region " + region + -3006 "; skipping."); -3007 LOG.debug("Exception details for failure to fetch wal coprocessor information.", exception); -3008 } -3009 } -3010 coprocessors.addAll(rsHost.getCoprocessors()); -3011 return coprocessors.toArray(new String[coprocessors.size()]); -3012 } -3013 -3014 /** -3015 * Try to close the region, logs a warning on failure but continues. -3016 * @param region Region to close -3017 */ -3018 private void closeRegionIgnoreErrors(HRegionInfo region, final boolean abort) { -3019 try { -3020 if (!closeRegion(region.getEncodedName(), abort, null)) { -3021 LOG.warn("Failed to close " + region.getRegionNameAsString() + -3022 " - ignoring and continuing"); -3023 } -3024 } catch (IOException e) { -3025 LOG.warn("Failed to close " + region.getRegionNameAsString() + -3026 " - ignoring and continuing", e); -3027 } -3028 } -3029 -3030 /** -3031 * Close asynchronously a region, can be called from the master or internally by the regionserver -3032 * when stopping. If called from the master, the region will update the znode status. -3033 * -3034 * <p> -3035 * If an opening was in progress, this method will cancel it, but will not start a new close. The -3036 * coprocessors are not called in this case. A NotServingRegionException exception is thrown. -3037 * </p> -3038 -3039 * <p> -3040 * If a close was in progress, this new request will be ignored, and an exception thrown. -3041 * </p> -3042 * -3043 * @param encodedName Region to close -3044 * @param abort True if we are aborting -3045 * @return True if closed a region. -3046 * @throws NotServingRegionException if the region is not online -3047 */ -3048 protected boolean closeRegion(String encodedName, final boolean abort, final ServerName sn) -3049 throws NotServingRegionException { -3050 //Check for permissions to close. -3051 Region actualRegion = this.getFromOnlineRegions(encodedName); -3052 // Can be null if we're calling close on a region that's not online -3053 if ((actualRegion != null) && (actualRegion.getCoprocessorHost() != null)) { -3054 try { -3055 actualRegion.getCoprocessorHost().preClose(false); -3056 } catch (IOException exp) { -3057 LOG.warn("Unable to close region: the coprocessor launched an error ", exp); -3058 return false; -3059 } -3060 } -3061 -3062 final Boolean previous = this.regionsInTransitionInRS.putIfAbsent(encodedName.getBytes(), -3063 Boolean.FALSE); -3064 -3065 if (Boolean.TRUE.equals(previous)) { -3066 LOG.info("Received CLOSE for the region:" + encodedName + " , which we are already " + -3067 "trying to OPEN. Cancelling OPENING."); -3068 if (!regionsInTransitionInRS.replace(encodedName.getBytes(), previous, Boolean.FALSE)){ -3069 // The replace failed. That should be an exceptional case, but theoretically it can happen. -3070 // We're going to try to do a standard close then. -3071 LOG.warn("The opening for region " + encodedName + " was done before we could cancel it." + -3072 " Doing a standard close now"); -3073 return closeRegion(encodedName, abort, sn); -3074 } -3075 // Let's get the region from the online region list again -3076 actualRegion = this.getFromOnlineRegions(encodedName); -3077 if (actualRegion == null) { // If already online, we still need to close it. -3078 LOG.info("The opening previously in progress has been cancelled by a CLOSE request."); -3079 // The master deletes the znode when it receives this exception. -3080 throw new NotServingRegionException("The region " + encodedName + -3081 " was opening but not yet served. Opening is cancelled."); -3082 } -3083 } else if (Boolean.FALSE.equals(previous)) { -3084 LOG.info("Received CLOSE for the region: " + encodedName + -3085 ", which we are already trying to CLOSE, but not completed yet"); -3086 return true; -3087 } -3088 -3089 if (actualRegion == null) { -3090 LOG.debug("Received CLOSE for a region which is not online, and we're not opening."); -3091 this.regionsInTransitionInRS.remove(encodedName.getBytes()); -3092 // The master deletes the znode when it receives this exception. -3093 throw new NotServingRegionException("The region " + encodedName + -3094 " is not online, and is not opening."); -3095 } -3096 -3097 CloseRegionHandler crh; -3098 final HRegionInfo hri = actualRegion.getRegionInfo(); -