HBASE-1102 boolean HTabble.exists()

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@730361 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andrew Kyle Purtell 2008-12-31 09:53:11 +00:00
parent f484944c6c
commit 0bbcc18c60
7 changed files with 124 additions and 4 deletions

View File

@ -200,6 +200,7 @@ Release 0.19.0 - Unreleased
HBASE-1066 Master should support close/open/reassignment/enable/disable
operations on individual regions
HBASE-1062 Compactions at (re)start on a large table can overwhelm DFS
HBASE-1102 boolean HTable.exists()
NEW FEATURES
HBASE-875 Use MurmurHash instead of JenkinsHash [in bloomfilters]

View File

@ -1207,6 +1207,70 @@ public class HTable {
);
}
/**
* Test for the existence of a row in the table.
*
* @param row The row
* @return true if the row exists, false otherwise
* @throws IOException
*/
public boolean exists(final byte [] row) throws IOException {
return exists(row, null, HConstants.LATEST_TIMESTAMP, null);
}
/**
* Test for the existence of a row and column in the table.
*
* @param row The row
* @param column The column
* @return true if the row exists, false otherwise
* @throws IOException
*/
public boolean exists(final byte [] row, final byte[] column)
throws IOException {
return exists(row, column, HConstants.LATEST_TIMESTAMP, null);
}
/**
* Test for the existence of a coordinate in the table.
*
* @param row The row
* @param column The column
* @param timestamp The timestamp
* @return true if the specified coordinate exists
* @throws IOException
*/
public boolean exists(final byte [] row, final byte [] column,
long timestamp) throws IOException {
return exists(row, column, timestamp, null);
}
/**
* Test for the existence of a coordinate in the table.
*
* @param row The row
* @param column The column
* @param timestamp The timestamp
* @param rl Existing row lock
* @return true if the specified coordinate exists
* @throws IOException
*/
public boolean exists(final byte [] row, final byte [] column,
final long timestamp, final RowLock rl) throws IOException {
return connection.getRegionServerWithRetries(
new ServerCallable<Boolean>(connection, tableName, row) {
public Boolean call() throws IOException {
long lockId = -1L;
if (rl != null) {
lockId = rl.getLockId();
}
return server.exists(location.getRegionInfo().getRegionName(), row,
column, timestamp, lockId);
}
}
);
}
/**
* Commit a BatchUpdate to the table.
* If autoFlush is false, the update is buffered

View File

@ -64,7 +64,8 @@ public interface HBaseRPCProtocolVersion extends VersionedProtocol {
* <li>Version 12: HServerLoad extensions (HBASE-1018).</li>
* <li>Version 13: HBASE-847</li>
* <li>Version 14: HBASE-900</li>
* <li>Version 15: HRegionInterface.exists</li>
* </ul>
*/
public static final long versionID = 14L;
public static final long versionID = 15L;
}

View File

@ -191,6 +191,20 @@ public interface HRegionInterface extends HBaseRPCProtocolVersion {
long timestamp, long lockId)
throws IOException;
/**
* Returns true if any cells exist for the given coordinate.
*
* @param regionName The name of the region
* @param row The row
* @param column The column, or null for any
* @param timestamp The timestamp, or LATEST_TIMESTAMP for any
* @param lockId lock id
* @return true if the row exists, false otherwise
* @throws IOException
*/
public boolean exists(byte [] regionName, byte [] row, byte [] column,
long timestamp, long lockID)
throws IOException;
//
// remote scanner interface

View File

@ -1502,6 +1502,35 @@ public class HRegion implements HConstants {
}
}
/**
* Tests for the existence of any cells for a given coordinate.
*
* @param row the row
* @param column the column, or null
* @param timestamp the timestamp, or HConstants.LATEST_VERSION for any
* @param lockid the existing lock, or null
* @return true if cells exist for the row, false otherwise
* @throws IOException
*/
public boolean exists(final byte[] row, final byte[] column,
final long timestamp, final Integer lockid)
throws IOException {
checkRow(row);
Integer lid = getLock(lockid, row);
try {
HStoreKey origin;
if (column != null) {
origin = new HStoreKey(row, column, timestamp);
} else {
origin = new HStoreKey(row, timestamp);
}
return !getKeys(origin, 1).isEmpty();
} finally {
if (lockid == null)
releaseRowLock(lid);
}
}
/**
* @throws IOException Throws exception if region is in read-only mode.
*/

View File

@ -1774,6 +1774,13 @@ public class HRegionServer implements HConstants, HRegionInterface, Runnable {
getLockFromId(lockId));
}
public boolean exists(byte[] regionName, byte[] row, byte[] column,
long timestamp, long lockId)
throws IOException {
return getRegion(regionName).exists(row, column, timestamp,
getLockFromId(lockId));
}
public long lockRow(byte [] regionName, byte [] row)
throws IOException {
checkOpen();

View File

@ -229,6 +229,10 @@ public class TestHTable extends HBaseClusterTestCase implements HConstants {
table.commit(batchUpdate);
assertTrue(table.exists(row));
for(int i = 0; i < 5; i++)
assertTrue(table.exists(row, Bytes.toBytes(COLUMN_FAMILY_STR+i)));
RowResult result = null;
result = table.getRow(row, new byte[][] {COLUMN_FAMILY});
for(int i = 0; i < 5; i++)