Skip to content

Commit e766dd7

Browse files
2005hithljApache9
authored andcommitted
HBASE-26462 Should persist restoreAcl flag in the procedure state for CloneSnapshotProcedure and RestoreSnapshotProcedure (#3921)
Signed-off-by: Yu Li <[email protected]> Signed-off-by: Duo Zhang <[email protected]>
1 parent 2382a70 commit e766dd7

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ message CloneSnapshotStateData {
207207
required TableSchema table_schema = 3;
208208
repeated RegionInfo region_info = 4;
209209
repeated RestoreParentToChildRegionsPair parent_to_child_regions_pair_list = 5;
210+
optional bool restore_acl = 6;
210211
}
211212

212213
enum RestoreSnapshotState {
@@ -225,6 +226,7 @@ message RestoreSnapshotStateData {
225226
repeated RegionInfo region_info_for_remove = 5;
226227
repeated RegionInfo region_info_for_add = 6;
227228
repeated RestoreParentToChildRegionsPair parent_to_child_regions_pair_list = 7;
229+
optional bool restore_acl = 8;
228230
}
229231

230232
enum DispatchMergingRegionsState {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.hadoop.hbase.master.procedure;
2020

21+
import com.google.errorprone.annotations.RestrictedApi;
2122
import java.io.IOException;
2223
import java.util.ArrayList;
2324
import java.util.HashMap;
@@ -271,6 +272,8 @@ protected void serializeStateData(ProcedureStateSerializer serializer)
271272
.setUserInfo(MasterProcedureUtil.toProtoUserInfo(getUser()))
272273
.setSnapshot(this.snapshot)
273274
.setTableSchema(ProtobufUtil.toTableSchema(tableDescriptor));
275+
276+
cloneSnapshotMsg.setRestoreAcl(restoreAcl);
274277
if (newRegions != null) {
275278
for (RegionInfo hri: newRegions) {
276279
cloneSnapshotMsg.addRegionInfo(ProtobufUtil.toRegionInfo(hri));
@@ -303,6 +306,9 @@ protected void deserializeStateData(ProcedureStateSerializer serializer)
303306
setUser(MasterProcedureUtil.toUserInfo(cloneSnapshotMsg.getUserInfo()));
304307
snapshot = cloneSnapshotMsg.getSnapshot();
305308
tableDescriptor = ProtobufUtil.toTableDescriptor(cloneSnapshotMsg.getTableSchema());
309+
if (cloneSnapshotMsg.hasRestoreAcl()) {
310+
restoreAcl = cloneSnapshotMsg.getRestoreAcl();
311+
}
306312
if (cloneSnapshotMsg.getRegionInfoCount() == 0) {
307313
newRegions = null;
308314
} else {
@@ -521,4 +527,13 @@ private void addRegionsToMeta(final MasterProcedureEnv env) throws IOException {
521527
metaChanges.updateMetaParentRegions(env.getMasterServices().getConnection(), newRegions);
522528
}
523529

530+
/**
531+
* Exposed for Testing: HBASE-26462
532+
*/
533+
@RestrictedApi(explanation = "Should only be called in tests", link = "",
534+
allowedOnPath = ".*/src/test/.*")
535+
public boolean getRestoreAcl() {
536+
return restoreAcl;
537+
}
538+
524539
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package org.apache.hadoop.hbase.master.procedure;
2020

21+
import com.google.errorprone.annotations.RestrictedApi;
2122
import java.io.IOException;
2223
import java.util.ArrayList;
2324
import java.util.HashMap;
@@ -271,6 +272,7 @@ protected void serializeStateData(ProcedureStateSerializer serializer)
271272
restoreSnapshotMsg.addParentToChildRegionsPairList (parentToChildrenPair);
272273
}
273274
}
275+
restoreSnapshotMsg.setRestoreAcl(restoreAcl);
274276
serializer.serialize(restoreSnapshotMsg.build());
275277
}
276278

@@ -320,6 +322,9 @@ protected void deserializeStateData(ProcedureStateSerializer serializer)
320322
parentToChildrenPair.getChild2RegionName()));
321323
}
322324
}
325+
if (restoreSnapshotMsg.hasRestoreAcl()) {
326+
restoreAcl = restoreSnapshotMsg.getRestoreAcl();
327+
}
323328
}
324329

325330
/**
@@ -545,4 +550,13 @@ private void restoreSnapshotAcl(final MasterProcedureEnv env) throws IOException
545550
env.getMasterServices().getConfiguration());
546551
}
547552
}
553+
554+
/**
555+
* Exposed for Testing: HBASE-26462
556+
*/
557+
@RestrictedApi(explanation = "Should only be called in tests", link = "",
558+
allowedOnPath = ".*/src/test/.*")
559+
public boolean getRestoreAcl() {
560+
return restoreAcl;
561+
}
548562
}

hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestCloneSnapshotProcedure.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hbase.master.procedure;
1919

20+
import static org.junit.Assert.assertEquals;
2021
import static org.junit.Assert.assertTrue;
2122

2223
import java.util.List;
@@ -161,6 +162,31 @@ public void testRecoveryAndDoubleExecution() throws Exception {
161162
clonedTableName);
162163
}
163164

165+
@Test
166+
public void testRecoverWithRestoreAclFlag() throws Exception {
167+
// This test is to solve the problems mentioned in HBASE-26462,
168+
// this needs to simulate the case of CloneSnapshotProcedure failure and recovery,
169+
// and verify whether 'restoreAcl' flag can obtain the correct value.
170+
171+
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
172+
final TableName clonedTableName = TableName.valueOf("testRecoverWithRestoreAclFlag");
173+
final TableDescriptor htd = createTableDescriptor(clonedTableName, CF);
174+
175+
SnapshotProtos.SnapshotDescription snapshotDesc = getSnapshot();
176+
ProcedureTestingUtility.setKillIfHasParent(procExec, false);
177+
ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
178+
179+
// Start the Clone snapshot procedure (with restoreAcl 'true') && kill the executor
180+
long procId = procExec.submitProcedure(
181+
new CloneSnapshotProcedure(procExec.getEnvironment(), htd, snapshotDesc, true));
182+
183+
MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);
184+
185+
CloneSnapshotProcedure result = (CloneSnapshotProcedure)procExec.getResult(procId);
186+
// check whether the 'restoreAcl' flag is true after deserialization from Pb.
187+
assertEquals(true, result.getRestoreAcl());
188+
}
189+
164190
@Test
165191
public void testRollbackAndDoubleExecution() throws Exception {
166192
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

hbase-server/src/test/java/org/apache/hadoop/hbase/master/procedure/TestRestoreSnapshotProcedure.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,25 @@ public void testRecoveryAndDoubleExecution() throws Exception {
210210
validateSnapshotRestore();
211211
}
212212

213+
@Test
214+
public void testRecoverWithRestoreAclFlag() throws Exception {
215+
// This test is to solve the problems mentioned in HBASE-26462,
216+
// this needs to simulate the case of RestoreSnapshotProcedure failure and recovery,
217+
// and verify whether 'restoreAcl' flag can obtain the correct value.
218+
219+
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
220+
ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
221+
222+
// Start the Restore snapshot procedure (with restoreAcl 'true') && kill the executor
223+
long procId = procExec.submitProcedure(
224+
new RestoreSnapshotProcedure(procExec.getEnvironment(), snapshotHTD, snapshot, true));
225+
MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);
226+
227+
RestoreSnapshotProcedure result = (RestoreSnapshotProcedure)procExec.getResult(procId);
228+
// check whether the restoreAcl flag is true after deserialization from Pb.
229+
assertEquals(true, result.getRestoreAcl());
230+
}
231+
213232
private void validateSnapshotRestore() throws IOException {
214233
try {
215234
UTIL.getAdmin().enableTable(snapshotTableName);

0 commit comments

Comments
 (0)