Skip to content

Commit 9ca71f6

Browse files
committed
HBASE-25549 A new hbase shell command: 'alter_lazy'
1 parent d6d67d1 commit 9ca71f6

21 files changed

Lines changed: 196 additions & 21 deletions

File tree

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,21 @@ default void modifyTable(TableDescriptor td) throws IOException {
10331033
* @return the result of the async modify. You can use Future.get(long, TimeUnit) to wait on the
10341034
* operation to complete
10351035
*/
1036-
Future<Void> modifyTableAsync(TableDescriptor td) throws IOException;
1036+
default Future<Void> modifyTableAsync(TableDescriptor td) throws IOException{
1037+
return modifyTableAsync(td, true);
1038+
}
1039+
1040+
/**
1041+
* Same as {@link #modifyTableAsync(TableDescriptor td)}. except the boolean
1042+
* {@code shouldReopenRegions} will control whether reopen regions after modifying done
1043+
* @param td description of the table
1044+
* @param shouldReopenRegions If false, only the TableDescriptor will be updated and
1045+
* regions belonging to the table will not be reopened
1046+
* @throws IOException if a remote or network exception occurs
1047+
* @return the result of the async modify. You can use Future.get(long, TimeUnit) to wait on the
1048+
* operation to complete
1049+
*/
1050+
Future<Void> modifyTableAsync(TableDescriptor td, boolean shouldReopenRegions) throws IOException;
10371051

10381052
/**
10391053
* Shuts down the HBase cluster.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ public Future<Void> modifyTableAsync(TableDescriptor td) throws IOException {
470470
return admin.modifyTable(td);
471471
}
472472

473+
@Override
474+
public Future<Void> modifyTableAsync(TableDescriptor td, boolean shouldReopenRegions) throws IOException {
475+
return admin.modifyTable(td, shouldReopenRegions);
476+
}
477+
473478
@Override
474479
public void shutdown() throws IOException {
475480
get(admin.shutdown());

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,19 @@ CompletableFuture<Void> createTable(TableDescriptor desc, byte[] startKey, byte[
180180
* Modify an existing table, more IRB friendly version.
181181
* @param desc modified description of the table
182182
*/
183-
CompletableFuture<Void> modifyTable(TableDescriptor desc);
183+
default CompletableFuture<Void> modifyTable(TableDescriptor desc){
184+
return modifyTable(desc, true);
185+
}
186+
187+
/**
188+
* Same as {@link #modifyTable(TableDescriptor td)}. except the boolean {@code shouldReopenRegions}
189+
* will control whether reopen regions after modifying done
190+
* @param desc description of the table
191+
* @param shouldReopenRegions If false, only the TableDescriptor will be updated and
192+
* the regions belonging to the table will not be reopened
193+
*/
194+
CompletableFuture<Void> modifyTable(TableDescriptor desc, boolean shouldReopenRegions);
195+
184196

185197
/**
186198
* Deletes a table.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ public CompletableFuture<Void> createTable(TableDescriptor desc, byte[][] splitK
143143

144144
@Override
145145
public CompletableFuture<Void> modifyTable(TableDescriptor desc) {
146-
return wrap(rawAdmin.modifyTable(desc));
146+
return modifyTable(desc, true);
147+
}
148+
149+
@Override
150+
public CompletableFuture<Void> modifyTable(TableDescriptor desc, boolean shouldReopenRegions) {
151+
return wrap(rawAdmin.modifyTable(desc, shouldReopenRegions));
147152
}
148153

149154
@Override

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,14 @@ private CompletableFuture<Void> createTable(TableName tableName, CreateTableRequ
656656

657657
@Override
658658
public CompletableFuture<Void> modifyTable(TableDescriptor desc) {
659+
return modifyTable(desc, true);
660+
}
661+
662+
@Override
663+
public CompletableFuture<Void> modifyTable(TableDescriptor desc, boolean shouldReopenRegions) {
659664
return this.<ModifyTableRequest, ModifyTableResponse> procedureCall(desc.getTableName(),
660665
RequestConverter.buildModifyTableRequest(desc.getTableName(), desc, ng.getNonceGroup(),
661-
ng.newNonce()), (s, c, req, done) -> s.modifyTable(c, req, done),
666+
ng.newNonce(), shouldReopenRegions), (s, c, req, done) -> s.modifyTable(c, req, done),
662667
(resp) -> resp.getProcId(), new ModifyTableProcedureBiConsumer(this, desc.getTableName()));
663668
}
664669

hbase-client/src/main/java/org/apache/hadoop/hbase/shaded/protobuf/RequestConverter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,15 +1203,17 @@ public static CreateTableRequest buildCreateTableRequest(
12031203
* @return a ModifyTableRequest
12041204
*/
12051205
public static ModifyTableRequest buildModifyTableRequest(
1206-
final TableName tableName,
1207-
final TableDescriptor tableDesc,
1208-
final long nonceGroup,
1209-
final long nonce) {
1206+
final TableName tableName,
1207+
final TableDescriptor tableDesc,
1208+
final long nonceGroup,
1209+
final long nonce,
1210+
final boolean shouldReopenRegions) {
12101211
ModifyTableRequest.Builder builder = ModifyTableRequest.newBuilder();
12111212
builder.setTableName(ProtobufUtil.toProtoTableName((tableName)));
12121213
builder.setTableSchema(ProtobufUtil.toTableSchema(tableDesc));
12131214
builder.setNonceGroup(nonceGroup);
12141215
builder.setNonce(nonce);
1216+
builder.setShouldReopenRegions(shouldReopenRegions);
12151217
return builder.build();
12161218
}
12171219

hbase-protocol-shaded/src/main/protobuf/server/master/Master.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ message ModifyTableRequest {
194194
required TableSchema table_schema = 2;
195195
optional uint64 nonce_group = 3 [default = 0];
196196
optional uint64 nonce = 4 [default = 0];
197+
optional bool should_reopen_regions = 5 [default = true];
197198
}
198199

199200
message ModifyTableResponse {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ message ModifyTableStateData {
8282
required TableSchema modified_table_schema = 3;
8383
required bool delete_column_family_in_modify = 4;
8484
optional bool should_check_descriptor = 5;
85+
optional bool should_reopen_regions = 6;
8586
}
8687

8788
enum TruncateTableState {

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,9 +2353,15 @@ protected String getDescription() {
23532353
});
23542354
}
23552355

2356+
private long modifyTable(final TableName tableName,
2357+
final TableDescriptorGetter newDescriptorGetter, final long nonceGroup, final long nonce,
2358+
final boolean shouldCheckDescriptor) throws IOException{
2359+
return modifyTable(tableName,newDescriptorGetter, nonceGroup, nonce, shouldCheckDescriptor, true);
2360+
}
2361+
23562362
private long modifyTable(final TableName tableName,
23572363
final TableDescriptorGetter newDescriptorGetter, final long nonceGroup, final long nonce,
2358-
final boolean shouldCheckDescriptor) throws IOException {
2364+
final boolean shouldCheckDescriptor, final boolean shouldReopenRegions) throws IOException {
23592365
return MasterProcedureUtil
23602366
.submitProcedure(new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) {
23612367
@Override
@@ -2374,7 +2380,7 @@ protected void run() throws IOException {
23742380
// checks. This will block only the beginning of the procedure. See HBASE-19953.
23752381
ProcedurePrepareLatch latch = ProcedurePrepareLatch.createBlockingLatch();
23762382
submitProcedure(new ModifyTableProcedure(procedureExecutor.getEnvironment(),
2377-
newDescriptor, latch, oldDescriptor, shouldCheckDescriptor));
2383+
newDescriptor, latch, oldDescriptor, shouldCheckDescriptor, shouldReopenRegions));
23782384
latch.await();
23792385

23802386
getMaster().getMasterCoprocessorHost().postModifyTable(tableName, oldDescriptor,
@@ -2391,14 +2397,14 @@ protected String getDescription() {
23912397

23922398
@Override
23932399
public long modifyTable(final TableName tableName, final TableDescriptor newDescriptor,
2394-
final long nonceGroup, final long nonce) throws IOException {
2400+
final long nonceGroup, final long nonce, final boolean shouldReopenRegions) throws IOException {
23952401
checkInitialized();
23962402
return modifyTable(tableName, new TableDescriptorGetter() {
23972403
@Override
23982404
public TableDescriptor get() throws IOException {
23992405
return newDescriptor;
24002406
}
2401-
}, nonceGroup, nonce, false);
2407+
}, nonceGroup, nonce, false, shouldReopenRegions);
24022408

24032409
}
24042410

hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,8 @@ public ModifyTableResponse modifyTable(RpcController controller,
14641464
ProtobufUtil.toTableName(req.getTableName()),
14651465
ProtobufUtil.toTableDescriptor(req.getTableSchema()),
14661466
req.getNonceGroup(),
1467-
req.getNonce());
1467+
req.getNonce(),
1468+
req.getShouldReopenRegions());
14681469
return ModifyTableResponse.newBuilder().setProcId(procId).build();
14691470
} catch (IOException ioe) {
14701471
throw new ServiceException(ioe);

0 commit comments

Comments
 (0)