From cb02d2c0c0727634363472a990da2bd037e29ff2 Mon Sep 17 00:00:00 2001 From: CHIA-PING TSAI Date: Thu, 23 Mar 2017 13:37:51 +0800 Subject: [PATCH] HBASE-15583 Any HTD we give out should be immutable --- bin/region_status.rb | 2 +- .../org/apache/hadoop/hbase/HTableDescriptor.java | 296 +++++---------------- .../java/org/apache/hadoop/hbase/client/Admin.java | 26 +- .../org/apache/hadoop/hbase/client/AsyncAdmin.java | 23 +- .../hadoop/hbase/client/AsyncHBaseAdmin.java | 5 +- .../org/apache/hadoop/hbase/client/HBaseAdmin.java | 19 +- .../org/apache/hadoop/hbase/client/HTable.java | 2 +- .../hbase/client/ImmutableHTableDescriptor.java | 89 +++++++ .../hbase/client/UnmodifyableHTableDescriptor.java | 129 --------- .../hadoop/hbase/shaded/protobuf/ProtobufUtil.java | 1 + .../client/TestImmutableHTableDescriptor.java | 116 ++++++++ .../client/TestUnmodifyableHTableDescriptor.java | 47 ---- .../apache/hadoop/hbase/rest/RowResourceBase.java | 2 +- .../hbase/rest/client/TestRemoteAdminRetries.java | 3 +- .../hadoop/hbase/rsgroup/RSGroupInfoManager.java | 1 - .../hbase/rsgroup/RSGroupInfoManagerImpl.java | 2 +- .../apache/hadoop/hbase/rsgroup/TestRSGroups.java | 2 +- .../hadoop/hbase/backup/util/RestoreTool.java | 6 +- .../apache/hadoop/hbase/HBaseTestingUtility.java | 2 +- .../hbase/TestFSTableDescriptorForceCreation.java | 2 +- .../hadoop/hbase/client/TestAsyncTableBatch.java | 2 +- .../TestReplicationAdminWithClusters.java | 4 +- .../TestSimpleRegionNormalizerOnCluster.java | 4 +- .../regionserver/TestEncryptionKeyRotation.java | 4 +- .../regionserver/TestEncryptionRandomKeying.java | 2 +- .../hadoop/hbase/regionserver/TestHRegion.java | 6 +- .../TestCoprocessorWhitelistMasterObserver.java | 4 +- .../hbase/snapshot/MobSnapshotTestingUtils.java | 2 +- .../hbase/snapshot/SnapshotTestingUtils.java | 2 +- .../hadoop/hbase/util/TestFSTableDescriptors.java | 6 +- .../hadoop/hbase/util/TestHBaseFsckEncryption.java | 2 +- .../hadoop/hbase/util/TestHBaseFsckOneRS.java | 2 +- hbase-shell/src/main/ruby/hbase/admin.rb | 11 +- .../src/main/ruby/shell/commands/alter_async.rb | 4 +- 34 files changed, 352 insertions(+), 478 deletions(-) create mode 100644 hbase-client/src/main/java/org/apache/hadoop/hbase/client/ImmutableHTableDescriptor.java delete mode 100644 hbase-client/src/main/java/org/apache/hadoop/hbase/client/UnmodifyableHTableDescriptor.java create mode 100644 hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestImmutableHTableDescriptor.java delete mode 100644 hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestUnmodifyableHTableDescriptor.java diff --git a/bin/region_status.rb b/bin/region_status.rb index 91873cb..f889de9 100644 --- a/bin/region_status.rb +++ b/bin/region_status.rb @@ -133,7 +133,7 @@ end # query the master to see how many regions are on region servers if not $tablename.nil? - $TableName = HTableDescriptor.new($tablename.to_java_bytes).getTableName() + $TableName = TableName.valueOf($tablename.to_java_bytes) end while true if $tablename.nil? diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java index 25fd896..3ec5f9a 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -30,6 +31,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; +import java.util.function.Function; import java.util.regex.Matcher; import org.apache.commons.logging.Log; @@ -57,11 +59,11 @@ public class HTableDescriptor implements Comparable { private static final Log LOG = LogFactory.getLog(HTableDescriptor.class); - private TableName name = null; + private final TableName name; /** * A map which holds the metadata information of the table. This metadata - * includes values like IS_ROOT, IS_META, DEFERRED_LOG_FLUSH, SPLIT_POLICY, + * includes values like IS_ROOT, IS_META, SPLIT_POLICY, * MAX_FILE_SIZE, READONLY, MEMSTORE_FLUSHSIZE etc... */ private final Map values = new HashMap<>(); @@ -145,17 +147,6 @@ public class HTableDescriptor implements Comparable { new Bytes(Bytes.toBytes(IS_META)); /** - * INTERNAL Used by HBase Shell interface to access this metadata - * attribute which denotes if the deferred log flush option is enabled. - * @deprecated Use {@link #DURABILITY} instead. - */ - @Deprecated - public static final String DEFERRED_LOG_FLUSH = "DEFERRED_LOG_FLUSH"; - @Deprecated - private static final Bytes DEFERRED_LOG_FLUSH_KEY = - new Bytes(Bytes.toBytes(DEFERRED_LOG_FLUSH)); - - /** * INTERNAL {@link Durability} setting for the table. */ public static final String DURABILITY = "DURABILITY"; @@ -208,8 +199,6 @@ public class HTableDescriptor implements Comparable { private static final Bytes TRUE = new Bytes(Bytes.toBytes(Boolean.TRUE.toString())); - private static final boolean DEFAULT_DEFERRED_LOG_FLUSH = false; - /** * Constant that denotes whether the table is READONLY by default and is false */ @@ -244,8 +233,6 @@ public class HTableDescriptor implements Comparable { DEFAULT_VALUES.put(READONLY, String.valueOf(DEFAULT_READONLY)); DEFAULT_VALUES.put(MEMSTORE_FLUSHSIZE, String.valueOf(DEFAULT_MEMSTORE_FLUSH_SIZE)); - DEFAULT_VALUES.put(DEFERRED_LOG_FLUSH, - String.valueOf(DEFAULT_DEFERRED_LOG_FLUSH)); DEFAULT_VALUES.put(DURABILITY, DEFAULT_DURABLITY.name()); //use the enum name DEFAULT_VALUES.put(REGION_REPLICATION, String.valueOf(DEFAULT_REGION_REPLICATION)); DEFAULT_VALUES.put(NORMALIZATION_ENABLED, String.valueOf(DEFAULT_NORMALIZATION_ENABLED)); @@ -258,20 +245,6 @@ public class HTableDescriptor implements Comparable { } /** - * Cache of whether this is a meta table or not. - */ - private volatile Boolean meta = null; - /** - * Cache of whether this is root table or not. - */ - private volatile Boolean root = null; - - /** - * Durability setting for the table - */ - private Durability durability = null; - - /** * Maps column family name to the respective HColumnDescriptors */ private final Map families = @@ -283,10 +256,7 @@ public class HTableDescriptor implements Comparable { */ @InterfaceAudience.Private protected HTableDescriptor(final TableName name, HColumnDescriptor[] families) { - setName(name); - for(HColumnDescriptor descriptor : families) { - this.families.put(descriptor.getName(), descriptor); - } + this(name, families, Collections.EMPTY_MAP); } /** @@ -295,26 +265,7 @@ public class HTableDescriptor implements Comparable { */ protected HTableDescriptor(final TableName name, HColumnDescriptor[] families, Map values) { - setName(name); - for(HColumnDescriptor descriptor : families) { - this.families.put(descriptor.getName(), descriptor); - } - for (Map.Entry entry : - values.entrySet()) { - setValue(entry.getKey(), entry.getValue()); - } - } - - /** - * Default constructor which constructs an empty object. - * For deserializing an HTableDescriptor instance only. - * @deprecated As of release 0.96 (HBASE-5453). - * This was made protected in 2.0.0 and will be removed in HBase 3.0.0. - * Used by Writables and Writables are going away. - */ - @Deprecated - protected HTableDescriptor() { - super(); + this(name, Arrays.asList(families), values, Collections.EMPTY_MAP); } /** @@ -323,28 +274,7 @@ public class HTableDescriptor implements Comparable { * @see HADOOP-1581 HBASE: (HBASE-174) Un-openable tablename bug */ public HTableDescriptor(final TableName name) { - super(); - setName(name); - } - - /** - * Construct a table descriptor specifying a byte array table name - * @param name Table name. - * @see HADOOP-1581 (HBASE-174) HBASE: Un-openable tablename bug - */ - @Deprecated - public HTableDescriptor(final byte[] name) { - this(TableName.valueOf(name)); - } - - /** - * Construct a table descriptor specifying a String table name - * @param name Table name. - * @see HADOOP-1581 (HBASE-174) HBASE: Un-openable tablename bug - */ - @Deprecated - public HTableDescriptor(final String name) { - this(TableName.valueOf(name)); + this(name, Collections.EMPTY_LIST, Collections.EMPTY_MAP, Collections.EMPTY_MAP); } /** @@ -368,19 +298,16 @@ public class HTableDescriptor implements Comparable { * @param desc The descriptor. */ public HTableDescriptor(final TableName name, final HTableDescriptor desc) { - super(); - setName(name); - setMetaFlags(this.name); - for (HColumnDescriptor c: desc.families.values()) { - this.families.put(c.getName(), new HColumnDescriptor(c)); - } - for (Map.Entry e : - desc.values.entrySet()) { - setValue(e.getKey(), e.getValue()); - } - for (Map.Entry e : desc.configuration.entrySet()) { - this.configuration.put(e.getKey(), e.getValue()); - } + this(name, desc.getFamilies(), desc.getValues(), desc.getConfiguration()); + } + + private HTableDescriptor(final TableName name, final Collection families, + Map values, Map configuration) { + this.name = name; + families.forEach(c -> this.families.put(c.getName(), new HColumnDescriptor(c))); + values.forEach(this.values::put); + configuration.forEach(this.configuration::put); + setMetaFlags(name); } /* @@ -391,8 +318,8 @@ public class HTableDescriptor implements Comparable { * @param name */ private void setMetaFlags(final TableName name) { - setMetaRegion(isRootRegion() || - name.equals(TableName.META_TABLE_NAME)); + values.put(IS_META_KEY, isRootRegion() || + name.equals(TableName.META_TABLE_NAME)? TRUE: FALSE); } /** @@ -401,10 +328,7 @@ public class HTableDescriptor implements Comparable { * @return true if this is a -ROOT- region */ public boolean isRootRegion() { - if (this.root == null) { - this.root = isSomething(IS_ROOT_KEY, false)? Boolean.TRUE: Boolean.FALSE; - } - return this.root.booleanValue(); + return isSomething(IS_ROOT_KEY, false); } /** @@ -427,15 +351,7 @@ public class HTableDescriptor implements Comparable { * region */ public boolean isMetaRegion() { - if (this.meta == null) { - this.meta = calculateIsMetaRegion(); - } - return this.meta.booleanValue(); - } - - private synchronized Boolean calculateIsMetaRegion() { - byte [] value = getValue(IS_META_KEY); - return (value != null)? Boolean.valueOf(Bytes.toString(value)): Boolean.FALSE; + return isSomething(IS_META_KEY, false); } private boolean isSomething(final Bytes key, @@ -448,18 +364,6 @@ public class HTableDescriptor implements Comparable { } /** - * INTERNAL Used to denote if the current table represents - * -ROOT- or hbase:meta region. This is used - * internally by the HTableDescriptor constructors - * - * @param isMeta true if its either -ROOT- or - * hbase:meta region - */ - protected void setMetaRegion(boolean isMeta) { - setValue(IS_META_KEY, isMeta? TRUE: FALSE); - } - - /** * Checks if the table is a hbase:meta table * * @return true if table is hbase:meta region. @@ -515,39 +419,35 @@ public class HTableDescriptor implements Comparable { * Setter for storing metadata as a (key, value) pair in {@link #values} map * * @param key The key. - * @param value The value. + * @param value The value. If null, removes the setting. * @see #values */ public HTableDescriptor setValue(byte[] key, byte[] value) { - setValue(new Bytes(key), new Bytes(value)); - return this; + return setValue(toBytesOrNull(key, v -> v), + toBytesOrNull(value, v -> v)); } /* * @param key The key. - * @param value The value. + * @param value The value. If null, removes the setting. */ private HTableDescriptor setValue(final Bytes key, final String value) { - setValue(key, new Bytes(Bytes.toBytes(value))); - return this; + return setValue(key, toBytesOrNull(value, Bytes::toBytes)); } /* * Setter for storing metadata as a (key, value) pair in {@link #values} map * * @param key The key. - * @param value The value. + * @param value The value. If null, removes the setting. */ public HTableDescriptor setValue(final Bytes key, final Bytes value) { - if (key.compareTo(DEFERRED_LOG_FLUSH_KEY) == 0) { - boolean isDeferredFlush = Boolean.valueOf(Bytes.toString(value.get())); - LOG.warn("HTableDescriptor property:" + DEFERRED_LOG_FLUSH + " is deprecated, " + - "use " + DURABILITY + " instead"); - setDurability(isDeferredFlush ? Durability.ASYNC_WAL : DEFAULT_DURABLITY); - return this; + if (value == null) { + remove(key); + } else { + values.put(key, value); } - values.put(key, value); return this; } @@ -555,16 +455,20 @@ public class HTableDescriptor implements Comparable { * Setter for storing metadata as a (key, value) pair in {@link #values} map * * @param key The key. - * @param value The value. + * @param value The value. If null, removes the setting. * @see #values */ public HTableDescriptor setValue(String key, String value) { - if (value == null) { - remove(key); + return setValue(toBytesOrNull(key, Bytes::toBytes), + toBytesOrNull(value, Bytes::toBytes)); + } + + private static Bytes toBytesOrNull(T t, Function f) { + if (t == null) { + return null; } else { - setValue(Bytes.toBytes(key), Bytes.toBytes(value)); + return new Bytes(f.apply(t)); } - return this; } /** @@ -635,8 +539,7 @@ public class HTableDescriptor implements Comparable { * @param isEnable True if enable compaction. */ public HTableDescriptor setCompactionEnabled(final boolean isEnable) { - setValue(COMPACTION_ENABLED_KEY, isEnable ? TRUE : FALSE); - return this; + return setValue(COMPACTION_ENABLED_KEY, isEnable ? TRUE : FALSE); } /** @@ -655,8 +558,7 @@ public class HTableDescriptor implements Comparable { * @param isEnable True if enable normalization. */ public HTableDescriptor setNormalizationEnabled(final boolean isEnable) { - setValue(NORMALIZATION_ENABLED_KEY, isEnable ? TRUE : FALSE); - return this; + return setValue(NORMALIZATION_ENABLED_KEY, isEnable ? TRUE : FALSE); } /** @@ -664,9 +566,7 @@ public class HTableDescriptor implements Comparable { * @param durability enum value */ public HTableDescriptor setDurability(Durability durability) { - this.durability = durability; - setValue(DURABILITY_KEY, durability.name()); - return this; + return setValue(DURABILITY_KEY, durability.name()); } /** @@ -674,21 +574,18 @@ public class HTableDescriptor implements Comparable { * @return durability setting for the table. */ public Durability getDurability() { - if (this.durability == null) { - byte[] durabilityValue = getValue(DURABILITY_KEY); - if (durabilityValue == null) { - this.durability = DEFAULT_DURABLITY; - } else { - try { - this.durability = Durability.valueOf(Bytes.toString(durabilityValue)); - } catch (IllegalArgumentException ex) { - LOG.warn("Received " + ex + " because Durability value for HTableDescriptor" - + " is not known. Durability:" + Bytes.toString(durabilityValue)); - this.durability = DEFAULT_DURABLITY; - } + byte[] durabilityValue = getValue(DURABILITY_KEY); + if (durabilityValue == null) { + return DEFAULT_DURABLITY; + } else { + try { + return Durability.valueOf(Bytes.toString(durabilityValue)); + } catch (IllegalArgumentException ex) { + LOG.warn("Received " + ex + " because Durability value for HTableDescriptor" + + " is not known. Durability:" + Bytes.toString(durabilityValue)); + return DEFAULT_DURABLITY; } } - return this.durability; } /** @@ -701,17 +598,6 @@ public class HTableDescriptor implements Comparable { } /** - * Get the name of the table as a byte array. - * - * @return name of table - * @deprecated Use {@link #getTableName()} instead - */ - @Deprecated - public byte[] getName() { - return name.getName(); - } - - /** * Get the name of the table as a String * * @return name of table as a String @@ -727,8 +613,7 @@ public class HTableDescriptor implements Comparable { * @param clazz the class name */ public HTableDescriptor setRegionSplitPolicyClassName(String clazz) { - setValue(SPLIT_POLICY, clazz); - return this; + return setValue(SPLIT_POLICY, clazz); } /** @@ -744,24 +629,6 @@ public class HTableDescriptor implements Comparable { } /** - * Set the name of the table. - * - * @param name name of table - */ - @Deprecated - public HTableDescriptor setName(byte[] name) { - setName(TableName.valueOf(name)); - return this; - } - - @Deprecated - public HTableDescriptor setName(TableName name) { - this.name = name; - setMetaFlags(this.name); - return this; - } - - /** * Returns the maximum size upto which a region can grow to after which a region * split is triggered. The region size is represented by the size of the biggest * store file in that region. @@ -794,8 +661,7 @@ public class HTableDescriptor implements Comparable { * before a split is triggered. */ public HTableDescriptor setMaxFileSize(long maxFileSize) { - setValue(MAX_FILESIZE_KEY, Long.toString(maxFileSize)); - return this; + return setValue(MAX_FILESIZE_KEY, Long.toString(maxFileSize)); } /** @@ -820,8 +686,7 @@ public class HTableDescriptor implements Comparable { * @param memstoreFlushSize memory cache flush size for each hregion */ public HTableDescriptor setMemStoreFlushSize(long memstoreFlushSize) { - setValue(MEMSTORE_FLUSHSIZE_KEY, Long.toString(memstoreFlushSize)); - return this; + return setValue(MEMSTORE_FLUSHSIZE_KEY, Long.toString(memstoreFlushSize)); } /** @@ -831,8 +696,7 @@ public class HTableDescriptor implements Comparable { * @param clazz the class name */ public HTableDescriptor setFlushPolicyClassName(String clazz) { - setValue(FLUSH_POLICY, clazz); - return this; + return setValue(FLUSH_POLICY, clazz); } /** @@ -859,8 +723,7 @@ public class HTableDescriptor implements Comparable { throw new IllegalArgumentException("Family '" + family.getNameAsString() + "' already exists so cannot be added"); } - this.families.put(family.getName(), family); - return this; + return setFamily(family); } /** @@ -876,7 +739,11 @@ public class HTableDescriptor implements Comparable { throw new IllegalArgumentException("Column family '" + family.getNameAsString() + "' does not exist"); } - this.families.put(family.getName(), family); + return setFamily(family); + } + + protected HTableDescriptor setFamily(HColumnDescriptor family) { + families.put(family.getName(), family); return this; } @@ -1070,8 +937,7 @@ public class HTableDescriptor implements Comparable { result = families.size() - other.families.size(); } if (result == 0 && families.size() != other.families.size()) { - result = Integer.valueOf(families.size()).compareTo( - Integer.valueOf(other.families.size())); + result = Integer.valueOf(families.size()).compareTo(other.families.size()); } if (result == 0) { for (Iterator it = families.values().iterator(), @@ -1143,9 +1009,8 @@ public class HTableDescriptor implements Comparable { * @param regionReplication the replication factor per region */ public HTableDescriptor setRegionReplication(int regionReplication) { - setValue(REGION_REPLICATION_KEY, + return setValue(REGION_REPLICATION_KEY, new Bytes(Bytes.toBytes(Integer.toString(regionReplication)))); - return this; } /** @@ -1168,14 +1033,12 @@ public class HTableDescriptor implements Comparable { setValue(REGION_MEMSTORE_REPLICATION_KEY, memstoreReplication ? TRUE : FALSE); // If the memstore replication is setup, we do not have to wait for observing a flush event // from primary before starting to serve reads, because gaps from replication is not applicable - setConfiguration(RegionReplicaUtil.REGION_REPLICA_WAIT_FOR_PRIMARY_FLUSH_CONF_KEY, + return setConfiguration(RegionReplicaUtil.REGION_REPLICA_WAIT_FOR_PRIMARY_FLUSH_CONF_KEY, Boolean.toString(memstoreReplication)); - return this; } public HTableDescriptor setPriority(int priority) { - setValue(PRIORITY_KEY, Integer.toString(priority)); - return this; + return setValue(PRIORITY_KEY, Integer.toString(priority)); } public int getPriority() { @@ -1253,8 +1116,7 @@ public class HTableDescriptor implements Comparable { * @throws IOException */ public HTableDescriptor addCoprocessor(String className) throws IOException { - addCoprocessor(className, null, Coprocessor.PRIORITY_USER, null); - return this; + return addCoprocessor(className, null, Coprocessor.PRIORITY_USER, null); } /** @@ -1349,8 +1211,7 @@ public class HTableDescriptor implements Comparable { } maxCoprocessorNumber++; String key = "coprocessor$" + Integer.toString(maxCoprocessorNumber); - this.values.put(new Bytes(Bytes.toBytes(key)), new Bytes(Bytes.toBytes(specStr))); - return this; + return setValue(new Bytes(Bytes.toBytes(key)), new Bytes(Bytes.toBytes(specStr))); } /** @@ -1441,25 +1302,6 @@ public class HTableDescriptor implements Comparable { remove(match); } - /** - * Returns the {@link Path} object representing the table directory under - * path rootdir - * - * Deprecated use FSUtils.getTableDir() instead. - * - * @param rootdir qualified path of HBase root directory - * @param tableName name of table - * @return {@link Path} for table - */ - @Deprecated - public static Path getTableDir(Path rootdir, final byte [] tableName) { - //This is bad I had to mirror code from FSUTils.getTableDir since - //there is no module dependency between hbase-client and hbase-server - TableName name = TableName.valueOf(tableName); - return new Path(rootdir, new Path(HConstants.BASE_NAMESPACE_DIR, - new Path(name.getNamespaceAsString(), new Path(name.getQualifierAsString())))); - } - public final static String NAMESPACE_FAMILY_INFO = "info"; public final static byte[] NAMESPACE_FAMILY_INFO_BYTES = Bytes.toBytes(NAMESPACE_FAMILY_INFO); public final static byte[] NAMESPACE_COL_DESC_BYTES = Bytes.toBytes("d"); diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java index cc14acd..bb17366 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java @@ -96,7 +96,7 @@ public interface Admin extends Abortable, Closeable { /** * List all the userspace tables. * - * @return - returns an array of HTableDescriptors + * @return - returns an array of read-only HTableDescriptors * @throws IOException if a remote or network exception occurs */ HTableDescriptor[] listTables() throws IOException; @@ -105,7 +105,7 @@ public interface Admin extends Abortable, Closeable { * List all the userspace tables matching the given pattern. * * @param pattern The compiled regular expression to match against - * @return - returns an array of HTableDescriptors + * @return - returns an array of read-only HTableDescriptors * @throws IOException if a remote or network exception occurs * @see #listTables() */ @@ -126,7 +126,7 @@ public interface Admin extends Abortable, Closeable { * * @param pattern The compiled regular expression to match against * @param includeSysTables False to match only against userspace tables - * @return - returns an array of HTableDescriptors + * @return - returns an array of read-only HTableDescriptors * @throws IOException if a remote or network exception occurs * @see #listTables() */ @@ -138,7 +138,7 @@ public interface Admin extends Abortable, Closeable { * * @param regex The regular expression to match against * @param includeSysTables False to match only against userspace tables - * @return - returns an array of HTableDescriptors + * @return - returns an array of read-only HTableDescriptors * @throws IOException if a remote or network exception occurs * @see #listTables(java.util.regex.Pattern, boolean) */ @@ -193,7 +193,7 @@ public interface Admin extends Abortable, Closeable { * Method for getting the tableDescriptor * * @param tableName as a {@link TableName} - * @return the tableDescriptor + * @return the read-only tableDescriptor * @throws org.apache.hadoop.hbase.TableNotFoundException * @throws IOException if a remote or network exception occurs */ @@ -294,7 +294,8 @@ public interface Admin extends Abortable, Closeable { * #listTables(java.lang.String)} and {@link #deleteTable(org.apache.hadoop.hbase.TableName)} * * @param regex The regular expression to match table names against - * @return Table descriptors for tables that couldn't be deleted + * @return Table descriptors for tables that couldn't be deleted. + * The return htds are read-only * @throws IOException * @see #deleteTables(java.util.regex.Pattern) * @see #deleteTable(org.apache.hadoop.hbase.TableName) @@ -309,6 +310,7 @@ public interface Admin extends Abortable, Closeable { * * @param pattern The pattern to match table names against * @return Table descriptors for tables that couldn't be deleted + * The return htds are read-only * @throws IOException */ HTableDescriptor[] deleteTables(Pattern pattern) throws IOException; @@ -374,6 +376,8 @@ public interface Admin extends Abortable, Closeable { * * @param regex The regular expression to match table names against * @throws IOException + * @return Table descriptors for tables that couldn't be enabled. + * The return HTDs are read-only. * @see #enableTables(java.util.regex.Pattern) * @see #enableTable(org.apache.hadoop.hbase.TableName) */ @@ -387,6 +391,8 @@ public interface Admin extends Abortable, Closeable { * * @param pattern The pattern to match table names against * @throws IOException + * @return Table descriptors for tables that couldn't be enabled. + * The return HTDs are read-only. */ HTableDescriptor[] enableTables(Pattern pattern) throws IOException; @@ -423,6 +429,7 @@ public interface Admin extends Abortable, Closeable { * * @param regex The regular expression to match table names against * @return Table descriptors for tables that couldn't be disabled + * The return htds are read-only * @throws IOException * @see #disableTables(java.util.regex.Pattern) * @see #disableTable(org.apache.hadoop.hbase.TableName) @@ -437,6 +444,7 @@ public interface Admin extends Abortable, Closeable { * * @param pattern The pattern to match table names against * @return Table descriptors for tables that couldn't be disabled + * The return htds are read-only * @throws IOException */ HTableDescriptor[] disableTables(Pattern pattern) throws IOException; @@ -1167,7 +1175,7 @@ public interface Admin extends Abortable, Closeable { * Get list of table descriptors by namespace * * @param name namespace name - * @return A descriptor + * @return HTD[] the read-only tableDescriptors * @throws IOException */ HTableDescriptor[] listTableDescriptorsByNamespace(final String name) @@ -1200,7 +1208,7 @@ public interface Admin extends Abortable, Closeable { * Get tableDescriptors * * @param tableNames List of table names - * @return HTD[] the tableDescriptor + * @return HTD[] the read-only tableDescriptors * @throws IOException if a remote or network exception occurs */ HTableDescriptor[] getTableDescriptorsByTableName(List tableNames) @@ -1210,7 +1218,7 @@ public interface Admin extends Abortable, Closeable { * Get tableDescriptors * * @param names List of table names - * @return HTD[] the tableDescriptor + * @return HTD[] the read-only tableDescriptors * @throws IOException if a remote or network exception occurs */ HTableDescriptor[] getTableDescriptors(List names) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java index 630ae47..07a36f6 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java @@ -51,7 +51,8 @@ public interface AsyncAdmin { /** * List all the userspace tables. - * @return - returns an array of HTableDescriptors wrapped by a {@link CompletableFuture}. + * @return - returns an array of read-only HTableDescriptors wrapped + * by a {@link CompletableFuture}. * @see #listTables(Pattern, boolean) */ CompletableFuture listTables(); @@ -60,7 +61,8 @@ public interface AsyncAdmin { * List all the tables matching the given pattern. * @param regex The regular expression to match against * @param includeSysTables False to match only against userspace tables - * @return - returns an array of HTableDescriptors wrapped by a {@link CompletableFuture}. + * @return - returns an array of read-only HTableDescriptors wrapped + * by a {@link CompletableFuture}. * @see #listTables(Pattern, boolean) */ CompletableFuture listTables(String regex, boolean includeSysTables); @@ -69,7 +71,8 @@ public interface AsyncAdmin { * List all the tables matching the given pattern. * @param pattern The compiled regular expression to match against * @param includeSysTables False to match only against userspace tables - * @return - returns an array of HTableDescriptors wrapped by a {@link CompletableFuture}. + * @return - returns an array of read-only HTableDescriptors wrapped + * by a {@link CompletableFuture}. */ CompletableFuture listTables(Pattern pattern, boolean includeSysTables); @@ -101,7 +104,7 @@ public interface AsyncAdmin { /** * Method for getting the tableDescriptor * @param tableName as a {@link TableName} - * @return the tableDescriptor wrapped by a {@link CompletableFuture}. + * @return the read-only tableDescriptor wrapped by a {@link CompletableFuture}. */ CompletableFuture getTableDescriptor(final TableName tableName); @@ -147,7 +150,7 @@ public interface AsyncAdmin { * {@link #deleteTable(org.apache.hadoop.hbase.TableName)} * @param regex The regular expression to match table names against * @return Table descriptors for tables that couldn't be deleted. The return value will be wrapped - * by a {@link CompletableFuture}. + * by a {@link CompletableFuture}. The return HTDs are read-only. */ CompletableFuture deleteTables(String regex); @@ -158,7 +161,7 @@ public interface AsyncAdmin { * {@link #deleteTable(org.apache.hadoop.hbase.TableName)} * @param pattern The pattern to match table names against * @return Table descriptors for tables that couldn't be deleted. The return value will be wrapped - * by a {@link CompletableFuture}. + * by a {@link CompletableFuture}. The return HTDs are read-only. */ CompletableFuture deleteTables(Pattern pattern); @@ -181,7 +184,7 @@ public interface AsyncAdmin { * {@link #enableTable(TableName)} * @param regex The regular expression to match table names against * @return Table descriptors for tables that couldn't be enabled. The return value will be wrapped - * by a {@link CompletableFuture}. + * by a {@link CompletableFuture}. The return HTDs are read-only. */ CompletableFuture enableTables(String regex); @@ -191,7 +194,7 @@ public interface AsyncAdmin { * {@link #enableTable(TableName)} * @param pattern The pattern to match table names against * @return Table descriptors for tables that couldn't be enabled. The return value will be wrapped - * by a {@link CompletableFuture}. + * by a {@link CompletableFuture}. The return HTDs are read-only. */ CompletableFuture enableTables(Pattern pattern); @@ -207,7 +210,7 @@ public interface AsyncAdmin { * {@link #disableTable(TableName)} * @param regex The regular expression to match table names against * @return Table descriptors for tables that couldn't be disabled. The return value will be wrapped by a - * {@link CompletableFuture}. + * {@link CompletableFuture}. The return HTDs are read-only. */ CompletableFuture disableTables(String regex); @@ -217,7 +220,7 @@ public interface AsyncAdmin { * {@link #disableTable(TableName)} * @param pattern The pattern to match table names against * @return Table descriptors for tables that couldn't be disabled. The return value will be wrapped by a - * {@link CompletableFuture}. + * {@link CompletableFuture}. The return HTDs are read-only. */ CompletableFuture disableTables(Pattern pattern); diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java index e2dc3d5..119040f 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java @@ -286,7 +286,8 @@ public class AsyncHBaseAdmin implements AsyncAdmin { . call( controller, stub, RequestConverter.buildGetTableDescriptorsRequest(pattern, includeSysTables), (s, c, req, done) -> s.getTableDescriptors(c, req, done), ( - resp) -> ProtobufUtil.getHTableDescriptorArray(resp))).call(); + resp) -> ImmutableHTableDescriptor.toReadOnly( + ProtobufUtil.getHTableDescriptorArray(resp)))).call(); } @Override @@ -326,7 +327,7 @@ public class AsyncHBaseAdmin implements AsyncAdmin { return; } if (!tableSchemas.isEmpty()) { - future.complete(ProtobufUtil.convertToHTableDesc(tableSchemas.get(0))); + future.complete(new ImmutableHTableDescriptor(ProtobufUtil.convertToHTableDesc(tableSchemas.get(0)))); } else { future.completeExceptionally(new TableNotFoundException(tableName.getNameAsString())); } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 1368038..6e410b1 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -362,8 +362,8 @@ public class HBaseAdmin implements Admin { @Override public HTableDescriptor[] listTables(final Pattern pattern, final boolean includeSysTables) throws IOException { - return executeCallable(new MasterCallable(getConnection(), - getRpcControllerFactory()) { + return ImmutableHTableDescriptor.toReadOnly(executeCallable( + new MasterCallable(getConnection(), getRpcControllerFactory()) { @Override protected HTableDescriptor[] rpcCall() throws Exception { GetTableDescriptorsRequest req = @@ -371,7 +371,7 @@ public class HBaseAdmin implements Admin { return ProtobufUtil.getHTableDescriptorArray(master.getTableDescriptors(getRpcController(), req)); } - }); + })); } @Override @@ -440,7 +440,7 @@ public class HBaseAdmin implements Admin { } }, rpcCallerFactory, operationTimeout, rpcTimeout); if (htd != null) { - return htd; + return new ImmutableHTableDescriptor(htd); } throw new TableNotFoundException(tableName.getNameAsString()); } @@ -531,7 +531,7 @@ public class HBaseAdmin implements Admin { super(admin, desc.getTableName(), (response != null && response.hasProcId()) ? response.getProcId() : null); this.splitKeys = splitKeys; - this.desc = desc; + this.desc = new ImmutableHTableDescriptor(desc); } @Override @@ -2143,8 +2143,7 @@ public class HBaseAdmin implements Admin { .build()).getTableSchemaList(); HTableDescriptor[] res = new HTableDescriptor[list.size()]; for(int i=0; i < list.size(); i++) { - - res[i] = ProtobufUtil.convertToHTableDesc(list.get(i)); + res[i] = new ImmutableHTableDescriptor(ProtobufUtil.convertToHTableDesc(list.get(i))); } return res; } @@ -2257,8 +2256,8 @@ public class HBaseAdmin implements Admin { @Override public HTableDescriptor[] getTableDescriptorsByTableName(final List tableNames) throws IOException { - return executeCallable(new MasterCallable(getConnection(), - getRpcControllerFactory()) { + return ImmutableHTableDescriptor.toReadOnly(executeCallable( + new MasterCallable(getConnection(), getRpcControllerFactory()) { @Override protected HTableDescriptor[] rpcCall() throws Exception { GetTableDescriptorsRequest req = @@ -2266,7 +2265,7 @@ public class HBaseAdmin implements Admin { return ProtobufUtil. getHTableDescriptorArray(master.getTableDescriptors(getRpcController(), req)); } - }); + })); } /** diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java index 3bdbed5..e89d4ed 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTable.java @@ -266,7 +266,7 @@ public class HTable implements Table { HTableDescriptor htd = HBaseAdmin.getTableDescriptor(tableName, connection, rpcCallerFactory, rpcControllerFactory, operationTimeout, readRpcTimeout); if (htd != null) { - return new UnmodifyableHTableDescriptor(htd); + return new ImmutableHTableDescriptor(htd); } return null; } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ImmutableHTableDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ImmutableHTableDescriptor.java new file mode 100644 index 0000000..3986bfa --- /dev/null +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/ImmutableHTableDescriptor.java @@ -0,0 +1,89 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.client; + +import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.classification.InterfaceAudience; +import org.apache.hadoop.hbase.classification.InterfaceStability; +import org.apache.hadoop.hbase.util.Bytes; + +/** + * Read-only table descriptor. + */ +@InterfaceAudience.Public +@InterfaceStability.Evolving +public class ImmutableHTableDescriptor extends HTableDescriptor { + + /** + * Make all HTD read-only. All elements will be replaced by immutable HTD. + * @param htds table description + * @return The return array is same as input. + */ + static HTableDescriptor[] toReadOnly(HTableDescriptor[] htds) { + if (htds == null) { + return null; + } + for (int i = 0; i < htds.length; ++i) { + if (!(htds[i] instanceof ImmutableHTableDescriptor)) { + htds[i] = new ImmutableHTableDescriptor(htds[i]); + } + } + return htds; + } + + /* + * Create an unmodifyable copy of an HTableDescriptor + * @param desc + */ + ImmutableHTableDescriptor(final HTableDescriptor desc) { + super(desc); + } + + @Override + protected ImmutableHTableDescriptor setFamily(HColumnDescriptor family) { + throw new UnsupportedOperationException("HTableDescriptor is read-only"); + } + + @Override + public HColumnDescriptor removeFamily(final byte [] column) { + throw new UnsupportedOperationException("HTableDescriptor is read-only"); + } + + @Override + public ImmutableHTableDescriptor setValue(final Bytes key, final Bytes value) { + throw new UnsupportedOperationException("HTableDescriptor is read-only"); + } + + @Override + public void remove(Bytes key) { + throw new UnsupportedOperationException("HTableDescriptor is read-only"); + } + + @Override + public ImmutableHTableDescriptor setConfiguration(String key, String value) { + throw new UnsupportedOperationException("HTableDescriptor is read-only"); + } + + @Override + public void removeConfiguration(final String key) { + throw new UnsupportedOperationException("HTableDescriptor is read-only"); + } +} diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/UnmodifyableHTableDescriptor.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/UnmodifyableHTableDescriptor.java deleted file mode 100644 index 59a1bd5..0000000 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/UnmodifyableHTableDescriptor.java +++ /dev/null @@ -1,129 +0,0 @@ -/** - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hbase.client; - -import org.apache.hadoop.hbase.HColumnDescriptor; -import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.classification.InterfaceAudience; -import org.apache.hadoop.hbase.classification.InterfaceStability; - -/** - * Read-only table descriptor. - */ -@InterfaceAudience.Public -@InterfaceStability.Evolving -public class UnmodifyableHTableDescriptor extends HTableDescriptor { - /** - * Default constructor. - * @deprecated As of release 2.0.0. This will be removed in HBase 3.0.0. - * Use {@link #UnmodifyableHTableDescriptor(HTableDescriptor)}. - */ - @Deprecated - public UnmodifyableHTableDescriptor() { - super(); - } - - /* - * Create an unmodifyable copy of an HTableDescriptor - * @param desc - */ - UnmodifyableHTableDescriptor(final HTableDescriptor desc) { - super(desc.getTableName(), getUnmodifyableFamilies(desc), desc.getValues()); - } - - - /* - * @param desc - * @return Families as unmodifiable array. - */ - private static HColumnDescriptor[] getUnmodifyableFamilies( - final HTableDescriptor desc) { - HColumnDescriptor [] f = new HColumnDescriptor[desc.getFamilies().size()]; - int i = 0; - for (HColumnDescriptor c: desc.getFamilies()) { - f[i++] = c; - } - return f; - } - - /** - * Does NOT add a column family. This object is immutable - * @param family HColumnDescriptor of familyto add. - */ - @Override - public UnmodifyableHTableDescriptor addFamily(final HColumnDescriptor family) { - throw new UnsupportedOperationException("HTableDescriptor is read-only"); - } - - @Override - public UnmodifyableHTableDescriptor modifyFamily(HColumnDescriptor family) { - throw new UnsupportedOperationException("HTableDescriptor is read-only"); - } - - /** - * @param column - * @return Column descriptor for the passed family name or the family on - * passed in column. - */ - @Override - public HColumnDescriptor removeFamily(final byte [] column) { - throw new UnsupportedOperationException("HTableDescriptor is read-only"); - } - - /** - * @see org.apache.hadoop.hbase.HTableDescriptor#setReadOnly(boolean) - */ - @Override - public UnmodifyableHTableDescriptor setReadOnly(boolean readOnly) { - throw new UnsupportedOperationException("HTableDescriptor is read-only"); - } - - /** - * @see org.apache.hadoop.hbase.HTableDescriptor#setValue(byte[], byte[]) - */ - @Override - public UnmodifyableHTableDescriptor setValue(byte[] key, byte[] value) { - throw new UnsupportedOperationException("HTableDescriptor is read-only"); - } - - /** - * @see org.apache.hadoop.hbase.HTableDescriptor#setValue(java.lang.String, java.lang.String) - */ - @Override - public UnmodifyableHTableDescriptor setValue(String key, String value) { - throw new UnsupportedOperationException("HTableDescriptor is read-only"); - } - - /** - * @see org.apache.hadoop.hbase.HTableDescriptor#setMaxFileSize(long) - */ - @Override - public UnmodifyableHTableDescriptor setMaxFileSize(long maxFileSize) { - throw new UnsupportedOperationException("HTableDescriptor is read-only"); - } - - /** - * @see org.apache.hadoop.hbase.HTableDescriptor#setMemStoreFlushSize(long) - */ - @Override - public UnmodifyableHTableDescriptor setMemStoreFlushSize(long memstoreFlushSize) { - throw new UnsupportedOperationException("HTableDescriptor is read-only"); - } -} diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java index f44979c..81c21bc 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/ProtobufUtil.java @@ -74,6 +74,7 @@ import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.SnapshotDescription; import org.apache.hadoop.hbase.client.SnapshotType; +import org.apache.hadoop.hbase.client.ImmutableHTableDescriptor; import org.apache.hadoop.hbase.client.metrics.ScanMetrics; import org.apache.hadoop.hbase.client.security.SecurityCapability; import org.apache.hadoop.hbase.exceptions.DeserializationException; diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestImmutableHTableDescriptor.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestImmutableHTableDescriptor.java new file mode 100644 index 0000000..bc29ef2 --- /dev/null +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestImmutableHTableDescriptor.java @@ -0,0 +1,116 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.client; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; +import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.apache.hadoop.hbase.util.BuilderStyleTest; +import org.apache.hadoop.hbase.util.Bytes; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TestName; + +@Category({ClientTests.class, SmallTests.class}) +public class TestImmutableHTableDescriptor { + @Rule + public TestName name = new TestName(); + private static final List> TEST_FUNCTION = Arrays.asList( + htd -> htd.setValue("a", "a"), + htd -> htd.setValue(Bytes.toBytes("a"), Bytes.toBytes("a")), + htd -> htd.setValue(new Bytes(Bytes.toBytes("a")), new Bytes(Bytes.toBytes("a"))), + htd -> htd.setCompactionEnabled(false), + htd -> htd.setConfiguration("aaa", "ccc"), + htd -> htd.setDurability(Durability.USE_DEFAULT), + htd -> htd.setFlushPolicyClassName("class"), + htd -> htd.setMaxFileSize(123), + htd -> htd.setMemStoreFlushSize(123123123), + htd -> htd.setNormalizationEnabled(false), + htd -> htd.setPriority(123), + htd -> htd.setReadOnly(true), + htd -> htd.setRegionMemstoreReplication(true), + htd -> htd.setRegionReplication(123), + htd -> htd.setRegionSplitPolicyClassName("class"), + htd -> htd.addFamily(new HColumnDescriptor(Bytes.toBytes("fm"))), + htd -> htd.remove(new Bytes(Bytes.toBytes("aaa"))), + htd -> htd.remove("aaa"), + htd -> htd.remove(Bytes.toBytes("aaa")), + htd -> htd.removeConfiguration("xxx"), + htd -> htd.removeFamily(Bytes.toBytes("fm")), + htd -> { + try { + htd.addCoprocessor("xxx"); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + ); + + @Test + public void testConvertToReadOnly() { + HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName())); + HTableDescriptor[] htds = new HTableDescriptor[10]; + for (int i = 0; i < htds.length; ++i) { + htds[i] = htd; + } + for (HTableDescriptor h : ImmutableHTableDescriptor.toReadOnly(htds)) { + assertTrue(h instanceof ImmutableHTableDescriptor); + assertTrue(h.equals(htd)); + } + } + + @Test + public void testImmutable() { + ImmutableHTableDescriptor htd = new ImmutableHTableDescriptor( + new HTableDescriptor(TableName.valueOf(name.getMethodName()))); + TEST_FUNCTION.forEach(f -> { + try { + f.accept(htd); + fail("UnmodifyableHTableDescriptor can't be modified!!!"); + } catch (UnsupportedOperationException e) { + } + }); + } + + @Test + public void testClassMethodsAreBuilderStyle() { + /* UnmodifyableHTableDescriptor should have a builder style setup where setXXX/addXXX methods + * can be chainable together: + * . For example: + * UnmodifyableHTableDescriptor d + * = new UnmodifyableHTableDescriptor() + * .setFoo(foo) + * .setBar(bar) + * .setBuz(buz) + * + * This test ensures that all methods starting with "set" returns the declaring object + */ + + BuilderStyleTest.assertClassesAreBuilderStyle(ImmutableHTableDescriptor.class); + } +} \ No newline at end of file diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestUnmodifyableHTableDescriptor.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestUnmodifyableHTableDescriptor.java deleted file mode 100644 index dca0c1f..0000000 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestUnmodifyableHTableDescriptor.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hadoop.hbase.client; - -import org.apache.hadoop.hbase.testclassification.ClientTests; -import org.apache.hadoop.hbase.testclassification.SmallTests; -import org.apache.hadoop.hbase.util.BuilderStyleTest; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -@Category({ClientTests.class, SmallTests.class}) -public class TestUnmodifyableHTableDescriptor { - - @Test - public void testClassMethodsAreBuilderStyle() { - /* UnmodifyableHTableDescriptor should have a builder style setup where setXXX/addXXX methods - * can be chainable together: - * . For example: - * UnmodifyableHTableDescriptor d - * = new UnmodifyableHTableDescriptor() - * .setFoo(foo) - * .setBar(bar) - * .setBuz(buz) - * - * This test ensures that all methods starting with "set" returns the declaring object - */ - - BuilderStyleTest.assertClassesAreBuilderStyle(UnmodifyableHTableDescriptor.class); - } - -} \ No newline at end of file diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/RowResourceBase.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/RowResourceBase.java index b4b00a9..406b4e5 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/RowResourceBase.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/RowResourceBase.java @@ -111,7 +111,7 @@ public class RowResourceBase { if (admin.tableExists(TABLE_NAME)) { TEST_UTIL.deleteTable(TABLE_NAME); } - HTableDescriptor htd = new HTableDescriptor(TABLE); + HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(TABLE)); htd.addFamily(new HColumnDescriptor(CFA)); htd.addFamily(new HColumnDescriptor(CFB)); admin.createTable(htd); diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteAdminRetries.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteAdminRetries.java index 7c888e0..b926d82 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteAdminRetries.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/client/TestRemoteAdminRetries.java @@ -32,6 +32,7 @@ import java.util.regex.Pattern; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.testclassification.RestTests; import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.util.Bytes; @@ -116,7 +117,7 @@ public class TestRemoteAdminRetries { testTimedOutCall(new CallExecutor() { @Override public void run() throws Exception { - remoteAdmin.createTable(new HTableDescriptor(Bytes.toBytes("TestTable"))); + remoteAdmin.createTable(new HTableDescriptor(TableName.valueOf("TestTable"))); } }); verify(client, times(RETRIES)).put(anyString(), anyString(), any(byte[].class)); diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java index ab5c09f..e1fd82c 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManager.java @@ -39,7 +39,6 @@ public interface RSGroupInfoManager { //Assigned before user tables TableName RSGROUP_TABLE_NAME = TableName.valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, "rsgroup"); - byte[] RSGROUP_TABLE_NAME_BYTES = RSGROUP_TABLE_NAME.toBytes(); String rsGroupZNode = "rsgroup"; byte[] META_FAMILY_BYTES = Bytes.toBytes("m"); byte[] META_QUALIFIER_BYTES = Bytes.toBytes("i"); diff --git a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java index 9f77c77..f2c6118 100644 --- a/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java +++ b/hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupInfoManagerImpl.java @@ -117,7 +117,7 @@ class RSGroupInfoManagerImpl implements RSGroupInfoManager { /** Table descriptor for hbase:rsgroup catalog table */ private final static HTableDescriptor RSGROUP_TABLE_DESC; static { - RSGROUP_TABLE_DESC = new HTableDescriptor(RSGROUP_TABLE_NAME_BYTES); + RSGROUP_TABLE_DESC = new HTableDescriptor(RSGROUP_TABLE_NAME); RSGROUP_TABLE_DESC.addFamily(new HColumnDescriptor(META_FAMILY_BYTES)); RSGROUP_TABLE_DESC.setRegionSplitPolicyClassName(DisabledRegionSplitPolicy.class.getName()); try { diff --git a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java index 3886684..d28bdb8 100644 --- a/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java +++ b/hbase-rsgroup/src/test/java/org/apache/hadoop/hbase/rsgroup/TestRSGroups.java @@ -187,7 +187,7 @@ public class TestRSGroups extends TestRSGroupsBase { final byte[] tableName = Bytes.toBytes(tablePrefix + "_testCreateAndAssign"); admin.modifyNamespace(NamespaceDescriptor.create("default") .addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, "default").build()); - final HTableDescriptor desc = new HTableDescriptor(tableName); + final HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); desc.addFamily(new HColumnDescriptor("f")); admin.createTable(desc); //wait for created table to be assigned diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/util/RestoreTool.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/util/RestoreTool.java index 79adcab..c1ce7a3 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/util/RestoreTool.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/util/RestoreTool.java @@ -187,7 +187,7 @@ public class RestoreTool { LOG.debug("Found descriptor " + tableDescriptor + " through " + incrBackupId); TableName newTableName = newTableNames[i]; - HTableDescriptor newTableDescriptor = admin.getTableDescriptor(newTableName); + HTableDescriptor newTableDescriptor = new HTableDescriptor(admin.getTableDescriptor(newTableName)); List families = Arrays.asList(tableDescriptor.getColumnFamilies()); List existingFamilies = Arrays.asList(newTableDescriptor.getColumnFamilies()); @@ -378,7 +378,7 @@ public class RestoreTool { LOG.debug("find table descriptor but no archive dir for table " + tableName + ", will only create table"); } - tableDescriptor.setName(newTableName); + tableDescriptor = new HTableDescriptor(newTableName, tableDescriptor); checkAndCreateTable(conn, tableBackupPath, tableName, newTableName, null, tableDescriptor, truncateIfExists); return; @@ -391,7 +391,7 @@ public class RestoreTool { if (tableDescriptor == null) { tableDescriptor = new HTableDescriptor(newTableName); } else { - tableDescriptor.setName(newTableName); + tableDescriptor = new HTableDescriptor(newTableName, tableDescriptor); } // record all region dirs: diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java index 696ea18..26a269c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java @@ -1728,7 +1728,7 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility { public static void setReplicas(Admin admin, TableName table, int replicaCount) throws IOException, InterruptedException { admin.disableTable(table); - HTableDescriptor desc = admin.getTableDescriptor(table); + HTableDescriptor desc = new HTableDescriptor(admin.getTableDescriptor(table)); desc.setRegionReplication(replicaCount); admin.modifyTable(desc.getTableName(), desc); admin.enableTable(table); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestFSTableDescriptorForceCreation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestFSTableDescriptorForceCreation.java index 7744631..7457f43 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestFSTableDescriptorForceCreation.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestFSTableDescriptorForceCreation.java @@ -59,7 +59,7 @@ public class TestFSTableDescriptorForceCreation { // Cleanup old tests if any detritus laying around. Path rootdir = new Path(UTIL.getDataTestDir(), name); FSTableDescriptors fstd = new FSTableDescriptors(UTIL.getConfiguration(), fs, rootdir); - HTableDescriptor htd = new HTableDescriptor(name); + HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name)); fstd.add(htd); assertFalse("Should not create new table descriptor", fstd.createTableDescriptor(htd, false)); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableBatch.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableBatch.java index 30b3b5b..61ff2be 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableBatch.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAsyncTableBatch.java @@ -216,7 +216,7 @@ public class TestAsyncTableBatch { @Test public void testPartialSuccess() throws IOException, InterruptedException, ExecutionException { Admin admin = TEST_UTIL.getAdmin(); - HTableDescriptor htd = admin.getTableDescriptor(TABLE_NAME); + HTableDescriptor htd = new HTableDescriptor(admin.getTableDescriptor(TABLE_NAME)); htd.addCoprocessor(ErrorInjectObserver.class.getName()); admin.modifyTable(TABLE_NAME, htd); AsyncTableBase table = tableGetter.apply(TABLE_NAME); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdminWithClusters.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdminWithClusters.java index 56f4141..f46354c 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdminWithClusters.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdminWithClusters.java @@ -77,7 +77,7 @@ public class TestReplicationAdminWithClusters extends TestReplicationBase { @Test(timeout = 300000) public void disableNotFullReplication() throws Exception { - HTableDescriptor table = admin2.getTableDescriptor(tableName); + HTableDescriptor table = new HTableDescriptor(admin2.getTableDescriptor(tableName)); HColumnDescriptor f = new HColumnDescriptor("notReplicatedFamily"); table.addFamily(f); admin1.disableTable(tableName); @@ -125,7 +125,7 @@ public class TestReplicationAdminWithClusters extends TestReplicationBase { @Test(timeout = 300000) public void testEnableReplicationWhenTableDescriptorIsNotSameInClusters() throws Exception { - HTableDescriptor table = admin2.getTableDescriptor(tableName); + HTableDescriptor table = new HTableDescriptor(admin2.getTableDescriptor(tableName)); HColumnDescriptor f = new HColumnDescriptor("newFamily"); table.addFamily(f); admin2.disableTable(tableName); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java index 19df42a..70a78de 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/normalizer/TestSimpleRegionNormalizerOnCluster.java @@ -140,7 +140,7 @@ public class TestSimpleRegionNormalizerOnCluster { region.flush(true); } - HTableDescriptor htd = admin.getTableDescriptor(TABLENAME); + HTableDescriptor htd = new HTableDescriptor(admin.getTableDescriptor(TABLENAME)); htd.setNormalizationEnabled(true); admin.modifyTable(TABLENAME, htd); @@ -217,7 +217,7 @@ public class TestSimpleRegionNormalizerOnCluster { region.flush(true); } - HTableDescriptor htd = admin.getTableDescriptor(tableName); + HTableDescriptor htd = new HTableDescriptor(admin.getTableDescriptor(tableName)); htd.setNormalizationEnabled(true); admin.modifyTable(tableName, htd); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java index b34c307..3db0c2d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionKeyRotation.java @@ -195,7 +195,7 @@ public class TestEncryptionKeyRotation { // Start the cluster back up TEST_UTIL.startMiniHBaseCluster(1, 1); // Verify the table can still be loaded - TEST_UTIL.waitTableAvailable(htd.getName(), 5000); + TEST_UTIL.waitTableAvailable(htd.getTableName(), 5000); // Double check that the store file keys can be unwrapped storeFilePaths = findStorefilePaths(htd.getTableName()); assertTrue(storeFilePaths.size() > 0); @@ -266,7 +266,7 @@ public class TestEncryptionKeyRotation { HColumnDescriptor hcd = htd.getFamilies().iterator().next(); // Create the test table TEST_UTIL.getAdmin().createTable(htd); - TEST_UTIL.waitTableAvailable(htd.getName(), 5000); + TEST_UTIL.waitTableAvailable(htd.getTableName(), 5000); // Create a store file Table table = TEST_UTIL.getConnection().getTable(htd.getTableName()); try { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionRandomKeying.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionRandomKeying.java index 2b0ab7b..51484ae 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionRandomKeying.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestEncryptionRandomKeying.java @@ -101,7 +101,7 @@ public class TestEncryptionRandomKeying { // Create the test table TEST_UTIL.getAdmin().createTable(htd); - TEST_UTIL.waitTableAvailable(htd.getName(), 5000); + TEST_UTIL.waitTableAvailable(htd.getTableName(), 5000); // Create a store file Table table = TEST_UTIL.getConnection().getTable(htd.getTableName()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java index eac3c77..8e48013 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java @@ -5732,7 +5732,7 @@ public class TestHRegion { LOG.info("RegionEventDescriptor from WAL: " + desc); assertEquals(RegionEventDescriptor.EventType.REGION_OPEN, desc.getEventType()); - assertTrue(Bytes.equals(desc.getTableName().toByteArray(), htd.getName())); + assertTrue(Bytes.equals(desc.getTableName().toByteArray(), htd.getTableName().toBytes())); assertTrue(Bytes.equals(desc.getEncodedRegionName().toByteArray(), hri.getEncodedNameAsBytes())); assertTrue(desc.getLogSequenceNumber() > 0); @@ -5852,7 +5852,7 @@ public class TestHRegion { LOG.info("RegionEventDescriptor from WAL: " + desc); assertEquals(RegionEventDescriptor.EventType.REGION_OPEN, desc.getEventType()); - assertTrue(Bytes.equals(desc.getTableName().toByteArray(), htd.getName())); + assertTrue(Bytes.equals(desc.getTableName().toByteArray(), htd.getTableName().toBytes())); assertTrue(Bytes.equals(desc.getEncodedRegionName().toByteArray(), hri.getEncodedNameAsBytes())); assertTrue(desc.getLogSequenceNumber() > 0); @@ -5938,7 +5938,7 @@ public class TestHRegion { LOG.info("RegionEventDescriptor from WAL: " + desc); assertEquals(RegionEventDescriptor.EventType.REGION_CLOSE, desc.getEventType()); - assertTrue(Bytes.equals(desc.getTableName().toByteArray(), htd.getName())); + assertTrue(Bytes.equals(desc.getTableName().toByteArray(), htd.getTableName().toBytes())); assertTrue(Bytes.equals(desc.getEncodedRegionName().toByteArray(), hri.getEncodedNameAsBytes())); assertTrue(desc.getLogSequenceNumber() > 0); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCoprocessorWhitelistMasterObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCoprocessorWhitelistMasterObserver.java index aeb909e..bc74f4f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCoprocessorWhitelistMasterObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCoprocessorWhitelistMasterObserver.java @@ -107,7 +107,7 @@ public class TestCoprocessorWhitelistMasterObserver extends SecureTestUtil { UTIL.waitUntilAllRegionsAssigned(TEST_TABLE); Connection connection = ConnectionFactory.createConnection(conf); Table t = connection.getTable(TEST_TABLE); - HTableDescriptor htd = t.getTableDescriptor(); + HTableDescriptor htd = new HTableDescriptor(t.getTableDescriptor()); htd.addCoprocessor("net.clayb.hbase.coprocessor.NotWhitelisted", new Path(coprocessorPath), Coprocessor.PRIORITY_USER, null); @@ -153,7 +153,7 @@ public class TestCoprocessorWhitelistMasterObserver extends SecureTestUtil { // coprocessor file admin.disableTable(TEST_TABLE); Table t = connection.getTable(TEST_TABLE); - HTableDescriptor htd = t.getTableDescriptor(); + HTableDescriptor htd = new HTableDescriptor(t.getTableDescriptor()); htd.addCoprocessor("net.clayb.hbase.coprocessor.Whitelisted", new Path(coprocessorPath), Coprocessor.PRIORITY_USER, null); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/MobSnapshotTestingUtils.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/MobSnapshotTestingUtils.java index d301214..3e1abb9 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/MobSnapshotTestingUtils.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/MobSnapshotTestingUtils.java @@ -147,7 +147,7 @@ public class MobSnapshotTestingUtils { @Override public HTableDescriptor createHtd(final String tableName) { - HTableDescriptor htd = new HTableDescriptor(tableName); + HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName)); HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY); hcd.setMobEnabled(true); hcd.setMobThreshold(0L); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java index ccad85b..3c10dee 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java @@ -680,7 +680,7 @@ public final class SnapshotTestingUtils { } public HTableDescriptor createHtd(final String tableName) { - HTableDescriptor htd = new HTableDescriptor(tableName); + HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName)); htd.addFamily(new HColumnDescriptor(TEST_FAMILY)); return htd; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java index ee048b7..8337eb0 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestFSTableDescriptors.java @@ -261,7 +261,7 @@ public class TestFSTableDescriptors { final int count = 10; // Write out table infos. for (int i = 0; i < count; i++) { - HTableDescriptor htd = new HTableDescriptor(name + i); + HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name + i)); htds.createTableDescriptor(htd); } @@ -294,7 +294,7 @@ public class TestFSTableDescriptors { final int count = 4; // Write out table infos. for (int i = 0; i < count; i++) { - HTableDescriptor htd = new HTableDescriptor(name + i); + HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name + i)); htds.createTableDescriptor(htd); } // add hbase:meta @@ -321,7 +321,7 @@ public class TestFSTableDescriptors { final int count = 10; // Write out table infos via non-cached FSTableDescriptors for (int i = 0; i < count; i++) { - HTableDescriptor htd = new HTableDescriptor(name + i); + HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name + i)); nonchtds.createTableDescriptor(htd); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckEncryption.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckEncryption.java index 54f310d..9391594 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckEncryption.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckEncryption.java @@ -92,7 +92,7 @@ public class TestHBaseFsckEncryption { cfKey)); htd.addFamily(hcd); TEST_UTIL.getAdmin().createTable(htd); - TEST_UTIL.waitTableAvailable(htd.getName(), 5000); + TEST_UTIL.waitTableAvailable(htd.getTableName(), 5000); } @After diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckOneRS.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckOneRS.java index 1d09dfa..74ef414 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckOneRS.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckOneRS.java @@ -248,7 +248,7 @@ public class TestHBaseFsckOneRS extends BaseTestHBaseFsck { status = FSTableDescriptors.getTableInfoPath(fs, hbaseTableDir); assertNotNull(status); - HTableDescriptor htd = admin.getTableDescriptor(tableName); + HTableDescriptor htd = new HTableDescriptor(admin.getTableDescriptor(tableName)); htd.setValue("NOT_DEFAULT", "true"); admin.disableTable(tableName); admin.modifyTable(tableName, htd); diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb index 6aaa130..98f78d4 100644 --- a/hbase-shell/src/main/ruby/hbase/admin.rb +++ b/hbase-shell/src/main/ruby/hbase/admin.rb @@ -589,7 +589,7 @@ module Hbase table_name = TableName.valueOf(table_name_str) # Get table descriptor - htd = @admin.getTableDescriptor(table_name) + htd = org.apache.hadoop.hbase.HTableDescriptor.new(@admin.getTableDescriptor(table_name)) hasTableUpdate = false # Process all args @@ -1201,15 +1201,6 @@ module Hbase htd.setNormalizationEnabled( JBoolean.valueOf(arg.delete(NORMALIZATION_ENABLED))) if arg[NORMALIZATION_ENABLED] htd.setMemStoreFlushSize(JLong.valueOf(arg.delete(MEMSTORE_FLUSHSIZE))) if arg[MEMSTORE_FLUSHSIZE] - # DEFERRED_LOG_FLUSH is deprecated and was replaced by DURABILITY. To keep backward compatible, it still exists. - # However, it has to be set before DURABILITY so that DURABILITY could overwrite if both args are set - if arg.include?(DEFERRED_LOG_FLUSH) - if arg.delete(DEFERRED_LOG_FLUSH).to_s.upcase == "TRUE" - htd.setDurability(org.apache.hadoop.hbase.client.Durability.valueOf("ASYNC_WAL")) - else - htd.setDurability(org.apache.hadoop.hbase.client.Durability.valueOf("SYNC_WAL")) - end - end htd.setDurability(org.apache.hadoop.hbase.client.Durability.valueOf(arg.delete(DURABILITY))) if arg[DURABILITY] htd.setPriority(JInteger.valueOf(arg.delete(org.apache.hadoop.hbase.HTableDescriptor::PRIORITY))) if arg[org.apache.hadoop.hbase.HTableDescriptor::PRIORITY] htd.setFlushPolicyClassName(arg.delete(org.apache.hadoop.hbase.HTableDescriptor::FLUSH_POLICY)) if arg[org.apache.hadoop.hbase.HTableDescriptor::FLUSH_POLICY] diff --git a/hbase-shell/src/main/ruby/shell/commands/alter_async.rb b/hbase-shell/src/main/ruby/shell/commands/alter_async.rb index e0f6deb..05335fb 100644 --- a/hbase-shell/src/main/ruby/shell/commands/alter_async.rb +++ b/hbase-shell/src/main/ruby/shell/commands/alter_async.rb @@ -40,8 +40,8 @@ or a shorter version: hbase> alter_async 'ns1:t1', 'delete' => 'f1' -You can also change table-scope attributes like MAX_FILESIZE -MEMSTORE_FLUSHSIZE, READONLY, and DEFERRED_LOG_FLUSH. +You can also change table-scope attributes like MAX_FILESIZE, +MEMSTORE_FLUSHSIZE, and READONLY. For example, to change the max size of a family to 128MB, do: -- 2.10.1 (Apple Git-78)