HBASE-655 Need programmatic way to add column family: need programmatic way to enable/disable table

Added HTable.isTableOnline and HTable.isTableOffline

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@662905 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jim Kellerman 2008-06-03 22:16:43 +00:00
parent 2a543ce103
commit fc7351288a
4 changed files with 182 additions and 2 deletions

View File

@ -36,6 +36,8 @@ Hbase Change Log
HBASE-656 Do not retry exceptions such as unknown scanner or illegal argument HBASE-656 Do not retry exceptions such as unknown scanner or illegal argument
HBASE-659 HLog#cacheFlushLock not cleared; hangs a region HBASE-659 HLog#cacheFlushLock not cleared; hangs a region
HBASE-663 Incorrect sequence number for cache flush HBASE-663 Incorrect sequence number for cache flush
HBASE-655 Need programmatic way to add column family: need programmatic way
to enable/disable table
IMPROVEMENTS IMPROVEMENTS
HBASE-559 MR example job to count table rows HBASE-559 MR example job to count table rows

View File

@ -42,13 +42,13 @@ import org.apache.hadoop.hbase.io.BatchUpdate;
import org.apache.hadoop.hbase.io.Cell; import org.apache.hadoop.hbase.io.Cell;
import org.apache.hadoop.hbase.io.RowResult; import org.apache.hadoop.hbase.io.RowResult;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Writables;
import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Text;
/** /**
* Used to communicate with a single HBase table * Used to communicate with a single HBase table
*/ */
public class HTable { public class HTable {
private final Log LOG = LogFactory.getLog(this.getClass());
private final HConnection connection; private final HConnection connection;
private final byte [] tableName; private final byte [] tableName;
private HBaseConfiguration configuration; private HBaseConfiguration configuration;
@ -125,6 +125,174 @@ public class HTable {
this.connection.locateRegion(tableName, HConstants.EMPTY_START_ROW); this.connection.locateRegion(tableName, HConstants.EMPTY_START_ROW);
} }
/**
* @param tableName name of table to check
* @return true if table is on-line
* @throws IOException
*/
public static boolean isTableOnline(Text tableName) throws IOException {
return isTableOnline(tableName.getBytes());
}
/**
* @param tableName name of table to check
* @return true if table is on-line
* @throws IOException
*/
public static boolean isTableOnline(String tableName) throws IOException {
return isTableOnline(Bytes.toBytes(tableName));
}
/**
* @param tableName name of table to check
* @return true if table is on-line
* @throws IOException
*/
public static boolean isTableOnline(byte[] tableName) throws IOException {
return isTableOnline(new HBaseConfiguration(), tableName);
}
/**
* @param conf HBaseConfiguration object
* @param tableName name of table to check
* @return true if table is on-line
* @throws IOException
*/
public static boolean isTableOnline(HBaseConfiguration conf, Text tableName)
throws IOException {
return isTableOnline(conf, tableName.getBytes());
}
/**
* @param conf HBaseConfiguration object
* @param tableName name of table to check
* @return true if table is on-line
* @throws IOException
*/
public static boolean isTableOnline(HBaseConfiguration conf, String tableName)
throws IOException {
return isTableOnline(conf, Bytes.toBytes(tableName));
}
/**
* @param conf HBaseConfiguration object
* @param tableName name of table to check
* @return true if table is on-line
* @throws IOException
*/
public static boolean isTableOnline(HBaseConfiguration conf, byte[] tableName)
throws IOException {
boolean online = true;
if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) {
// The root region is always on-line
return true;
}
HTable meta = new HTable(conf,
Bytes.equals(tableName, HConstants.META_TABLE_NAME) ?
HConstants.ROOT_TABLE_NAME : HConstants.META_TABLE_NAME);
Scanner s = meta.getScanner(HConstants.COL_REGIONINFO_ARRAY,
HRegionInfo.createRegionName(tableName, null, HConstants.NINES));
try {
RowResult r = null;
while ((r = s.next()) != null) {
Cell c = r.get(HConstants.COL_REGIONINFO);
if (c != null) {
HRegionInfo info = Writables.getHRegionInfoOrNull(c.getValue());
if (info != null) {
if (info.isOffline()) {
online = false;
break;
}
}
}
}
} finally {
s.close();
}
return online;
}
/**
* @param tableName name of table to check
* @return true if table is on-line
* @throws IOException
*/
public static boolean isTableOffline(Text tableName) throws IOException {
return isTableOffline(tableName.getBytes());
}
/**
* @param tableName name of table to check
* @return true if table is on-line
* @throws IOException
*/
public static boolean isTableOffline(String tableName) throws IOException {
return isTableOffline(Bytes.toBytes(tableName));
}
/**
* @param tableName name of table to check
* @return true if table is on-line
* @throws IOException
*/
public static boolean isTableOffline(byte[] tableName) throws IOException {
return isTableOffline(new HBaseConfiguration(), tableName);
}
/**
* @param conf HBaseConfiguration object
* @param tableName name of table to check
* @return true if table is on-line
* @throws IOException
*/
public static boolean isTableOffline(HBaseConfiguration conf, Text tableName)
throws IOException {
return isTableOffline(conf, tableName.getBytes());
}
/**
* @param conf HBaseConfiguration object
* @param tableName name of table to check
* @return true if table is on-line
* @throws IOException
*/
public static boolean isTableOffline(HBaseConfiguration conf, String tableName)
throws IOException {
return isTableOffline(conf, Bytes.toBytes(tableName));
}
/**
* @param conf HBaseConfiguration object
* @param tableName name of table to check
* @return true if table is off-line
* @throws IOException
*/
public static boolean isTableOffline(HBaseConfiguration conf, byte[] tableName)
throws IOException {
boolean offline = true;
if (Bytes.equals(tableName, HConstants.ROOT_TABLE_NAME)) {
// The root region is always online
return false;
}
HTable meta = new HTable(conf, HConstants.META_TABLE_NAME);
Scanner s = meta.getScanner(HConstants.COL_REGIONINFO_ARRAY,
HRegionInfo.createRegionName(tableName, null, HConstants.NINES));
try {
RowResult r = null;
while ((r = s.next()) != null) {
Cell c = r.get(HConstants.COL_REGIONINFO);
if (c != null) {
HRegionInfo info = Writables.getHRegionInfoOrNull(c.getValue());
if (info != null) {
if (!info.isOffline()) {
offline = false;
break;
}
}
}
}
} finally {
s.close();
}
return offline;
}
/** /**
* Find region location hosting passed row using cached info * Find region location hosting passed row using cached info
* @param row Row to find. * @param row Row to find.
@ -912,6 +1080,7 @@ public class HTable {
* Completely delete the row's cells. * Completely delete the row's cells.
* *
* @param row Key of the row you want to completely delete. * @param row Key of the row you want to completely delete.
* @param column column to be deleted
* @throws IOException * @throws IOException
*/ */
public void deleteAll(final byte [] row, final byte [] column) public void deleteAll(final byte [] row, final byte [] column)

View File

@ -629,6 +629,9 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
/** {@inheritDoc} */ /** {@inheritDoc} */
public void deleteTable(final byte [] tableName) throws IOException { public void deleteTable(final byte [] tableName) throws IOException {
if (Bytes.equals(tableName, ROOT_TABLE_NAME)) {
throw new IOException("Can't delete root table");
}
new TableDelete(this, tableName).process(); new TableDelete(this, tableName).process();
LOG.info("deleted table: " + Bytes.toString(tableName)); LOG.info("deleted table: " + Bytes.toString(tableName));
} }
@ -654,11 +657,17 @@ public class HMaster extends Thread implements HConstants, HMasterInterface,
/** {@inheritDoc} */ /** {@inheritDoc} */
public void enableTable(final byte [] tableName) throws IOException { public void enableTable(final byte [] tableName) throws IOException {
if (Bytes.equals(tableName, ROOT_TABLE_NAME)) {
throw new IOException("Can't enable root table");
}
new ChangeTableState(this, tableName, true).process(); new ChangeTableState(this, tableName, true).process();
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
public void disableTable(final byte [] tableName) throws IOException { public void disableTable(final byte [] tableName) throws IOException {
if (Bytes.equals(tableName, ROOT_TABLE_NAME)) {
throw new IOException("Can't disable root table");
}
new ChangeTableState(this, tableName, false).process(); new ChangeTableState(this, tableName, false).process();
} }

View File

@ -438,7 +438,7 @@ public class HStore implements HConstants {
try { try {
// Try fixing this file.. if we can. Use the hbase version of fix. // Try fixing this file.. if we can. Use the hbase version of fix.
// Need to remove the old index file first else fix won't go ahead. // Need to remove the old index file first else fix won't go ahead.
this.fs.delete(new Path(mapfile, MapFile.INDEX_FILE_NAME)); this.fs.delete(new Path(mapfile, MapFile.INDEX_FILE_NAME), false);
long count = MapFile.fix(this.fs, mapfile, HStoreFile.HbaseMapFile.KEY_CLASS, long count = MapFile.fix(this.fs, mapfile, HStoreFile.HbaseMapFile.KEY_CLASS,
HStoreFile.HbaseMapFile.VALUE_CLASS, false, this.conf); HStoreFile.HbaseMapFile.VALUE_CLASS, false, this.conf);
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {