Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6508B18DF9 for ; Mon, 2 Nov 2015 03:51:33 +0000 (UTC) Received: (qmail 15415 invoked by uid 500); 2 Nov 2015 03:51:33 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 15383 invoked by uid 500); 2 Nov 2015 03:51:33 -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 15374 invoked by uid 99); 2 Nov 2015 03:51:33 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Nov 2015 03:51:33 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id A1568C22E6 for ; Mon, 2 Nov 2015 03:51:32 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.99 X-Spam-Level: X-Spam-Status: No, score=0.99 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id OMiMScrgExOt for ; Mon, 2 Nov 2015 03:51:27 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTP id 952B4444D5 for ; Mon, 2 Nov 2015 03:51:11 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 26D79E0FFF for ; Mon, 2 Nov 2015 03:51:10 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 25FF43A019A for ; Mon, 2 Nov 2015 03:51:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1711891 [24/50] - in /hbase/hbase.apache.org/trunk: ./ apidocs/ apidocs/org/apache/hadoop/hbase/ apidocs/org/apache/hadoop/hbase/class-use/ apidocs/org/apache/hadoop/hbase/client/ apidocs/org/apache/hadoop/hbase/client/class-use/ apidocs/o... Date: Mon, 02 Nov 2015 03:51:05 -0000 To: commits@hbase.apache.org From: misty@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151102035110.25FF43A019A@svn01-us-west.apache.org> Modified: hbase/hbase.apache.org/trunk/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.ProcedureFuture.html URL: http://svn.apache.org/viewvc/hbase/hbase.apache.org/trunk/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.ProcedureFuture.html?rev=1711891&r1=1711890&r2=1711891&view=diff ============================================================================== --- hbase/hbase.apache.org/trunk/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.ProcedureFuture.html (original) +++ hbase/hbase.apache.org/trunk/devapidocs/src-html/org/apache/hadoop/hbase/client/HBaseAdmin.ProcedureFuture.html Mon Nov 2 03:51:02 2015 @@ -2099,2804 +2099,2806 @@ 2091 compact(master, getMobRegionInfo(tableName), major, columnFamily); 2092 break; 2093 case NORMAL: -2094 ZooKeeperWatcher zookeeper = null; -2095 try { -2096 checkTableExists(tableName); -2097 zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), -2098 new ThrowableAbortable()); -2099 List<Pair<HRegionInfo, ServerName>> pairs; -2100 if (TableName.META_TABLE_NAME.equals(tableName)) { -2101 pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper); -2102 } else { -2103 pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName); -2104 } -2105 for (Pair<HRegionInfo, ServerName> pair: pairs) { -2106 if (pair.getFirst().isOffline()) continue; -2107 if (pair.getSecond() == null) continue; -2108 try { -2109 compact(pair.getSecond(), pair.getFirst(), major, columnFamily); -2110 } catch (NotServingRegionException e) { -2111 if (LOG.isDebugEnabled()) { -2112 LOG.debug("Trying to" + (major ? " major" : "") + " compact " + -2113 pair.getFirst() + ": " + -2114 StringUtils.stringifyException(e)); -2115 } -2116 } -2117 } -2118 } finally { -2119 if (zookeeper != null) { -2120 zookeeper.close(); -2121 } -2122 } -2123 break; -2124 } -2125 } -2126 -2127 /** -2128 * Compact an individual region. -2129 * Asynchronous operation. -2130 * -2131 * @param regionName region to compact -2132 * @param columnFamily column family within a table or region -2133 * @param major True if we are to do a major compaction. -2134 * @throws IOException if a remote or network exception occurs -2135 * @throws InterruptedException -2136 */ -2137 private void compactRegion(final byte[] regionName, final byte[] columnFamily,final boolean major) -2138 throws IOException { -2139 Pair<HRegionInfo, ServerName> regionServerPair = getRegion(regionName); -2140 if (regionServerPair == null) { -2141 throw new IllegalArgumentException("Invalid region: " + Bytes.toStringBinary(regionName)); -2142 } -2143 if (regionServerPair.getSecond() == null) { -2144 throw new NoServerForRegionException(Bytes.toStringBinary(regionName)); -2145 } -2146 compact(regionServerPair.getSecond(), regionServerPair.getFirst(), major, columnFamily); -2147 } -2148 -2149 private void compact(final ServerName sn, final HRegionInfo hri, -2150 final boolean major, final byte [] family) -2151 throws IOException { -2152 AdminService.BlockingInterface admin = this.connection.getAdmin(sn); -2153 CompactRegionRequest request = -2154 RequestConverter.buildCompactRegionRequest(hri.getRegionName(), major, family); -2155 try { -2156 admin.compactRegion(null, request); -2157 } catch (ServiceException se) { -2158 throw ProtobufUtil.getRemoteException(se); -2159 } -2160 } -2161 -2162 /** -2163 * Move the region <code>r</code> to <code>dest</code>. -2164 * @param encodedRegionName The encoded region name; i.e. the hash that makes -2165 * up the region name suffix: e.g. if regionname is -2166 * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>, -2167 * then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>. -2168 * @param destServerName The servername of the destination regionserver. If -2169 * passed the empty byte array we'll assign to a random server. A server name -2170 * is made of host, port and startcode. Here is an example: -2171 * <code> host187.example.com,60020,1289493121758</code> -2172 * @throws UnknownRegionException Thrown if we can't find a region named -2173 * <code>encodedRegionName</code> -2174 */ -2175 @Override -2176 public void move(final byte [] encodedRegionName, final byte [] destServerName) -2177 throws IOException { -2178 -2179 executeCallable(new MasterCallable<Void>(getConnection()) { -2180 @Override -2181 public Void call(int callTimeout) throws ServiceException { -2182 try { -2183 MoveRegionRequest request = -2184 RequestConverter.buildMoveRegionRequest(encodedRegionName, destServerName); -2185 master.moveRegion(null, request); -2186 } catch (DeserializationException de) { -2187 LOG.error("Could not parse destination server name: " + de); -2188 throw new ServiceException(new DoNotRetryIOException(de)); -2189 } -2190 return null; -2191 } -2192 }); -2193 } -2194 -2195 /** -2196 * @param regionName -2197 * Region name to assign. -2198 * @throws MasterNotRunningException -2199 * @throws ZooKeeperConnectionException -2200 * @throws IOException -2201 */ -2202 @Override -2203 public void assign(final byte[] regionName) throws MasterNotRunningException, -2204 ZooKeeperConnectionException, IOException { -2205 final byte[] toBeAssigned = getRegionName(regionName); -2206 executeCallable(new MasterCallable<Void>(getConnection()) { -2207 @Override -2208 public Void call(int callTimeout) throws ServiceException { -2209 AssignRegionRequest request = -2210 RequestConverter.buildAssignRegionRequest(toBeAssigned); -2211 master.assignRegion(null,request); -2212 return null; -2213 } -2214 }); -2215 } -2216 -2217 /** -2218 * Unassign a region from current hosting regionserver. Region will then be -2219 * assigned to a regionserver chosen at random. Region could be reassigned -2220 * back to the same server. Use {@link #move(byte[], byte[])} if you want -2221 * to control the region movement. -2222 * @param regionName Region to unassign. Will clear any existing RegionPlan -2223 * if one found. -2224 * @param force If true, force unassign (Will remove region from -2225 * regions-in-transition too if present. If results in double assignment -2226 * use hbck -fix to resolve. To be used by experts). -2227 * @throws MasterNotRunningException -2228 * @throws ZooKeeperConnectionException -2229 * @throws IOException -2230 */ -2231 @Override -2232 public void unassign(final byte [] regionName, final boolean force) -2233 throws MasterNotRunningException, ZooKeeperConnectionException, IOException { -2234 final byte[] toBeUnassigned = getRegionName(regionName); -2235 executeCallable(new MasterCallable<Void>(getConnection()) { -2236 @Override -2237 public Void call(int callTimeout) throws ServiceException { -2238 UnassignRegionRequest request = -2239 RequestConverter.buildUnassignRegionRequest(toBeUnassigned, force); -2240 master.unassignRegion(null, request); -2241 return null; -2242 } -2243 }); -2244 } -2245 -2246 /** -2247 * Offline specified region from master's in-memory state. It will not attempt to reassign the -2248 * region as in unassign. This API can be used when a region not served by any region server and -2249 * still online as per Master's in memory state. If this API is incorrectly used on active region -2250 * then master will loose track of that region. -2251 * -2252 * This is a special method that should be used by experts or hbck. -2253 * -2254 * @param regionName -2255 * Region to offline. -2256 * @throws IOException -2257 */ -2258 @Override -2259 public void offline(final byte [] regionName) -2260 throws IOException { -2261 executeCallable(new MasterCallable<Void>(getConnection()) { -2262 @Override -2263 public Void call(int callTimeout) throws ServiceException { -2264 master.offlineRegion(null,RequestConverter.buildOfflineRegionRequest(regionName)); -2265 return null; -2266 } -2267 }); -2268 } -2269 -2270 /** -2271 * Turn the load balancer on or off. -2272 * @param on If true, enable balancer. If false, disable balancer. -2273 * @param synchronous If true, it waits until current balance() call, if outstanding, to return. -2274 * @return Previous balancer value -2275 */ -2276 @Override -2277 public boolean setBalancerRunning(final boolean on, final boolean synchronous) -2278 throws IOException { -2279 return executeCallable(new MasterCallable<Boolean>(getConnection()) { -2280 @Override -2281 public Boolean call(int callTimeout) throws ServiceException { -2282 SetBalancerRunningRequest req = -2283 RequestConverter.buildSetBalancerRunningRequest(on, synchronous); -2284 return master.setBalancerRunning(null, req).getPrevBalanceValue(); -2285 } -2286 }); -2287 } -2288 -2289 /** -2290 * Invoke the balancer. Will run the balancer and if regions to move, it will -2291 * go ahead and do the reassignments. Can NOT run for various reasons. Check -2292 * logs. -2293 * @return True if balancer ran, false otherwise. -2294 */ -2295 @Override -2296 public boolean balancer() throws IOException { -2297 return executeCallable(new MasterCallable<Boolean>(getConnection()) { -2298 @Override -2299 public Boolean call(int callTimeout) throws ServiceException { -2300 return master.balance(null, RequestConverter.buildBalanceRequest(false)).getBalancerRan(); -2301 } -2302 }); -2303 } -2304 -2305 @Override -2306 public boolean balancer(final boolean force) throws IOException { -2307 return executeCallable(new MasterCallable<Boolean>(getConnection()) { -2308 @Override -2309 public Boolean call(int callTimeout) throws ServiceException { -2310 return master.balance(null, RequestConverter.buildBalanceRequest(force)).getBalancerRan(); -2311 } -2312 }); -2313 } -2314 -2315 /** -2316 * Query the state of the balancer from the Master. It's not a guarantee that the balancer is -2317 * actually running this very moment, but that it will run. -2318 * -2319 * @return True if the balancer is enabled, false otherwise. -2320 */ -2321 @Override -2322 public boolean isBalancerEnabled() throws IOException { -2323 return executeCallable(new MasterCallable<Boolean>(getConnection()) { -2324 @Override -2325 public Boolean call(int callTimeout) throws ServiceException { -2326 return master.isBalancerEnabled(null, RequestConverter.buildIsBalancerEnabledRequest()) -2327 .getEnabled(); -2328 } -2329 }); -2330 } -2331 -2332 /** -2333 * Invoke region normalizer. Can NOT run for various reasons. Check logs. -2334 * -2335 * @return True if region normalizer ran, false otherwise. -2336 */ -2337 @Override -2338 public boolean normalize() throws IOException { -2339 return executeCallable(new MasterCallable<Boolean>(getConnection()) { -2340 @Override -2341 public Boolean call(int callTimeout) throws ServiceException { -2342 return master.normalize(null, -2343 RequestConverter.buildNormalizeRequest()).getNormalizerRan(); -2344 } -2345 }); -2346 } -2347 -2348 /** -2349 * Query the current state of the region normalizer -2350 * -2351 * @return true if region normalizer is enabled, false otherwise. -2352 */ -2353 public boolean isNormalizerEnabled() throws IOException { -2354 return executeCallable(new MasterCallable<Boolean>(getConnection()) { -2355 @Override -2356 public Boolean call(int callTimeout) throws ServiceException { -2357 return master.isNormalizerEnabled(null, -2358 RequestConverter.buildIsNormalizerEnabledRequest()).getEnabled(); -2359 } -2360 }); -2361 } -2362 -2363 /** -2364 * Turn region normalizer on or off. -2365 * -2366 * @return Previous normalizer value -2367 */ -2368 public boolean setNormalizerRunning(final boolean on) throws IOException { -2369 return executeCallable(new MasterCallable<Boolean>(getConnection()) { -2370 @Override -2371 public Boolean call(int callTimeout) throws ServiceException { -2372 SetNormalizerRunningRequest req = -2373 RequestConverter.buildSetNormalizerRunningRequest(on); -2374 return master.setNormalizerRunning(null, req).getPrevNormalizerValue(); -2375 } -2376 }); -2377 } -2378 -2379 /** -2380 * Enable/Disable the catalog janitor -2381 * @param enable if true enables the catalog janitor -2382 * @return the previous state -2383 * @throws MasterNotRunningException -2384 */ -2385 @Override -2386 public boolean enableCatalogJanitor(final boolean enable) -2387 throws IOException { -2388 return executeCallable(new MasterCallable<Boolean>(getConnection()) { -2389 @Override -2390 public Boolean call(int callTimeout) throws ServiceException { -2391 return master.enableCatalogJanitor(null, -2392 RequestConverter.buildEnableCatalogJanitorRequest(enable)).getPrevValue(); -2393 } -2394 }); -2395 } -2396 -2397 /** -2398 * Ask for a scan of the catalog table -2399 * @return the number of entries cleaned -2400 * @throws MasterNotRunningException -2401 */ -2402 @Override -2403 public int runCatalogScan() throws IOException { -2404 return executeCallable(new MasterCallable<Integer>(getConnection()) { -2405 @Override -2406 public Integer call(int callTimeout) throws ServiceException { -2407 return master.runCatalogScan(null, -2408 RequestConverter.buildCatalogScanRequest()).getScanResult(); -2409 } -2410 }); -2411 } -2412 -2413 /** -2414 * Query on the catalog janitor state (Enabled/Disabled?) -2415 * @throws org.apache.hadoop.hbase.MasterNotRunningException -2416 */ -2417 @Override -2418 public boolean isCatalogJanitorEnabled() throws IOException { -2419 return executeCallable(new MasterCallable<Boolean>(getConnection()) { -2420 @Override -2421 public Boolean call(int callTimeout) throws ServiceException { -2422 return master.isCatalogJanitorEnabled(null, -2423 RequestConverter.buildIsCatalogJanitorEnabledRequest()).getValue(); -2424 } -2425 }); -2426 } -2427 -2428 /** -2429 * Merge two regions. Asynchronous operation. -2430 * @param encodedNameOfRegionA encoded name of region a -2431 * @param encodedNameOfRegionB encoded name of region b -2432 * @param forcible true if do a compulsory merge, otherwise we will only merge -2433 * two adjacent regions -2434 * @throws IOException -2435 */ -2436 @Override -2437 public void mergeRegions(final byte[] encodedNameOfRegionA, -2438 final byte[] encodedNameOfRegionB, final boolean forcible) -2439 throws IOException { -2440 Pair<HRegionInfo, ServerName> pair = getRegion(encodedNameOfRegionA); -2441 if (pair != null && pair.getFirst().getReplicaId() != HRegionInfo.DEFAULT_REPLICA_ID) -2442 throw new IllegalArgumentException("Can't invoke merge on non-default regions directly"); -2443 pair = getRegion(encodedNameOfRegionB); -2444 if (pair != null && pair.getFirst().getReplicaId() != HRegionInfo.DEFAULT_REPLICA_ID) -2445 throw new IllegalArgumentException("Can't invoke merge on non-default regions directly"); -2446 executeCallable(new MasterCallable<Void>(getConnection()) { -2447 @Override -2448 public Void call(int callTimeout) throws ServiceException { -2449 try { -2450 DispatchMergingRegionsRequest request = RequestConverter -2451 .buildDispatchMergingRegionsRequest(encodedNameOfRegionA, -2452 encodedNameOfRegionB, forcible); -2453 master.dispatchMergingRegions(null, request); -2454 } catch (DeserializationException de) { -2455 LOG.error("Could not parse destination server name: " + de); -2456 } -2457 return null; -2458 } -2459 }); -2460 } -2461 -2462 /** -2463 * {@inheritDoc} -2464 */ -2465 @Override -2466 public void split(final TableName tableName) -2467 throws IOException { -2468 split(tableName, null); -2469 } -2470 -2471 /** -2472 * {@inheritDoc} -2473 */ -2474 @Override -2475 public void splitRegion(final byte[] regionName) -2476 throws IOException { -2477 splitRegion(regionName, null); -2478 } -2479 -2480 /** -2481 * @deprecated Use {@link #split(org.apache.hadoop.hbase.TableName)} or {@link #splitRegion -2482 * (byte[])} instead. -2483 */ -2484 @Deprecated -2485 public void split(final String tableNameOrRegionName) -2486 throws IOException, InterruptedException { -2487 split(Bytes.toBytes(tableNameOrRegionName)); -2488 } -2489 -2490 /** -2491 * @deprecated Use {@link #split(org.apache.hadoop.hbase.TableName)} or {@link #splitRegion -2492 * (byte[])} instead. -2493 */ -2494 @Deprecated -2495 public void split(final byte[] tableNameOrRegionName) -2496 throws IOException, InterruptedException { -2497 split(tableNameOrRegionName, null); -2498 } -2499 -2500 /** -2501 * {@inheritDoc} -2502 */ -2503 @Override -2504 public void split(final TableName tableName, final byte [] splitPoint) -2505 throws IOException { -2506 ZooKeeperWatcher zookeeper = null; -2507 try { -2508 checkTableExists(tableName); -2509 zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), -2510 new ThrowableAbortable()); -2511 List<Pair<HRegionInfo, ServerName>> pairs; -2512 if (TableName.META_TABLE_NAME.equals(tableName)) { -2513 pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper); -2514 } else { -2515 pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName); -2516 } -2517 for (Pair<HRegionInfo, ServerName> pair: pairs) { -2518 // May not be a server for a particular row -2519 if (pair.getSecond() == null) continue; -2520 HRegionInfo r = pair.getFirst(); -2521 // check for parents -2522 if (r.isSplitParent()) continue; -2523 // if a split point given, only split that particular region -2524 if (r.getReplicaId() != HRegionInfo.DEFAULT_REPLICA_ID || -2525 (splitPoint != null && !r.containsRow(splitPoint))) continue; -2526 // call out to region server to do split now -2527 split(pair.getSecond(), pair.getFirst(), splitPoint); -2528 } -2529 } finally { -2530 if (zookeeper != null) { -2531 zookeeper.close(); -2532 } -2533 } -2534 } -2535 -2536 /** -2537 * {@inheritDoc} -2538 */ -2539 @Override -2540 public void splitRegion(final byte[] regionName, final byte [] splitPoint) -2541 throws IOException { -2542 Pair<HRegionInfo, ServerName> regionServerPair = getRegion(regionName); -2543 if (regionServerPair == null) { -2544 throw new IllegalArgumentException("Invalid region: " + Bytes.toStringBinary(regionName)); -2545 } -2546 if (regionServerPair.getFirst() != null && -2547 regionServerPair.getFirst().getReplicaId() != HRegionInfo.DEFAULT_REPLICA_ID) { -2548 throw new IllegalArgumentException("Can't split replicas directly. " -2549 + "Replicas are auto-split when their primary is split."); -2550 } -2551 if (regionServerPair.getSecond() == null) { -2552 throw new NoServerForRegionException(Bytes.toStringBinary(regionName)); -2553 } -2554 split(regionServerPair.getSecond(), regionServerPair.getFirst(), splitPoint); -2555 } -2556 -2557 /** -2558 * @deprecated Use {@link #split(org.apache.hadoop.hbase.TableName, -2559 * byte[])} or {@link #splitRegion(byte[], byte[])} instead. -2560 */ -2561 @Deprecated -2562 public void split(final String tableNameOrRegionName, -2563 final String splitPoint) throws IOException { -2564 split(Bytes.toBytes(tableNameOrRegionName), Bytes.toBytes(splitPoint)); -2565 } -2566 -2567 /** -2568 * @deprecated Use {@link #split(org.apache.hadoop.hbase.TableName, -2569 * byte[])} or {@link #splitRegion(byte[], byte[])} instead. -2570 */ -2571 @Deprecated -2572 public void split(final byte[] tableNameOrRegionName, -2573 final byte [] splitPoint) throws IOException { -2574 try { -2575 splitRegion(tableNameOrRegionName, splitPoint); -2576 } catch (IllegalArgumentException e) { -2577 // Bad region, try table -2578 split(TableName.valueOf(tableNameOrRegionName), splitPoint); -2579 } -2580 } -2581 -2582 @VisibleForTesting -2583 public void split(final ServerName sn, final HRegionInfo hri, -2584 byte[] splitPoint) throws IOException { -2585 if (hri.getStartKey() != null && splitPoint != null && -2586 Bytes.compareTo(hri.getStartKey(), splitPoint) == 0) { -2587 throw new IOException("should not give a splitkey which equals to startkey!"); -2588 } -2589 // TODO: This is not executed via retries -2590 AdminService.BlockingInterface admin = this.connection.getAdmin(sn); -2591 ProtobufUtil.split(admin, hri, splitPoint); -2592 } -2593 -2594 /** -2595 * Modify an existing table, more IRB friendly version. Asynchronous operation. -2596 * This means that it may be a while before your schema change is updated across all of the -2597 * table. You can use Future.get(long, TimeUnit) to wait on the operation to complete. -2598 * It may throw ExecutionException if there was an error while executing the operation -2599 * or TimeoutException in case the wait timeout was not long enough to allow the -2600 * operation to complete. -2601 * -2602 * @param tableName name of table. -2603 * @param htd modified description of the table -2604 * @throws IOException if a remote or network exception occurs -2605 * @return the result of the async modify. You can use Future.get(long, TimeUnit) to wait on the -2606 * operation to complete. -2607 */ -2608 @Override -2609 public Future<Void> modifyTable(final TableName tableName, final HTableDescriptor htd) -2610 throws IOException { -2611 if (!tableName.equals(htd.getTableName())) { -2612 throw new IllegalArgumentException("the specified table name '" + tableName + -2613 "' doesn't match with the HTD one: " + htd.getTableName()); -2614 } -2615 -2616 ModifyTableResponse response = executeCallable( -2617 new MasterCallable<ModifyTableResponse>(getConnection()) { -2618 @Override -2619 public ModifyTableResponse call(int callTimeout) throws ServiceException { -2620 ModifyTableRequest request = RequestConverter.buildModifyTableRequest( -2621 tableName, htd, ng.getNonceGroup(), ng.newNonce()); -2622 return master.modifyTable(null, request); -2623 } -2624 }); -2625 -2626 return new ModifyTableFuture(this, tableName, response); -2627 } -2628 -2629 private static class ModifyTableFuture extends TableFuture<Void> { -2630 public ModifyTableFuture(final HBaseAdmin admin, final TableName tableName, -2631 final ModifyTableResponse response) { -2632 super(admin, tableName, -2633 (response != null && response.hasProcId()) ? response.getProcId() : null); -2634 } -2635 -2636 public ModifyTableFuture(final HBaseAdmin admin, final TableName tableName, final Long procId) { -2637 super(admin, tableName, procId); -2638 } -2639 -2640 @Override -2641 public String getOperationType() { -2642 return "MODIFY"; -2643 } -2644 -2645 @Override -2646 protected Void postOperationResult(final Void result, final long deadlineTs) -2647 throws IOException, TimeoutException { -2648 // The modify operation on the table is asynchronous on the server side irrespective -2649 // of whether Procedure V2 is supported or not. So, we wait in the client till -2650 // all regions get updated. -2651 waitForSchemaUpdate(deadlineTs); -2652 return result; -2653 } -2654 } -2655 -2656 public void modifyTable(final byte[] tableName, final HTableDescriptor htd) -2657 throws IOException { -2658 modifyTable(TableName.valueOf(tableName), htd); -2659 } -2660 -2661 public void modifyTable(final String tableName, final HTableDescriptor htd) -2662 throws IOException { -2663 modifyTable(TableName.valueOf(tableName), htd); -2664 } -2665 -2666 /** -2667 * @param regionName Name of a region. -2668 * @return a pair of HRegionInfo and ServerName if <code>regionName</code> is -2669 * a verified region name (we call {@link -2670 * MetaTableAccessor#getRegion(HConnection, byte[])} -2671 * else null. -2672 * Throw IllegalArgumentException if <code>regionName</code> is null. -2673 * @throws IOException -2674 */ -2675 Pair<HRegionInfo, ServerName> getRegion(final byte[] regionName) throws IOException { -2676 if (regionName == null) { -2677 throw new IllegalArgumentException("Pass a table name or region name"); -2678 } -2679 Pair<HRegionInfo, ServerName> pair = -2680 MetaTableAccessor.getRegion(connection, regionName); -2681 if (pair == null) { -2682 final AtomicReference<Pair<HRegionInfo, ServerName>> result = -2683 new AtomicReference<Pair<HRegionInfo, ServerName>>(null); -2684 final String encodedName = Bytes.toString(regionName); -2685 MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() { -2686 @Override -2687 public boolean visit(Result data) throws IOException { -2688 HRegionInfo info = HRegionInfo.getHRegionInfo(data); -2689 if (info == null) { -2690 LOG.warn("No serialized HRegionInfo in " + data); -2691 return true; -2692 } -2693 RegionLocations rl = MetaTableAccessor.getRegionLocations(data); -2694 boolean matched = false; -2695 ServerName sn = null; -2696 if (rl != null) { -2697 for (HRegionLocation h : rl.getRegionLocations()) { -2698 if (h != null && encodedName.equals(h.getRegionInfo().getEncodedName())) { -2699 sn = h.getServerName(); -2700 info = h.getRegionInfo(); -2701 matched = true; -2702 } -2703 } -2704 } -2705 if (!matched) return true; -2706 result.set(new Pair<HRegionInfo, ServerName>(info, sn)); -2707 return false; // found the region, stop -2708 } -2709 }; -2710 -2711 MetaTableAccessor.fullScanRegions(connection, visitor); -2712 pair = result.get(); -2713 } -2714 return pair; -2715 } -2716 -2717 /** -2718 * If the input is a region name, it is returned as is. If it's an -2719 * encoded region name, the corresponding region is found from meta -2720 * and its region name is returned. If we can't find any region in -2721 * meta matching the input as either region name or encoded region -2722 * name, the input is returned as is. We don't throw unknown -2723 * region exception. -2724 */ -2725 private byte[] getRegionName( -2726 final byte[] regionNameOrEncodedRegionName) throws IOException { -2727 if (Bytes.equals(regionNameOrEncodedRegionName, -2728 HRegionInfo.FIRST_META_REGIONINFO.getRegionName()) -2729 || Bytes.equals(regionNameOrEncodedRegionName, -2730 HRegionInfo.FIRST_META_REGIONINFO.getEncodedNameAsBytes())) { -2731 return HRegionInfo.FIRST_META_REGIONINFO.getRegionName(); -2732 } -2733 byte[] tmp = regionNameOrEncodedRegionName; -2734 Pair<HRegionInfo, ServerName> regionServerPair = getRegion(regionNameOrEncodedRegionName); -2735 if (regionServerPair != null && regionServerPair.getFirst() != null) { -2736 tmp = regionServerPair.getFirst().getRegionName(); -2737 } -2738 return tmp; -2739 } -2740 -2741 /** -2742 * Check if table exists or not -2743 * @param tableName Name of a table. -2744 * @return tableName instance -2745 * @throws IOException if a remote or network exception occurs. -2746 * @throws TableNotFoundException if table does not exist. -2747 */ -2748 private TableName checkTableExists(final TableName tableName) -2749 throws IOException { -2750 return executeCallable(new ConnectionCallable<TableName>(getConnection()) { -2751 @Override -2752 public TableName call(int callTimeout) throws ServiceException, IOException { -2753 if (!MetaTableAccessor.tableExists(connection, tableName)) { -2754 throw new TableNotFoundException(tableName); -2755 } -2756 return tableName; -2757 } -2758 }); -2759 } -2760 -2761 /** -2762 * Shuts down the HBase cluster -2763 * @throws IOException if a remote or network exception occurs -2764 */ -2765 @Override -2766 public synchronized void shutdown() throws IOException { -2767 executeCallable(new MasterCallable<Void>(getConnection()) { -2768 @Override -2769 public Void call(int callTimeout) throws ServiceException { -2770 master.shutdown(null,ShutdownRequest.newBuilder().build()); -2771 return null; -2772 } -2773 }); -2774 } -2775 -2776 /** -2777 * Shuts down the current HBase master only. -2778 * Does not shutdown the cluster. -2779 * @see #shutdown() -2780 * @throws IOException if a remote or network exception occurs -2781 */ -2782 @Override -2783 public synchronized void stopMaster() throws IOException { -2784 executeCallable(new MasterCallable<Void>(getConnection()) { -2785 @Override -2786 public Void call(int callTimeout) throws ServiceException { -2787 master.stopMaster(null, StopMasterRequest.newBuilder().build()); -2788 return null; -2789 } -2790 }); -2791 } -2792 -2793 /** -2794 * Stop the designated regionserver -2795 * @param hostnamePort Hostname and port delimited by a <code>:</code> as in -2796 * <code>example.org:1234</code> -2797 * @throws IOException if a remote or network exception occurs -2798 */ -2799 @Override -2800 public synchronized void stopRegionServer(final String hostnamePort) -2801 throws IOException { -2802 String hostname = Addressing.parseHostname(hostnamePort); -2803 int port = Addressing.parsePort(hostnamePort); -2804 AdminService.BlockingInterface admin = -2805 this.connection.getAdmin(ServerName.valueOf(hostname, port, 0)); -2806 StopServerRequest request = RequestConverter.buildStopServerRequest( -2807 "Called by admin client " + this.connection.toString()); -2808 try { -2809 admin.stopServer(null, request); -2810 } catch (ServiceException se) { -2811 throw ProtobufUtil.getRemoteException(se); -2812 } -2813 } -2814 +2094 default: +2095 ZooKeeperWatcher zookeeper = null; +2096 try { +2097 checkTableExists(tableName); +2098 zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), +2099 new ThrowableAbortable()); +2100 List<Pair<HRegionInfo, ServerName>> pairs; +2101 if (TableName.META_TABLE_NAME.equals(tableName)) { +2102 pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper); +2103 } else { +2104 pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName); +2105 } +2106 for (Pair<HRegionInfo, ServerName> pair: pairs) { +2107 if (pair.getFirst().isOffline()) continue; +2108 if (pair.getSecond() == null) continue; +2109 try { +2110 compact(pair.getSecond(), pair.getFirst(), major, columnFamily); +2111 } catch (NotServingRegionException e) { +2112 if (LOG.isDebugEnabled()) { +2113 LOG.debug("Trying to" + (major ? " major" : "") + " compact " + +2114 pair.getFirst() + ": " + +2115 StringUtils.stringifyException(e)); +2116 } +2117 } +2118 } +2119 } finally { +2120 if (zookeeper != null) { +2121 zookeeper.close(); +2122 } +2123 } +2124 break; +2125 } +2126 } +2127 +2128 /** +2129 * Compact an individual region. +2130 * Asynchronous operation. +2131 * +2132 * @param regionName region to compact +2133 * @param columnFamily column family within a table or region +2134 * @param major True if we are to do a major compaction. +2135 * @throws IOException if a remote or network exception occurs +2136 * @throws InterruptedException +2137 */ +2138 private void compactRegion(final byte[] regionName, final byte[] columnFamily,final boolean major) +2139 throws IOException { +2140 Pair<HRegionInfo, ServerName> regionServerPair = getRegion(regionName); +2141 if (regionServerPair == null) { +2142 throw new IllegalArgumentException("Invalid region: " + Bytes.toStringBinary(regionName)); +2143 } +2144 if (regionServerPair.getSecond() == null) { +2145 throw new NoServerForRegionException(Bytes.toStringBinary(regionName)); +2146 } +2147 compact(regionServerPair.getSecond(), regionServerPair.getFirst(), major, columnFamily); +2148 } +2149 +2150 private void compact(final ServerName sn, final HRegionInfo hri, +2151 final boolean major, final byte [] family) +2152 throws IOException { +2153 AdminService.BlockingInterface admin = this.connection.getAdmin(sn); +2154 CompactRegionRequest request = +2155 RequestConverter.buildCompactRegionRequest(hri.getRegionName(), major, family); +2156 try { +2157 admin.compactRegion(null, request); +2158 } catch (ServiceException se) { +2159 throw ProtobufUtil.getRemoteException(se); +2160 } +2161 } +2162 +2163 /** +2164 * Move the region <code>r</code> to <code>dest</code>. +2165 * @param encodedRegionName The encoded region name; i.e. the hash that makes +2166 * up the region name suffix: e.g. if regionname is +2167 * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>, +2168 * then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>. +2169 * @param destServerName The servername of the destination regionserver. If +2170 * passed the empty byte array we'll assign to a random server. A server name +2171 * is made of host, port and startcode. Here is an example: +2172 * <code> host187.example.com,60020,1289493121758</code> +2173 * @throws UnknownRegionException Thrown if we can't find a region named +2174 * <code>encodedRegionName</code> +2175 */ +2176 @Override +2177 public void move(final byte [] encodedRegionName, final byte [] destServerName) +2178 throws IOException { +2179 +2180 executeCallable(new MasterCallable<Void>(getConnection()) { +2181 @Override +2182 public Void call(int callTimeout) throws ServiceException { +2183 try { +2184 MoveRegionRequest request = +2185 RequestConverter.buildMoveRegionRequest(encodedRegionName, destServerName); +2186 master.moveRegion(null, request); +2187 } catch (DeserializationException de) { +2188 LOG.error("Could not parse destination server name: " + de); +2189 throw new ServiceException(new DoNotRetryIOException(de)); +2190 } +2191 return null; +2192 } +2193 }); +2194 } +2195 +2196 /** +2197 * @param regionName +2198 * Region name to assign. +2199 * @throws MasterNotRunningException +2200 * @throws ZooKeeperConnectionException +2201 * @throws IOException +2202 */ +2203 @Override +2204 public void assign(final byte[] regionName) throws MasterNotRunningException, +2205 ZooKeeperConnectionException, IOException { +2206 final byte[] toBeAssigned = getRegionName(regionName); +2207 executeCallable(new MasterCallable<Void>(getConnection()) { +2208 @Override +2209 public Void call(int callTimeout) throws ServiceException { +2210 AssignRegionRequest request = +2211 RequestConverter.buildAssignRegionRequest(toBeAssigned); +2212 master.assignRegion(null,request); +2213 return null; +2214 } +2215 }); +2216 } +2217 +2218 /** +2219 * Unassign a region from current hosting regionserver. Region will then be +2220 * assigned to a regionserver chosen at random. Region could be reassigned +2221 * back to the same server. Use {@link #move(byte[], byte[])} if you want +2222 * to control the region movement. +2223 * @param regionName Region to unassign. Will clear any existing RegionPlan +2224 * if one found. +2225 * @param force If true, force unassign (Will remove region from +2226 * regions-in-transition too if present. If results in double assignment +2227 * use hbck -fix to resolve. To be used by experts). +2228 * @throws MasterNotRunningException +2229 * @throws ZooKeeperConnectionException +2230 * @throws IOException +2231 */ +2232 @Override +2233 public void unassign(final byte [] regionName, final boolean force) +2234 throws MasterNotRunningException, ZooKeeperConnectionException, IOException { +2235 final byte[] toBeUnassigned = getRegionName(regionName); +2236 executeCallable(new MasterCallable<Void>(getConnection()) { +2237 @Override +2238 public Void call(int callTimeout) throws ServiceException { +2239 UnassignRegionRequest request = +2240 RequestConverter.buildUnassignRegionRequest(toBeUnassigned, force); +2241 master.unassignRegion(null, request); +2242 return null; +2243 } +2244 }); +2245 } +2246 +2247 /** +2248 * Offline specified region from master's in-memory state. It will not attempt to reassign the +2249 * region as in unassign. This API can be used when a region not served by any region server and [... 4721 lines stripped ...]