Skip to content

Commit 989bfea

Browse files
authored
HBASE-28216 HDFS erasure coding support for table data dirs (#5591)
Signed-off-by: Nihal Jain <nihaljain@apache.org> Signed-off-by: Wei-Chiu Chuang <weichiu@apache.org> Signed-off-by: Duo Zhang <zhangduo@apache.org>
1 parent c28e285 commit 989bfea

19 files changed

Lines changed: 892 additions & 58 deletions

File tree

hbase-client/src/main/java/org/apache/hadoop/hbase/HTableDescriptor.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public class HTableDescriptor implements TableDescriptor, Comparable<HTableDescr
8686
TableDescriptorBuilder.DEFAULT_REGION_REPLICATION;
8787
public static final boolean DEFAULT_REGION_MEMSTORE_REPLICATION =
8888
TableDescriptorBuilder.DEFAULT_REGION_MEMSTORE_REPLICATION;
89+
90+
public static final String ERASURE_CODING_POLICY = TableDescriptorBuilder.ERASURE_CODING_POLICY;
8991
protected final ModifyableTableDescriptor delegatee;
9092

9193
/**
@@ -260,6 +262,28 @@ public HTableDescriptor setCompactionEnabled(final boolean isEnable) {
260262
return this;
261263
}
262264

265+
/**
266+
* Sets the HDFS erasure coding policy for the table. This will be propagated to HDFS for the data
267+
* dir of the table. Erasure coding is an alternative to normal replication which takes less space
268+
* at the cost of locality. The policy must be available and enabled on the hdfs cluster before
269+
* being set.
270+
* @param policy the policy to set, or null to disable erasure coding
271+
*/
272+
public HTableDescriptor setErasureCodingPolicy(final String policy) {
273+
getDelegateeForModification().setErasureCodingPolicy(policy);
274+
return this;
275+
}
276+
277+
/**
278+
* The HDFS erasure coding policy for a table. This will be set on the data dir of the table, and
279+
* is an alternative to normal replication which takes less space at the cost of locality.
280+
* @return the current policy, or null if undefined
281+
*/
282+
@Override
283+
public String getErasureCodingPolicy() {
284+
return delegatee.getErasureCodingPolicy();
285+
}
286+
263287
/**
264288
* Check if the region split enable flag of the table is true. If flag is false then no split will
265289
* be done.

hbase-client/src/main/java/org/apache/hadoop/hbase/client/TableDescriptor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,15 @@ default Collection<String> getCoprocessors() {
280280
*/
281281
boolean isReadOnly();
282282

283+
/**
284+
* The HDFS erasure coding policy for a table. This will be set on the data dir of the table, and
285+
* is an alternative to normal replication which takes less space at the cost of locality.
286+
* @return the current policy, or null if undefined
287+
*/
288+
default String getErasureCodingPolicy() {
289+
return null;
290+
}
291+
283292
/**
284293
* Returns Name of this table and then a map of all of the column family descriptors (with only
285294
* the non-default column family attributes)

hbase-client/src/main/java/org/apache/hadoop/hbase/client/TableDescriptorBuilder.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,14 @@ public class TableDescriptorBuilder {
148148
private static final Bytes REGION_MEMSTORE_REPLICATION_KEY =
149149
new Bytes(Bytes.toBytes(REGION_MEMSTORE_REPLICATION));
150150

151+
/**
152+
* If non-null, the HDFS erasure coding policy to set on the data dir of the table
153+
*/
154+
public static final String ERASURE_CODING_POLICY = "ERASURE_CODING_POLICY";
155+
private static final Bytes ERASURE_CODING_POLICY_KEY =
156+
new Bytes(Bytes.toBytes(ERASURE_CODING_POLICY));
157+
158+
private static final String DEFAULT_ERASURE_CODING_POLICY = null;
151159
/**
152160
* Used by shell/rest interface to access this metadata attribute which denotes if the table
153161
* should be treated by region normalizer.
@@ -234,6 +242,7 @@ public class TableDescriptorBuilder {
234242
DEFAULT_VALUES.put(DURABILITY, DEFAULT_DURABLITY.name()); // use the enum name
235243
DEFAULT_VALUES.put(REGION_REPLICATION, String.valueOf(DEFAULT_REGION_REPLICATION));
236244
DEFAULT_VALUES.put(PRIORITY, String.valueOf(DEFAULT_PRIORITY));
245+
DEFAULT_VALUES.put(ERASURE_CODING_POLICY, String.valueOf(DEFAULT_ERASURE_CODING_POLICY));
237246
DEFAULT_VALUES.keySet().stream().map(s -> new Bytes(Bytes.toBytes(s)))
238247
.forEach(RESERVED_KEYWORDS::add);
239248
RESERVED_KEYWORDS.add(IS_META_KEY);
@@ -532,6 +541,11 @@ public TableDescriptorBuilder setReadOnly(final boolean readOnly) {
532541
return this;
533542
}
534543

544+
public TableDescriptorBuilder setErasureCodingPolicy(String policy) {
545+
desc.setErasureCodingPolicy(policy);
546+
return this;
547+
}
548+
535549
public TableDescriptorBuilder setRegionMemStoreReplication(boolean memstoreReplication) {
536550
desc.setRegionMemStoreReplication(memstoreReplication);
537551
return this;
@@ -802,6 +816,28 @@ public ModifyableTableDescriptor setReadOnly(final boolean readOnly) {
802816
return setValue(READONLY_KEY, Boolean.toString(readOnly));
803817
}
804818

819+
/**
820+
* The HDFS erasure coding policy for a table. This will be set on the data dir of the table,
821+
* and is an alternative to normal replication which takes less space at the cost of locality.
822+
* @return the current policy, or null if undefined
823+
*/
824+
@Override
825+
public String getErasureCodingPolicy() {
826+
return getValue(ERASURE_CODING_POLICY);
827+
}
828+
829+
/**
830+
* Sets the HDFS erasure coding policy for the table. This will be propagated to HDFS for the
831+
* data dir of the table. Erasure coding is an alternative to normal replication which takes
832+
* less space at the cost of locality. The policy must be available and enabled on the hdfs
833+
* cluster before being set.
834+
* @param policy the policy to set, or null to disable erasure coding
835+
* @return the modifyable TD
836+
*/
837+
public ModifyableTableDescriptor setErasureCodingPolicy(String policy) {
838+
return setValue(ERASURE_CODING_POLICY_KEY, policy);
839+
}
840+
805841
/**
806842
* Check if the compaction enable flag of the table is true. If flag is false then no
807843
* minor/major compactions will be done in real.

hbase-client/src/test/java/org/apache/hadoop/hbase/client/TestTableDescriptorBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,10 @@ public void testStringCustomizedValues() throws HBaseException {
365365
htd.toStringCustomizedValues());
366366

367367
htd = TableDescriptorBuilder.newBuilder(htd).setMaxFileSize("10737942528")
368-
.setMemStoreFlushSize("256MB").build();
368+
.setMemStoreFlushSize("256MB").setErasureCodingPolicy("RS-6-3-1024k").build();
369369
assertEquals(
370370
"'testStringCustomizedValues', " + "{TABLE_ATTRIBUTES => {DURABILITY => 'ASYNC_WAL', "
371-
+ "MAX_FILESIZE => '10737942528 B (10GB 512KB)', "
371+
+ "ERASURE_CODING_POLICY => 'RS-6-3-1024k', MAX_FILESIZE => '10737942528 B (10GB 512KB)', "
372372
+ "MEMSTORE_FLUSHSIZE => '268435456 B (256MB)'}}, "
373373
+ "{NAME => 'cf', BLOCKSIZE => '131072 B (128KB)'}",
374374
htd.toStringCustomizedValues());

hbase-protocol-shaded/src/main/protobuf/MasterProcedure.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ enum CreateTableState {
5656
CREATE_TABLE_ASSIGN_REGIONS = 4;
5757
CREATE_TABLE_UPDATE_DESC_CACHE = 5;
5858
CREATE_TABLE_POST_OPERATION = 6;
59+
CREATE_TABLE_SET_ERASURE_CODING_POLICY = 7;
5960
}
6061

6162
message CreateTableStateData {
@@ -74,6 +75,7 @@ enum ModifyTableState {
7475
MODIFY_TABLE_REOPEN_ALL_REGIONS = 7;
7576
MODIFY_TABLE_CLOSE_EXCESS_REPLICAS = 8;
7677
MODIFY_TABLE_ASSIGN_NEW_REPLICAS = 9;
78+
MODIFY_TABLE_SYNC_ERASURE_CODING_POLICY = 10;
7779
}
7880

7981
message ModifyTableStateData {
@@ -267,6 +269,7 @@ enum CloneSnapshotState {
267269
CLONE_SNAPSHOT_UPDATE_DESC_CACHE = 5;
268270
CLONE_SNAPSHOT_POST_OPERATION = 6;
269271
CLONE_SNAPHOST_RESTORE_ACL = 7;
272+
CLONE_SNAPSHOT_SET_ERASURE_CODING_POLICY = 8;
270273
}
271274

272275
message CloneSnapshotStateData {
@@ -285,6 +288,7 @@ enum RestoreSnapshotState {
285288
RESTORE_SNAPSHOT_WRITE_FS_LAYOUT = 3;
286289
RESTORE_SNAPSHOT_UPDATE_META = 4;
287290
RESTORE_SNAPSHOT_RESTORE_ACL = 5;
291+
RESTORE_SNAPSHOT_SYNC_ERASURE_CODING_POLICY = 6;
288292
}
289293

290294
message RestoreSnapshotStateData {
@@ -296,6 +300,7 @@ message RestoreSnapshotStateData {
296300
repeated RegionInfo region_info_for_add = 6;
297301
repeated RestoreParentToChildRegionsPair parent_to_child_regions_pair_list = 7;
298302
optional bool restore_acl = 8;
303+
required TableSchema old_table_schema = 9;
299304
}
300305

301306
enum DispatchMergingRegionsState {

0 commit comments

Comments
 (0)