HBASE-2460 add_table.rb deletes any tables for which the target table name is a prefix

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@935114 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2010-04-17 02:49:02 +00:00
parent 0dcf305575
commit f6fb68ab0c
2 changed files with 10 additions and 3 deletions

View File

@ -275,6 +275,8 @@ Release 0.21.0 - Unreleased
HBASE-2453 Revisit compaction policies after HBASE-2248 commit
(Jonathan Gray via Stack)
HBASE-2458 Client stuck in TreeMap,remove (Todd Lipcon via Stack)
HBASE-2460 add_table.rb deletes any tables for which the target table name
is a prefix (Todd Lipcon via Stack)
IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable

View File

@ -69,11 +69,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()
@ -101,14 +105,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