From d11960feef2d28bd45dbe754c8884c3a8584b003 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Tue, 27 Nov 2007 06:12:46 +0000 Subject: [PATCH] HADOOP-2289 Useless efforts of looking for the non-existant table in select command. git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@598524 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../hbase/generated/master/master_jsp.java | 20 +++++++++++--- .../hadoop/hbase/shell/AlterCommand.java | 27 ++++++++++++------- .../hadoop/hbase/shell/CreateCommand.java | 16 ++++++++--- .../hadoop/hbase/shell/DeleteCommand.java | 7 +++++ .../hadoop/hbase/shell/EnableCommand.java | 7 +++++ .../hadoop/hbase/shell/InsertCommand.java | 7 +++++ .../hadoop/hbase/shell/SelectCommand.java | 7 +++++ 8 files changed, 76 insertions(+), 17 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 4000199018d..e3d77ba9795 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -46,6 +46,8 @@ Trunk (unreleased changes) HADOOP-2139 (phase 1) Increase parallelism in region servers. HADOOP-2267 [Hbase Shell] Change the prompt's title from 'hbase' to 'hql'. HADOOP-2139 (phase 2) Make region server more event driven + HADOOP-2289 Useless efforts of looking for the non-existant table in select + command. Release 0.15.1 Branch 0.15 diff --git a/src/java/org/apache/hadoop/hbase/generated/master/master_jsp.java b/src/java/org/apache/hadoop/hbase/generated/master/master_jsp.java index b4b4378d0c9..6b2f53e6aed 100644 --- a/src/java/org/apache/hadoop/hbase/generated/master/master_jsp.java +++ b/src/java/org/apache/hadoop/hbase/generated/master/master_jsp.java @@ -103,13 +103,21 @@ public final class master_jsp extends org.apache.jasper.runtime.HttpJspBase out.print(msg ); out.write("

\n\n

Region Servers

\n"); if (serverToServerInfos != null && serverToServerInfos.size() > 0) { - out.write("\n\n\n\n"); + out.write('\n'); + int totalRegions = 0; + int totalRequests = 0; + + out.write("\n\n
AddressStart CodeLoad
\n\n\n"); for (Map.Entry e: serverToServerInfos.entrySet()) { HServerInfo hsi = e.getValue(); String url = "http://" + hsi.getServerAddress().getBindAddress().toString() + ":" + hsi.getInfoPort() + "/"; String load = hsi.getLoad().toString(); + totalRegions += hsi.getLoad().getNumberOfRegions(); + totalRequests += hsi.getLoad().getNumberOfRequests(); long startCode = hsi.getStartCode(); String address = hsi.getServerAddress().toString(); @@ -122,9 +130,15 @@ public final class master_jsp extends org.apache.jasper.runtime.HttpJspBase out.print( startCode ); out.write("\n"); + out.write("\n"); } - out.write("\n
AddressStart CodeLoad
"); out.print( load ); - out.write("
\n

Load is requests per hbase.regionsserver.msginterval ("); + out.write("\nTotal: servers: "); + out.print( serverToServerInfos.size() ); + out.write(" requests: "); + out.print( totalRequests ); + out.write(" regions: "); + out.print( totalRegions ); + out.write("\n\n\n

Load is requests per hbase.regionsserver.msginterval ("); out.print(interval); out.write(" second(s)) and count of regions loaded

\n"); } diff --git a/src/java/org/apache/hadoop/hbase/shell/AlterCommand.java b/src/java/org/apache/hadoop/hbase/shell/AlterCommand.java index dcfd4385c8c..25c06687120 100644 --- a/src/java/org/apache/hadoop/hbase/shell/AlterCommand.java +++ b/src/java/org/apache/hadoop/hbase/shell/AlterCommand.java @@ -28,6 +28,8 @@ import java.util.Set; import org.apache.hadoop.hbase.HBaseAdmin; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HConnection; +import org.apache.hadoop.hbase.HConnectionManager; import org.apache.hadoop.io.Text; /** @@ -38,7 +40,7 @@ public class AlterCommand extends SchemaModificationCommand { private OperationType operationType = OperationType.NOOP; private Map> columnSpecMap = new HashMap>(); - private String table; + private String tableName; private String column; // column to be dropped public AlterCommand(Writer o) { @@ -47,28 +49,33 @@ public class AlterCommand extends SchemaModificationCommand { public ReturnMsg execute(HBaseConfiguration conf) { try { + HConnection conn = HConnectionManager.getConnection(conf); + if (!conn.tableExists(new Text(this.tableName))) { + return new ReturnMsg(0, "'" + this.tableName + "' Table not found"); + } + HBaseAdmin admin = new HBaseAdmin(conf); Set columns = null; HColumnDescriptor columnDesc = null; switch (operationType) { case ADD: - disableTable(admin, table); + disableTable(admin, tableName); columns = columnSpecMap.keySet(); for (String c : columns) { columnDesc = getColumnDescriptor(c, columnSpecMap.get(c)); - println("Adding " + c + " to " + table + + println("Adding " + c + " to " + tableName + "... Please wait."); - admin.addColumn(new Text(table), columnDesc); + admin.addColumn(new Text(tableName), columnDesc); } - enableTable(admin, table); + enableTable(admin, tableName); break; case DROP: - disableTable(admin, table); - println("Dropping " + column + " from " + table + + disableTable(admin, tableName); + println("Dropping " + column + " from " + tableName + "... Please wait."); column = appendDelimiter(column); - admin.deleteColumn(new Text(table), new Text(column)); - enableTable(admin, table); + admin.deleteColumn(new Text(tableName), new Text(column)); + enableTable(admin, tableName); break; case CHANGE: // Not yet supported @@ -98,7 +105,7 @@ public class AlterCommand extends SchemaModificationCommand { * @param t Table to be altered. */ public void setTable(String t) { - this.table = t; + this.tableName = t; } /** diff --git a/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java b/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java index ef692732372..9ef573faca2 100644 --- a/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java +++ b/src/java/org/apache/hadoop/hbase/shell/CreateCommand.java @@ -27,13 +27,16 @@ import java.util.Set; import org.apache.hadoop.hbase.HBaseAdmin; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HConnection; +import org.apache.hadoop.hbase.HConnectionManager; import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.io.Text; /** * Creates tables. */ public class CreateCommand extends SchemaModificationCommand { - private String tableName; + private Text tableName; private Map> columnSpecMap = new HashMap>(); @@ -43,8 +46,13 @@ public class CreateCommand extends SchemaModificationCommand { public ReturnMsg execute(HBaseConfiguration conf) { try { + HConnection conn = HConnectionManager.getConnection(conf); + if (conn.tableExists(this.tableName)) { + return new ReturnMsg(0, "'" + this.tableName + "' Table already exist"); + } + HBaseAdmin admin = new HBaseAdmin(conf); - HTableDescriptor tableDesc = new HTableDescriptor(tableName); + HTableDescriptor tableDesc = new HTableDescriptor(tableName.toString()); HColumnDescriptor columnDesc = null; Set columns = columnSpecMap.keySet(); for (String column : columns) { @@ -66,8 +74,8 @@ public class CreateCommand extends SchemaModificationCommand { * Sets the table to be created. * @param table Table to be created */ - public void setTable(String table) { - this.tableName = table; + public void setTable(String tableName) { + this.tableName = new Text(tableName); } /** diff --git a/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java b/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java index bcde0a85c7f..32314756d74 100644 --- a/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java +++ b/src/java/org/apache/hadoop/hbase/shell/DeleteCommand.java @@ -26,6 +26,8 @@ import java.util.List; import org.apache.hadoop.hbase.HBaseAdmin; import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConnection; +import org.apache.hadoop.hbase.HConnectionManager; import org.apache.hadoop.hbase.HTable; import org.apache.hadoop.io.Text; @@ -46,6 +48,11 @@ public class DeleteCommand extends BasicCommand { throw new IllegalArgumentException("Column list is null"); } try { + HConnection conn = HConnectionManager.getConnection(conf); + if (!conn.tableExists(new Text(this.tableName))) { + return new ReturnMsg(0, "'" + this.tableName + "' Table not found"); + } + HBaseAdmin admin = new HBaseAdmin(conf); HTable hTable = new HTable(conf, new Text(tableName)); long lockID = hTable.startUpdate(new Text(rowKey)); diff --git a/src/java/org/apache/hadoop/hbase/shell/EnableCommand.java b/src/java/org/apache/hadoop/hbase/shell/EnableCommand.java index b4c5356f5ff..446a5c7cb20 100644 --- a/src/java/org/apache/hadoop/hbase/shell/EnableCommand.java +++ b/src/java/org/apache/hadoop/hbase/shell/EnableCommand.java @@ -24,6 +24,8 @@ import java.io.Writer; import org.apache.hadoop.hbase.HBaseAdmin; import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConnection; +import org.apache.hadoop.hbase.HConnectionManager; import org.apache.hadoop.io.Text; /** @@ -39,6 +41,11 @@ public class EnableCommand extends BasicCommand { public ReturnMsg execute(HBaseConfiguration conf) { assert tableName != null; try { + HConnection conn = HConnectionManager.getConnection(conf); + if (!conn.tableExists(new Text(this.tableName))) { + return new ReturnMsg(0, "'" + this.tableName + "' Table not found"); + } + HBaseAdmin admin = new HBaseAdmin(conf); admin.enableTable(new Text(tableName)); return new ReturnMsg(1, "Table enabled successfully."); diff --git a/src/java/org/apache/hadoop/hbase/shell/InsertCommand.java b/src/java/org/apache/hadoop/hbase/shell/InsertCommand.java index e352f27ad86..51c7bdfca73 100644 --- a/src/java/org/apache/hadoop/hbase/shell/InsertCommand.java +++ b/src/java/org/apache/hadoop/hbase/shell/InsertCommand.java @@ -24,6 +24,8 @@ import java.io.Writer; import java.util.List; import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConnection; +import org.apache.hadoop.hbase.HConnectionManager; import org.apache.hadoop.hbase.HTable; import org.apache.hadoop.io.Text; @@ -44,6 +46,11 @@ public class InsertCommand extends BasicCommand { if (this.tableName == null || this.values == null || this.rowKey == null) return new ReturnMsg(0, "Syntax error : Please check 'Insert' syntax."); + HConnection conn = HConnectionManager.getConnection(conf); + if (!conn.tableExists(this.tableName)) { + return new ReturnMsg(0, "'" + this.tableName + "' Table not found"); + } + if (this.columnfamilies.size() != this.values.size()) return new ReturnMsg(0, "Mismatch between values list and columnfamilies list"); diff --git a/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java b/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java index 37558b4234f..13a1fde9909 100644 --- a/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java +++ b/src/java/org/apache/hadoop/hbase/shell/SelectCommand.java @@ -30,6 +30,8 @@ import java.util.TreeMap; import org.apache.hadoop.hbase.HBaseAdmin; import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConnection; +import org.apache.hadoop.hbase.HConnectionManager; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HScannerInterface; import org.apache.hadoop.hbase.HStoreKey; @@ -80,6 +82,11 @@ public class SelectCommand extends BasicCommand { return new ReturnMsg(0, "Syntax error : Please check 'Select' syntax."); } try { + HConnection conn = HConnectionManager.getConnection(conf); + if (!conn.tableExists(this.tableName)) { + return new ReturnMsg(0, "'" + this.tableName + "' Table not found"); + } + HTable table = new HTable(conf, this.tableName); HBaseAdmin admin = new HBaseAdmin(conf); int count = 0;