commit 6ca516940ef7a07e2d2e32aafa95506dd1036674 Author: Nicolas Spiegelberg Date: 5 weeks ago Adding a script to check if table descriptors for each region in META for a given table are consistent. Summary: This script compares the table descriptors in META for all regions of a particular table to the table's descriptor (which is just the descriptor for the first region). Test Plan: Tested on dev cluster. Reviewed By: kannan Reviewers: kannan, nspiegelberg CC: nileema, kannan, madhuvaidya Differential Revision: 308037 git-svn-id: https://svn.apache.org/repos/asf/hbase/branches/0.89@1181944 13f79535-47bb-0310-9956-ffa450edef68 diff --git a/bin/check_schema_consistency.rb b/bin/check_schema_consistency.rb new file mode 100644 index 0000000..e62acac --- /dev/null +++ b/bin/check_schema_consistency.rb @@ -0,0 +1,68 @@ +include Java +import org.apache.commons.logging.LogFactory +import org.apache.hadoop.hbase.HBaseConfiguration +import org.apache.hadoop.hbase.HConstants +import org.apache.hadoop.hbase.HRegionInfo +import org.apache.hadoop.hbase.HTableDescriptor +import org.apache.hadoop.hbase.client.HTable +import org.apache.hadoop.hbase.client.Scan +import org.apache.hadoop.hbase.util.Bytes +import org.apache.hadoop.hbase.util.Writables + +# This script goes through META for a table and checks +#that the table descriptor across regions is consistent. + +#get table descriptor from meta row +def getTD(result) + hri = Writables.getHRegionInfo(result.getValue(HConstants::CATALOG_FAMILY, HConstants::REGIONINFO_QUALIFIER)) + td = hri.getTableDesc() + return td +end + + +# Name of this script +NAME = "check_schema_consistency" + +# Print usage for this script +def usage + puts 'Usage: %s.rb TABLE' % NAME + exit! +end + +# Check arguments +if ARGV.size != 1 + usage +else + tableName = ARGV[0] +end + +LOG = LogFactory.getLog(NAME) + +c = HBaseConfiguration.new() +c.set("fs.default.name", c.get(HConstants::HBASE_DIR)) + +table = HTable.new(c, Bytes.toBytes(tableName)) +td = table.getTableDescriptor() + +LOG.info("Scanning META") +metaTable = HTable.new(c, HConstants::META_TABLE_NAME) +tableNameMetaPrefix = tableName + HConstants::META_ROW_DELIMITER.chr +scan = Scan.new(Bytes.toBytes(tableNameMetaPrefix + HConstants::META_ROW_DELIMITER.chr)) +scanner = metaTable.getScanner(scan) +while (result = scanner.next()) + rowid = Bytes.toString(result.getRow()) + rowidStr = java.lang.String.new(rowid) + if not rowidStr.startsWith(tableNameMetaPrefix) + # Gone too far, break + break + end + rtd = getTD(result) + if !td.equals(rtd) + LOG.warn("Meta table descriptor not consistent: " + rowid) + LOG.info("Original Table desc: " + td.toString()) + LOG.warn("Region Table desc: " + rtd.toString()) + end +end +scanner.close() + +LOG.info("Scan of META complete")