-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-30357 OpenRegionProcedure#restoreSucceedState ignores persisted transitionCode, forcing OPEN even after a real FAILED_OPEN #8622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mnpoonia
wants to merge
4
commits into
apache:master
Choose a base branch
from
mnpoonia:HBASE-30357-restoreSucceedState-failed-open
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
89a3dfb
HBASE-30357 OpenRegionProcedure#restoreSucceedState ignores persisted…
mnpoonia 2389c26
HBASE-30357 Rewrite TestOpenRegionProcedureRestoreFailedOpen to resta…
mnpoonia a7d59a7
HBASE-30357 Fix misattributed lock comment in TestOpenRegionProcedure…
mnpoonia 11fd7ad
HBASE-30357 Remove redundant waitFor/proc lookup in TestOpenRegionPro…
mnpoonia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
...a/org/apache/hadoop/hbase/master/assignment/TestOpenRegionProcedureRestoreFailedOpen.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| /* | ||
| * 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.master.assignment; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.PleaseHoldException; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.client.RegionInfo; | ||
| import org.apache.hadoop.hbase.master.HMaster; | ||
| import org.apache.hadoop.hbase.master.MasterServices; | ||
| import org.apache.hadoop.hbase.master.RegionPlan; | ||
| import org.apache.hadoop.hbase.master.RegionState; | ||
| import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; | ||
| import org.apache.hadoop.hbase.master.procedure.MasterProcedureTestingUtility; | ||
| import org.apache.hadoop.hbase.master.region.MasterRegion; | ||
| import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; | ||
| import org.apache.hadoop.hbase.testclassification.MasterTests; | ||
| import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
| import org.apache.hadoop.hbase.util.Bytes; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Tag; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; | ||
| import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition; | ||
| import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionStateTransition.TransitionCode; | ||
| import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionRequest; | ||
| import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.ReportRegionStateTransitionResponse; | ||
|
|
||
| /** | ||
| * HBASE-30357: OpenRegionProcedure#restoreSucceedState() must not force the region state to OPEN on | ||
| * master-failover restore when the persisted transition code is actually FAILED_OPEN. | ||
| * <p/> | ||
| * To reproduce the exact crash window without racing a genuinely reporting RS, we intercept the | ||
| * RS's real OPENED report on the master side and rewrite it to FAILED_OPEN before it is persisted. | ||
| * While still on the RPC handler thread (i.e. before the woken child OpenRegionProcedure gets a | ||
| * chance to run its own execute() and persist anything to meta), we lock the RegionStateNode and | ||
| * perform a genuine restart of the master's ProcedureExecutor/AssignmentManager, forcing a real | ||
| * reload from the WALProcedureStore and hbase:meta - exactly the mechanism restoreSucceedState() is | ||
| * meant to handle. | ||
| */ | ||
| @Tag(MasterTests.TAG) | ||
| @Tag(MediumTests.TAG) | ||
| public class TestOpenRegionProcedureRestoreFailedOpen { | ||
|
|
||
| private static final long AWAIT_TIMEOUT_SECONDS = 30; | ||
|
|
||
| private static final AtomicReference<CountDownLatch> ARRIVE = new AtomicReference<>(); | ||
|
|
||
| private static final AtomicReference<CountDownLatch> PROCEED = new AtomicReference<>(); | ||
|
|
||
| private static final class AssignmentManagerForTest extends AssignmentManager { | ||
|
|
||
| public AssignmentManagerForTest(MasterServices master, MasterRegion masterRegion) { | ||
| super(master, masterRegion); | ||
| } | ||
|
|
||
| @Override | ||
| public ReportRegionStateTransitionResponse reportRegionStateTransition( | ||
| ReportRegionStateTransitionRequest req) throws PleaseHoldException { | ||
| RegionStateTransition transition = req.getTransition(0); | ||
| RegionInfo hri = ProtobufUtil.toRegionInfo(transition.getRegionInfo(0)); | ||
| if (transition.getTransitionCode() != TransitionCode.OPENED || !hri.getTable().equals(NAME)) { | ||
| return super.reportRegionStateTransition(req); | ||
| } | ||
| CountDownLatch arrive = ARRIVE.getAndSet(null); | ||
| if (arrive == null) { | ||
| return super.reportRegionStateTransition(req); | ||
| } | ||
| ReportRegionStateTransitionRequest failedOpenReq = req.toBuilder() | ||
| .setTransition(0, transition.toBuilder().setTransitionCode(TransitionCode.FAILED_OPEN) | ||
| .setOpenSeqNum(HConstants.NO_SEQNUM).build()) | ||
| .build(); | ||
| RegionStateNode regionNode = getRegionStates().getRegionStateNode(hri); | ||
| // AssignmentManager#updateRegionTransition() (called from super.reportRegionStateTransition | ||
| // below) also locks this same RegionStateNode; that only works here because the lock is | ||
| // reentrant for the same thread (see RegionStateNodeLock#lock0). | ||
| regionNode.lock(); | ||
| try { | ||
| // persists REPORT_SUCCEED/FAILED_OPEN to the real WALProcedureStore and wakes the child | ||
| // OpenRegionProcedure, but since we still hold the RegionStateNode lock here (reentrant, | ||
| // same thread), the woken child can not resume and complete its own meta update - this is | ||
| // exactly the window a real master crash would leave us in. | ||
| ReportRegionStateTransitionResponse resp = super.reportRegionStateTransition(failedOpenReq); | ||
| arrive.countDown(); | ||
| CountDownLatch proceed = PROCEED.get(); | ||
| if (!proceed.await(AWAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)) { | ||
| throw new RuntimeException("Timed out waiting for PROCEED"); | ||
| } | ||
| return resp; | ||
| } catch (InterruptedException e) { | ||
| throw new RuntimeException(e); | ||
| } finally { | ||
| regionNode.unlock(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static final class HMasterForTest extends HMaster { | ||
|
|
||
| public HMasterForTest(Configuration conf) throws IOException { | ||
| super(conf); | ||
| } | ||
|
|
||
| @Override | ||
| protected AssignmentManager createAssignmentManager(MasterServices master, | ||
| MasterRegion masterRegion) { | ||
| return new AssignmentManagerForTest(master, masterRegion); | ||
| } | ||
| } | ||
|
|
||
| private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); | ||
|
|
||
| private static final TableName NAME = | ||
| TableName.valueOf("TestOpenRegionProcedureRestoreFailedOpen"); | ||
|
|
||
| private static final byte[] CF = Bytes.toBytes("cf"); | ||
|
|
||
| @BeforeAll | ||
| public static void setUpBeforeClass() throws Exception { | ||
| UTIL.getConfiguration().setClass(HConstants.MASTER_IMPL, HMasterForTest.class, HMaster.class); | ||
| UTIL.startMiniCluster(1); | ||
| UTIL.createTable(NAME, CF); | ||
| UTIL.waitTableAvailable(NAME); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void tearDownAfterClass() throws Exception { | ||
| UTIL.shutdownMiniCluster(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRestoreDoesNotForceOpenAfterFailedOpen() throws Exception { | ||
| HMaster master = UTIL.getMiniHBaseCluster().getMaster(); | ||
| ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor(); | ||
| AssignmentManager am = master.getAssignmentManager(); | ||
| RegionInfo region = UTIL.getAdmin().getRegions(NAME).get(0); | ||
| RegionStateNode regionNode = am.getRegionStates().getRegionStateNode(region); | ||
|
|
||
| CountDownLatch arrive = new CountDownLatch(1); | ||
| CountDownLatch proceed = new CountDownLatch(1); | ||
| ARRIVE.set(arrive); | ||
| PROCEED.set(proceed); | ||
| Future<byte[]> future = am.moveAsync( | ||
| new RegionPlan(region, regionNode.getRegionLocation(), regionNode.getRegionLocation())); | ||
| // arrive counts down only after the RS's OPENED report is intercepted, rewritten to | ||
| // FAILED_OPEN, and persisted, so waiting on it alone is sufficient synchronization | ||
| assertTrue(arrive.await(AWAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS)); | ||
|
|
||
| MasterProcedureTestingUtility.restartMasterProcedureExecutor(procExec); | ||
| RegionStateNode reloaded = am.getRegionStates().getRegionStateNode(region); | ||
| assertNotEquals(RegionState.State.OPEN, reloaded.getState()); | ||
|
|
||
| proceed.countDown(); | ||
| future.get(AWAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
FAILED_OPENthe only case where we have this problem? What about split/merge reverted states?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question — I checked both cases:
CloseRegionProcedure: no analogous bug possible.CloseRegionProcedure.checkTransitiononly ever acceptsCLOSED(CloseRegionProcedure.java:99-106) — there's noFAILED_CLOSE/revert code in the protocol at all (the RS aborts instead of reporting a close failure). SotransitionCodeis structurally guaranteed to beCLOSEDwhenever it's persisted for this procedure, andrestoreSucceedStatecan't mis-restore something that only ever has one valid value.Split/merge: these don't go through
RegionRemoteProcedureBase/OpenRegionProcedure/CloseRegionProcedure/restoreSucceedStateat all — they're driven bySplitTableRegionProcedure/MergeTableRegionsProcedureand reported via a separate switch inAssignmentManager.reportRegionStateTransition, which routesREADY_TO_SPLIT/READY_TO_MERGEto their own handlers. Those handlers rejectSPLIT/MERGED/SPLIT_REVERTED/MERGE_REVERTEDoutright — those codes predate AMv2 (from the 1.x ZK-less-assignment era, HBASE-11059) and exist only as a rolling-upgrade compatibility guard against an old (<2.0) RS still reporting the legacy codes. No current RS code ever sends them.So
FAILED_OPENis the only live instance of this restore-path gap — nothing further to fix here.