HBASE-845 HCM.isTableEnabled doesn't really tell if it is, or not
HBASE-903 [shell] Can't set table descriptor attributes when I alter a table git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@738927 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
476da38f1f
commit
86e3267abb
|
@ -29,6 +29,8 @@ Release 0.20.0 - Unreleased
|
||||||
HBASE-1064 HBase REST xml/json improvements (Brian Beggs working of
|
HBASE-1064 HBase REST xml/json improvements (Brian Beggs working of
|
||||||
initial Michael Gottesman work via Stack)
|
initial Michael Gottesman work via Stack)
|
||||||
HBASE-5121 Fix shell usage for format.width
|
HBASE-5121 Fix shell usage for format.width
|
||||||
|
HBASE-845 HCM.isTableEnabled doesn't really tell if it is, or not
|
||||||
|
HBASE-903 [shell] Can't set table descriptor attributes when I alter a table
|
||||||
|
|
||||||
Release 0.19.0 - 01/21/2009
|
Release 0.19.0 - 01/21/2009
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
10
bin/HBase.rb
10
bin/HBase.rb
|
@ -8,6 +8,7 @@
|
||||||
# whether the table exists and returns nil regardless.
|
# whether the table exists and returns nil regardless.
|
||||||
include Java
|
include Java
|
||||||
include_class('java.lang.Integer') {|package,name| "J#{name}" }
|
include_class('java.lang.Integer') {|package,name| "J#{name}" }
|
||||||
|
include_class('java.lang.Long') {|package,name| "J#{name}" }
|
||||||
include_class('java.lang.Boolean') {|package,name| "J#{name}" }
|
include_class('java.lang.Boolean') {|package,name| "J#{name}" }
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.client.HBaseAdmin
|
import org.apache.hadoop.hbase.client.HBaseAdmin
|
||||||
|
@ -203,6 +204,15 @@ module HBase
|
||||||
method = args.delete(METHOD)
|
method = args.delete(METHOD)
|
||||||
if method == "delete"
|
if method == "delete"
|
||||||
@admin.deleteColumn(tableName, makeColumnName(args[NAME]))
|
@admin.deleteColumn(tableName, makeColumnName(args[NAME]))
|
||||||
|
elsif method == "table_att"
|
||||||
|
args[MAX_FILESIZE]? htd.setMaxFileSize(JLong.valueOf(args[MAX_FILESIZE])) :
|
||||||
|
htd.setMaxFileSize(HTableDescriptor::DEFAULT_MAX_FILESIZE);
|
||||||
|
args[READONLY]? htd.setReadOnly(JBoolean.valueOf(args[READONLY])) :
|
||||||
|
htd.setReadOnly(HTableDescriptor::DEFAULT_READONLY);
|
||||||
|
args[MEMCACHE_FLUSHSIZE]?
|
||||||
|
htd.setMemcacheFlushSize(JLong.valueOf(args[MEMCACHE_FLUSHSIZE])) :
|
||||||
|
htd.setMemcacheFlushSize(HTableDescriptor::DEFAULT_MEMCACHE_FLUSH_SIZE);
|
||||||
|
@admin.modifyTable(tableName.to_java_bytes,htd)
|
||||||
else
|
else
|
||||||
descriptor = hcd(args)
|
descriptor = hcd(args)
|
||||||
if (htd.hasFamily(descriptor.getNameAsString().to_java_bytes))
|
if (htd.hasFamily(descriptor.getNameAsString().to_java_bytes))
|
||||||
|
|
|
@ -156,6 +156,12 @@ HBASE SHELL COMMANDS:
|
||||||
To delete the 'f1' column family in table 't1', do:
|
To delete the 'f1' column family in table 't1', do:
|
||||||
hbase> alter 't1', {NAME => 'f1', METHOD => 'delete'}
|
hbase> alter 't1', {NAME => 'f1', METHOD => 'delete'}
|
||||||
|
|
||||||
|
You can also change table-scope attributes like MAX_FILESIZE
|
||||||
|
MEMCACHE_FLUSHSIZE and READONLY.
|
||||||
|
|
||||||
|
For example, to change the max size of a family to 128MB, do:
|
||||||
|
hbase> alter 't1', {METHOD => 'table_att', MAX_FILESIZE => '134217728'}
|
||||||
|
|
||||||
count Count the number of rows in a table. This operation may take a LONG
|
count Count the number of rows in a table. This operation may take a LONG
|
||||||
time (Run '$HADOOP_HOME/bin/hadoop jar hbase.jar rowcount' to run a
|
time (Run '$HADOOP_HOME/bin/hadoop jar hbase.jar rowcount' to run a
|
||||||
counting mapreduce job). Current count is shown every 1000 rows by
|
counting mapreduce job). Current count is shown every 1000 rows by
|
||||||
|
|
|
@ -92,6 +92,8 @@ public class HTableDescriptor implements WritableComparable<HTableDescriptor>, I
|
||||||
|
|
||||||
public static final int DEFAULT_MEMCACHE_FLUSH_SIZE = 1024*1024*64;
|
public static final int DEFAULT_MEMCACHE_FLUSH_SIZE = 1024*1024*64;
|
||||||
|
|
||||||
|
public static final int DEFAULT_MAX_FILESIZE = 1024*1024*256;
|
||||||
|
|
||||||
private volatile Boolean meta = null;
|
private volatile Boolean meta = null;
|
||||||
private volatile Boolean root = null;
|
private volatile Boolean root = null;
|
||||||
|
|
||||||
|
|
|
@ -366,7 +366,7 @@ public class HBaseAdmin {
|
||||||
|
|
||||||
// Wait until all regions are disabled
|
// Wait until all regions are disabled
|
||||||
for (int tries = 0;
|
for (int tries = 0;
|
||||||
(tries < numRetries) && (isTableEnabled(tableName));
|
(tries < numRetries) && (!isTableDisabled(tableName));
|
||||||
tries++) {
|
tries++) {
|
||||||
if (LOG.isDebugEnabled()) {
|
if (LOG.isDebugEnabled()) {
|
||||||
LOG.debug("Sleep. Waiting for all regions to be disabled from " +
|
LOG.debug("Sleep. Waiting for all regions to be disabled from " +
|
||||||
|
@ -382,7 +382,7 @@ public class HBaseAdmin {
|
||||||
Bytes.toString(tableName));
|
Bytes.toString(tableName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isTableEnabled(tableName)) {
|
if (!isTableDisabled(tableName)) {
|
||||||
throw new RegionException("Retries exhausted, it took too long to wait"+
|
throw new RegionException("Retries exhausted, it took too long to wait"+
|
||||||
" for the table " + Bytes.toString(tableName) + " to be disabled.");
|
" for the table " + Bytes.toString(tableName) + " to be disabled.");
|
||||||
}
|
}
|
||||||
|
@ -406,6 +406,15 @@ public class HBaseAdmin {
|
||||||
return connection.isTableEnabled(tableName);
|
return connection.isTableEnabled(tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param tableName name of table to check
|
||||||
|
* @return true if table is off-line
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public boolean isTableDisabled(byte[] tableName) throws IOException {
|
||||||
|
return connection.isTableDisabled(tableName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a column to an existing table
|
* Add a column to an existing table
|
||||||
*
|
*
|
||||||
|
@ -635,6 +644,17 @@ public class HBaseAdmin {
|
||||||
modifyTable(tableName == null? null: tableName, op, args);
|
modifyTable(tableName == null? null: tableName, op, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modify an existing table, more IRB friendly version.
|
||||||
|
* @param tableName name of table.
|
||||||
|
* @param htd modified description of the table
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void modifyTable(final byte [] tableName, HTableDescriptor htd)
|
||||||
|
throws IOException {
|
||||||
|
modifyTable(tableName, HConstants.MODIFY_TABLE_SET_HTD, htd);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify an existing table
|
* Modify an existing table
|
||||||
*
|
*
|
||||||
|
|
|
@ -54,12 +54,22 @@ public interface HConnection {
|
||||||
throws MasterNotRunningException;
|
throws MasterNotRunningException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* A table that isTableEnabled == false and isTableDisabled == false
|
||||||
|
* is possible. This happens when a table has a lot of regions
|
||||||
|
* that must be processed.
|
||||||
* @param tableName
|
* @param tableName
|
||||||
* @return true if the table is enabled, false otherwise
|
* @return true if the table is enabled, false otherwise
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public boolean isTableEnabled(byte[] tableName) throws IOException;
|
public boolean isTableEnabled(byte[] tableName) throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param tableName
|
||||||
|
* @return true if the table is disabled, false otherwise
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public boolean isTableDisabled(byte[] tableName) throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all the userspace tables. In other words, scan the META table.
|
* List all the userspace tables. In other words, scan the META table.
|
||||||
*
|
*
|
||||||
|
|
|
@ -317,6 +317,23 @@ public class HConnectionManager implements HConstants {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTableEnabled(byte[] tableName) throws IOException {
|
public boolean isTableEnabled(byte[] tableName) throws IOException {
|
||||||
|
return testTableOnlineState(tableName, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTableDisabled(byte[] tableName) throws IOException {
|
||||||
|
return testTableOnlineState(tableName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If online == true
|
||||||
|
* Returns true if all regions are online
|
||||||
|
* Returns false in any other case
|
||||||
|
* If online == false
|
||||||
|
* Returns true if all regions are offline
|
||||||
|
* Returns false in any other case
|
||||||
|
*/
|
||||||
|
private boolean testTableOnlineState(byte[] tableName,
|
||||||
|
boolean online) throws IOException {
|
||||||
if (!tableExists(tableName)) {
|
if (!tableExists(tableName)) {
|
||||||
throw new TableNotFoundException(Bytes.toString(tableName));
|
throw new TableNotFoundException(Bytes.toString(tableName));
|
||||||
}
|
}
|
||||||
|
@ -325,38 +342,30 @@ public class HConnectionManager implements HConstants {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean result = true;
|
|
||||||
int rowsScanned = 0;
|
int rowsScanned = 0;
|
||||||
|
int rowsOffline = 0;
|
||||||
byte[] startKey =
|
byte[] startKey =
|
||||||
HRegionInfo.createRegionName(tableName, null, HConstants.ZEROES);
|
HRegionInfo.createRegionName(tableName, null, HConstants.ZEROES);
|
||||||
|
byte[] endKey = null;
|
||||||
HRegionInfo currentRegion = null;
|
HRegionInfo currentRegion = null;
|
||||||
do {
|
ScannerCallable s = new ScannerCallable(this,
|
||||||
if (currentRegion != null) {
|
(Bytes.equals(tableName, HConstants.META_TABLE_NAME) ?
|
||||||
byte[] endKey = currentRegion.getEndKey();
|
HConstants.ROOT_TABLE_NAME : HConstants.META_TABLE_NAME),
|
||||||
if (endKey == null ||
|
HConstants.COL_REGIONINFO_ARRAY, startKey,
|
||||||
HStoreKey.equalsTwoRowKeys(currentRegion, endKey,
|
HConstants.LATEST_TIMESTAMP, null
|
||||||
HConstants.EMPTY_BYTE_ARRAY)) {
|
);
|
||||||
// We have reached the end of the table and we're done
|
try {
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
HRegionInfo oldRegion = currentRegion;
|
|
||||||
if (oldRegion != null) {
|
|
||||||
startKey = oldRegion.getEndKey();
|
|
||||||
}
|
|
||||||
ScannerCallable s = new ScannerCallable(this,
|
|
||||||
(Bytes.equals(tableName, HConstants.META_TABLE_NAME) ?
|
|
||||||
HConstants.ROOT_TABLE_NAME : HConstants.META_TABLE_NAME),
|
|
||||||
HConstants.COL_REGIONINFO_ARRAY, startKey,
|
|
||||||
HConstants.LATEST_TIMESTAMP, null
|
|
||||||
);
|
|
||||||
// Open scanner
|
// Open scanner
|
||||||
getRegionServerWithRetries(s);
|
getRegionServerWithRetries(s);
|
||||||
currentRegion = s.getHRegionInfo();
|
do {
|
||||||
try {
|
HRegionInfo oldRegion = currentRegion;
|
||||||
|
if (oldRegion != null) {
|
||||||
|
startKey = oldRegion.getEndKey();
|
||||||
|
}
|
||||||
|
currentRegion = s.getHRegionInfo();
|
||||||
RowResult r = null;
|
RowResult r = null;
|
||||||
RowResult[] rrs = null;
|
RowResult[] rrs = null;
|
||||||
while (result && (rrs = getRegionServerWithRetries(s)) != null) {
|
while ((rrs = getRegionServerWithRetries(s)) != null) {
|
||||||
r = rrs[0];
|
r = rrs[0];
|
||||||
Cell c = r.get(HConstants.COL_REGIONINFO);
|
Cell c = r.get(HConstants.COL_REGIONINFO);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
|
@ -366,18 +375,23 @@ public class HConnectionManager implements HConstants {
|
||||||
if (info != null) {
|
if (info != null) {
|
||||||
if (Bytes.equals(info.getTableDesc().getName(), tableName)) {
|
if (Bytes.equals(info.getTableDesc().getName(), tableName)) {
|
||||||
rowsScanned += 1;
|
rowsScanned += 1;
|
||||||
result = !info.isOffline();
|
rowsOffline += info.isOffline() ? 1 : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
endKey = currentRegion.getEndKey();
|
||||||
s.setClose();
|
} while (!(endKey == null || HStoreKey.equalsTwoRowKeys(currentRegion,
|
||||||
getRegionServerWithRetries(s);
|
endKey, HConstants.EMPTY_BYTE_ARRAY)));
|
||||||
}
|
}
|
||||||
} while (result);
|
finally {
|
||||||
return rowsScanned > 0 && result;
|
s.setClose();
|
||||||
|
}
|
||||||
|
boolean onlineOffline =
|
||||||
|
online ? rowsOffline == 0 : rowsOffline == rowsScanned;
|
||||||
|
return rowsScanned > 0 && onlineOffline;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class HTableDescriptorFinder
|
private class HTableDescriptorFinder
|
||||||
|
|
Loading…
Reference in New Issue