Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make `ensureTableFamilyExists' and `ensureTableExists' cheaper.

Due to a bug in HBase (HBASE-3170), checking whether a table or
table+family exists was actually downloading the first key of the
table (regardless of what the key is).  Instead of doing a `get'
we now only do an `exists' RPC, which still forces the RegionServer
to load the first row in memory, but at least doesn't cause it to
send it over the wire.

Change-Id: Ie26a91e58722b73a6b39804e5d453e5e16b14e77
  • Loading branch information...
commit 33ebf2bde040880c95c061df81f24e28c283a19a 1 parent 07065fd
@tsuna tsuna authored
Showing with 21 additions and 4 deletions.
  1. +15 −0 src/GetRequest.java
  2. +6 −4 src/HBaseClient.java
View
15 src/GetRequest.java
@@ -102,6 +102,21 @@ static HBaseRpc exists(final byte[] table, final byte[] key) {
}
/**
+ * Package-private factory method to build an "exists" RPC.
+ * @param table The non-empty name of the table to use.
+ * @param key The row key to get in that table.
+ * @param family The column family to get in the table.
+ * @return An {@link HBaseRpc} that will return a {@link Boolean}
+ * indicating whether or not the given table / key exists.
+ */
+ static HBaseRpc exists(final byte[] table,
+ final byte[] key, final byte[] family) {
+ final GetRequest rpc = new GetRequest(0F, table, key);
+ rpc.family(family);
+ return rpc;
+ }
+
+ /**
* Specifies a particular column family to get.
* @param family The column family.
* <strong>This byte array will NOT be copied.</strong>
View
10 src/HBaseClient.java
@@ -860,12 +860,14 @@ public String toString() {
final byte[] family) {
// Just "fault in" the first region of the table. Not the most optimal or
// useful thing to do but gets the job done for now. TODO(tsuna): Improve.
- final GetRequest dummy = new GetRequest(table, EMPTY_ARRAY);
- if (family != EMPTY_ARRAY) {
- dummy.family(family);
+ final HBaseRpc dummy;
+ if (family == EMPTY_ARRAY) {
+ dummy = GetRequest.exists(table, EMPTY_ARRAY);
+ } else {
+ dummy = GetRequest.exists(table, EMPTY_ARRAY, family);
}
@SuppressWarnings("unchecked")
- final Deferred<Object> d = (Deferred) get(dummy);
+ final Deferred<Object> d = (Deferred) sendRpcToRegion(dummy);
return d;
}
Please sign in to comment.
Something went wrong with that request. Please try again.