commit ea017483eb3dc397bacf6531239c69eb01b9ce70 Author: Todd Lipcon Date: Fri Apr 16 11:47:05 2010 -0700 HBASE-2460. Fix add_table.rb to properly fix just the specified table even if it is the prefix of another table name. Also check that the source directory exists before proceeding. diff --git bin/add_table.rb bin/add_table.rb index 8d7920d..7cb03e5 100644 --- bin/add_table.rb +++ bin/add_table.rb @@ -50,11 +50,15 @@ end # Get cmdline args. srcdir = fs.makeQualified(Path.new(java.lang.String.new(ARGV[0]))) +if not fs.exists(srcdir) + raise IOError.new("src dir " + srcdir.toString() + " doesn't exist!") +end + # Get table name tableName = nil if ARGV.size > 1 tableName = ARGV[1] - raise IOError("Not supported yet") + raise IOError.new("Not supported yet") elsif # If none provided use dirname tableName = srcdir.getName() @@ -82,14 +86,15 @@ end # Scan the .META. and remove all lines that begin with tablename LOG.info("Deleting mention of " + tableName + " from .META.") metaTable = HTable.new(c, HConstants::META_TABLE_NAME) -scan = Scan.new(tableName.to_java_bytes) +tableNameMetaPrefix = tableName + HConstants::META_ROW_DELIMITER.chr +scan = Scan.new((tableNameMetaPrefix + HConstants::META_ROW_DELIMITER.chr).to_java_bytes) scanner = metaTable.getScanner(scan) # Use java.lang.String doing compares. Ruby String is a bit odd. tableNameStr = java.lang.String.new(tableName) while (result = scanner.next()) rowid = Bytes.toString(result.getRow()) rowidStr = java.lang.String.new(rowid) - if not rowidStr.startsWith(tableNameStr) + if not rowidStr.startsWith(tableNameMetaPrefix) # Gone too far, break break end