From 89e715fd8dd8f6d1787aebbed66fe08e63a53b33 Mon Sep 17 00:00:00 2001 From: Alex Newman Date: Mon, 16 Jan 2012 10:24:02 -0800 Subject: [PATCH] HBASE-2600. Change how we do meta tables; from tablename+STARTROW+randomid to instead, tablename+ENDROW+randomid Removed all references to getClosestRowOrBefore --- .../java/org/apache/hadoop/hbase/HConstants.java | 8 +- .../java/org/apache/hadoop/hbase/HRegionInfo.java | 304 ++++--- .../org/apache/hadoop/hbase/HTableDescriptor.java | 66 ++- .../java/org/apache/hadoop/hbase/KeyValue.java | 2 +- .../apache/hadoop/hbase/catalog/MetaReader.java | 33 +- .../org/apache/hadoop/hbase/client/HBaseAdmin.java | 4 +- .../hadoop/hbase/client/HConnectionManager.java | 144 ++- .../org/apache/hadoop/hbase/client/HTable.java | 14 - .../hadoop/hbase/client/HTableInterface.java | 17 - .../org/apache/hadoop/hbase/client/HTablePool.java | 5 - .../apache/hadoop/hbase/client/MetaScanner.java | 45 +- .../hbase/coprocessor/BaseRegionObserver.java | 12 - .../hadoop/hbase/coprocessor/CoprocessorHost.java | 5 - .../hadoop/hbase/coprocessor/RegionObserver.java | 34 - .../apache/hadoop/hbase/ipc/HRegionInterface.java | 14 - .../master/handler/ServerShutdownHandler.java | 2 +- .../regionserver/GetClosestRowBeforeTracker.java | 240 ----- .../apache/hadoop/hbase/regionserver/HRegion.java | 56 - .../hadoop/hbase/regionserver/HRegionServer.java | 16 - .../apache/hadoop/hbase/regionserver/MemStore.java | 105 -- .../hbase/regionserver/RegionCoprocessorHost.java | 54 - .../apache/hadoop/hbase/regionserver/Store.java | 126 --- .../apache/hadoop/hbase/rest/RegionsResource.java | 17 +- .../hadoop/hbase/rest/client/RemoteHTable.java | 4 - .../hadoop/hbase/rest/model/TableRegionModel.java | 35 +- .../apache/hadoop/hbase/thrift/ThriftServer.java | 18 +- .../hadoop/hbase/thrift/generated/Hbase.java | 1066 -------------------- .../org/apache/hadoop/hbase/thrift/Hbase.thrift | 16 - .../java/org/apache/hadoop/hbase/TestKeyValue.java | 10 +- .../hadoop/hbase/client/TestFromClientSide.java | 50 - .../hbase/coprocessor/SimpleRegionObserver.java | 28 - .../regionserver/TestGetClosestAtOrBefore.java | 348 ------- .../hadoop/hbase/regionserver/TestHRegionInfo.java | 13 +- .../hadoop/hbase/regionserver/TestMinVersions.java | 42 - .../hadoop/hbase/rest/TestStatusResource.java | 17 +- .../hbase/rest/model/TestTableRegionModel.java | 28 +- 36 files changed, 456 insertions(+), 2542 deletions(-) delete mode 100644 src/main/java/org/apache/hadoop/hbase/regionserver/GetClosestRowBeforeTracker.java delete mode 100644 src/test/java/org/apache/hadoop/hbase/regionserver/TestGetClosestAtOrBefore.java diff --git src/main/java/org/apache/hadoop/hbase/HConstants.java src/main/java/org/apache/hadoop/hbase/HConstants.java index 904e2d2..5d8854b 100644 --- src/main/java/org/apache/hadoop/hbase/HConstants.java +++ src/main/java/org/apache/hadoop/hbase/HConstants.java @@ -44,7 +44,10 @@ public final class HConstants { /** long constant for zero */ public static final Long ZERO_L = Long.valueOf(0L); + public static final String NINES = "99999999999999"; + + @Deprecated public static final String ZEROES = "00000000000000"; // For migration @@ -249,7 +252,7 @@ public final class HConstants { // Always store the location of the root table's HRegion. // This HRegion is never split. - // region name = table + startkey + regionid. This is the row key. + // region name = table + endkey + regionid. This is the row key. // each row in the root and meta tables describes exactly 1 region // Do we ever need to know all the information that we are storing? @@ -272,9 +275,6 @@ public final class HConstants { /** The META table's name. */ public static final byte [] META_TABLE_NAME = Bytes.toBytes(".META."); - /** delimiter used between portions of a region name */ - public static final int META_ROW_DELIMITER = ','; - /** The catalog family as a string*/ public static final String CATALOG_FAMILY_STR = "info"; diff --git src/main/java/org/apache/hadoop/hbase/HRegionInfo.java src/main/java/org/apache/hadoop/hbase/HRegionInfo.java index 74cb821..2b57cd1 100644 --- src/main/java/org/apache/hadoop/hbase/HRegionInfo.java +++ src/main/java/org/apache/hadoop/hbase/HRegionInfo.java @@ -23,6 +23,8 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.EOFException; import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.MappedByteBuffer; import java.util.Arrays; import org.apache.commons.logging.Log; @@ -31,6 +33,8 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.KeyValue.KVComparator; + + import org.apache.hadoop.hbase.migration.HRegionInfo090x; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.FSTableDescriptors; @@ -57,13 +61,13 @@ implements WritableComparable { * in the filesystem. * * New region name format: - * <tablename>,,<startkey>,<regionIdTimestamp>.<encodedName>. + * <tablename>,,<endkey>,<regionIdTimestamp>.<encodedName>. * where, * <encodedName> is a hex version of the MD5 hash of - * <tablename>,<startkey>,<regionIdTimestamp> + * <tablename>,<endkey>,<regionIdTimestamp> * * The old region name format: - * <tablename>,<startkey>,<regionIdTimestamp> + * <tablename>,<endkey>,<regionIdTimestamp> * For region names in the old format, the encoded name is a 32-bit * JenkinsHash integer value (in its decimal notation, string form). *

@@ -77,8 +81,8 @@ implements WritableComparable { /** Separator used to demarcate the encodedName in a region name * in the new format. See description on new format above. */ - private static final int ENC_SEPARATOR = '.'; - public static final int MD5_HEX_LENGTH = 32; + public static final int ENC_SEPARATOR = '.'; + public static final int MD5_HEX_LENGTH = 32; /** * Does region name contain its encoded name? @@ -91,7 +95,7 @@ implements WritableComparable { if ((regionName.length >= 1) && (regionName[regionName.length - 1] == ENC_SEPARATOR)) { // region name is new format. it contains the encoded name. - return true; + return true; } return false; } @@ -104,7 +108,7 @@ implements WritableComparable { String encodedName; if (hasEncodedName(regionName)) { // region is in new format: - // ,,/encodedName/ + // ,,/encodedName/ encodedName = Bytes.toString(regionName, regionName.length - MD5_HEX_LENGTH - 1, MD5_HEX_LENGTH); @@ -137,13 +141,19 @@ implements WritableComparable { /** delimiter used between portions of a region name */ public static final int DELIMITER = ','; + // It should say, the tablename encoded in the region ends with !, + // but the last region's tablename ends with " + public static final int END_OF_TABLE_NAME = 33; // The ascii for ! + public static final int END_OF_TABLE_NAME_FOR_EMPTY_ENDKEY = + END_OF_TABLE_NAME + 1; + /** HRegionInfo for root region */ public static final HRegionInfo ROOT_REGIONINFO = - new HRegionInfo(0L, Bytes.toBytes("-ROOT-")); + new HRegionInfo(0L, HConstants.ROOT_TABLE_NAME); /** HRegionInfo for first meta region */ public static final HRegionInfo FIRST_META_REGIONINFO = - new HRegionInfo(1L, Bytes.toBytes(".META.")); + new HRegionInfo(1L, HConstants.META_TABLE_NAME); private byte [] endKey = HConstants.EMPTY_BYTE_ARRAY; // This flag is in the parent of a split while the parent is still referenced @@ -272,7 +282,11 @@ implements WritableComparable { this.offLine = false; this.regionId = regionid; - this.regionName = createRegionName(this.tableName, startKey, regionId, true); + this.regionName = createRegionName(this.tableName, + startKey, + endKey, + regionId, + true); this.regionNameStr = Bytes.toStringBinary(this.regionName); this.split = split; @@ -283,7 +297,19 @@ implements WritableComparable { setHashCode(); } - /** + private byte[] createRegionName(byte[] tableName, + byte[] startKey, + byte[] endKey, + long regionId, + boolean b) { + return createRegionName(tableName, + startKey, + endKey, + Long.toString(regionId), + b); + } + + /** * Costruct a copy of another HRegionInfo * * @param other @@ -303,35 +329,29 @@ implements WritableComparable { } - /** - * Make a region name of passed parameters. - * @param tableName - * @param startKey Can be null - * @param regionid Region id (Usually timestamp from when region was created). - * @param newFormat should we create the region name in the new format - * (such that it contains its encoded name?). - * @return Region name made of passed tableName, startKey and id - */ - public static byte [] createRegionName(final byte [] tableName, - final byte [] startKey, final long regionid, boolean newFormat) { - return createRegionName(tableName, startKey, Long.toString(regionid), newFormat); - } - - /** - * Make a region name of passed parameters. - * @param tableName - * @param startKey Can be null - * @param id Region id (Usually timestamp from when region was created). - * @param newFormat should we create the region name in the new format - * (such that it contains its encoded name?). - * @return Region name made of passed tableName, startKey and id - */ - public static byte [] createRegionName(final byte [] tableName, - final byte [] startKey, final String id, boolean newFormat) { - return createRegionName(tableName, startKey, Bytes.toBytes(id), newFormat); - } + /** + * Make a region name of passed parameters. + * + * + * @param tableName + * @param regionid Region id (Usually timestamp from when region was + * created). + * @param newFormat should we create the region name in the new format + * (such that it contains its encoded name?). + * @return Region name made of passed tableName, endKey and id + */ + public static byte[] createRegionName(final byte[] tableName, + final byte[] endKey, + final long regionid, + boolean newFormat) { + return createRegionName(tableName, + null, + endKey, + Long.toString(regionid), + newFormat); + } - /** +/** * Make a region name of passed parameters. * @param tableName * @param startKey Can be null @@ -340,48 +360,94 @@ implements WritableComparable { * (such that it contains its encoded name?). * @return Region name made of passed tableName, startKey and id */ - public static byte [] createRegionName(final byte [] tableName, - final byte [] startKey, final byte [] id, boolean newFormat) { - byte [] b = new byte [tableName.length + 2 + id.length + - (startKey == null? 0: startKey.length) + - (newFormat ? (MD5_HEX_LENGTH + 2) : 0)]; - - int offset = tableName.length; - System.arraycopy(tableName, 0, b, 0, offset); - b[offset++] = DELIMITER; - if (startKey != null && startKey.length > 0) { - System.arraycopy(startKey, 0, b, offset, startKey.length); - offset += startKey.length; + public static byte [] createRegionName(final byte[] tableName, + final byte[] startKey, + final byte[] endKey, + final String id, + boolean newFormat) { + return createRegionName(tableName, + startKey, + endKey, + Bytes.toBytes(id), + newFormat); + } + /** + * Make a region name of passed parameters. + * + * @param tableName + * @param startKey Can be null + * @param endKey Can be null + * @param id Region id (Usually timestamp from when region was + * created). + * @param newFormat should we create the region name in the new format + * (such that it contains its encoded name?). + * @return Region name made of passed tableName, endKey and id + */ + + public static byte[] createRegionName(final byte[] tableName, + final byte[] startKey, + final byte[] endKey, + final byte[] id, + boolean newFormat) { + // Allocate room for the tablename along with the end of table + // marker and the delimiter. + int allocation = tableName.length + 2; + + // If the endKey is null just allocate space for the delimiter, else + // allocate enough for the key and a delimiter + allocation += endKey == null ? 1 : endKey.length + 1; + allocation += id == null ? 0 : id.length; + + ByteBuffer byteArrayDataOutput = MappedByteBuffer.allocate(allocation); + byteArrayDataOutput.put(tableName); + + if (endKey == null || endKey.length <= 0) { + byteArrayDataOutput.put((byte)END_OF_TABLE_NAME_FOR_EMPTY_ENDKEY); + byteArrayDataOutput.put((byte)DELIMITER); + } else { + byteArrayDataOutput.put((byte)END_OF_TABLE_NAME); + byteArrayDataOutput.put((byte)DELIMITER); + byteArrayDataOutput.put(endKey); + } + byteArrayDataOutput.put((byte)DELIMITER); + + if (id != null && id.length > 0) { + byteArrayDataOutput.put(id); + } + + if (newFormat) { + return addEncoding(byteArrayDataOutput.array()); + } else { + return byteArrayDataOutput.array(); + } } - b[offset++] = DELIMITER; - System.arraycopy(id, 0, b, offset, id.length); - offset += id.length; - - if (newFormat) { - // - // Encoded name should be built into the region name. - // - // Use the region name thus far (namely, ,,) - // to compute a MD5 hash to be used as the encoded name, and append - // it to the byte buffer. - // - String md5Hash = MD5Hash.getMD5AsHex(b, 0, offset); - byte [] md5HashBytes = Bytes.toBytes(md5Hash); - - if (md5HashBytes.length != MD5_HEX_LENGTH) { - LOG.error("MD5-hash length mismatch: Expected=" + MD5_HEX_LENGTH + - "; Got=" + md5HashBytes.length); - } - // now append the bytes '..' to the end - b[offset++] = ENC_SEPARATOR; - System.arraycopy(md5HashBytes, 0, b, offset, MD5_HEX_LENGTH); - offset += MD5_HEX_LENGTH; - b[offset++] = ENC_SEPARATOR; + private static byte[] addEncoding(final byte[] metaKey) { + + + // + // Encoded name should be built into the region name. + // + // Use the region name thus far (namely, tablename followed by ! or " + // ! means it is not the last region in the table + // and " means that it is the last region in the table. ,,) + // to compute a MD5 hash to be used as the encoded name, and append + // it to the byte buffer. + // + + final byte[] md5HashBytes = MD5Hash.getMD5AsHex(metaKey).getBytes(); + + if (md5HashBytes.length != MD5_HEX_LENGTH) { + LOG.error("MD5-hash length mismatch: Expected=" + MD5_HEX_LENGTH + + "; Got=" + md5HashBytes.length); + } + + byte[] encoding = Bytes.add(new byte[]{ENC_SEPARATOR}, + md5HashBytes, + new byte[]{ENC_SEPARATOR}); + return Bytes.add(metaKey, encoding); } - - return b; - } + /** * Gets the table name from the specified region name. @@ -392,7 +458,7 @@ implements WritableComparable { int offset = -1; for (int i = 0; i < regionName.length; i++) { if (regionName[i] == DELIMITER) { - offset = i; + offset = i - 1; break; } } @@ -401,47 +467,49 @@ implements WritableComparable { return tableName; } - /** - * Separate elements of a regionName. - * @param regionName - * @return Array of byte[] containing tableName, startKey and id - * @throws IOException - */ - public static byte [][] parseRegionName(final byte [] regionName) - throws IOException { - int offset = -1; - for (int i = 0; i < regionName.length; i++) { - if (regionName[i] == DELIMITER) { - offset = i; - break; - } + /** + * Separate elements of a regionName. + * + * @param regionName + * @return Array of byte[] containing the tablename, endKey and id + * @throws IOException + */ + public static byte[][] parseRegionName(final byte[] regionName) + throws IOException { + int offset = -1; + + for (int i = 0; i < regionName.length; i++) { + if (regionName[i] == DELIMITER) { + offset = i - 1; + break; + } + } + if (offset == -1) throw new IOException("Invalid regionName format"); + byte[] tableName = new byte[offset]; + System.arraycopy(regionName, 0, tableName, 0, offset); + offset = -1; + for (int i = regionName.length - 1; i > 0; i--) { + if (regionName[i] == DELIMITER) { + offset = i; + break; + } + } + if (offset == -1) throw new IOException("Invalid regionName format"); + byte[] endKey = HConstants.EMPTY_BYTE_ARRAY; + if (offset != tableName.length + 1) { + endKey = new byte[offset - tableName.length - 1]; + System.arraycopy(regionName, tableName.length + 1, endKey, 0, + offset - tableName.length - 1); + } + byte[] id = new byte[regionName.length - offset - 1]; + System.arraycopy(regionName, offset + 1, id, 0, + regionName.length - offset - 1); + byte[][] elements = new byte[3][]; + elements[0] = tableName; + elements[1] = endKey; + elements[2] = id; + return elements; } - if(offset == -1) throw new IOException("Invalid regionName format"); - byte [] tableName = new byte[offset]; - System.arraycopy(regionName, 0, tableName, 0, offset); - offset = -1; - for (int i = regionName.length - 1; i > 0; i--) { - if(regionName[i] == DELIMITER) { - offset = i; - break; - } - } - if(offset == -1) throw new IOException("Invalid regionName format"); - byte [] startKey = HConstants.EMPTY_BYTE_ARRAY; - if(offset != tableName.length + 1) { - startKey = new byte[offset - tableName.length - 1]; - System.arraycopy(regionName, tableName.length + 1, startKey, 0, - offset - tableName.length - 1); - } - byte [] id = new byte[regionName.length - offset - 1]; - System.arraycopy(regionName, offset + 1, id, 0, - regionName.length - offset - 1); - byte [][] elements = new byte[3][]; - elements[0] = tableName; - elements[1] = startKey; - elements[2] = id; - return elements; - } /** @return the regionId */ public long getRegionId(){ diff --git src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java index 133759d..10eec21 100644 --- src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java +++ src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java @@ -258,13 +258,65 @@ public class HTableDescriptor implements WritableComparable { } } - /* - * Set meta flags on this table. - * IS_ROOT_KEY is set if its a -ROOT- table - * IS_META_KEY is set either if its a -ROOT- or a .META. table - * Called by constructors. - * @param name - */ + /** + * This gives you a stop row for scanning for a particular region in meta. + * It's important that we don't scan past the end of the regions for a + * particular table. + * + * @param tableName The tablename in meta in which we want + * to provide a stopRow for scanning for. + * @return The stopRow to prevent scanning past the last region in meta for + * a table. + */ + + public static byte[] getStopRow(final byte[] tableName) { + final int allocation = tableName.length + 3; + byte[] b = new byte[allocation]; + int offset = tableName.length; + System.arraycopy(tableName, 0, b, 0, offset); + + b[offset++] = (byte) (HRegionInfo.END_OF_TABLE_NAME_FOR_EMPTY_ENDKEY + 1); + b[offset++] = HRegionInfo.DELIMITER; + b[offset++] = HRegionInfo.DELIMITER; + return b; + } + + /** + * Get the first possible region that could match a particular + * tablename and searchrow. + * + * @param tableName The tableName in which we are searching for the matching + * region. + * @param searchRow The row in which we are searching for the matching region + * @return The first possible matching region. + */ + public static byte[] getStartRow(final byte[] tableName, + final byte[] searchRow) { + + if (searchRow == null || searchRow.length == 0) { + final int allocation = tableName.length + 3; + byte[] startRow = new byte[allocation]; + System.arraycopy(tableName, 0, startRow, 0, tableName.length); + startRow[tableName.length] = HRegionInfo.END_OF_TABLE_NAME - 1; + startRow[tableName.length + 1] = HRegionInfo.DELIMITER; + startRow[tableName.length + 2] = HRegionInfo.DELIMITER; + return startRow; + } + + return HRegionInfo.createRegionName(tableName, + null, + searchRow, + HConstants.NINES, + false); + } + + /* + * Set meta flags on this table. + * IS_ROOT_KEY is set if its a -ROOT- table + * IS_META_KEY is set either if its a -ROOT- or a .META. table + * Called by constructors. + * @param name + */ private void setMetaFlags(final byte [] name) { setRootRegion(Bytes.equals(name, HConstants.ROOT_TABLE_NAME)); setMetaRegion(isRootRegion() || diff --git src/main/java/org/apache/hadoop/hbase/KeyValue.java src/main/java/org/apache/hadoop/hbase/KeyValue.java index be7e2d8..4a40cb0 100644 --- src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -1896,7 +1896,7 @@ public class KeyValue implements Writable, HeapSize { // Rows look like this: .META.,ROW_FROM_META,RID // LOG.info("ROOT " + Bytes.toString(left, loffset, llength) + // "---" + Bytes.toString(right, roffset, rlength)); - final int metalength = 7; // '.META.' length + final int metalength = 8; // '.META.' length int lmetaOffsetPlusDelimiter = loffset + metalength; int leftFarDelimiter = getDelimiterInReverse(left, lmetaOffsetPlusDelimiter, diff --git src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java index e5e60a8..97a33e1 100644 --- src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java +++ src/main/java/org/apache/hadoop/hbase/catalog/MetaReader.java @@ -443,7 +443,9 @@ public class MetaReader { this.results.add(this.current); } }; - fullScan(catalogTracker, visitor, getTableStartRowForMeta(tableNameBytes)); + byte[] startRow = HTableDescriptor.getStartRow(tableName.getBytes(), + HConstants.EMPTY_BYTE_ARRAY); + fullScan(catalogTracker, visitor, startRow); // If visitor has results >= 1 then table exists. return visitor.getResults().size() >= 1; } @@ -502,18 +504,7 @@ public class MetaReader { return Bytes.equals(tableName, current.getTableName()); } - /** - * @param tableName - * @return Place to start Scan in .META. when passed a - * tableName; returns <tableName&rt; <,&rt; <,&rt; - */ - static byte [] getTableStartRowForMeta(final byte [] tableName) { - byte [] startRow = new byte[tableName.length + 2]; - System.arraycopy(tableName, 0, startRow, 0, tableName.length); - startRow[startRow.length - 2] = HRegionInfo.DELIMITER; - startRow[startRow.length - 1] = HRegionInfo.DELIMITER; - return startRow; - } + /** * This method creates a Scan object that will only scan catalog rows that @@ -527,12 +518,12 @@ public class MetaReader { public static Scan getScanForTableName(byte[] tableName) { String strName = Bytes.toString(tableName); // Start key is just the table name with delimiters - byte[] startKey = Bytes.toBytes(strName + ",,"); + byte[] startKey = HTableDescriptor.getStartRow(tableName, + HConstants.EMPTY_BYTE_ARRAY); // Stop key appends the smallest possible char to the table name - byte[] stopKey = Bytes.toBytes(strName + " ,,"); + byte[] stopKey = HTableDescriptor.getStopRow(tableName); - Scan scan = new Scan(startKey); - scan.setStopRow(stopKey); + Scan scan = new Scan(startKey, stopKey); return scan; } @@ -547,7 +538,7 @@ public class MetaReader { getTableRegionsAndLocations(CatalogTracker catalogTracker, String tableName) throws IOException, InterruptedException { return getTableRegionsAndLocations(catalogTracker, Bytes.toBytes(tableName), - true); + true); } /** @@ -597,8 +588,10 @@ public class MetaReader { this.results.add(this.current); } }; - fullScan(catalogTracker, visitor, getTableStartRowForMeta(tableName), - Bytes.equals(tableName, HConstants.META_TABLE_NAME)); + byte[] startRow = HTableDescriptor.getStartRow(tableName, + HConstants.EMPTY_BYTE_ARRAY); + boolean isMeta = Bytes.equals(tableName, HConstants.META_TABLE_NAME); + fullScan(catalogTracker, visitor, startRow, isMeta); return visitor.getResults(); } diff --git src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 88c381f..6ca3c34 100644 --- src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -1553,8 +1553,8 @@ public class HBaseAdmin implements Abortable, Closeable { private HRegionLocation getFirstMetaServerForTable(final byte [] tableName) throws IOException { - return connection.locateRegion(HConstants.META_TABLE_NAME, - HRegionInfo.createRegionName(tableName, null, HConstants.NINES, false)); + byte[] metaRowKey = HTableDescriptor.getStartRow(tableName, null); + return connection.locateRegion(HConstants.META_TABLE_NAME, metaRowKey); } /** diff --git src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java index 99f90b2..c934aa5 100644 --- src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -822,8 +822,13 @@ public class HConnectionManager { return null; } } else if (Bytes.equals(tableName, HConstants.META_TABLE_NAME)) { - return locateRegionInMeta(HConstants.ROOT_TABLE_NAME, tableName, row, - useCache, metaRegionLock); + + //HARD CODED TO POINT TO THE FIRST META TABLE + return locateRegionInMeta(HConstants.ROOT_TABLE_NAME, + HConstants.META_TABLE_NAME, + HConstants.EMPTY_BYTE_ARRAY, + useCache, + metaRegionLock); } else { // Region not in the cache - have to go to the meta RS return locateRegionInMeta(HConstants.META_TABLE_NAME, tableName, row, @@ -891,9 +896,51 @@ public class HConnectionManager { } } + + private HRegionInfo resultToHRegionInfo(final Result result, + byte[] tableName, + byte[] parentTable) + throws IOException { + + if (result == null) { + throw new TableNotFoundException(Bytes.toString(tableName)); + } + + byte[] value = result.getValue(HConstants.CATALOG_FAMILY, + HConstants.REGIONINFO_QUALIFIER); + + if (value == null || value.length == 0) { + throw new IOException("HRegionInfo was null or empty in " + + Bytes.toString(parentTable) + + ", row=" + + result); + } + + HRegionInfo regionInfo = Writables.getHRegionInfo(value); + + // possible we got a region of a different table... + + if (!Bytes.equals(regionInfo.getTableName(), tableName)) { + String errorMsg = "Table '" + Bytes.toString(tableName) + "' was not found, got: "; + if (regionInfo != null) { + errorMsg += Bytes.toString(regionInfo.getTableName()) + "."; + } + throw new TableNotFoundException(errorMsg); + } + + return regionInfo; + } + private boolean finishedScanningForRegion(HRegionInfo regionInfo) { + if (regionInfo == null || regionInfo.isOffline() || regionInfo.isSplit()) { + return false; + } + return true; + } + /* * Search one of the meta tables (-ROOT- or .META.) for the HRegionLocation - * info that contains the table and row we're seeking. + * info that contains the table and row we're seeking. If the row is null or 0 length + * then return a key which scans to the first meta key for the table. */ private HRegionLocation locateRegionInMeta(final byte [] parentTable, final byte [] tableName, final byte [] row, boolean useCache, @@ -909,17 +956,13 @@ public class HConnectionManager { } } - // build the key of the meta region we should be looking for. - // the extra 9's on the end are necessary to allow "exact" matches - // without knowing the precise region names. - byte [] metaKey = HRegionInfo.createRegionName(tableName, row, - HConstants.NINES, false); + final byte [] metaKey = HTableDescriptor.getStartRow(tableName, row); for (int tries = 0; true; tries++) { if (tries >= numRetries) { throw new NoServerForRegionException("Unable to find region for " + Bytes.toStringBinary(row) + " after " + numRetries + " tries."); } - + Result regionInfoRow = null; HRegionLocation metaLocation = null; try { // locate the root or meta region @@ -929,10 +972,11 @@ public class HConnectionManager { HRegionInterface server = getHRegionConnection(metaLocation.getHostname(), metaLocation.getPort()); - Result regionInfoRow = null; // This block guards against two threads trying to load the meta // region at the same time. The first will load the meta region and // the second will use the value that the first one found. + + HRegionInfo regionInfo = null; synchronized (regionLockObject) { // If the parent table is META, we may want to pre-fetch some // region info into the global region cache for this table. @@ -954,46 +998,62 @@ public class HConnectionManager { deleteCachedLocation(tableName, row); } - // Query the root or meta region for the location of the meta region - regionInfoRow = server.getClosestRowBefore( - metaLocation.getRegionInfo().getRegionName(), metaKey, - HConstants.CATALOG_FAMILY); - } - if (regionInfoRow == null) { - throw new TableNotFoundException(Bytes.toString(tableName)); - } - byte [] value = regionInfoRow.getValue(HConstants.CATALOG_FAMILY, - HConstants.REGIONINFO_QUALIFIER); - if (value == null || value.length == 0) { - throw new IOException("HRegionInfo was null or empty in " + - Bytes.toString(parentTable) + ", row=" + regionInfoRow); - } - // convert the row result into the HRegionLocation we need! - HRegionInfo regionInfo = (HRegionInfo) Writables.getWritable( - value, new HRegionInfo()); - // possible we got a region of a different table... - if (!Bytes.equals(regionInfo.getTableName(), tableName)) { - throw new TableNotFoundException( - "Table '" + Bytes.toString(tableName) + "' was not found, got: " + - Bytes.toString(regionInfo.getTableName()) + "."); + byte[] stopRow = HTableDescriptor.getStopRow(tableName); + Scan scan = new Scan(metaKey).addFamily(HConstants.CATALOG_FAMILY); + byte[] regionName = metaLocation.getRegionInfo().getRegionName(); + long scannerId = server.openScanner(regionName, scan); + + // We always try to get two rows just in case one of them is a split. + Result[] result = server.next(scannerId, 2); + + // We haven't cleared the meta entry out of the table yet + if (result == null || result.length <= 0 ) { + throw new TableNotFoundException("Table '" + Bytes.toString(tableName) + + " we searched for the StartKey: " + Bytes.toString(metaKey) + + " startKey lastChar's int value: " + (int) metaKey[metaKey.length -3] + + " with the stopKey: " + Bytes.toString(stopRow) + + " stopRow lastChar's int value: " + (int) stopRow[stopRow.length -3] + + " with parentTable:" + Bytes.toString(parentTable)); + } else if (result.length == 2) { + regionInfoRow = result[0]; + regionInfo = resultToHRegionInfo(regionInfoRow, + tableName, + parentTable); + if (regionInfo.isOffline()) { + regionInfoRow = result[1]; + regionInfo = resultToHRegionInfo(regionInfoRow, + tableName, + parentTable); + } + } else { + regionInfoRow = result[0]; + regionInfo = resultToHRegionInfo(regionInfoRow, tableName, parentTable); + } + } + + if (regionInfo == null) { + throw new TableNotFoundException("Table '" + + Bytes.toString(tableName) + "' was not found, got: " + + Bytes.toString(regionInfo.getTableName()) + "."); } + if (regionInfo.isSplit()) { throw new RegionOfflineException("the only available region for" + - " the required row is a split parent," + - " the daughters should be online soon: " + - regionInfo.getRegionNameAsString()); + " the required row is a split parent," + + " the daughters should be online soon: " + + regionInfo.getRegionNameAsString()); } if (regionInfo.isOffline()) { throw new RegionOfflineException("the region is offline, could" + - " be caused by a disable table call: " + - regionInfo.getRegionNameAsString()); + " be caused by a disable table call: " + + regionInfo.getRegionNameAsString()); } - value = regionInfoRow.getValue(HConstants.CATALOG_FAMILY, - HConstants.SERVER_QUALIFIER); String hostAndPort = ""; - if (value != null) { - hostAndPort = Bytes.toString(value); + if (regionInfoRow.getValue(HConstants.CATALOG_FAMILY, + HConstants.SERVER_QUALIFIER) != null) { + hostAndPort = Bytes.toString(regionInfoRow.getValue(HConstants.CATALOG_FAMILY, + HConstants.SERVER_QUALIFIER)); } if (hostAndPort.equals("")) { throw new NoServerForRegionException("No server address listed " + @@ -1849,4 +1909,4 @@ public class HConnectionManager { c.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, retries); log.debug("Set serverside HConnection retries=" + retries); } -} \ No newline at end of file +} diff --git src/main/java/org/apache/hadoop/hbase/client/HTable.java src/main/java/org/apache/hadoop/hbase/client/HTable.java index 8aeccb6..56bcd96 100644 --- src/main/java/org/apache/hadoop/hbase/client/HTable.java +++ src/main/java/org/apache/hadoop/hbase/client/HTable.java @@ -562,20 +562,6 @@ public class HTable implements HTableInterface { return allRegions; } - /** - * {@inheritDoc} - */ - @Override - public Result getRowOrBefore(final byte[] row, final byte[] family) - throws IOException { - return new ServerCallable(connection, tableName, row, operationTimeout) { - public Result call() throws IOException { - return server.getClosestRowBefore(location.getRegionInfo().getRegionName(), - row, family); - } - }.withRetries(); - } - /** * {@inheritDoc} */ diff --git src/main/java/org/apache/hadoop/hbase/client/HTableInterface.java src/main/java/org/apache/hadoop/hbase/client/HTableInterface.java index 8af8c28..df89af1 100644 --- src/main/java/org/apache/hadoop/hbase/client/HTableInterface.java +++ src/main/java/org/apache/hadoop/hbase/client/HTableInterface.java @@ -130,23 +130,6 @@ public interface HTableInterface extends Closeable { Result[] get(List gets) throws IOException; /** - * Return the row that matches row exactly, - * or the one that immediately precedes it. - * - * @param row A row key. - * @param family Column family to include in the {@link Result}. - * @throws IOException if a remote or network exception occurs. - * @since 0.20.0 - * - * @deprecated As of version 0.92 this method is deprecated without - * replacement. - * getRowOrBefore is used internally to find entries in .META. and makes - * various assumptions about the table (which are true for .META. but not - * in general) to be efficient. - */ - Result getRowOrBefore(byte[] row, byte[] family) throws IOException; - - /** * Returns a scanner on the current table as specified by the {@link Scan} * object. * Note that the passed {@link Scan}'s start row and caching properties diff --git src/main/java/org/apache/hadoop/hbase/client/HTablePool.java src/main/java/org/apache/hadoop/hbase/client/HTablePool.java index a5c198f..83fecb1 100755 --- src/main/java/org/apache/hadoop/hbase/client/HTablePool.java +++ src/main/java/org/apache/hadoop/hbase/client/HTablePool.java @@ -372,11 +372,6 @@ public class HTablePool implements Closeable { } @Override - public Result getRowOrBefore(byte[] row, byte[] family) throws IOException { - return table.getRowOrBefore(row, family); - } - - @Override public ResultScanner getScanner(Scan scan) throws IOException { return table.getScanner(scan); } diff --git src/main/java/org/apache/hadoop/hbase/client/MetaScanner.java src/main/java/org/apache/hadoop/hbase/client/MetaScanner.java index f0c6828..f557168 100644 --- src/main/java/org/apache/hadoop/hbase/client/MetaScanner.java +++ src/main/java/org/apache/hadoop/hbase/client/MetaScanner.java @@ -31,8 +31,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; +import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.ServerName; -import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.client.HConnectionManager.HConnectable; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Writables; @@ -138,39 +138,17 @@ public class MetaScanner { // if row is not null, we want to use the startKey of the row's region as // the startRow for the meta scan. - byte[] startRow; - if (row != null) { - // Scan starting at a particular row in a particular table - assert tableName != null; - byte[] searchRow = - HRegionInfo.createRegionName(tableName, row, HConstants.NINES, - false); - HTable metaTable = new HTable(configuration, HConstants.META_TABLE_NAME); - Result startRowResult = metaTable.getRowOrBefore(searchRow, - HConstants.CATALOG_FAMILY); - if (startRowResult == null) { - throw new TableNotFoundException("Cannot find row in .META. for table: " - + Bytes.toString(tableName) + ", row=" + Bytes.toStringBinary(searchRow)); - } - byte[] value = startRowResult.getValue(HConstants.CATALOG_FAMILY, - HConstants.REGIONINFO_QUALIFIER); - if (value == null || value.length == 0) { - throw new IOException("HRegionInfo was null or empty in Meta for " + - Bytes.toString(tableName) + ", row=" + Bytes.toStringBinary(searchRow)); - } - HRegionInfo regionInfo = Writables.getHRegionInfo(value); + byte[] startRow; + byte[] stopRow; - byte[] rowBefore = regionInfo.getStartKey(); - startRow = HRegionInfo.createRegionName(tableName, rowBefore, - HConstants.ZEROES, false); - } else if (tableName == null || tableName.length == 0) { + if (tableName == null || tableName.length == 0) { // Full META scan startRow = HConstants.EMPTY_START_ROW; + stopRow = null; } else { - // Scan META for an entire table - startRow = HRegionInfo.createRegionName( - tableName, HConstants.EMPTY_START_ROW, HConstants.ZEROES, false); + startRow = HTableDescriptor.getStartRow(tableName, row); + stopRow = HTableDescriptor.getStopRow(tableName); } // Scan over each meta region @@ -178,8 +156,15 @@ public class MetaScanner { int rows = Math.min(rowLimit, configuration.getInt( HConstants.HBASE_META_SCANNER_CACHING, HConstants.DEFAULT_HBASE_META_SCANNER_CACHING)); + do { - final Scan scan = new Scan(startRow).addFamily(HConstants.CATALOG_FAMILY); + Scan scan; + if (stopRow != null) { // Support full meta scans + scan = new Scan(startRow, stopRow).addFamily(HConstants.CATALOG_FAMILY); + } else { + scan = new Scan(startRow).addFamily(HConstants.CATALOG_FAMILY); + } + if (LOG.isDebugEnabled()) { LOG.debug("Scanning " + Bytes.toString(metaTableName) + " starting at row=" + Bytes.toStringBinary(startRow) + " for max=" + diff --git src/main/java/org/apache/hadoop/hbase/coprocessor/BaseRegionObserver.java src/main/java/org/apache/hadoop/hbase/coprocessor/BaseRegionObserver.java index 7a7b896..4476a55 100644 --- src/main/java/org/apache/hadoop/hbase/coprocessor/BaseRegionObserver.java +++ src/main/java/org/apache/hadoop/hbase/coprocessor/BaseRegionObserver.java @@ -100,18 +100,6 @@ public abstract class BaseRegionObserver implements RegionObserver { final Store store, final StoreFile resultFile) { } @Override - public void preGetClosestRowBefore(final ObserverContext e, - final byte [] row, final byte [] family, final Result result) - throws IOException { - } - - @Override - public void postGetClosestRowBefore(final ObserverContext e, - final byte [] row, final byte [] family, final Result result) - throws IOException { - } - - @Override public void preGet(final ObserverContext e, final Get get, final List results) throws IOException { } diff --git src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java index b47423c..3d979b2 100644 --- src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java +++ src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java @@ -365,11 +365,6 @@ public abstract class CoprocessorHost { } } - public Result getRowOrBefore(byte[] row, byte[] family) - throws IOException { - return table.getRowOrBefore(row, family); - } - public Result get(Get get) throws IOException { return table.get(get); } diff --git src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java index c0a4184..9114884 100644 --- src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java +++ src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java @@ -162,40 +162,6 @@ public interface RegionObserver extends Coprocessor { boolean abortRequested); /** - * Called before a client makes a GetClosestRowBefore request. - *

- * Call CoprocessorEnvironment#bypass to skip default actions - *

- * Call CoprocessorEnvironment#complete to skip any subsequent chained - * coprocessors - * @param c the environment provided by the region server - * @param row the row - * @param family the family - * @param result The result to return to the client if default processing - * is bypassed. Can be modified. Will not be used if default processing - * is not bypassed. - * @throws IOException if an error occurred on the coprocessor - */ - void preGetClosestRowBefore(final ObserverContext c, - final byte [] row, final byte [] family, final Result result) - throws IOException; - - /** - * Called after a client makes a GetClosestRowBefore request. - *

- * Call CoprocessorEnvironment#complete to skip any subsequent chained - * coprocessors - * @param c the environment provided by the region server - * @param row the row - * @param family the desired family - * @param result the result to return to the client, modify as necessary - * @throws IOException if an error occurred on the coprocessor - */ - void postGetClosestRowBefore(final ObserverContext c, - final byte [] row, final byte [] family, final Result result) - throws IOException; - - /** * Called before the client performs a Get *

* Call CoprocessorEnvironment#bypass to skip default actions diff --git src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java index 25ae9a8..e602499 100644 --- src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java +++ src/main/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java @@ -130,20 +130,6 @@ public interface HRegionInterface extends VersionedProtocol, Stoppable, Abortabl throws IllegalArgumentException; /** - * Return all the data for the row that matches row exactly, - * or the one that immediately preceeds it. - * - * @param regionName region name - * @param row row key - * @param family Column family to look for row in. - * @return map of values - * @throws IOException e - */ - public Result getClosestRowBefore(final byte [] regionName, - final byte [] row, final byte [] family) - throws IOException; - - /** * Perform Get operation. * @param regionName name of region to get from * @param get Get operation diff --git src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java index 8f4f4b8..bf4d978 100644 --- src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java +++ src/main/java/org/apache/hadoop/hbase/master/handler/ServerShutdownHandler.java @@ -442,7 +442,7 @@ public class ServerShutdownHandler extends EventHandler { return false; } // If our start rows do not compare, move on. - if (!Bytes.equals(daughter.getStartKey(), hri.getStartKey())) { + if (!Bytes.equals(daughter.getEndKey(), hri.getEndKey())) { return false; } // Else, table name and start rows compare. It means that the daughter diff --git src/main/java/org/apache/hadoop/hbase/regionserver/GetClosestRowBeforeTracker.java src/main/java/org/apache/hadoop/hbase/regionserver/GetClosestRowBeforeTracker.java deleted file mode 100644 index 3a26bbb..0000000 --- src/main/java/org/apache/hadoop/hbase/regionserver/GetClosestRowBeforeTracker.java +++ /dev/null @@ -1,240 +0,0 @@ -/* - * Copyright 2009 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.regionserver; - -import java.util.NavigableMap; -import java.util.NavigableSet; -import java.util.TreeMap; -import java.util.TreeSet; - -import org.apache.hadoop.hbase.HRegionInfo; -import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.KeyValue.KVComparator; -import org.apache.hadoop.hbase.util.Bytes; - -/** - * State and utility processing {@link HRegion#getClosestRowBefore(byte[], byte[])}. - * Like {@link ScanDeleteTracker} and {@link ScanDeleteTracker} but does not - * implement the {@link DeleteTracker} interface since state spans rows (There - * is no update nor reset method). - */ -class GetClosestRowBeforeTracker { - private final KeyValue targetkey; - // Any cell w/ a ts older than this is expired. - private final long oldestts; - private KeyValue candidate = null; - private final KVComparator kvcomparator; - // Flag for whether we're doing getclosest on a metaregion. - private final boolean metaregion; - // Offset and length into targetkey demarking table name (if in a metaregion). - private final int rowoffset; - private final int tablenamePlusDelimiterLength; - - // Deletes keyed by row. Comparator compares on row portion of KeyValue only. - private final NavigableMap> deletes; - - /** - * @param c - * @param kv Presume first on row: i.e. empty column, maximum timestamp and - * a type of Type.Maximum - * @param ttl Time to live in ms for this Store - * @param metaregion True if this is .META. or -ROOT- region. - */ - GetClosestRowBeforeTracker(final KVComparator c, final KeyValue kv, - final long ttl, final boolean metaregion) { - super(); - this.metaregion = metaregion; - this.targetkey = kv; - // If we are in a metaregion, then our table name is the prefix on the - // targetkey. - this.rowoffset = kv.getRowOffset(); - int l = -1; - if (metaregion) { - l = KeyValue.getDelimiter(kv.getBuffer(), rowoffset, kv.getRowLength(), - HRegionInfo.DELIMITER) - this.rowoffset; - } - this.tablenamePlusDelimiterLength = metaregion? l + 1: -1; - this.oldestts = System.currentTimeMillis() - ttl; - this.kvcomparator = c; - KeyValue.RowComparator rc = new KeyValue.RowComparator(this.kvcomparator); - this.deletes = new TreeMap>(rc); - } - - /** - * @param kv - * @return True if this kv is expired. - */ - boolean isExpired(final KeyValue kv) { - return Store.isExpired(kv, this.oldestts); - } - - /* - * Add the specified KeyValue to the list of deletes. - * @param kv - */ - private void addDelete(final KeyValue kv) { - NavigableSet rowdeletes = this.deletes.get(kv); - if (rowdeletes == null) { - rowdeletes = new TreeSet(this.kvcomparator); - this.deletes.put(kv, rowdeletes); - } - rowdeletes.add(kv); - } - - /* - * @param kv Adds candidate if nearer the target than previous candidate. - * @return True if updated candidate. - */ - private boolean addCandidate(final KeyValue kv) { - if (!isDeleted(kv) && isBetterCandidate(kv)) { - this.candidate = kv; - return true; - } - return false; - } - - boolean isBetterCandidate(final KeyValue contender) { - return this.candidate == null || - (this.kvcomparator.compareRows(this.candidate, contender) < 0 && - this.kvcomparator.compareRows(contender, this.targetkey) <= 0); - } - - /* - * Check if specified KeyValue buffer has been deleted by a previously - * seen delete. - * @param kv - * @return true is the specified KeyValue is deleted, false if not - */ - private boolean isDeleted(final KeyValue kv) { - if (this.deletes.isEmpty()) return false; - NavigableSet rowdeletes = this.deletes.get(kv); - if (rowdeletes == null || rowdeletes.isEmpty()) return false; - return isDeleted(kv, rowdeletes); - } - - /** - * Check if the specified KeyValue buffer has been deleted by a previously - * seen delete. - * @param kv - * @param ds - * @return True is the specified KeyValue is deleted, false if not - */ - public boolean isDeleted(final KeyValue kv, final NavigableSet ds) { - if (deletes == null || deletes.isEmpty()) return false; - for (KeyValue d: ds) { - long kvts = kv.getTimestamp(); - long dts = d.getTimestamp(); - if (d.isDeleteFamily()) { - if (kvts <= dts) return true; - continue; - } - // Check column - int ret = Bytes.compareTo(kv.getBuffer(), kv.getQualifierOffset(), - kv.getQualifierLength(), - d.getBuffer(), d.getQualifierOffset(), d.getQualifierLength()); - if (ret <= -1) { - // This delete is for an earlier column. - continue; - } else if (ret >= 1) { - // Beyond this kv. - break; - } - // Check Timestamp - if (kvts > dts) return false; - - // Check Type - switch (KeyValue.Type.codeToType(d.getType())) { - case Delete: return kvts == dts; - case DeleteColumn: return true; - default: continue; - } - } - return false; - } - - /* - * Handle keys whose values hold deletes. - * Add to the set of deletes and then if the candidate keys contain any that - * might match, then check for a match and remove it. Implies candidates - * is made with a Comparator that ignores key type. - * @param kv - * @return True if we removed k from candidates. - */ - boolean handleDeletes(final KeyValue kv) { - addDelete(kv); - boolean deleted = false; - if (!hasCandidate()) return deleted; - if (isDeleted(this.candidate)) { - this.candidate = null; - deleted = true; - } - return deleted; - } - - /** - * Do right thing with passed key, add to deletes or add to candidates. - * @param kv - * @return True if we added a candidate - */ - boolean handle(final KeyValue kv) { - if (kv.isDelete()) { - handleDeletes(kv); - return false; - } - return addCandidate(kv); - } - - /** - * @return True if has candidate - */ - public boolean hasCandidate() { - return this.candidate != null; - } - - /** - * @return Best candidate or null. - */ - public KeyValue getCandidate() { - return this.candidate; - } - - public KeyValue getTargetKey() { - return this.targetkey; - } - - /** - * @param kv Current kv - * @param First on row kv. - * @param state - * @return True if we went too far, past the target key. - */ - boolean isTooFar(final KeyValue kv, final KeyValue firstOnRow) { - return this.kvcomparator.compareRows(kv, firstOnRow) > 0; - } - - boolean isTargetTable(final KeyValue kv) { - if (!metaregion) return true; - // Compare start of keys row. Compare including delimiter. Saves having - // to calculate where tablename ends in the candidate kv. - return Bytes.compareTo(this.targetkey.getBuffer(), this.rowoffset, - this.tablenamePlusDelimiterLength, - kv.getBuffer(), kv.getRowOffset(), this.tablenamePlusDelimiterLength) == 0; - } -} \ No newline at end of file diff --git src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 48f6d77..4d2b382 100644 --- src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -1539,62 +1539,6 @@ public class HRegion implements HeapSize { // , Writable{ // get() methods for client use. ////////////////////////////////////////////////////////////////////////////// /** - * Return all the data for the row that matches row exactly, - * or the one that immediately preceeds it, at or immediately before - * ts. - * - * @param row row key - * @return map of values - * @throws IOException - */ - Result getClosestRowBefore(final byte [] row) - throws IOException{ - return getClosestRowBefore(row, HConstants.CATALOG_FAMILY); - } - - /** - * Return all the data for the row that matches row exactly, - * or the one that immediately preceeds it, at or immediately before - * ts. - * - * @param row row key - * @param family column family to find on - * @return map of values - * @throws IOException read exceptions - */ - public Result getClosestRowBefore(final byte [] row, final byte [] family) - throws IOException { - if (coprocessorHost != null) { - Result result = new Result(); - if (coprocessorHost.preGetClosestRowBefore(row, family, result)) { - return result; - } - } - // look across all the HStores for this region and determine what the - // closest key is across all column families, since the data may be sparse - checkRow(row, "getClosestRowBefore"); - startRegionOperation(); - this.readRequestsCount.increment(); - try { - Store store = getStore(family); - // get the closest key. (HStore.getRowKeyAtOrBefore can return null) - KeyValue key = store.getRowKeyAtOrBefore(row); - Result result = null; - if (key != null) { - Get get = new Get(key.getRow()); - get.addFamily(family); - result = get(get, null); - } - if (coprocessorHost != null) { - coprocessorHost.postGetClosestRowBefore(row, family, result); - } - return result; - } finally { - closeRegionOperation(); - } - } - - /** * Return an iterator that scans over the HRegion, returning the indicated * columns and rows specified by the {@link Scan}. *

diff --git src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 79373e1..46967d8 100644 --- src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -1899,22 +1899,6 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, return getRegion(regionName).getRegionInfo(); } - public Result getClosestRowBefore(final byte[] regionName, final byte[] row, - final byte[] family) throws IOException { - checkOpen(); - requestCount.incrementAndGet(); - try { - // locate the region we're operating on - HRegion region = getRegion(regionName); - // ask the region for all the data - - Result r = region.getClosestRowBefore(row, family); - return r; - } catch (Throwable t) { - throw convertThrowableToIOE(cleanup(t)); - } - } - /** {@inheritDoc} */ public Result get(byte[] regionName, Get get) throws IOException { checkOpen(); diff --git src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java index 50e7fe0..63b1136 100644 --- src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java +++ src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java @@ -352,88 +352,6 @@ public class MemStore implements HeapSize { } /** - * @param state column/delete tracking state - */ - void getRowKeyAtOrBefore(final GetClosestRowBeforeTracker state) { - this.lock.readLock().lock(); - try { - getRowKeyAtOrBefore(kvset, state); - getRowKeyAtOrBefore(snapshot, state); - } finally { - this.lock.readLock().unlock(); - } - } - - /* - * @param set - * @param state Accumulates deletes and candidates. - */ - private void getRowKeyAtOrBefore(final NavigableSet set, - final GetClosestRowBeforeTracker state) { - if (set.isEmpty()) { - return; - } - if (!walkForwardInSingleRow(set, state.getTargetKey(), state)) { - // Found nothing in row. Try backing up. - getRowKeyBefore(set, state); - } - } - - /* - * Walk forward in a row from firstOnRow. Presumption is that - * we have been passed the first possible key on a row. As we walk forward - * we accumulate deletes until we hit a candidate on the row at which point - * we return. - * @param set - * @param firstOnRow First possible key on this row. - * @param state - * @return True if we found a candidate walking this row. - */ - private boolean walkForwardInSingleRow(final SortedSet set, - final KeyValue firstOnRow, final GetClosestRowBeforeTracker state) { - boolean foundCandidate = false; - SortedSet tail = set.tailSet(firstOnRow); - if (tail.isEmpty()) return foundCandidate; - for (Iterator i = tail.iterator(); i.hasNext();) { - KeyValue kv = i.next(); - // Did we go beyond the target row? If so break. - if (state.isTooFar(kv, firstOnRow)) break; - if (state.isExpired(kv)) { - i.remove(); - continue; - } - // If we added something, this row is a contender. break. - if (state.handle(kv)) { - foundCandidate = true; - break; - } - } - return foundCandidate; - } - - /* - * Walk backwards through the passed set a row at a time until we run out of - * set or until we get a candidate. - * @param set - * @param state - */ - private void getRowKeyBefore(NavigableSet set, - final GetClosestRowBeforeTracker state) { - KeyValue firstOnRow = state.getTargetKey(); - for (Member p = memberOfPreviousRow(set, state, firstOnRow); - p != null; p = memberOfPreviousRow(p.set, state, firstOnRow)) { - // Make sure we don't fall out of our table. - if (!state.isTargetTable(p.kv)) break; - // Stop looking if we've exited the better candidate range. - if (!state.isBetterCandidate(p.kv)) break; - // Make into firstOnRow - firstOnRow = new KeyValue(p.kv.getRow(), HConstants.LATEST_TIMESTAMP); - // If we find something, break; - if (walkForwardInSingleRow(p.set, firstOnRow, state)) break; - } - } - - /** * Given the specs of a column, update it, first by inserting a new record, * then removing the old one. Since there is only 1 KeyValue involved, the memstoreTS * will be set to 0, thus ensuring that they instantly appear to anyone. The underlying @@ -608,29 +526,6 @@ public class MemStore implements HeapSize { } } - /* - * @param set Set to walk back in. Pass a first in row or we'll return - * same row (loop). - * @param state Utility and context. - * @param firstOnRow First item on the row after the one we want to find a - * member in. - * @return Null or member of row previous to firstOnRow - */ - private Member memberOfPreviousRow(NavigableSet set, - final GetClosestRowBeforeTracker state, final KeyValue firstOnRow) { - NavigableSet head = set.headSet(firstOnRow, false); - if (head.isEmpty()) return null; - for (Iterator i = head.descendingIterator(); i.hasNext();) { - KeyValue found = i.next(); - if (state.isExpired(found)) { - i.remove(); - continue; - } - return new Member(head, found); - } - return null; - } - /** * @return scanner on memstore and snapshot in this order. */ diff --git src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java index a3850e5..34143a4 100644 --- src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java +++ src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java @@ -484,60 +484,6 @@ public class RegionCoprocessorHost // RegionObserver support /** - * @param row the row key - * @param family the family - * @param result the result set from the region - * @return true if default processing should be bypassed - * @exception IOException Exception - */ - public boolean preGetClosestRowBefore(final byte[] row, final byte[] family, - final Result result) throws IOException { - boolean bypass = false; - ObserverContext ctx = null; - for (RegionEnvironment env: coprocessors) { - if (env.getInstance() instanceof RegionObserver) { - ctx = ObserverContext.createAndPrepare(env, ctx); - try { - ((RegionObserver)env.getInstance()).preGetClosestRowBefore(ctx, row, - family, result); - } catch (Throwable e) { - handleCoprocessorThrowable(env, e); - } - bypass |= ctx.shouldBypass(); - if (ctx.shouldComplete()) { - break; - } - } - } - return bypass; - } - - /** - * @param row the row key - * @param family the family - * @param result the result set from the region - * @exception IOException Exception - */ - public void postGetClosestRowBefore(final byte[] row, final byte[] family, - final Result result) throws IOException { - ObserverContext ctx = null; - for (RegionEnvironment env: coprocessors) { - if (env.getInstance() instanceof RegionObserver) { - ctx = ObserverContext.createAndPrepare(env, ctx); - try { - ((RegionObserver)env.getInstance()).postGetClosestRowBefore(ctx, row, - family, result); - } catch (Throwable e) { - handleCoprocessorThrowable(env, e); - } - if (ctx.shouldComplete()) { - break; - } - } - } - } - - /** * @param get the Get request * @return true if default processing should be bypassed * @exception IOException Exception diff --git src/main/java/org/apache/hadoop/hbase/regionserver/Store.java src/main/java/org/apache/hadoop/hbase/regionserver/Store.java index 636e533..42085d0 100644 --- src/main/java/org/apache/hadoop/hbase/regionserver/Store.java +++ src/main/java/org/apache/hadoop/hbase/regionserver/Store.java @@ -1630,99 +1630,6 @@ public class Store extends SchemaConfigured implements HeapSize { return key.getTimestamp() < oldestTimestamp; } - /** - * Find the key that matches row exactly, or the one that immediately - * preceeds it. WARNING: Only use this method on a table where writes occur - * with strictly increasing timestamps. This method assumes this pattern of - * writes in order to make it reasonably performant. Also our search is - * dependent on the axiom that deletes are for cells that are in the container - * that follows whether a memstore snapshot or a storefile, not for the - * current container: i.e. we'll see deletes before we come across cells we - * are to delete. Presumption is that the memstore#kvset is processed before - * memstore#snapshot and so on. - * @param row The row key of the targeted row. - * @return Found keyvalue or null if none found. - * @throws IOException - */ - KeyValue getRowKeyAtOrBefore(final byte[] row) throws IOException { - // If minVersions is set, we will not ignore expired KVs. - // As we're only looking for the latest matches, that should be OK. - // With minVersions > 0 we guarantee that any KV that has any version - // at all (expired or not) has at least one version that will not expire. - // Note that this method used to take a KeyValue as arguments. KeyValue - // can be back-dated, a row key cannot. - long ttlToUse = scanInfo.getMinVersions() > 0 ? Long.MAX_VALUE : this.ttl; - - KeyValue kv = new KeyValue(row, HConstants.LATEST_TIMESTAMP); - - GetClosestRowBeforeTracker state = new GetClosestRowBeforeTracker( - this.comparator, kv, ttlToUse, this.region.getRegionInfo().isMetaRegion()); - this.lock.readLock().lock(); - try { - // First go to the memstore. Pick up deletes and candidates. - this.memstore.getRowKeyAtOrBefore(state); - // Check if match, if we got a candidate on the asked for 'kv' row. - // Process each store file. Run through from newest to oldest. - for (StoreFile sf : Lists.reverse(storefiles)) { - // Update the candidate keys from the current map file - rowAtOrBeforeFromStoreFile(sf, state); - } - return state.getCandidate(); - } finally { - this.lock.readLock().unlock(); - } - } - - /* - * Check an individual MapFile for the row at or before a given row. - * @param f - * @param state - * @throws IOException - */ - private void rowAtOrBeforeFromStoreFile(final StoreFile f, - final GetClosestRowBeforeTracker state) - throws IOException { - StoreFile.Reader r = f.getReader(); - if (r == null) { - LOG.warn("StoreFile " + f + " has a null Reader"); - return; - } - // TODO: Cache these keys rather than make each time? - byte [] fk = r.getFirstKey(); - KeyValue firstKV = KeyValue.createKeyValueFromKey(fk, 0, fk.length); - byte [] lk = r.getLastKey(); - KeyValue lastKV = KeyValue.createKeyValueFromKey(lk, 0, lk.length); - KeyValue firstOnRow = state.getTargetKey(); - if (this.comparator.compareRows(lastKV, firstOnRow) < 0) { - // If last key in file is not of the target table, no candidates in this - // file. Return. - if (!state.isTargetTable(lastKV)) return; - // If the row we're looking for is past the end of file, set search key to - // last key. TODO: Cache last and first key rather than make each time. - firstOnRow = new KeyValue(lastKV.getRow(), HConstants.LATEST_TIMESTAMP); - } - // Get a scanner that caches blocks and that uses pread. - HFileScanner scanner = r.getHFileReader().getScanner(true, true, false); - // Seek scanner. If can't seek it, return. - if (!seekToScanner(scanner, firstOnRow, firstKV)) return; - // If we found candidate on firstOnRow, just return. THIS WILL NEVER HAPPEN! - // Unlikely that there'll be an instance of actual first row in table. - if (walkForwardInSingleRow(scanner, firstOnRow, state)) return; - // If here, need to start backing up. - while (scanner.seekBefore(firstOnRow.getBuffer(), firstOnRow.getKeyOffset(), - firstOnRow.getKeyLength())) { - KeyValue kv = scanner.getKeyValue(); - if (!state.isTargetTable(kv)) break; - if (!state.isBetterCandidate(kv)) break; - // Make new first on row. - firstOnRow = new KeyValue(kv.getRow(), HConstants.LATEST_TIMESTAMP); - // Seek scanner. If can't seek it, break. - if (!seekToScanner(scanner, firstOnRow, firstKV)) break; - // If we find something, break; - if (walkForwardInSingleRow(scanner, firstOnRow, state)) break; - } - } - /* * Seek the file scanner to firstOnRow or first entry in file. * @param scanner @@ -1743,39 +1650,6 @@ public class Store extends SchemaConfigured implements HeapSize { return result >= 0; } - /* - * When we come in here, we are probably at the kv just before we break into - * the row that firstOnRow is on. Usually need to increment one time to get - * on to the row we are interested in. - * @param scanner - * @param firstOnRow - * @param state - * @return True we found a candidate. - * @throws IOException - */ - private boolean walkForwardInSingleRow(final HFileScanner scanner, - final KeyValue firstOnRow, - final GetClosestRowBeforeTracker state) - throws IOException { - boolean foundCandidate = false; - do { - KeyValue kv = scanner.getKeyValue(); - // If we are not in the row, skip. - if (this.comparator.compareRows(kv, firstOnRow) < 0) continue; - // Did we go beyond the target row? If so break. - if (state.isTooFar(kv, firstOnRow)) break; - if (state.isExpired(kv)) { - continue; - } - // If we added something, this row is a contender. break. - if (state.handle(kv)) { - foundCandidate = true; - break; - } - } while(scanner.next()); - return foundCandidate; - } - public boolean canSplit() { this.lock.readLock().lock(); try { diff --git src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java index bf85bc1..be5db4c 100644 --- src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java +++ src/main/java/org/apache/hadoop/hbase/rest/RegionsResource.java @@ -21,8 +21,8 @@ package org.apache.hadoop.hbase.rest; import java.io.IOException; -import java.net.InetSocketAddress; import java.util.Map; +import java.util.NavigableMap; import javax.ws.rs.GET; import javax.ws.rs.Produces; @@ -37,7 +37,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.HRegionInfo; -import org.apache.hadoop.hbase.HServerAddress; +import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.HTableInterface; @@ -67,12 +67,12 @@ public class RegionsResource extends ResourceBase { this.tableResource = tableResource; } - private Map getTableRegions() + private NavigableMap getTableRegions() throws IOException { HTablePool pool = servlet.getTablePool(); HTableInterface table = pool.getTable(tableResource.getName()); try { - return ((HTable)table).getRegionsInfo(); + return ((HTable)table).getRegionLocations(); } finally { pool.putTable(table); } @@ -88,15 +88,14 @@ public class RegionsResource extends ResourceBase { try { String tableName = tableResource.getName(); TableInfoModel model = new TableInfoModel(tableName); - Map regions = getTableRegions(); - for (Map.Entry e: regions.entrySet()) { + NavigableMap regions = getTableRegions(); + for (Map.Entry e: regions.entrySet()) { HRegionInfo hri = e.getKey(); - HServerAddress addr = e.getValue(); - InetSocketAddress sa = addr.getInetSocketAddress(); + ServerName addr = e.getValue(); model.add( new TableRegionModel(tableName, hri.getRegionId(), hri.getStartKey(), hri.getEndKey(), - sa.getHostName() + ":" + Integer.valueOf(sa.getPort()))); + addr.getHostname() + ":" + Integer.valueOf(addr.getPort()))); } ResponseBuilder response = Response.ok(model); response.cacheControl(cacheControl); diff --git src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java index f93c81d..4e9199c 100644 --- src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java +++ src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java @@ -570,10 +570,6 @@ public class RemoteHTable implements HTableInterface { return true; } - public Result getRowOrBefore(byte[] row, byte[] family) throws IOException { - throw new IOException("getRowOrBefore not supported"); - } - public RowLock lockRow(byte[] row) throws IOException { throw new IOException("lockRow not implemented"); } diff --git src/main/java/org/apache/hadoop/hbase/rest/model/TableRegionModel.java src/main/java/org/apache/hadoop/hbase/rest/model/TableRegionModel.java index 67e7a04..17f699f 100644 --- src/main/java/org/apache/hadoop/hbase/rest/model/TableRegionModel.java +++ src/main/java/org/apache/hadoop/hbase/rest/model/TableRegionModel.java @@ -66,8 +66,7 @@ public class TableRegionModel implements Serializable { * @param startKey the start key of the region * @param endKey the end key of the region */ - public TableRegionModel(String table, long id, byte[] startKey, - byte[] endKey) { + public TableRegionModel(String table, long id, byte[] startKey, byte[] endKey) { this(table, id, startKey, endKey, null); } @@ -79,8 +78,7 @@ public class TableRegionModel implements Serializable { * @param endKey the end key of the region * @param location the name and port of the region server hosting the region */ - public TableRegionModel(String table, long id, byte[] startKey, - byte[] endKey, String location) { + public TableRegionModel(String table, long id, byte[] startKey, byte[] endKey, String location) { this.table = table; this.id = id; this.startKey = startKey; @@ -95,9 +93,11 @@ public class TableRegionModel implements Serializable { public String getName() { byte [] tableNameAsBytes = Bytes.toBytes(this.table); byte [] nameAsBytes = HRegionInfo.createRegionName(tableNameAsBytes, - this.startKey, this.id, - !HTableDescriptor.isMetaTable(tableNameAsBytes)); - return Bytes.toString(nameAsBytes); + this.startKey, + this.endKey, + Long.toString(this.id).getBytes(), + !HTableDescriptor.isMetaTable(tableNameAsBytes)); + return Bytes.toStringBinary(nameAsBytes); } /** @@ -109,6 +109,14 @@ public class TableRegionModel implements Serializable { } /** + * @return the table name + */ + @XmlAttribute + public String getTable() { + return table; + } + + /** * @return the start key */ @XmlAttribute @@ -133,15 +141,10 @@ public class TableRegionModel implements Serializable { } /** - * @param name region printable name + * @param table the table name */ - public void setName(String name) { - String split[] = name.split(","); - this.table = split[0]; - this.startKey = Bytes.toBytes(split[1]); - String tail = split[2]; - split = tail.split("\\."); - id = Long.valueOf(split[0]); + public void setTable(String table) { + this.table = table; } /** @@ -185,6 +188,8 @@ public class TableRegionModel implements Serializable { sb.append(Bytes.toString(startKey)); sb.append("'\n endKey='"); sb.append(Bytes.toString(endKey)); + sb.append("'\n table='"); + sb.append(table); if (location != null) { sb.append("'\n location='"); sb.append(location); diff --git src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java index 3fa5d41..e5d3768 100644 --- src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java +++ src/main/java/org/apache/hadoop/hbase/thrift/ThriftServer.java @@ -1018,24 +1018,12 @@ public class ThriftServer { } @Override - public List getRowOrBefore(ByteBuffer tableName, ByteBuffer row, - ByteBuffer family) throws IOError { - try { - HTable table = getTable(getBytes(tableName)); - Result result = table.getRowOrBefore(getBytes(row), getBytes(family)); - return ThriftUtilities.cellFromHBase(result.raw()); - } catch (IOException e) { - throw new IOError(e.getMessage()); - } - } - - @Override public TRegionInfo getRegionInfo(ByteBuffer searchRow) throws IOError { try { HTable table = getTable(HConstants.META_TABLE_NAME); - Result startRowResult = table.getRowOrBefore( - searchRow.array(), HConstants.CATALOG_FAMILY); - + Scan scan = new Scan(searchRow.array()); + ResultScanner scanner = table.getScanner(scan); + Result startRowResult = scanner.next(); if (startRowResult == null) { throw new IOException("Cannot find row in .META., row=" + Bytes.toString(searchRow.array())); diff --git src/main/java/org/apache/hadoop/hbase/thrift/generated/Hbase.java src/main/java/org/apache/hadoop/hbase/thrift/generated/Hbase.java index 9e31c61..2ea0ff3 100644 --- src/main/java/org/apache/hadoop/hbase/thrift/generated/Hbase.java +++ src/main/java/org/apache/hadoop/hbase/thrift/generated/Hbase.java @@ -527,19 +527,6 @@ public class Hbase { public void scannerClose(int id) throws IOError, IllegalArgument, org.apache.thrift.TException; /** - * Get the row just before the specified one. - * - * @return value for specified row/column - * - * @param tableName name of table - * - * @param row row key - * - * @param family column name - */ - public List getRowOrBefore(ByteBuffer tableName, ByteBuffer row, ByteBuffer family) throws IOError, org.apache.thrift.TException; - - /** * Get the regininfo for the specified row. It scans * the metatable to find region's start and end keys. * @@ -630,8 +617,6 @@ public class Hbase { public void scannerClose(int id, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; - public void getRowOrBefore(ByteBuffer tableName, ByteBuffer row, ByteBuffer family, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; - public void getRegionInfo(ByteBuffer row, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException; } @@ -1715,34 +1700,6 @@ public class Hbase { return; } - public List getRowOrBefore(ByteBuffer tableName, ByteBuffer row, ByteBuffer family) throws IOError, org.apache.thrift.TException - { - send_getRowOrBefore(tableName, row, family); - return recv_getRowOrBefore(); - } - - public void send_getRowOrBefore(ByteBuffer tableName, ByteBuffer row, ByteBuffer family) throws org.apache.thrift.TException - { - getRowOrBefore_args args = new getRowOrBefore_args(); - args.setTableName(tableName); - args.setRow(row); - args.setFamily(family); - sendBase("getRowOrBefore", args); - } - - public List recv_getRowOrBefore() throws IOError, org.apache.thrift.TException - { - getRowOrBefore_result result = new getRowOrBefore_result(); - receiveBase(result, "getRowOrBefore"); - if (result.isSetSuccess()) { - return result.success; - } - if (result.io != null) { - throw result.io; - } - throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "getRowOrBefore failed: unknown result"); - } - public TRegionInfo getRegionInfo(ByteBuffer row) throws IOError, org.apache.thrift.TException { send_getRegionInfo(row); @@ -3215,44 +3172,6 @@ public class Hbase { } } - public void getRowOrBefore(ByteBuffer tableName, ByteBuffer row, ByteBuffer family, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { - checkReady(); - getRowOrBefore_call method_call = new getRowOrBefore_call(tableName, row, family, resultHandler, this, ___protocolFactory, ___transport); - this.___currentMethod = method_call; - ___manager.call(method_call); - } - - public static class getRowOrBefore_call extends org.apache.thrift.async.TAsyncMethodCall { - private ByteBuffer tableName; - private ByteBuffer row; - private ByteBuffer family; - public getRowOrBefore_call(ByteBuffer tableName, ByteBuffer row, ByteBuffer family, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException { - super(client, protocolFactory, transport, resultHandler, false); - this.tableName = tableName; - this.row = row; - this.family = family; - } - - public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException { - prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("getRowOrBefore", org.apache.thrift.protocol.TMessageType.CALL, 0)); - getRowOrBefore_args args = new getRowOrBefore_args(); - args.setTableName(tableName); - args.setRow(row); - args.setFamily(family); - args.write(prot); - prot.writeMessageEnd(); - } - - public List getResult() throws IOError, org.apache.thrift.TException { - if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) { - throw new IllegalStateException("Method call not finished!"); - } - org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array()); - org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport); - return (new Client(prot)).recv_getRowOrBefore(); - } - } - public void getRegionInfo(ByteBuffer row, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException { checkReady(); getRegionInfo_call method_call = new getRegionInfo_call(row, resultHandler, this, ___protocolFactory, ___transport); @@ -3337,7 +3256,6 @@ public class Hbase { processMap.put("scannerGet", new scannerGet()); processMap.put("scannerGetList", new scannerGetList()); processMap.put("scannerClose", new scannerClose()); - processMap.put("getRowOrBefore", new getRowOrBefore()); processMap.put("getRegionInfo", new getRegionInfo()); return processMap; } @@ -4150,26 +4068,6 @@ public class Hbase { } } - private static class getRowOrBefore extends org.apache.thrift.ProcessFunction { - public getRowOrBefore() { - super("getRowOrBefore"); - } - - protected getRowOrBefore_args getEmptyArgsInstance() { - return new getRowOrBefore_args(); - } - - protected getRowOrBefore_result getResult(I iface, getRowOrBefore_args args) throws org.apache.thrift.TException { - getRowOrBefore_result result = new getRowOrBefore_result(); - try { - result.success = iface.getRowOrBefore(args.tableName, args.row, args.family); - } catch (IOError io) { - result.io = io; - } - return result; - } - } - private static class getRegionInfo extends org.apache.thrift.ProcessFunction { public getRegionInfo() { super("getRegionInfo"); @@ -38773,970 +38671,6 @@ public class Hbase { } - public static class getRowOrBefore_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { - private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getRowOrBefore_args"); - - private static final org.apache.thrift.protocol.TField TABLE_NAME_FIELD_DESC = new org.apache.thrift.protocol.TField("tableName", org.apache.thrift.protocol.TType.STRING, (short)1); - private static final org.apache.thrift.protocol.TField ROW_FIELD_DESC = new org.apache.thrift.protocol.TField("row", org.apache.thrift.protocol.TType.STRING, (short)2); - private static final org.apache.thrift.protocol.TField FAMILY_FIELD_DESC = new org.apache.thrift.protocol.TField("family", org.apache.thrift.protocol.TType.STRING, (short)3); - - /** - * name of table - */ - public ByteBuffer tableName; // required - /** - * row key - */ - public ByteBuffer row; // required - /** - * column name - */ - public ByteBuffer family; // required - - /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ - public enum _Fields implements org.apache.thrift.TFieldIdEnum { - /** - * name of table - */ - TABLE_NAME((short)1, "tableName"), - /** - * row key - */ - ROW((short)2, "row"), - /** - * column name - */ - FAMILY((short)3, "family"); - - private static final Map byName = new HashMap(); - - static { - for (_Fields field : EnumSet.allOf(_Fields.class)) { - byName.put(field.getFieldName(), field); - } - } - - /** - * Find the _Fields constant that matches fieldId, or null if its not found. - */ - public static _Fields findByThriftId(int fieldId) { - switch(fieldId) { - case 1: // TABLE_NAME - return TABLE_NAME; - case 2: // ROW - return ROW; - case 3: // FAMILY - return FAMILY; - default: - return null; - } - } - - /** - * Find the _Fields constant that matches fieldId, throwing an exception - * if it is not found. - */ - public static _Fields findByThriftIdOrThrow(int fieldId) { - _Fields fields = findByThriftId(fieldId); - if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); - return fields; - } - - /** - * Find the _Fields constant that matches name, or null if its not found. - */ - public static _Fields findByName(String name) { - return byName.get(name); - } - - private final short _thriftId; - private final String _fieldName; - - _Fields(short thriftId, String fieldName) { - _thriftId = thriftId; - _fieldName = fieldName; - } - - public short getThriftFieldId() { - return _thriftId; - } - - public String getFieldName() { - return _fieldName; - } - } - - // isset id assignments - - public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; - static { - Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); - tmpMap.put(_Fields.TABLE_NAME, new org.apache.thrift.meta_data.FieldMetaData("tableName", org.apache.thrift.TFieldRequirementType.DEFAULT, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , "Text"))); - tmpMap.put(_Fields.ROW, new org.apache.thrift.meta_data.FieldMetaData("row", org.apache.thrift.TFieldRequirementType.DEFAULT, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , "Text"))); - tmpMap.put(_Fields.FAMILY, new org.apache.thrift.meta_data.FieldMetaData("family", org.apache.thrift.TFieldRequirementType.DEFAULT, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING , "Text"))); - metaDataMap = Collections.unmodifiableMap(tmpMap); - org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getRowOrBefore_args.class, metaDataMap); - } - - public getRowOrBefore_args() { - } - - public getRowOrBefore_args( - ByteBuffer tableName, - ByteBuffer row, - ByteBuffer family) - { - this(); - this.tableName = tableName; - this.row = row; - this.family = family; - } - - /** - * Performs a deep copy on other. - */ - public getRowOrBefore_args(getRowOrBefore_args other) { - if (other.isSetTableName()) { - this.tableName = other.tableName; - } - if (other.isSetRow()) { - this.row = other.row; - } - if (other.isSetFamily()) { - this.family = other.family; - } - } - - public getRowOrBefore_args deepCopy() { - return new getRowOrBefore_args(this); - } - - @Override - public void clear() { - this.tableName = null; - this.row = null; - this.family = null; - } - - /** - * name of table - */ - public byte[] getTableName() { - setTableName(org.apache.thrift.TBaseHelper.rightSize(tableName)); - return tableName == null ? null : tableName.array(); - } - - public ByteBuffer bufferForTableName() { - return tableName; - } - - /** - * name of table - */ - public getRowOrBefore_args setTableName(byte[] tableName) { - setTableName(tableName == null ? (ByteBuffer)null : ByteBuffer.wrap(tableName)); - return this; - } - - public getRowOrBefore_args setTableName(ByteBuffer tableName) { - this.tableName = tableName; - return this; - } - - public void unsetTableName() { - this.tableName = null; - } - - /** Returns true if field tableName is set (has been assigned a value) and false otherwise */ - public boolean isSetTableName() { - return this.tableName != null; - } - - public void setTableNameIsSet(boolean value) { - if (!value) { - this.tableName = null; - } - } - - /** - * row key - */ - public byte[] getRow() { - setRow(org.apache.thrift.TBaseHelper.rightSize(row)); - return row == null ? null : row.array(); - } - - public ByteBuffer bufferForRow() { - return row; - } - - /** - * row key - */ - public getRowOrBefore_args setRow(byte[] row) { - setRow(row == null ? (ByteBuffer)null : ByteBuffer.wrap(row)); - return this; - } - - public getRowOrBefore_args setRow(ByteBuffer row) { - this.row = row; - return this; - } - - public void unsetRow() { - this.row = null; - } - - /** Returns true if field row is set (has been assigned a value) and false otherwise */ - public boolean isSetRow() { - return this.row != null; - } - - public void setRowIsSet(boolean value) { - if (!value) { - this.row = null; - } - } - - /** - * column name - */ - public byte[] getFamily() { - setFamily(org.apache.thrift.TBaseHelper.rightSize(family)); - return family == null ? null : family.array(); - } - - public ByteBuffer bufferForFamily() { - return family; - } - - /** - * column name - */ - public getRowOrBefore_args setFamily(byte[] family) { - setFamily(family == null ? (ByteBuffer)null : ByteBuffer.wrap(family)); - return this; - } - - public getRowOrBefore_args setFamily(ByteBuffer family) { - this.family = family; - return this; - } - - public void unsetFamily() { - this.family = null; - } - - /** Returns true if field family is set (has been assigned a value) and false otherwise */ - public boolean isSetFamily() { - return this.family != null; - } - - public void setFamilyIsSet(boolean value) { - if (!value) { - this.family = null; - } - } - - public void setFieldValue(_Fields field, Object value) { - switch (field) { - case TABLE_NAME: - if (value == null) { - unsetTableName(); - } else { - setTableName((ByteBuffer)value); - } - break; - - case ROW: - if (value == null) { - unsetRow(); - } else { - setRow((ByteBuffer)value); - } - break; - - case FAMILY: - if (value == null) { - unsetFamily(); - } else { - setFamily((ByteBuffer)value); - } - break; - - } - } - - public Object getFieldValue(_Fields field) { - switch (field) { - case TABLE_NAME: - return getTableName(); - - case ROW: - return getRow(); - - case FAMILY: - return getFamily(); - - } - throw new IllegalStateException(); - } - - /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ - public boolean isSet(_Fields field) { - if (field == null) { - throw new IllegalArgumentException(); - } - - switch (field) { - case TABLE_NAME: - return isSetTableName(); - case ROW: - return isSetRow(); - case FAMILY: - return isSetFamily(); - } - throw new IllegalStateException(); - } - - @Override - public boolean equals(Object that) { - if (that == null) - return false; - if (that instanceof getRowOrBefore_args) - return this.equals((getRowOrBefore_args)that); - return false; - } - - public boolean equals(getRowOrBefore_args that) { - if (that == null) - return false; - - boolean this_present_tableName = true && this.isSetTableName(); - boolean that_present_tableName = true && that.isSetTableName(); - if (this_present_tableName || that_present_tableName) { - if (!(this_present_tableName && that_present_tableName)) - return false; - if (!this.tableName.equals(that.tableName)) - return false; - } - - boolean this_present_row = true && this.isSetRow(); - boolean that_present_row = true && that.isSetRow(); - if (this_present_row || that_present_row) { - if (!(this_present_row && that_present_row)) - return false; - if (!this.row.equals(that.row)) - return false; - } - - boolean this_present_family = true && this.isSetFamily(); - boolean that_present_family = true && that.isSetFamily(); - if (this_present_family || that_present_family) { - if (!(this_present_family && that_present_family)) - return false; - if (!this.family.equals(that.family)) - return false; - } - - return true; - } - - @Override - public int hashCode() { - return 0; - } - - public int compareTo(getRowOrBefore_args other) { - if (!getClass().equals(other.getClass())) { - return getClass().getName().compareTo(other.getClass().getName()); - } - - int lastComparison = 0; - getRowOrBefore_args typedOther = (getRowOrBefore_args)other; - - lastComparison = Boolean.valueOf(isSetTableName()).compareTo(typedOther.isSetTableName()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetTableName()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.tableName, typedOther.tableName); - if (lastComparison != 0) { - return lastComparison; - } - } - lastComparison = Boolean.valueOf(isSetRow()).compareTo(typedOther.isSetRow()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetRow()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.row, typedOther.row); - if (lastComparison != 0) { - return lastComparison; - } - } - lastComparison = Boolean.valueOf(isSetFamily()).compareTo(typedOther.isSetFamily()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetFamily()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.family, typedOther.family); - if (lastComparison != 0) { - return lastComparison; - } - } - return 0; - } - - public _Fields fieldForId(int fieldId) { - return _Fields.findByThriftId(fieldId); - } - - public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { - org.apache.thrift.protocol.TField field; - iprot.readStructBegin(); - while (true) - { - field = iprot.readFieldBegin(); - if (field.type == org.apache.thrift.protocol.TType.STOP) { - break; - } - switch (field.id) { - case 1: // TABLE_NAME - if (field.type == org.apache.thrift.protocol.TType.STRING) { - this.tableName = iprot.readBinary(); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - case 2: // ROW - if (field.type == org.apache.thrift.protocol.TType.STRING) { - this.row = iprot.readBinary(); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - case 3: // FAMILY - if (field.type == org.apache.thrift.protocol.TType.STRING) { - this.family = iprot.readBinary(); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - default: - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - iprot.readFieldEnd(); - } - iprot.readStructEnd(); - - // check for required fields of primitive type, which can't be checked in the validate method - validate(); - } - - public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { - validate(); - - oprot.writeStructBegin(STRUCT_DESC); - if (this.tableName != null) { - oprot.writeFieldBegin(TABLE_NAME_FIELD_DESC); - oprot.writeBinary(this.tableName); - oprot.writeFieldEnd(); - } - if (this.row != null) { - oprot.writeFieldBegin(ROW_FIELD_DESC); - oprot.writeBinary(this.row); - oprot.writeFieldEnd(); - } - if (this.family != null) { - oprot.writeFieldBegin(FAMILY_FIELD_DESC); - oprot.writeBinary(this.family); - oprot.writeFieldEnd(); - } - oprot.writeFieldStop(); - oprot.writeStructEnd(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("getRowOrBefore_args("); - boolean first = true; - - sb.append("tableName:"); - if (this.tableName == null) { - sb.append("null"); - } else { - sb.append(this.tableName); - } - first = false; - if (!first) sb.append(", "); - sb.append("row:"); - if (this.row == null) { - sb.append("null"); - } else { - sb.append(this.row); - } - first = false; - if (!first) sb.append(", "); - sb.append("family:"); - if (this.family == null) { - sb.append("null"); - } else { - sb.append(this.family); - } - first = false; - sb.append(")"); - return sb.toString(); - } - - public void validate() throws org.apache.thrift.TException { - // check for required fields - } - - private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { - try { - write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - - private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { - try { - read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - - } - - public static class getRowOrBefore_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { - private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getRowOrBefore_result"); - - private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.LIST, (short)0); - private static final org.apache.thrift.protocol.TField IO_FIELD_DESC = new org.apache.thrift.protocol.TField("io", org.apache.thrift.protocol.TType.STRUCT, (short)1); - - public List success; // required - public IOError io; // required - - /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ - public enum _Fields implements org.apache.thrift.TFieldIdEnum { - SUCCESS((short)0, "success"), - IO((short)1, "io"); - - private static final Map byName = new HashMap(); - - static { - for (_Fields field : EnumSet.allOf(_Fields.class)) { - byName.put(field.getFieldName(), field); - } - } - - /** - * Find the _Fields constant that matches fieldId, or null if its not found. - */ - public static _Fields findByThriftId(int fieldId) { - switch(fieldId) { - case 0: // SUCCESS - return SUCCESS; - case 1: // IO - return IO; - default: - return null; - } - } - - /** - * Find the _Fields constant that matches fieldId, throwing an exception - * if it is not found. - */ - public static _Fields findByThriftIdOrThrow(int fieldId) { - _Fields fields = findByThriftId(fieldId); - if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); - return fields; - } - - /** - * Find the _Fields constant that matches name, or null if its not found. - */ - public static _Fields findByName(String name) { - return byName.get(name); - } - - private final short _thriftId; - private final String _fieldName; - - _Fields(short thriftId, String fieldName) { - _thriftId = thriftId; - _fieldName = fieldName; - } - - public short getThriftFieldId() { - return _thriftId; - } - - public String getFieldName() { - return _fieldName; - } - } - - // isset id assignments - - public static final Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> metaDataMap; - static { - Map<_Fields, org.apache.thrift.meta_data.FieldMetaData> tmpMap = new EnumMap<_Fields, org.apache.thrift.meta_data.FieldMetaData>(_Fields.class); - tmpMap.put(_Fields.SUCCESS, new org.apache.thrift.meta_data.FieldMetaData("success", org.apache.thrift.TFieldRequirementType.DEFAULT, - new org.apache.thrift.meta_data.ListMetaData(org.apache.thrift.protocol.TType.LIST, - new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, TCell.class)))); - tmpMap.put(_Fields.IO, new org.apache.thrift.meta_data.FieldMetaData("io", org.apache.thrift.TFieldRequirementType.DEFAULT, - new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT))); - metaDataMap = Collections.unmodifiableMap(tmpMap); - org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(getRowOrBefore_result.class, metaDataMap); - } - - public getRowOrBefore_result() { - } - - public getRowOrBefore_result( - List success, - IOError io) - { - this(); - this.success = success; - this.io = io; - } - - /** - * Performs a deep copy on other. - */ - public getRowOrBefore_result(getRowOrBefore_result other) { - if (other.isSetSuccess()) { - List __this__success = new ArrayList(); - for (TCell other_element : other.success) { - __this__success.add(new TCell(other_element)); - } - this.success = __this__success; - } - if (other.isSetIo()) { - this.io = new IOError(other.io); - } - } - - public getRowOrBefore_result deepCopy() { - return new getRowOrBefore_result(this); - } - - @Override - public void clear() { - this.success = null; - this.io = null; - } - - public int getSuccessSize() { - return (this.success == null) ? 0 : this.success.size(); - } - - public java.util.Iterator getSuccessIterator() { - return (this.success == null) ? null : this.success.iterator(); - } - - public void addToSuccess(TCell elem) { - if (this.success == null) { - this.success = new ArrayList(); - } - this.success.add(elem); - } - - public List getSuccess() { - return this.success; - } - - public getRowOrBefore_result setSuccess(List success) { - this.success = success; - return this; - } - - public void unsetSuccess() { - this.success = null; - } - - /** Returns true if field success is set (has been assigned a value) and false otherwise */ - public boolean isSetSuccess() { - return this.success != null; - } - - public void setSuccessIsSet(boolean value) { - if (!value) { - this.success = null; - } - } - - public IOError getIo() { - return this.io; - } - - public getRowOrBefore_result setIo(IOError io) { - this.io = io; - return this; - } - - public void unsetIo() { - this.io = null; - } - - /** Returns true if field io is set (has been assigned a value) and false otherwise */ - public boolean isSetIo() { - return this.io != null; - } - - public void setIoIsSet(boolean value) { - if (!value) { - this.io = null; - } - } - - public void setFieldValue(_Fields field, Object value) { - switch (field) { - case SUCCESS: - if (value == null) { - unsetSuccess(); - } else { - setSuccess((List)value); - } - break; - - case IO: - if (value == null) { - unsetIo(); - } else { - setIo((IOError)value); - } - break; - - } - } - - public Object getFieldValue(_Fields field) { - switch (field) { - case SUCCESS: - return getSuccess(); - - case IO: - return getIo(); - - } - throw new IllegalStateException(); - } - - /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ - public boolean isSet(_Fields field) { - if (field == null) { - throw new IllegalArgumentException(); - } - - switch (field) { - case SUCCESS: - return isSetSuccess(); - case IO: - return isSetIo(); - } - throw new IllegalStateException(); - } - - @Override - public boolean equals(Object that) { - if (that == null) - return false; - if (that instanceof getRowOrBefore_result) - return this.equals((getRowOrBefore_result)that); - return false; - } - - public boolean equals(getRowOrBefore_result that) { - if (that == null) - return false; - - boolean this_present_success = true && this.isSetSuccess(); - boolean that_present_success = true && that.isSetSuccess(); - if (this_present_success || that_present_success) { - if (!(this_present_success && that_present_success)) - return false; - if (!this.success.equals(that.success)) - return false; - } - - boolean this_present_io = true && this.isSetIo(); - boolean that_present_io = true && that.isSetIo(); - if (this_present_io || that_present_io) { - if (!(this_present_io && that_present_io)) - return false; - if (!this.io.equals(that.io)) - return false; - } - - return true; - } - - @Override - public int hashCode() { - return 0; - } - - public int compareTo(getRowOrBefore_result other) { - if (!getClass().equals(other.getClass())) { - return getClass().getName().compareTo(other.getClass().getName()); - } - - int lastComparison = 0; - getRowOrBefore_result typedOther = (getRowOrBefore_result)other; - - lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(typedOther.isSetSuccess()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetSuccess()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, typedOther.success); - if (lastComparison != 0) { - return lastComparison; - } - } - lastComparison = Boolean.valueOf(isSetIo()).compareTo(typedOther.isSetIo()); - if (lastComparison != 0) { - return lastComparison; - } - if (isSetIo()) { - lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.io, typedOther.io); - if (lastComparison != 0) { - return lastComparison; - } - } - return 0; - } - - public _Fields fieldForId(int fieldId) { - return _Fields.findByThriftId(fieldId); - } - - public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { - org.apache.thrift.protocol.TField field; - iprot.readStructBegin(); - while (true) - { - field = iprot.readFieldBegin(); - if (field.type == org.apache.thrift.protocol.TType.STOP) { - break; - } - switch (field.id) { - case 0: // SUCCESS - if (field.type == org.apache.thrift.protocol.TType.LIST) { - { - org.apache.thrift.protocol.TList _list150 = iprot.readListBegin(); - this.success = new ArrayList(_list150.size); - for (int _i151 = 0; _i151 < _list150.size; ++_i151) - { - TCell _elem152; // required - _elem152 = new TCell(); - _elem152.read(iprot); - this.success.add(_elem152); - } - iprot.readListEnd(); - } - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - case 1: // IO - if (field.type == org.apache.thrift.protocol.TType.STRUCT) { - this.io = new IOError(); - this.io.read(iprot); - } else { - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - break; - default: - org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type); - } - iprot.readFieldEnd(); - } - iprot.readStructEnd(); - - // check for required fields of primitive type, which can't be checked in the validate method - validate(); - } - - public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { - oprot.writeStructBegin(STRUCT_DESC); - - if (this.isSetSuccess()) { - oprot.writeFieldBegin(SUCCESS_FIELD_DESC); - { - oprot.writeListBegin(new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRUCT, this.success.size())); - for (TCell _iter153 : this.success) - { - _iter153.write(oprot); - } - oprot.writeListEnd(); - } - oprot.writeFieldEnd(); - } else if (this.isSetIo()) { - oprot.writeFieldBegin(IO_FIELD_DESC); - this.io.write(oprot); - oprot.writeFieldEnd(); - } - oprot.writeFieldStop(); - oprot.writeStructEnd(); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder("getRowOrBefore_result("); - boolean first = true; - - sb.append("success:"); - if (this.success == null) { - sb.append("null"); - } else { - sb.append(this.success); - } - first = false; - if (!first) sb.append(", "); - sb.append("io:"); - if (this.io == null) { - sb.append("null"); - } else { - sb.append(this.io); - } - first = false; - sb.append(")"); - return sb.toString(); - } - - public void validate() throws org.apache.thrift.TException { - // check for required fields - } - - private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { - try { - write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - - private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { - try { - read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); - } catch (org.apache.thrift.TException te) { - throw new java.io.IOException(te); - } - } - - } - public static class getRegionInfo_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable { private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getRegionInfo_args"); diff --git src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift index 5821d31..67043f5 100644 --- src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift +++ src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift @@ -782,22 +782,6 @@ service Hbase { ) throws (1:IOError io, 2:IllegalArgument ia) /** - * Get the row just before the specified one. - * - * @return value for specified row/column - */ - list getRowOrBefore( - /** name of table */ - 1:Text tableName, - - /** row key */ - 2:Text row, - - /** column name */ - 3:Text family - ) throws (1:IOError io) - - /** * Get the regininfo for the specified row. It scans * the metatable to find region's start and end keys. * diff --git src/test/java/org/apache/hadoop/hbase/TestKeyValue.java src/test/java/org/apache/hadoop/hbase/TestKeyValue.java index dc4ee8d..7b076d5 100644 --- src/test/java/org/apache/hadoop/hbase/TestKeyValue.java +++ src/test/java/org/apache/hadoop/hbase/TestKeyValue.java @@ -116,12 +116,14 @@ public class TestKeyValue extends TestCase { public void testMoreComparisons() throws Exception { // Root compares long now = System.currentTimeMillis(); - KeyValue a = new KeyValue(Bytes.toBytes(".META.,,99999999999999"), now); - KeyValue b = new KeyValue(Bytes.toBytes(".META.,,1"), now); + String lastMeta = ".META.\",,99999999999999"; + String firstMeta = ".META.\",,1"; + KeyValue a = new KeyValue(Bytes.toBytes(lastMeta), now); + KeyValue b = new KeyValue(Bytes.toBytes(firstMeta), now); KVComparator c = new KeyValue.RootComparator(); assertTrue(c.compare(b, a) < 0); - KeyValue aa = new KeyValue(Bytes.toBytes(".META.,,1"), now); - KeyValue bb = new KeyValue(Bytes.toBytes(".META.,,1"), + KeyValue aa = new KeyValue(Bytes.toBytes(firstMeta), now); + KeyValue bb = new KeyValue(Bytes.toBytes(firstMeta), Bytes.toBytes("info"), Bytes.toBytes("regioninfo"), 1235943454602L, (byte[])null); assertTrue(c.compare(aa, bb) < 0); diff --git src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java index ab80020..898d215 100644 --- src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java +++ src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java @@ -3955,56 +3955,6 @@ public class TestFromClientSide { } } - @Test - public void testGetClosestRowBefore() throws IOException { - final byte [] tableAname = Bytes.toBytes("testGetClosestRowBefore"); - final byte [] row = Bytes.toBytes("row"); - - - byte[] firstRow = Bytes.toBytes("ro"); - byte[] beforeFirstRow = Bytes.toBytes("rn"); - byte[] beforeSecondRow = Bytes.toBytes("rov"); - - HTable table = TEST_UTIL.createTable(tableAname, - new byte [][] {HConstants.CATALOG_FAMILY, Bytes.toBytes("info2")}); - Put put = new Put(firstRow); - Put put2 = new Put(row); - byte[] zero = new byte[]{0}; - byte[] one = new byte[]{1}; - - put.add(HConstants.CATALOG_FAMILY, null, zero); - put2.add(HConstants.CATALOG_FAMILY, null, one); - - table.put(put); - table.put(put2); - - Result result = null; - - // Test before first that null is returned - result = table.getRowOrBefore(beforeFirstRow, HConstants.CATALOG_FAMILY); - assertTrue(result == null); - - // Test at first that first is returned - result = table.getRowOrBefore(firstRow, HConstants.CATALOG_FAMILY); - assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null)); - assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), zero)); - - // Test in between first and second that first is returned - result = table.getRowOrBefore(beforeSecondRow, HConstants.CATALOG_FAMILY); - assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null)); - assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), zero)); - - // Test at second make sure second is returned - result = table.getRowOrBefore(row, HConstants.CATALOG_FAMILY); - assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null)); - assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), one)); - - // Test after second, make sure second is returned - result = table.getRowOrBefore(Bytes.add(row,one), HConstants.CATALOG_FAMILY); - assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null)); - assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), one)); - } - /** * For HBASE-2156 * @throws Exception diff --git src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java index dacb936..a2f5dfc 100644 --- src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java +++ src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java @@ -73,8 +73,6 @@ public class SimpleRegionObserver extends BaseRegionObserver { boolean hadPostPut = false; boolean hadPreDeleted = false; boolean hadPostDeleted = false; - boolean hadPreGetClosestRowBefore = false; - boolean hadPostGetClosestRowBefore = false; boolean hadPreIncrement = false; boolean hadPostIncrement = false; boolean hadPreWALRestored = false; @@ -345,32 +343,6 @@ public class SimpleRegionObserver extends BaseRegionObserver { } @Override - public void preGetClosestRowBefore(final ObserverContext c, - final byte[] row, final byte[] family, final Result result) - throws IOException { - RegionCoprocessorEnvironment e = c.getEnvironment(); - assertNotNull(e); - assertNotNull(e.getRegion()); - assertNotNull(row); - assertNotNull(result); - if (beforeDelete) { - hadPreGetClosestRowBefore = true; - } - } - - @Override - public void postGetClosestRowBefore(final ObserverContext c, - final byte[] row, final byte[] family, final Result result) - throws IOException { - RegionCoprocessorEnvironment e = c.getEnvironment(); - assertNotNull(e); - assertNotNull(e.getRegion()); - assertNotNull(row); - assertNotNull(result); - hadPostGetClosestRowBefore = true; - } - - @Override public Result preIncrement(final ObserverContext c, final Increment increment) throws IOException { hadPreIncrement = true; diff --git src/test/java/org/apache/hadoop/hbase/regionserver/TestGetClosestAtOrBefore.java src/test/java/org/apache/hadoop/hbase/regionserver/TestGetClosestAtOrBefore.java deleted file mode 100644 index 5f97167..0000000 --- src/test/java/org/apache/hadoop/hbase/regionserver/TestGetClosestAtOrBefore.java +++ /dev/null @@ -1,348 +0,0 @@ -/** - * Copyright 2009 The Apache Software Foundation - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.hadoop.hbase.regionserver; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.fs.FileSystem; -import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hbase.*; -import org.apache.hadoop.hbase.client.Delete; -import org.apache.hadoop.hbase.client.Put; -import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.client.Scan; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.hbase.util.Writables; -import org.apache.hadoop.hdfs.MiniDFSCluster; -import org.junit.experimental.categories.Category; - -/** - * {@link TestGet} is a medley of tests of get all done up as a single test. - * This class - */ -@Category(SmallTests.class) -public class TestGetClosestAtOrBefore extends HBaseTestCase { - private static final Log LOG = LogFactory.getLog(TestGetClosestAtOrBefore.class); - - private static final byte[] T00 = Bytes.toBytes("000"); - private static final byte[] T10 = Bytes.toBytes("010"); - private static final byte[] T11 = Bytes.toBytes("011"); - private static final byte[] T12 = Bytes.toBytes("012"); - private static final byte[] T20 = Bytes.toBytes("020"); - private static final byte[] T30 = Bytes.toBytes("030"); - private static final byte[] T31 = Bytes.toBytes("031"); - private static final byte[] T35 = Bytes.toBytes("035"); - private static final byte[] T40 = Bytes.toBytes("040"); - - - - public void testUsingMetaAndBinary() throws IOException { - FileSystem filesystem = FileSystem.get(conf); - Path rootdir = testDir; - // Up flush size else we bind up when we use default catalog flush of 16k. - HTableDescriptor.META_TABLEDESC.setMemStoreFlushSize(64 * 1024 * 1024); - - HRegion mr = HRegion.createHRegion(HRegionInfo.FIRST_META_REGIONINFO, - rootdir, this.conf, HTableDescriptor.META_TABLEDESC); - try { - // Write rows for three tables 'A', 'B', and 'C'. - for (char c = 'A'; c < 'D'; c++) { - HTableDescriptor htd = new HTableDescriptor("" + c); - final int last = 128; - final int interval = 2; - for (int i = 0; i <= last; i += interval) { - HRegionInfo hri = new HRegionInfo(htd.getName(), - i == 0? HConstants.EMPTY_BYTE_ARRAY: Bytes.toBytes((byte)i), - i == last? HConstants.EMPTY_BYTE_ARRAY: Bytes.toBytes((byte)i + interval)); - Put put = new Put(hri.getRegionName()); - put.setWriteToWAL(false); - put.add(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER, - Writables.getBytes(hri)); - mr.put(put, false); - } - } - InternalScanner s = mr.getScanner(new Scan()); - try { - List keys = new ArrayList(); - while(s.next(keys)) { - LOG.info(keys); - keys.clear(); - } - } finally { - s.close(); - } - findRow(mr, 'C', 44, 44); - findRow(mr, 'C', 45, 44); - findRow(mr, 'C', 46, 46); - findRow(mr, 'C', 43, 42); - mr.flushcache(); - findRow(mr, 'C', 44, 44); - findRow(mr, 'C', 45, 44); - findRow(mr, 'C', 46, 46); - findRow(mr, 'C', 43, 42); - // Now delete 'C' and make sure I don't get entries from 'B'. - byte [] firstRowInC = HRegionInfo.createRegionName(Bytes.toBytes("" + 'C'), - HConstants.EMPTY_BYTE_ARRAY, HConstants.ZEROES, false); - Scan scan = new Scan(firstRowInC); - s = mr.getScanner(scan); - try { - List keys = new ArrayList(); - while (s.next(keys)) { - mr.delete(new Delete(keys.get(0).getRow()), null, false); - keys.clear(); - } - } finally { - s.close(); - } - // Assert we get null back (pass -1). - findRow(mr, 'C', 44, -1); - findRow(mr, 'C', 45, -1); - findRow(mr, 'C', 46, -1); - findRow(mr, 'C', 43, -1); - mr.flushcache(); - findRow(mr, 'C', 44, -1); - findRow(mr, 'C', 45, -1); - findRow(mr, 'C', 46, -1); - findRow(mr, 'C', 43, -1); - } finally { - if (mr != null) { - try { - mr.close(); - } catch (Exception e) { - e.printStackTrace(); - } - mr.getLog().closeAndDelete(); - } - } - } - - /* - * @param mr - * @param table - * @param rowToFind - * @param answer Pass -1 if we're not to find anything. - * @return Row found. - * @throws IOException - */ - private byte [] findRow(final HRegion mr, final char table, - final int rowToFind, final int answer) - throws IOException { - byte [] tableb = Bytes.toBytes("" + table); - // Find the row. - byte [] tofindBytes = Bytes.toBytes((short)rowToFind); - byte [] metaKey = HRegionInfo.createRegionName(tableb, tofindBytes, - HConstants.NINES, false); - LOG.info("find=" + new String(metaKey)); - Result r = mr.getClosestRowBefore(metaKey); - if (answer == -1) { - assertNull(r); - return null; - } - assertTrue(Bytes.compareTo(Bytes.toBytes((short)answer), - extractRowFromMetaRow(r.getRow())) == 0); - return r.getRow(); - } - - private byte [] extractRowFromMetaRow(final byte [] b) { - int firstDelimiter = KeyValue.getDelimiter(b, 0, b.length, - HRegionInfo.DELIMITER); - int lastDelimiter = KeyValue.getDelimiterInReverse(b, 0, b.length, - HRegionInfo.DELIMITER); - int length = lastDelimiter - firstDelimiter - 1; - byte [] row = new byte[length]; - System.arraycopy(b, firstDelimiter + 1, row, 0, length); - return row; - } - - /** - * Test file of multiple deletes and with deletes as final key. - * @see HBASE-751 - */ - public void testGetClosestRowBefore3() throws IOException{ - HRegion region = null; - byte [] c0 = COLUMNS[0]; - byte [] c1 = COLUMNS[1]; - try { - HTableDescriptor htd = createTableDescriptor(getName()); - region = createNewHRegion(htd, null, null); - - Put p = new Put(T00); - p.add(c0, c0, T00); - region.put(p); - - p = new Put(T10); - p.add(c0, c0, T10); - region.put(p); - - p = new Put(T20); - p.add(c0, c0, T20); - region.put(p); - - Result r = region.getClosestRowBefore(T20, c0); - assertTrue(Bytes.equals(T20, r.getRow())); - - Delete d = new Delete(T20); - d.deleteColumn(c0, c0); - region.delete(d, null, false); - - r = region.getClosestRowBefore(T20, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - - p = new Put(T30); - p.add(c0, c0, T30); - region.put(p); - - r = region.getClosestRowBefore(T30, c0); - assertTrue(Bytes.equals(T30, r.getRow())); - - d = new Delete(T30); - d.deleteColumn(c0, c0); - region.delete(d, null, false); - - r = region.getClosestRowBefore(T30, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - r = region.getClosestRowBefore(T31, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - - region.flushcache(); - - // try finding "010" after flush - r = region.getClosestRowBefore(T30, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - r = region.getClosestRowBefore(T31, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - - // Put into a different column family. Should make it so I still get t10 - p = new Put(T20); - p.add(c1, c1, T20); - region.put(p); - - r = region.getClosestRowBefore(T30, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - r = region.getClosestRowBefore(T31, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - - region.flushcache(); - - r = region.getClosestRowBefore(T30, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - r = region.getClosestRowBefore(T31, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - - // Now try combo of memcache and mapfiles. Delete the t20 COLUMS[1] - // in memory; make sure we get back t10 again. - d = new Delete(T20); - d.deleteColumn(c1, c1); - region.delete(d, null, false); - r = region.getClosestRowBefore(T30, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - - // Ask for a value off the end of the file. Should return t10. - r = region.getClosestRowBefore(T31, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - region.flushcache(); - r = region.getClosestRowBefore(T31, c0); - assertTrue(Bytes.equals(T10, r.getRow())); - - // Ok. Let the candidate come out of hfile but have delete of - // the candidate be in memory. - p = new Put(T11); - p.add(c0, c0, T11); - region.put(p); - d = new Delete(T10); - d.deleteColumn(c1, c1); - r = region.getClosestRowBefore(T12, c0); - assertTrue(Bytes.equals(T11, r.getRow())); - } finally { - if (region != null) { - try { - region.close(); - } catch (Exception e) { - e.printStackTrace(); - } - region.getLog().closeAndDelete(); - } - } - } - - /** For HBASE-694 */ - public void testGetClosestRowBefore2() throws IOException{ - HRegion region = null; - byte [] c0 = COLUMNS[0]; - try { - HTableDescriptor htd = createTableDescriptor(getName()); - region = createNewHRegion(htd, null, null); - - Put p = new Put(T10); - p.add(c0, c0, T10); - region.put(p); - - p = new Put(T30); - p.add(c0, c0, T30); - region.put(p); - - p = new Put(T40); - p.add(c0, c0, T40); - region.put(p); - - // try finding "035" - Result r = region.getClosestRowBefore(T35, c0); - assertTrue(Bytes.equals(T30, r.getRow())); - - region.flushcache(); - - // try finding "035" - r = region.getClosestRowBefore(T35, c0); - assertTrue(Bytes.equals(T30, r.getRow())); - - p = new Put(T20); - p.add(c0, c0, T20); - region.put(p); - - // try finding "035" - r = region.getClosestRowBefore(T35, c0); - assertTrue(Bytes.equals(T30, r.getRow())); - - region.flushcache(); - - // try finding "035" - r = region.getClosestRowBefore(T35, c0); - assertTrue(Bytes.equals(T30, r.getRow())); - } finally { - if (region != null) { - try { - region.close(); - } catch (Exception e) { - e.printStackTrace(); - } - region.getLog().closeAndDelete(); - } - } - } - - @org.junit.Rule - public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu = - new org.apache.hadoop.hbase.ResourceCheckerJUnitRule(); -} - diff --git src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java index 6e1211b..0657ae3 100644 --- src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java +++ src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java @@ -43,20 +43,23 @@ public class TestHRegionInfo { final byte [] tn = Bytes.toBytes(tableName); String startKey = "startkey"; final byte [] sk = Bytes.toBytes(startKey); - String id = "id"; + String endKey = "endkey"; + final byte [] ek = Bytes.toBytes(endKey); + + String id = "id"; // old format region name - byte [] name = HRegionInfo.createRegionName(tn, sk, id, false); + byte [] name = HRegionInfo.createRegionName(tn, sk, ek, id, false); String nameStr = Bytes.toString(name); - assertEquals(tableName + "," + startKey + "," + id, nameStr); + assertEquals(tableName + "!," + endKey + "," + id, nameStr); // new format region name. String md5HashInHex = MD5Hash.getMD5AsHex(name); assertEquals(HRegionInfo.MD5_HEX_LENGTH, md5HashInHex.length()); - name = HRegionInfo.createRegionName(tn, sk, id, true); + name = HRegionInfo.createRegionName(tn, sk, ek, id, true); nameStr = Bytes.toString(name); - assertEquals(tableName + "," + startKey + "," + assertEquals(tableName + "!," + endKey + "," + id + "." + md5HashInHex + ".", nameStr); } diff --git src/test/java/org/apache/hadoop/hbase/regionserver/TestMinVersions.java src/test/java/org/apache/hadoop/hbase/regionserver/TestMinVersions.java index 33c78ab..fa1f37d 100644 --- src/test/java/org/apache/hadoop/hbase/regionserver/TestMinVersions.java +++ src/test/java/org/apache/hadoop/hbase/regionserver/TestMinVersions.java @@ -47,48 +47,6 @@ public class TestMinVersions extends HBaseTestCase { private final byte[] c0 = COLUMNS[0]; /** - * Verify behavior of getClosestBefore(...) - */ - public void testGetClosestBefore() throws Exception { - HTableDescriptor htd = createTableDescriptor(getName(), 1, 1000, 1, false); - HRegion region = createNewHRegion(htd, null, null); - - // 2s in the past - long ts = EnvironmentEdgeManager.currentTimeMillis() - 2000; - - Put p = new Put(T1, ts); - p.add(c0, c0, T1); - region.put(p); - - p = new Put(T1, ts+1); - p.add(c0, c0, T4); - region.put(p); - - p = new Put(T3, ts); - p.add(c0, c0, T3); - region.put(p); - - // now make sure that getClosestBefore(...) get can - // rows that would be expired without minVersion. - // also make sure it gets the latest version - Result r = region.getClosestRowBefore(T1, c0); - checkResult(r, c0, T4); - - r = region.getClosestRowBefore(T2, c0); - checkResult(r, c0, T4); - - // now flush/compact - region.flushcache(); - region.compactStores(true); - - r = region.getClosestRowBefore(T1, c0); - checkResult(r, c0, T4); - - r = region.getClosestRowBefore(T2, c0); - checkResult(r, c0, T4); - } - - /** * Test mixed memstore and storefile scanning * with minimum versions. */ diff --git src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java index cffdcb6..108c9a1 100644 --- src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java +++ src/test/java/org/apache/hadoop/hbase/rest/TestStatusResource.java @@ -27,6 +27,8 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.MediumTests; import org.apache.hadoop.hbase.rest.client.Client; import org.apache.hadoop.hbase.rest.client.Cluster; @@ -42,8 +44,19 @@ import org.junit.experimental.categories.Category; @Category(MediumTests.class) public class TestStatusResource { - private static final byte[] ROOT_REGION_NAME = Bytes.toBytes("-ROOT-,,0"); - private static final byte[] META_REGION_NAME = Bytes.toBytes(".META.,,1"); + + private static final byte[] ROOT_REGION_NAME = HRegionInfo.createRegionName(HConstants.ROOT_TABLE_NAME, + HConstants.EMPTY_BYTE_ARRAY, + HConstants.EMPTY_BYTE_ARRAY, + "0".getBytes(), + false); + + private static final byte[] META_REGION_NAME = HRegionInfo.createRegionName(HConstants.META_TABLE_NAME, + HConstants.EMPTY_BYTE_ARRAY, + HConstants.EMPTY_BYTE_ARRAY, + "1".getBytes(), + false); + private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private static final HBaseRESTTestingUtility REST_TEST_UTIL = diff --git src/test/java/org/apache/hadoop/hbase/rest/model/TestTableRegionModel.java src/test/java/org/apache/hadoop/hbase/rest/model/TestTableRegionModel.java index b6f0ab5..754c04b 100644 --- src/test/java/org/apache/hadoop/hbase/rest/model/TestTableRegionModel.java +++ src/test/java/org/apache/hadoop/hbase/rest/model/TestTableRegionModel.java @@ -45,7 +45,8 @@ public class TestTableRegionModel extends TestCase { " endKey=\"enp5eng=\"" + " startKey=\"YWJyYWNhZGJyYQ==\"" + " id=\"8731042424\"" + - " name=\"testtable,abracadbra,8731042424\"/>"; + " table=\"testtable\"" + + " name=\"testtable,zzyzx,8731042424\"/>"; private JAXBContext context; @@ -55,9 +56,7 @@ public class TestTableRegionModel extends TestCase { } private TableRegionModel buildTestModel() { - TableRegionModel model = - new TableRegionModel(TABLE, ID, START_KEY, END_KEY, LOCATION); - return model; + return new TableRegionModel(TABLE, ID, START_KEY, END_KEY, LOCATION); } @SuppressWarnings("unused") @@ -77,9 +76,12 @@ public class TestTableRegionModel extends TestCase { assertTrue(Bytes.equals(model.getEndKey(), END_KEY)); assertEquals(model.getId(), ID); assertEquals(model.getLocation(), LOCATION); - assertEquals(model.getName(), - TABLE + "," + Bytes.toString(START_KEY) + "," + Long.toString(ID) + - ".ad9860f031282c46ed431d7af8f94aca."); + byte[] regionInfo = HRegionInfo.createRegionName(TABLE.getBytes(), + START_KEY, + END_KEY, + Long.toString(ID).getBytes(), + true); + assertEquals(model.getName(), Bytes.toStringBinary(regionInfo)); } public void testBuildModel() throws Exception { @@ -90,17 +92,13 @@ public class TestTableRegionModel extends TestCase { TableRegionModel model = buildTestModel(); String modelName = model.getName(); HRegionInfo hri = new HRegionInfo(Bytes.toBytes(TABLE), - START_KEY, END_KEY, false, ID); + START_KEY, + END_KEY, + false, + ID); assertEquals(modelName, hri.getRegionNameAsString()); } - public void testSetName() { - TableRegionModel model = buildTestModel(); - String name = model.getName(); - model.setName(name); - assertEquals(name, model.getName()); - } - public void testFromXML() throws Exception { checkModel(fromXML(AS_XML)); } -- 1.7.4.4