-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-30335 Seed master flushedSequenceIdByRegion with openSeqNum on region OPEN #8584
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
base: master
Are you sure you want to change the base?
Changes from all commits
ab5a3e9
731f6c9
cf1120c
20432cb
095ed06
a59f828
7761ebf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2287,6 +2287,10 @@ void regionOpenedWithoutPersistingToMeta(RegionStateNode regionNode) | |
| RegionInfo regionInfo = regionNode.getRegionInfo(); | ||
| regionStates.addRegionToServer(regionNode); | ||
| regionStates.removeFromFailedOpen(regionInfo); | ||
| // HBASE-30335: seed the master's flushed sequence cache with openSeqNum so a subsequent | ||
| // WAL split (e.g. source RS crashes after drain-move) recognizes already-durable edits | ||
| // instead of writing orphaned recovered.edits. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to add tests.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Umeshkumar9414 Added a unit test. |
||
| master.getServerManager().reportRegionOpen(regionInfo, regionNode.getOpenSeqNum()); | ||
| } | ||
|
|
||
| // should be called under the RegionStateNode lock | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /* | ||
| * 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; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hbase.HBaseConfiguration; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.client.RegionInfo; | ||
| import org.apache.hadoop.hbase.client.RegionInfoBuilder; | ||
| import org.apache.hadoop.hbase.master.assignment.AssignmentManager; | ||
| import org.apache.hadoop.hbase.master.assignment.RegionStates; | ||
| import org.apache.hadoop.hbase.testclassification.MasterTests; | ||
| import org.apache.hadoop.hbase.testclassification.SmallTests; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Tag; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| @Tag(MasterTests.TAG) | ||
| @Tag(SmallTests.TAG) | ||
| public class TestServerManager { | ||
|
|
||
| private static final class DummyMasterServices extends MockNoopMasterServices { | ||
| private final AssignmentManager am; | ||
|
|
||
| DummyMasterServices(Configuration conf) { | ||
| super(conf); | ||
| am = mock(AssignmentManager.class); | ||
| RegionStates rss = mock(RegionStates.class); | ||
| when(am.getRegionStates()).thenReturn(rss); | ||
| } | ||
|
|
||
| @Override | ||
| public AssignmentManager getAssignmentManager() { | ||
| return am; | ||
| } | ||
| } | ||
|
|
||
| private ServerManager sm; | ||
| private RegionInfo region; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| Configuration conf = HBaseConfiguration.create(); | ||
| sm = new ServerManager(new DummyMasterServices(conf), new DummyRegionServerList()); | ||
| region = RegionInfoBuilder.newBuilder(TableName.valueOf("t")).build(); | ||
| } | ||
|
|
||
| private long lastFlushed(RegionInfo ri) { | ||
| return sm.getLastFlushedSequenceId(ri.getEncodedNameAsBytes()).getLastFlushedSequenceId(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testReportRegionOpenSeedsFlushedSequenceId() { | ||
| assertEquals(HConstants.NO_SEQNUM, lastFlushed(region)); | ||
| sm.reportRegionOpen(region, 42L); | ||
| assertEquals(42L, lastFlushed(region)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testReportRegionOpenDoesNotRegressExistingValue() { | ||
| sm.reportRegionOpen(region, 100L); | ||
| // A later OPEN carrying a smaller openSeqNum (e.g. after a restart replayed less) must not | ||
| // clobber a higher watermark already seeded here or supplied by a heartbeat. | ||
| sm.reportRegionOpen(region, 50L); | ||
| assertEquals(100L, lastFlushed(region)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testReportRegionOpenIgnoresNoSeqNum() { | ||
| sm.reportRegionOpen(region, HConstants.NO_SEQNUM); | ||
| assertEquals(HConstants.NO_SEQNUM, lastFlushed(region)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testReportRegionOpenIgnoresNegativeSeqNum() { | ||
| sm.reportRegionOpen(region, -5L); | ||
| assertEquals(HConstants.NO_SEQNUM, lastFlushed(region)); | ||
| } | ||
| } |
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 catch — the race is real.
updateLastFlushedSequenceIdsreadsflushedSequenceIdByRegionat line 292 and does a conditionalputat line 300 without holding any lock, so the following interleaving is possible:existingValue = null.reportRegionOpen(regionInfo, openSeqNum=10)executes its atomicmerge(Math::max)→ map now has10.completedSeqId = 3→ map regresses to3.The read-then-put pattern predates this PR, but HBASE-30335 sharpens the exposure. Before this change every writer to the map was the same heartbeat path carrying monotonically-nondecreasing values from a single RS — a lost update was self-healing on the next heartbeat. With the new OPEN-time seed, the writer values are heterogeneous (a fresh
openSeqNumafter reopen can be strictly greater than any stale RS'scompletedSequenceIdobserved during graceful drain / failover), and a regression on this path is not self-healing because the OPEN seed happens once per region open, not periodically.Filing this as a follow-up JIRA to keep this PR's diff focused on the seed installation and to make bisection precise if either change regresses. The follow-up will convert both the region-level and per-store read-then-put pairs to atomic
compute(...)and add a concurrency test that racesreportRegionOpen(high)against a heartbeat-shapedregionServerReport(low)and asserts the final map holdshigh. Will link the follow-up PR here once it's up.