Skip to content

Commit 771e552

Browse files
BukrosSzabolcsjoshelser
authored andcommitted
HBASE-26286: Add support for specifying store file tracker when restoring or cloning snapshot
Closes #3851 Signed-off-by: Duo Zhang <zhangduo@apache.org> Signed-off-by: Josh Elser <elserj@apache.org>
1 parent d00b5fa commit 771e552

File tree

24 files changed

+357
-61
lines changed

24 files changed

+357
-61
lines changed

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

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import org.apache.yetus.audience.InterfaceAudience;
7070

7171
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList;
72+
import org.apache.yetus.audience.InterfaceStability;
7273

7374
/**
7475
* The administrative API for HBase. Obtain an instance from {@link Connection#getAdmin()} and
@@ -1620,7 +1621,7 @@ default void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot)
16201621
* @throws IllegalArgumentException if the restore request is formatted incorrectly
16211622
*/
16221623
void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot, boolean restoreAcl)
1623-
throws IOException, RestoreSnapshotException;
1624+
throws IOException, RestoreSnapshotException;
16241625

16251626
/**
16261627
* Create a new table by cloning the snapshot content.
@@ -1633,7 +1634,25 @@ void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot, boolean
16331634
*/
16341635
default void cloneSnapshot(String snapshotName, TableName tableName)
16351636
throws IOException, TableExistsException, RestoreSnapshotException {
1636-
cloneSnapshot(snapshotName, tableName, false);
1637+
cloneSnapshot(snapshotName, tableName, false, null);
1638+
}
1639+
1640+
/**
1641+
* Create a new table by cloning the snapshot content.
1642+
* @param snapshotName name of the snapshot to be cloned
1643+
* @param tableName name of the table where the snapshot will be restored
1644+
* @param restoreAcl <code>true</code> to clone acl into newly created table
1645+
* @param customSFT specify the StoreFileTracker used for the table
1646+
* @throws IOException if a remote or network exception occurs
1647+
* @throws TableExistsException if table to be created already exists
1648+
* @throws RestoreSnapshotException if snapshot failed to be cloned
1649+
* @throws IllegalArgumentException if the specified table has not a valid name
1650+
*/
1651+
default void cloneSnapshot(String snapshotName, TableName tableName, boolean restoreAcl,
1652+
String customSFT)
1653+
throws IOException, TableExistsException, RestoreSnapshotException {
1654+
get(cloneSnapshotAsync(snapshotName, tableName, restoreAcl, customSFT), getSyncWaitTimeout(),
1655+
TimeUnit.MILLISECONDS);
16371656
}
16381657

16391658
/**
@@ -1680,8 +1699,25 @@ default Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName
16801699
* @throws RestoreSnapshotException if snapshot failed to be cloned
16811700
* @throws IllegalArgumentException if the specified table has not a valid name
16821701
*/
1683-
Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName, boolean restoreAcl)
1684-
throws IOException, TableExistsException, RestoreSnapshotException;
1702+
default Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName,
1703+
boolean restoreAcl)
1704+
throws IOException, TableExistsException, RestoreSnapshotException {
1705+
return cloneSnapshotAsync(snapshotName, tableName, restoreAcl, null);
1706+
}
1707+
1708+
/**
1709+
* Create a new table by cloning the snapshot content.
1710+
* @param snapshotName name of the snapshot to be cloned
1711+
* @param tableName name of the table where the snapshot will be restored
1712+
* @param restoreAcl <code>true</code> to clone acl into newly created table
1713+
* @param customSFT specify the StroreFileTracker used for the table
1714+
* @throws IOException if a remote or network exception occurs
1715+
* @throws TableExistsException if table to be created already exists
1716+
* @throws RestoreSnapshotException if snapshot failed to be cloned
1717+
* @throws IllegalArgumentException if the specified table has not a valid name
1718+
*/
1719+
Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName, boolean restoreAcl,
1720+
String customSFT) throws IOException, TableExistsException, RestoreSnapshotException;
16851721

16861722
/**
16871723
* Execute a distributed procedure on a cluster.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,14 +644,15 @@ public void restoreSnapshot(String snapshotName) throws IOException, RestoreSnap
644644

645645
@Override
646646
public void restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot, boolean restoreAcl)
647-
throws IOException, RestoreSnapshotException {
647+
throws IOException, RestoreSnapshotException {
648648
get(admin.restoreSnapshot(snapshotName, takeFailSafeSnapshot, restoreAcl));
649649
}
650650

651651
@Override
652652
public Future<Void> cloneSnapshotAsync(String snapshotName, TableName tableName,
653-
boolean restoreAcl) throws IOException, TableExistsException, RestoreSnapshotException {
654-
return admin.cloneSnapshot(snapshotName, tableName, restoreAcl);
653+
boolean restoreAcl, String customSFT)
654+
throws IOException, TableExistsException, RestoreSnapshotException {
655+
return admin.cloneSnapshot(snapshotName, tableName, restoreAcl, customSFT);
655656
}
656657

657658
@Override

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
@@ -895,8 +895,20 @@ default CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tab
895895
* @param tableName name of the table where the snapshot will be restored
896896
* @param restoreAcl <code>true</code> to restore acl of snapshot
897897
*/
898+
default CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName,
899+
boolean restoreAcl) {
900+
return cloneSnapshot(snapshotName, tableName, restoreAcl, null);
901+
}
902+
903+
/**
904+
* Create a new table by cloning the snapshot content.
905+
* @param snapshotName name of the snapshot to be cloned
906+
* @param tableName name of the table where the snapshot will be restored
907+
* @param restoreAcl <code>true</code> to restore acl of snapshot
908+
* @param customSFT specify the StroreFileTracker used for the table
909+
*/
898910
CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName,
899-
boolean restoreAcl);
911+
boolean restoreAcl, String customSFT);
900912

901913
/**
902914
* List completed snapshots.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,14 @@ public CompletableFuture<Void> restoreSnapshot(String snapshotName) {
488488

489489
@Override
490490
public CompletableFuture<Void> restoreSnapshot(String snapshotName, boolean takeFailSafeSnapshot,
491-
boolean restoreAcl) {
491+
boolean restoreAcl) {
492492
return wrap(rawAdmin.restoreSnapshot(snapshotName, takeFailSafeSnapshot, restoreAcl));
493493
}
494494

495495
@Override
496496
public CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName,
497-
boolean restoreAcl) {
498-
return wrap(rawAdmin.cloneSnapshot(snapshotName, tableName, restoreAcl));
497+
boolean restoreAcl, String customSFT) {
498+
return wrap(rawAdmin.cloneSnapshot(snapshotName, tableName, restoreAcl, customSFT));
499499
}
500500

501501
@Override

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ public interface ColumnFamilyDescriptor {
195195
* @return A clone value. Null if no mapping for the key
196196
*/
197197
Bytes getValue(Bytes key);
198+
/**
199+
* @param key The key.
200+
* @return A clone value. Null if no mapping for the key
201+
*/
202+
String getValue(String key);
198203
/**
199204
* @param key The key.
200205
* @return A clone value. Null if no mapping for the key

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,12 @@ public byte[] getValue(byte[] key) {
671671
return value == null ? null : value.get();
672672
}
673673

674+
@Override
675+
public String getValue(String key) {
676+
Bytes rval = values.get(new Bytes(Bytes.toBytes(key)));
677+
return rval == null ? null : Bytes.toString(rval.get(), rval.getOffset(), rval.getLength());
678+
}
679+
674680
@Override
675681
public Map<Bytes, Bytes> getValues() {
676682
return Collections.unmodifiableMap(values);

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ public CompletableFuture<Void> restoreSnapshot(String snapshotName, boolean take
19671967
} else if (!exists) {
19681968
// if table does not exist, then just clone snapshot into new table.
19691969
completeConditionalOnFuture(future,
1970-
internalRestoreSnapshot(snapshotName, finalTableName, restoreAcl));
1970+
internalRestoreSnapshot(snapshotName, finalTableName, restoreAcl, null));
19711971
} else {
19721972
addListener(isTableDisabled(finalTableName), (disabled, err4) -> {
19731973
if (err4 != null) {
@@ -2003,12 +2003,13 @@ private CompletableFuture<Void> restoreSnapshot(String snapshotName, TableName t
20032003
future.completeExceptionally(err);
20042004
} else {
20052005
// Step.2 Restore snapshot
2006-
addListener(internalRestoreSnapshot(snapshotName, tableName, restoreAcl),
2006+
addListener(internalRestoreSnapshot(snapshotName, tableName, restoreAcl, null),
20072007
(void2, err2) -> {
20082008
if (err2 != null) {
20092009
// Step.3.a Something went wrong during the restore and try to rollback.
20102010
addListener(
2011-
internalRestoreSnapshot(failSafeSnapshotSnapshotName, tableName, restoreAcl),
2011+
internalRestoreSnapshot(failSafeSnapshotSnapshotName, tableName, restoreAcl,
2012+
null),
20122013
(void3, err3) -> {
20132014
if (err3 != null) {
20142015
future.completeExceptionally(err3);
@@ -2036,7 +2037,7 @@ private CompletableFuture<Void> restoreSnapshot(String snapshotName, TableName t
20362037
});
20372038
return future;
20382039
} else {
2039-
return internalRestoreSnapshot(snapshotName, tableName, restoreAcl);
2040+
return internalRestoreSnapshot(snapshotName, tableName, restoreAcl, null);
20402041
}
20412042
}
20422043

@@ -2053,7 +2054,7 @@ private <T> void completeConditionalOnFuture(CompletableFuture<T> dependentFutur
20532054

20542055
@Override
20552056
public CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tableName,
2056-
boolean restoreAcl) {
2057+
boolean restoreAcl, String customSFT) {
20572058
CompletableFuture<Void> future = new CompletableFuture<>();
20582059
addListener(tableExists(tableName), (exists, err) -> {
20592060
if (err != null) {
@@ -2062,25 +2063,30 @@ public CompletableFuture<Void> cloneSnapshot(String snapshotName, TableName tabl
20622063
future.completeExceptionally(new TableExistsException(tableName));
20632064
} else {
20642065
completeConditionalOnFuture(future,
2065-
internalRestoreSnapshot(snapshotName, tableName, restoreAcl));
2066+
internalRestoreSnapshot(snapshotName, tableName, restoreAcl, customSFT));
20662067
}
20672068
});
20682069
return future;
20692070
}
20702071

20712072
private CompletableFuture<Void> internalRestoreSnapshot(String snapshotName, TableName tableName,
2072-
boolean restoreAcl) {
2073+
boolean restoreAcl, String customSFT) {
20732074
SnapshotProtos.SnapshotDescription snapshot = SnapshotProtos.SnapshotDescription.newBuilder()
20742075
.setName(snapshotName).setTable(tableName.getNameAsString()).build();
20752076
try {
20762077
ClientSnapshotDescriptionUtils.assertSnapshotRequestIsValid(snapshot);
20772078
} catch (IllegalArgumentException e) {
20782079
return failedFuture(e);
20792080
}
2081+
RestoreSnapshotRequest.Builder builder =
2082+
RestoreSnapshotRequest.newBuilder().setSnapshot(snapshot).setNonceGroup(ng.getNonceGroup())
2083+
.setNonce(ng.newNonce()).setRestoreACL(restoreAcl);
2084+
if(customSFT != null){
2085+
builder.setCustomSFT(customSFT);
2086+
}
20802087
return waitProcedureResult(this.<Long> newMasterCaller().action((controller, stub) -> this
20812088
.<RestoreSnapshotRequest, RestoreSnapshotResponse, Long> call(controller, stub,
2082-
RestoreSnapshotRequest.newBuilder().setSnapshot(snapshot).setNonceGroup(ng.getNonceGroup())
2083-
.setNonce(ng.newNonce()).setRestoreACL(restoreAcl).build(),
2089+
builder.build(),
20842090
(s, c, req, done) -> s.restoreSnapshot(c, req, done), (resp) -> resp.getProcId()))
20852091
.call());
20862092
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ message RestoreSnapshotRequest {
462462
optional uint64 nonce_group = 2 [default = 0];
463463
optional uint64 nonce = 3 [default = 0];
464464
optional bool restoreACL = 4 [default = false];
465+
optional string customSFT = 5;
465466
}
466467

467468
message RestoreSnapshotResponse {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ message CloneSnapshotStateData {
208208
repeated RegionInfo region_info = 4;
209209
repeated RestoreParentToChildRegionsPair parent_to_child_regions_pair_list = 5;
210210
optional bool restore_acl = 6;
211+
optional string customSFT = 7;
211212
}
212213

213214
enum RestoreSnapshotState {

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,8 +2619,8 @@ public TableDescriptor get() throws IOException {
26192619

26202620
}
26212621

2622-
public long restoreSnapshot(final SnapshotDescription snapshotDesc,
2623-
final long nonceGroup, final long nonce, final boolean restoreAcl) throws IOException {
2622+
public long restoreSnapshot(final SnapshotDescription snapshotDesc, final long nonceGroup,
2623+
final long nonce, final boolean restoreAcl, final String customSFT) throws IOException {
26242624
checkInitialized();
26252625
getSnapshotManager().checkSnapshotSupport();
26262626

@@ -2629,18 +2629,19 @@ public long restoreSnapshot(final SnapshotDescription snapshotDesc,
26292629
getClusterSchema().getNamespace(dstTable.getNamespaceAsString());
26302630

26312631
return MasterProcedureUtil.submitProcedure(
2632-
new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) {
2633-
@Override
2634-
protected void run() throws IOException {
2632+
new MasterProcedureUtil.NonceProcedureRunnable(this, nonceGroup, nonce) {
2633+
@Override
2634+
protected void run() throws IOException {
26352635
setProcId(
2636-
getSnapshotManager().restoreOrCloneSnapshot(snapshotDesc, getNonceKey(), restoreAcl));
2637-
}
2636+
getSnapshotManager().restoreOrCloneSnapshot(snapshotDesc, getNonceKey(), restoreAcl,
2637+
customSFT));
2638+
}
26382639

2639-
@Override
2640-
protected String getDescription() {
2641-
return "RestoreSnapshotProcedure";
2642-
}
2643-
});
2640+
@Override
2641+
protected String getDescription() {
2642+
return "RestoreSnapshotProcedure";
2643+
}
2644+
});
26442645
}
26452646

26462647
private void checkTableExists(final TableName tableName)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@ public RestoreSnapshotResponse restoreSnapshot(RpcController controller,
15861586
RestoreSnapshotRequest request) throws ServiceException {
15871587
try {
15881588
long procId = server.restoreSnapshot(request.getSnapshot(), request.getNonceGroup(),
1589-
request.getNonce(), request.getRestoreACL());
1589+
request.getNonce(), request.getRestoreACL(), request.getCustomSFT());
15901590
return RestoreSnapshotResponse.newBuilder().setProcId(procId).build();
15911591
} catch (ForeignException e) {
15921592
throw new ServiceException(e.getCause());

0 commit comments

Comments
 (0)