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 680B5200D5C for ; Thu, 30 Nov 2017 16:18:48 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 668B2160C22; Thu, 30 Nov 2017 15:18:48 +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 19DE1160C1F for ; Thu, 30 Nov 2017 16:18:45 +0100 (CET) Received: (qmail 59936 invoked by uid 500); 30 Nov 2017 15:18:43 -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 58163 invoked by uid 99); 30 Nov 2017 15:18:41 -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; Thu, 30 Nov 2017 15:18:41 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 774BCDF9AB; Thu, 30 Nov 2017 15:18:41 +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: Thu, 30 Nov 2017 15:19:01 -0000 Message-Id: <172c41b585fe4f658bddf242cfb7a3d6@git.apache.org> In-Reply-To: <383c8eb04c5540608a217c62dc39a689@git.apache.org> References: <383c8eb04c5540608a217c62dc39a689@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [22/51] [partial] hbase-site git commit: Published site at . archived-at: Thu, 30 Nov 2017 15:18:48 -0000 http://git-wip-us.apache.org/repos/asf/hbase-site/blob/713d773f/devapidocs/src-html/org/apache/hadoop/hbase/Version.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/Version.html b/devapidocs/src-html/org/apache/hadoop/hbase/Version.html index 01c0791..4d26b63 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/Version.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/Version.html @@ -16,11 +16,11 @@ 008@InterfaceAudience.Private 009public class Version { 010 public static final String version = "3.0.0-SNAPSHOT"; -011 public static final String revision = "8b32d3792934507c774997cd82dc061b75410f83"; +011 public static final String revision = "6a6409a30aa634875467683203de0e21e0491986"; 012 public static final String user = "jenkins"; -013 public static final String date = "Wed Nov 29 14:42:11 UTC 2017"; +013 public static final String date = "Thu Nov 30 14:42:34 UTC 2017"; 014 public static final String url = "git://asf920.gq1.ygridcore.net/home/jenkins/jenkins-slave/workspace/hbase_generate_website/hbase"; -015 public static final String srcChecksum = "aea71cf3474c2eecf646181c5e4c0fa3"; +015 public static final String srcChecksum = "252c37b6e2a91e50595f45109cbc77dd"; 016} http://git-wip-us.apache.org/repos/asf/hbase-site/blob/713d773f/devapidocs/src-html/org/apache/hadoop/hbase/client/ConnectionUtils.MasterlessConnection.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/client/ConnectionUtils.MasterlessConnection.html b/devapidocs/src-html/org/apache/hadoop/hbase/client/ConnectionUtils.MasterlessConnection.html index 1bddf29..f667b93 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/client/ConnectionUtils.MasterlessConnection.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/client/ConnectionUtils.MasterlessConnection.html @@ -124,380 +124,381 @@ 116 HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER); 117 // Go big. Multiply by 10. If we can't get to meta after this many retries 118 // then something seriously wrong. -119 int serversideMultiplier = c.getInt("hbase.client.serverside.retries.multiplier", 10); -120 int retries = hcRetries * serversideMultiplier; -121 c.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, retries); -122 log.info(sn + " server-side Connection retries=" + retries); -123 } -124 -125 /** -126 * A ClusterConnection that will short-circuit RPC making direct invocations against the -127 * localhost if the invocation target is 'this' server; save on network and protobuf -128 * invocations. -129 */ -130 // TODO This has to still do PB marshalling/unmarshalling stuff. Check how/whether we can avoid. -131 @VisibleForTesting // Class is visible so can assert we are short-circuiting when expected. -132 public static class ShortCircuitingClusterConnection extends ConnectionImplementation { -133 private final ServerName serverName; -134 private final AdminService.BlockingInterface localHostAdmin; -135 private final ClientService.BlockingInterface localHostClient; -136 -137 private ShortCircuitingClusterConnection(Configuration conf, ExecutorService pool, User user, -138 ServerName serverName, AdminService.BlockingInterface admin, -139 ClientService.BlockingInterface client) -140 throws IOException { -141 super(conf, pool, user); -142 this.serverName = serverName; -143 this.localHostAdmin = admin; -144 this.localHostClient = client; -145 } -146 -147 @Override -148 public AdminService.BlockingInterface getAdmin(ServerName sn) throws IOException { -149 return serverName.equals(sn) ? this.localHostAdmin : super.getAdmin(sn); -150 } -151 -152 @Override -153 public ClientService.BlockingInterface getClient(ServerName sn) throws IOException { -154 return serverName.equals(sn) ? this.localHostClient : super.getClient(sn); -155 } -156 -157 @Override -158 public MasterKeepAliveConnection getKeepAliveMasterService() throws MasterNotRunningException { -159 if (this.localHostClient instanceof MasterService.BlockingInterface) { -160 return new ShortCircuitMasterConnection((MasterService.BlockingInterface)this.localHostClient); -161 } -162 return super.getKeepAliveMasterService(); -163 } -164 } -165 -166 /** -167 * Creates a short-circuit connection that can bypass the RPC layer (serialization, -168 * deserialization, networking, etc..) when talking to a local server. -169 * @param conf the current configuration -170 * @param pool the thread pool to use for batch operations -171 * @param user the user the connection is for -172 * @param serverName the local server name -173 * @param admin the admin interface of the local server -174 * @param client the client interface of the local server -175 * @return an short-circuit connection. -176 * @throws IOException if IO failure occurred -177 */ -178 public static ClusterConnection createShortCircuitConnection(final Configuration conf, -179 ExecutorService pool, User user, final ServerName serverName, -180 final AdminService.BlockingInterface admin, final ClientService.BlockingInterface client) -181 throws IOException { -182 if (user == null) { -183 user = UserProvider.instantiate(conf).getCurrent(); -184 } -185 return new ShortCircuitingClusterConnection(conf, pool, user, serverName, admin, client); -186 } -187 -188 /** -189 * Setup the connection class, so that it will not depend on master being online. Used for testing -190 * @param conf configuration to set -191 */ -192 @VisibleForTesting -193 public static void setupMasterlessConnection(Configuration conf) { -194 conf.set(ClusterConnection.HBASE_CLIENT_CONNECTION_IMPL, MasterlessConnection.class.getName()); -195 } -196 -197 /** -198 * Some tests shut down the master. But table availability is a master RPC which is performed on -199 * region re-lookups. -200 */ -201 static class MasterlessConnection extends ConnectionImplementation { -202 MasterlessConnection(Configuration conf, ExecutorService pool, User user) throws IOException { -203 super(conf, pool, user); -204 } -205 -206 @Override -207 public boolean isTableDisabled(TableName tableName) throws IOException { -208 // treat all tables as enabled -209 return false; -210 } -211 } -212 -213 /** -214 * Return retires + 1. The returned value will be in range [1, Integer.MAX_VALUE]. -215 */ -216 static int retries2Attempts(int retries) { -217 return Math.max(1, retries == Integer.MAX_VALUE ? Integer.MAX_VALUE : retries + 1); -218 } -219 -220 /** -221 * Get a unique key for the rpc stub to the given server. -222 */ -223 static String getStubKey(String serviceName, ServerName serverName, boolean hostnameCanChange) { -224 // Sometimes, servers go down and they come back up with the same hostname but a different -225 // IP address. Force a resolution of the rsHostname by trying to instantiate an -226 // InetSocketAddress, and this way we will rightfully get a new stubKey. -227 // Also, include the hostname in the key so as to take care of those cases where the -228 // DNS name is different but IP address remains the same. -229 String hostname = serverName.getHostname(); -230 int port = serverName.getPort(); -231 if (hostnameCanChange) { -232 try { -233 InetAddress ip = InetAddress.getByName(hostname); -234 return serviceName + "@" + hostname + "-" + ip.getHostAddress() + ":" + port; -235 } catch (UnknownHostException e) { -236 LOG.warn("Can not resolve " + hostname + ", please check your network", e); -237 } -238 } -239 return serviceName + "@" + hostname + ":" + port; -240 } -241 -242 static void checkHasFamilies(Mutation mutation) { -243 Preconditions.checkArgument(mutation.numFamilies() > 0, -244 "Invalid arguments to %s, zero columns specified", mutation.toString()); -245 } -246 -247 /** Dummy nonce generator for disabled nonces. */ -248 static final NonceGenerator NO_NONCE_GENERATOR = new NonceGenerator() { -249 -250 @Override -251 public long newNonce() { -252 return HConstants.NO_NONCE; -253 } -254 -255 @Override -256 public long getNonceGroup() { -257 return HConstants.NO_NONCE; -258 } -259 }; -260 -261 // A byte array in which all elements are the max byte, and it is used to -262 // construct closest front row -263 static final byte[] MAX_BYTE_ARRAY = Bytes.createMaxByteArray(9); -264 -265 /** -266 * Create the closest row after the specified row -267 */ -268 static byte[] createClosestRowAfter(byte[] row) { -269 return Arrays.copyOf(row, row.length + 1); -270 } -271 -272 /** -273 * Create a row before the specified row and very close to the specified row. -274 */ -275 static byte[] createCloseRowBefore(byte[] row) { -276 if (row.length == 0) { -277 return MAX_BYTE_ARRAY; -278 } -279 if (row[row.length - 1] == 0) { -280 return Arrays.copyOf(row, row.length - 1); -281 } else { -282 byte[] nextRow = new byte[row.length + MAX_BYTE_ARRAY.length]; -283 System.arraycopy(row, 0, nextRow, 0, row.length - 1); -284 nextRow[row.length - 1] = (byte) ((row[row.length - 1] & 0xFF) - 1); -285 System.arraycopy(MAX_BYTE_ARRAY, 0, nextRow, row.length, MAX_BYTE_ARRAY.length); -286 return nextRow; -287 } -288 } -289 -290 static boolean isEmptyStartRow(byte[] row) { -291 return Bytes.equals(row, EMPTY_START_ROW); -292 } -293 -294 static boolean isEmptyStopRow(byte[] row) { -295 return Bytes.equals(row, EMPTY_END_ROW); -296 } -297 -298 static void resetController(HBaseRpcController controller, long timeoutNs) { -299 controller.reset(); -300 if (timeoutNs >= 0) { -301 controller.setCallTimeout( -302 (int) Math.min(Integer.MAX_VALUE, TimeUnit.NANOSECONDS.toMillis(timeoutNs))); -303 } -304 } -305 -306 static Throwable translateException(Throwable t) { -307 if (t instanceof UndeclaredThrowableException && t.getCause() != null) { -308 t = t.getCause(); -309 } -310 if (t instanceof RemoteException) { -311 t = ((RemoteException) t).unwrapRemoteException(); -312 } -313 if (t instanceof ServiceException && t.getCause() != null) { -314 t = translateException(t.getCause()); -315 } -316 return t; -317 } -318 -319 static long calcEstimatedSize(Result rs) { -320 long estimatedHeapSizeOfResult = 0; -321 // We don't make Iterator here -322 for (Cell cell : rs.rawCells()) { -323 estimatedHeapSizeOfResult += PrivateCellUtil.estimatedHeapSizeOf(cell); -324 } -325 return estimatedHeapSizeOfResult; -326 } -327 -328 static Result filterCells(Result result, Cell keepCellsAfter) { -329 if (keepCellsAfter == null) { -330 // do not need to filter -331 return result; -332 } -333 // not the same row -334 if (!PrivateCellUtil.matchingRows(keepCellsAfter, result.getRow(), 0, result.getRow().length)) { -335 return result; -336 } -337 Cell[] rawCells = result.rawCells(); -338 int index = -339 Arrays.binarySearch(rawCells, keepCellsAfter, CellComparator.getInstance()::compareWithoutRow); -340 if (index < 0) { -341 index = -index - 1; -342 } else { -343 index++; -344 } -345 if (index == 0) { -346 return result; -347 } -348 if (index == rawCells.length) { -349 return null; -350 } -351 return Result.create(Arrays.copyOfRange(rawCells, index, rawCells.length), null, -352 result.isStale(), result.mayHaveMoreCellsInRow()); -353 } -354 -355 // Add a delta to avoid timeout immediately after a retry sleeping. -356 static final long SLEEP_DELTA_NS = TimeUnit.MILLISECONDS.toNanos(1); -357 -358 static Get toCheckExistenceOnly(Get get) { -359 if (get.isCheckExistenceOnly()) { -360 return get; -361 } -362 return ReflectionUtils.newInstance(get.getClass(), get).setCheckExistenceOnly(true); -363 } -364 -365 static List<Get> toCheckExistenceOnly(List<Get> gets) { -366 return gets.stream().map(ConnectionUtils::toCheckExistenceOnly).collect(toList()); -367 } -368 -369 static RegionLocateType getLocateType(Scan scan) { -370 if (scan.isReversed()) { -371 if (isEmptyStartRow(scan.getStartRow())) { -372 return RegionLocateType.BEFORE; -373 } else { -374 return scan.includeStartRow() ? RegionLocateType.CURRENT : RegionLocateType.BEFORE; -375 } -376 } else { -377 return scan.includeStartRow() ? RegionLocateType.CURRENT : RegionLocateType.AFTER; -378 } -379 } -380 -381 static boolean noMoreResultsForScan(Scan scan, RegionInfo info) { -382 if (isEmptyStopRow(info.getEndKey())) { -383 return true; -384 } -385 if (isEmptyStopRow(scan.getStopRow())) { -386 return false; -387 } -388 int c = Bytes.compareTo(info.getEndKey(), scan.getStopRow()); -389 // 1. if our stop row is less than the endKey of the region -390 // 2. if our stop row is equal to the endKey of the region and we do not include the stop row -391 // for scan. -392 return c > 0 || (c == 0 && !scan.includeStopRow()); -393 } -394 -395 static boolean noMoreResultsForReverseScan(Scan scan, RegionInfo info) { -396 if (isEmptyStartRow(info.getStartKey())) { -397 return true; -398 } -399 if (isEmptyStopRow(scan.getStopRow())) { -400 return false; -401 } -402 // no need to test the inclusive of the stop row as the start key of a region is included in -403 // the region. -404 return Bytes.compareTo(info.getStartKey(), scan.getStopRow()) <= 0; -405 } -406 -407 static <T> CompletableFuture<List<T>> allOf(List<CompletableFuture<T>> futures) { -408 return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) -409 .thenApply(v -> futures.stream().map(f -> f.getNow(null)).collect(toList())); -410 } -411 -412 public static ScanResultCache createScanResultCache(Scan scan) { -413 if (scan.getAllowPartialResults()) { -414 return new AllowPartialScanResultCache(); -415 } else if (scan.getBatch() > 0) { -416 return new BatchScanResultCache(scan.getBatch()); -417 } else { -418 return new CompleteScanResultCache(); -419 } -420 } -421 -422 private static final String MY_ADDRESS = getMyAddress(); -423 -424 private static String getMyAddress() { -425 try { -426 return DNS.getDefaultHost("default", "default"); -427 } catch (UnknownHostException uhe) { -428 LOG.error("cannot determine my address", uhe); -429 return null; -430 } -431 } -432 -433 static boolean isRemote(String host) { -434 return !host.equalsIgnoreCase(MY_ADDRESS); -435 } -436 -437 static void incRPCCallsMetrics(ScanMetrics scanMetrics, boolean isRegionServerRemote) { -438 if (scanMetrics == null) { -439 return; -440 } -441 scanMetrics.countOfRPCcalls.incrementAndGet(); -442 if (isRegionServerRemote) { -443 scanMetrics.countOfRemoteRPCcalls.incrementAndGet(); -444 } -445 } -446 -447 static void incRPCRetriesMetrics(ScanMetrics scanMetrics, boolean isRegionServerRemote) { -448 if (scanMetrics == null) { -449 return; -450 } -451 scanMetrics.countOfRPCRetries.incrementAndGet(); -452 if (isRegionServerRemote) { -453 scanMetrics.countOfRemoteRPCRetries.incrementAndGet(); -454 } -455 } -456 -457 static void updateResultsMetrics(ScanMetrics scanMetrics, Result[] rrs, -458 boolean isRegionServerRemote) { -459 if (scanMetrics == null || rrs == null || rrs.length == 0) { -460 return; -461 } -462 long resultSize = 0; -463 for (Result rr : rrs) { -464 for (Cell cell : rr.rawCells()) { -465 resultSize += PrivateCellUtil.estimatedSerializedSizeOf(cell); -466 } -467 } -468 scanMetrics.countOfBytesInResults.addAndGet(resultSize); -469 if (isRegionServerRemote) { -470 scanMetrics.countOfBytesInRemoteResults.addAndGet(resultSize); -471 } -472 } -473 -474 /** -475 * Use the scan metrics returned by the server to add to the identically named counters in the -476 * client side metrics. If a counter does not exist with the same name as the server side metric, -477 * the attempt to increase the counter will fail. -478 */ -479 static void updateServerSideMetrics(ScanMetrics scanMetrics, ScanResponse response) { -480 if (scanMetrics == null || response == null || !response.hasScanMetrics()) { -481 return; -482 } -483 ResponseConverter.getScanMetrics(response).forEach(scanMetrics::addToCounter); -484 } -485 -486 static void incRegionCountMetrics(ScanMetrics scanMetrics) { -487 if (scanMetrics == null) { -488 return; -489 } -490 scanMetrics.countOfRegions.incrementAndGet(); -491 } -492} +119 int serversideMultiplier = c.getInt(HConstants.HBASE_CLIENT_SERVERSIDE_RETRIES_MULTIPLIER, +120 HConstants.DEFAULT_HBASE_CLIENT_SERVERSIDE_RETRIES_MULTIPLIER); +121 int retries = hcRetries * serversideMultiplier; +122 c.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, retries); +123 log.info(sn + " server-side Connection retries=" + retries); +124 } +125 +126 /** +127 * A ClusterConnection that will short-circuit RPC making direct invocations against the +128 * localhost if the invocation target is 'this' server; save on network and protobuf +129 * invocations. +130 */ +131 // TODO This has to still do PB marshalling/unmarshalling stuff. Check how/whether we can avoid. +132 @VisibleForTesting // Class is visible so can assert we are short-circuiting when expected. +133 public static class ShortCircuitingClusterConnection extends ConnectionImplementation { +134 private final ServerName serverName; +135 private final AdminService.BlockingInterface localHostAdmin; +136 private final ClientService.BlockingInterface localHostClient; +137 +138 private ShortCircuitingClusterConnection(Configuration conf, ExecutorService pool, User user, +139 ServerName serverName, AdminService.BlockingInterface admin, +140 ClientService.BlockingInterface client) +141 throws IOException { +142 super(conf, pool, user); +143 this.serverName = serverName; +144 this.localHostAdmin = admin; +145 this.localHostClient = client; +146 } +147 +148 @Override +149 public AdminService.BlockingInterface getAdmin(ServerName sn) throws IOException { +150 return serverName.equals(sn) ? this.localHostAdmin : super.getAdmin(sn); +151 } +152 +153 @Override +154 public ClientService.BlockingInterface getClient(ServerName sn) throws IOException { +155 return serverName.equals(sn) ? this.localHostClient : super.getClient(sn); +156 } +157 +158 @Override +159 public MasterKeepAliveConnection getKeepAliveMasterService() throws MasterNotRunningException { +160 if (this.localHostClient instanceof MasterService.BlockingInterface) { +161 return new ShortCircuitMasterConnection((MasterService.BlockingInterface)this.localHostClient); +162 } +163 return super.getKeepAliveMasterService(); +164 } +165 } +166 +167 /** +168 * Creates a short-circuit connection that can bypass the RPC layer (serialization, +169 * deserialization, networking, etc..) when talking to a local server. +170 * @param conf the current configuration +171 * @param pool the thread pool to use for batch operations +172 * @param user the user the connection is for +173 * @param serverName the local server name +174 * @param admin the admin interface of the local server +175 * @param client the client interface of the local server +176 * @return an short-circuit connection. +177 * @throws IOException if IO failure occurred +178 */ +179 public static ClusterConnection createShortCircuitConnection(final Configuration conf, +180 ExecutorService pool, User user, final ServerName serverName, +181 final AdminService.BlockingInterface admin, final ClientService.BlockingInterface client) +182 throws IOException { +183 if (user == null) { +184 user = UserProvider.instantiate(conf).getCurrent(); +185 } +186 return new ShortCircuitingClusterConnection(conf, pool, user, serverName, admin, client); +187 } +188 +189 /** +190 * Setup the connection class, so that it will not depend on master being online. Used for testing +191 * @param conf configuration to set +192 */ +193 @VisibleForTesting +194 public static void setupMasterlessConnection(Configuration conf) { +195 conf.set(ClusterConnection.HBASE_CLIENT_CONNECTION_IMPL, MasterlessConnection.class.getName()); +196 } +197 +198 /** +199 * Some tests shut down the master. But table availability is a master RPC which is performed on +200 * region re-lookups. +201 */ +202 static class MasterlessConnection extends ConnectionImplementation { +203 MasterlessConnection(Configuration conf, ExecutorService pool, User user) throws IOException { +204 super(conf, pool, user); +205 } +206 +207 @Override +208 public boolean isTableDisabled(TableName tableName) throws IOException { +209 // treat all tables as enabled +210 return false; +211 } +212 } +213 +214 /** +215 * Return retires + 1. The returned value will be in range [1, Integer.MAX_VALUE]. +216 */ +217 static int retries2Attempts(int retries) { +218 return Math.max(1, retries == Integer.MAX_VALUE ? Integer.MAX_VALUE : retries + 1); +219 } +220 +221 /** +222 * Get a unique key for the rpc stub to the given server. +223 */ +224 static String getStubKey(String serviceName, ServerName serverName, boolean hostnameCanChange) { +225 // Sometimes, servers go down and they come back up with the same hostname but a different +226 // IP address. Force a resolution of the rsHostname by trying to instantiate an +227 // InetSocketAddress, and this way we will rightfully get a new stubKey. +228 // Also, include the hostname in the key so as to take care of those cases where the +229 // DNS name is different but IP address remains the same. +230 String hostname = serverName.getHostname(); +231 int port = serverName.getPort(); +232 if (hostnameCanChange) { +233 try { +234 InetAddress ip = InetAddress.getByName(hostname); +235 return serviceName + "@" + hostname + "-" + ip.getHostAddress() + ":" + port; +236 } catch (UnknownHostException e) { +237 LOG.warn("Can not resolve " + hostname + ", please check your network", e); +238 } +239 } +240 return serviceName + "@" + hostname + ":" + port; +241 } +242 +243 static void checkHasFamilies(Mutation mutation) { +244 Preconditions.checkArgument(mutation.numFamilies() > 0, +245 "Invalid arguments to %s, zero columns specified", mutation.toString()); +246 } +247 +248 /** Dummy nonce generator for disabled nonces. */ +249 static final NonceGenerator NO_NONCE_GENERATOR = new NonceGenerator() { +250 +251 @Override +252 public long newNonce() { +253 return HConstants.NO_NONCE; +254 } +255 +256 @Override +257 public long getNonceGroup() { +258 return HConstants.NO_NONCE; +259 } +260 }; +261 +262 // A byte array in which all elements are the max byte, and it is used to +263 // construct closest front row +264 static final byte[] MAX_BYTE_ARRAY = Bytes.createMaxByteArray(9); +265 +266 /** +267 * Create the closest row after the specified row +268 */ +269 static byte[] createClosestRowAfter(byte[] row) { +270 return Arrays.copyOf(row, row.length + 1); +271 } +272 +273 /** +274 * Create a row before the specified row and very close to the specified row. +275 */ +276 static byte[] createCloseRowBefore(byte[] row) { +277 if (row.length == 0) { +278 return MAX_BYTE_ARRAY; +279 } +280 if (row[row.length - 1] == 0) { +281 return Arrays.copyOf(row, row.length - 1); +282 } else { +283 byte[] nextRow = new byte[row.length + MAX_BYTE_ARRAY.length]; +284 System.arraycopy(row, 0, nextRow, 0, row.length - 1); +285 nextRow[row.length - 1] = (byte) ((row[row.length - 1] & 0xFF) - 1); +286 System.arraycopy(MAX_BYTE_ARRAY, 0, nextRow, row.length, MAX_BYTE_ARRAY.length); +287 return nextRow; +288 } +289 } +290 +291 static boolean isEmptyStartRow(byte[] row) { +292 return Bytes.equals(row, EMPTY_START_ROW); +293 } +294 +295 static boolean isEmptyStopRow(byte[] row) { +296 return Bytes.equals(row, EMPTY_END_ROW); +297 } +298 +299 static void resetController(HBaseRpcController controller, long timeoutNs) { +300 controller.reset(); +301 if (timeoutNs >= 0) { +302 controller.setCallTimeout( +303 (int) Math.min(Integer.MAX_VALUE, TimeUnit.NANOSECONDS.toMillis(timeoutNs))); +304 } +305 } +306 +307 static Throwable translateException(Throwable t) { +308 if (t instanceof UndeclaredThrowableException && t.getCause() != null) { +309 t = t.getCause(); +310 } +311 if (t instanceof RemoteException) { +312 t = ((RemoteException) t).unwrapRemoteException(); +313 } +314 if (t instanceof ServiceException && t.getCause() != null) { +315 t = translateException(t.getCause()); +316 } +317 return t; +318 } +319 +320 static long calcEstimatedSize(Result rs) { +321 long estimatedHeapSizeOfResult = 0; +322 // We don't make Iterator here +323 for (Cell cell : rs.rawCells()) { +324 estimatedHeapSizeOfResult += PrivateCellUtil.estimatedHeapSizeOf(cell); +325 } +326 return estimatedHeapSizeOfResult; +327 } +328 +329 static Result filterCells(Result result, Cell keepCellsAfter) { +330 if (keepCellsAfter == null) { +331 // do not need to filter +332 return result; +333 } +334 // not the same row +335 if (!PrivateCellUtil.matchingRows(keepCellsAfter, result.getRow(), 0, result.getRow().length)) { +336 return result; +337 } +338 Cell[] rawCells = result.rawCells(); +339 int index = +340 Arrays.binarySearch(rawCells, keepCellsAfter, CellComparator.getInstance()::compareWithoutRow); +341 if (index < 0) { +342 index = -index - 1; +343 } else { +344 index++; +345 } +346 if (index == 0) { +347 return result; +348 } +349 if (index == rawCells.length) { +350 return null; +351 } +352 return Result.create(Arrays.copyOfRange(rawCells, index, rawCells.length), null, +353 result.isStale(), result.mayHaveMoreCellsInRow()); +354 } +355 +356 // Add a delta to avoid timeout immediately after a retry sleeping. +357 static final long SLEEP_DELTA_NS = TimeUnit.MILLISECONDS.toNanos(1); +358 +359 static Get toCheckExistenceOnly(Get get) { +360 if (get.isCheckExistenceOnly()) { +361 return get; +362 } +363 return ReflectionUtils.newInstance(get.getClass(), get).setCheckExistenceOnly(true); +364 } +365 +366 static List<Get> toCheckExistenceOnly(List<Get> gets) { +367 return gets.stream().map(ConnectionUtils::toCheckExistenceOnly).collect(toList()); +368 } +369 +370 static RegionLocateType getLocateType(Scan scan) { +371 if (scan.isReversed()) { +372 if (isEmptyStartRow(scan.getStartRow())) { +373 return RegionLocateType.BEFORE; +374 } else { +375 return scan.includeStartRow() ? RegionLocateType.CURRENT : RegionLocateType.BEFORE; +376 } +377 } else { +378 return scan.includeStartRow() ? RegionLocateType.CURRENT : RegionLocateType.AFTER; +379 } +380 } +381 +382 static boolean noMoreResultsForScan(Scan scan, RegionInfo info) { +383 if (isEmptyStopRow(info.getEndKey())) { +384 return true; +385 } +386 if (isEmptyStopRow(scan.getStopRow())) { +387 return false; +388 } +389 int c = Bytes.compareTo(info.getEndKey(), scan.getStopRow()); +390 // 1. if our stop row is less than the endKey of the region +391 // 2. if our stop row is equal to the endKey of the region and we do not include the stop row +392 // for scan. +393 return c > 0 || (c == 0 && !scan.includeStopRow()); +394 } +395 +396 static boolean noMoreResultsForReverseScan(Scan scan, RegionInfo info) { +397 if (isEmptyStartRow(info.getStartKey())) { +398 return true; +399 } +400 if (isEmptyStopRow(scan.getStopRow())) { +401 return false; +402 } +403 // no need to test the inclusive of the stop row as the start key of a region is included in +404 // the region. +405 return Bytes.compareTo(info.getStartKey(), scan.getStopRow()) <= 0; +406 } +407 +408 static <T> CompletableFuture<List<T>> allOf(List<CompletableFuture<T>> futures) { +409 return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])) +410 .thenApply(v -> futures.stream().map(f -> f.getNow(null)).collect(toList())); +411 } +412 +413 public static ScanResultCache createScanResultCache(Scan scan) { +414 if (scan.getAllowPartialResults()) { +415 return new AllowPartialScanResultCache(); +416 } else if (scan.getBatch() > 0) { +417 return new BatchScanResultCache(scan.getBatch()); +418 } else { +419 return new CompleteScanResultCache(); +420 } +421 } +422 +423 private static final String MY_ADDRESS = getMyAddress(); +424 +425 private static String getMyAddress() { +426 try { +427 return DNS.getDefaultHost("default", "default"); +428 } catch (UnknownHostException uhe) { +429 LOG.error("cannot determine my address", uhe); +430 return null; +431 } +432 } +433 +434 static boolean isRemote(String host) { +435 return !host.equalsIgnoreCase(MY_ADDRESS); +436 } +437 +438 static void incRPCCallsMetrics(ScanMetrics scanMetrics, boolean isRegionServerRemote) { +439 if (scanMetrics == null) { +440 return; +441 } +442 scanMetrics.countOfRPCcalls.incrementAndGet(); +443 if (isRegionServerRemote) { +444 scanMetrics.countOfRemoteRPCcalls.incrementAndGet(); +445 } +446 } +447 +448 static void incRPCRetriesMetrics(ScanMetrics scanMetrics, boolean isRegionServerRemote) { +449 if (scanMetrics == null) { +450 return; +451 } +452 scanMetrics.countOfRPCRetries.incrementAndGet(); +453 if (isRegionServerRemote) { +454 scanMetrics.countOfRemoteRPCRetries.incrementAndGet(); +455 } +456 } +457 +458 static void updateResultsMetrics(ScanMetrics scanMetrics, Result[] rrs, +459 boolean isRegionServerRemote) { +460 if (scanMetrics == null || rrs == null || rrs.length == 0) { +461 return; +462 } +463 long resultSize = 0; +464 for (Result rr : rrs) { +465 for (Cell cell : rr.rawCells()) { +466 resultSize += PrivateCellUtil.estimatedSerializedSizeOf(cell); +467 } +468 } +469 scanMetrics.countOfBytesInResults.addAndGet(resultSize); +470 if (isRegionServerRemote) { +471 scanMetrics.countOfBytesInRemoteResults.addAndGet(resultSize); +472 } +473 } +474 +475 /** +476 * Use the scan metrics returned by the server to add to the identically named counters in the +477 * client side metrics. If a counter does not exist with the same name as the server side metric, +478 * the attempt to increase the counter will fail. +479 */ +480 static void updateServerSideMetrics(ScanMetrics scanMetrics, ScanResponse response) { +481 if (scanMetrics == null || response == null || !response.hasScanMetrics()) { +482 return; +483 } +484 ResponseConverter.getScanMetrics(response).forEach(scanMetrics::addToCounter); +485 } +486 +487 static void incRegionCountMetrics(ScanMetrics scanMetrics) { +488 if (scanMetrics == null) { +489 return; +490 } +491 scanMetrics.countOfRegions.incrementAndGet(); +492 } +493}