You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 19:43:22 UTC

svn commit: r1181944 - /hbase/branches/0.89/bin/check_schema_consistency.rb

Author: nspiegelberg
Date: Tue Oct 11 17:43:22 2011
New Revision: 1181944

URL: http://svn.apache.org/viewvc?rev=1181944&view=rev
Log:
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

Added:
    hbase/branches/0.89/bin/check_schema_consistency.rb

Added: hbase/branches/0.89/bin/check_schema_consistency.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/bin/check_schema_consistency.rb?rev=1181944&view=auto
==============================================================================
--- hbase/branches/0.89/bin/check_schema_consistency.rb (added)
+++ hbase/branches/0.89/bin/check_schema_consistency.rb Tue Oct 11 17:43:22 2011
@@ -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")