-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-30241 TestMobCloneSnapshotFromClientAfterSplittingRegion is fla… #8387
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
liuxiaocs7
wants to merge
2
commits into
apache:master
Choose a base branch
from
liuxiaocs7:HBASE-30241
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
2 commits
Select commit
Hold shift + click to select a range
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
220 changes: 220 additions & 0 deletions
220
...che/hadoop/hbase/client/CloneSnapshotFromClientAfterSplittingRegionWithLinksTestBase.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,220 @@ | ||
| /* | ||
| * 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.client; | ||
|
|
||
| import static org.awaitility.Awaitility.await; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertFalse; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.io.IOException; | ||
| import java.time.Duration; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.apache.hadoop.hbase.MetaTableAccessor; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.master.RegionState; | ||
| import org.apache.hadoop.hbase.master.assignment.RegionStates; | ||
| import org.apache.hadoop.hbase.master.cleaner.TimeToLiveHFileCleaner; | ||
| import org.apache.hadoop.hbase.regionserver.HRegion; | ||
| import org.apache.hadoop.hbase.regionserver.HStore; | ||
| import org.apache.hadoop.hbase.regionserver.HStoreFile; | ||
| import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; | ||
| import org.apache.hadoop.hbase.util.Bytes; | ||
| import org.apache.hadoop.hbase.util.PairOfSameType; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.TestTemplate; | ||
|
|
||
| /** | ||
| * Base class for testing the clone-snapshot flow when the snapshot was taken after a split that | ||
| * produced whole-file {@code HFileLink}s for the daughters instead of {@code Reference} files. | ||
| * <p> | ||
| * Since HBASE-26421, a split builds an {@code HFileLink} (not a {@code Reference}) for a daughter | ||
| * whenever a store file lies entirely on one side of the split point. When every store file falls | ||
| * on one side, the snapshot contains no reference files at all, so the daughters link directly to | ||
| * the snapshot files and do not depend on the cloned parent region. This is the complement of the | ||
| * {@code Reference} case verified by {@code CloneSnapshotFromClientAfterSplittingRegionTestBase} | ||
| * (the regression HBASE-29111 guards against): here there is no parent-to-daughter mapping to | ||
| * record, and the cloned table must still be safe after the source table and snapshot are removed. | ||
| */ | ||
| public class CloneSnapshotFromClientAfterSplittingRegionWithLinksTestBase | ||
| extends CloneSnapshotFromClientTestBase { | ||
|
|
||
| private static final byte[] QUALIFIER = Bytes.toBytes("q"); | ||
|
|
||
| private static final int ROWS_PER_BATCH = 10; | ||
|
|
||
| // Two disjoint key ranges and a split point strictly between them. After splitting, the "low" | ||
| // store file lies entirely below SPLIT_KEY and the "high" store file entirely above it, so each | ||
| // daughter receives one whole store file as an HFileLink and neither side gets a Reference. | ||
| private static final String LOW_PREFIX = "a"; | ||
| private static final String HIGH_PREFIX = "z"; | ||
| private static final byte[] SPLIT_KEY = Bytes.toBytes("m"); | ||
|
|
||
| private TableName clonedTableName; | ||
| private String snapshotName; | ||
|
|
||
| protected CloneSnapshotFromClientAfterSplittingRegionWithLinksTestBase(int numReplicas) { | ||
| super(numReplicas); | ||
| } | ||
|
|
||
| protected static void setupConfiguration() { | ||
| CloneSnapshotFromClientTestBase.setupConfiguration(); | ||
| // CloneSnapshotFromClientTestBase already disables compaction, which keeps the two store files | ||
| // we create from being merged into one that would straddle the split point. On top of that, | ||
| // make archived files immediately eligible for cleaning so that the data-survival check below | ||
| // is meaningful: only the cloned table's HFileLink back-references should keep them alive. | ||
| TEST_UTIL.getConfiguration().setLong(TimeToLiveHFileCleaner.TTL_CONF_KEY, 0); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initSnapshotNames(long tid) { | ||
| clonedTableName = TableName.valueOf(getValidMethodName() + "-clone-" + tid); | ||
| snapshotName = "snaptb-links-" + tid; | ||
| } | ||
|
|
||
| @Override | ||
| protected void createTableAndSnapshots() throws Exception { | ||
| createTable(); | ||
| admin.catalogJanitorSwitch(false); | ||
| } | ||
|
|
||
| @AfterEach | ||
| public void tearDownClone() throws Exception { | ||
| admin.catalogJanitorSwitch(true); | ||
|
liuxiaocs7 marked this conversation as resolved.
|
||
| if (clonedTableName != null && admin.tableExists(clonedTableName)) { | ||
| TEST_UTIL.deleteTable(clonedTableName); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create a single-region table so that we fully control its store files before splitting. | ||
| */ | ||
| @Override | ||
| protected void createTable() throws IOException, InterruptedException { | ||
| SnapshotTestingUtils.createTable(TEST_UTIL, tableName, numReplicas, 1, FAMILY); | ||
| } | ||
|
|
||
| @TestTemplate | ||
| public void testClonedTableWithLinksSurvivesSourceDeletion() throws Exception { | ||
| // Write two store files whose key ranges are disjoint and sit on opposite sides of SPLIT_KEY. | ||
| int totalRows = loadTwoDisjointStoreFiles(); | ||
|
|
||
| // Split between the two ranges. Each daughter receives one whole store file as an HFileLink, | ||
| // so the snapshot contains only HFileLinks and no Reference files. | ||
| int numRegions = admin.getRegions(tableName).size(); | ||
| admin.split(tableName, SPLIT_KEY); | ||
| await().atMost(Duration.ofSeconds(60)).untilAsserted( | ||
| () -> assertEquals(numRegions + numReplicas, admin.getRegions(tableName).size())); | ||
|
|
||
| // Guard: the split must have produced only HFileLinks (no Reference files) for the daughters, | ||
| // otherwise this test would silently degrade into the Reference case. | ||
| assertDaughtersHaveOnlyLinks(); | ||
|
|
||
| // Take a snapshot and clone it. | ||
| admin.snapshot(snapshotName, tableName); | ||
| admin.cloneSnapshot(snapshotName, clonedTableName); | ||
| SnapshotTestingUtils.waitForTableToBeOnline(TEST_UTIL, clonedTableName); | ||
|
|
||
| // The cloned table must contain all rows. | ||
| verifyRowCount(TEST_UTIL, clonedTableName, totalRows); | ||
|
|
||
| // Guard: because the daughters were cloned from whole-file HFileLinks (not References), the | ||
| // cloned table's meta does not record the parent's split daughters (SPLITA/SPLITB). The | ||
| // daughters link directly to the snapshot files and do not depend on the cloned parent. | ||
| assertClonedSplitParentHasNoDaughters(); | ||
|
|
||
| // Remove the source table and the snapshot, then run the HFile cleaner. The cloned table's | ||
| // HFileLinks (and their back-references) must keep the underlying files alive in the archive. | ||
| TEST_UTIL.deleteTable(tableName); | ||
| admin.deleteSnapshot(snapshotName); | ||
| runHFileCleaner(); | ||
|
|
||
| // Reopen the cloned table to force the store files to be re-resolved from disk, then verify | ||
| // that no data was lost. | ||
| admin.disableTable(clonedTableName); | ||
| admin.enableTable(clonedTableName); | ||
| SnapshotTestingUtils.waitForTableToBeOnline(TEST_UTIL, clonedTableName); | ||
| verifyRowCount(TEST_UTIL, clonedTableName, totalRows); | ||
| } | ||
|
|
||
| private int loadTwoDisjointStoreFiles() throws IOException { | ||
| try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { | ||
| putBatch(table, LOW_PREFIX); | ||
| TEST_UTIL.flush(tableName); | ||
| putBatch(table, HIGH_PREFIX); | ||
| TEST_UTIL.flush(tableName); | ||
| return countRows(table); | ||
| } | ||
| } | ||
|
|
||
| private void putBatch(Table table, String prefix) throws IOException { | ||
| List<Put> puts = new ArrayList<>(); | ||
| for (int i = 0; i < ROWS_PER_BATCH; i++) { | ||
| Put put = new Put(Bytes.toBytes(prefix + String.format("%03d", i))); | ||
| put.addColumn(FAMILY, QUALIFIER, Bytes.toBytes(prefix + i)); | ||
| puts.add(put); | ||
| } | ||
| table.put(puts); | ||
| } | ||
|
|
||
| private void assertDaughtersHaveOnlyLinks() throws IOException { | ||
| int linkFiles = 0; | ||
| for (HRegion region : TEST_UTIL.getHBaseCluster().getRegions(tableName)) { | ||
| if ( | ||
| !RegionReplicaUtil.isDefaultReplica(region.getRegionInfo()) | ||
| || region.getRegionInfo().isSplitParent() | ||
| ) { | ||
| continue; | ||
| } | ||
| for (HStore store : region.getStores()) { | ||
| for (HStoreFile sf : store.getStorefiles()) { | ||
| assertTrue(sf.getFileInfo().isLink(), | ||
| "Expected only whole-file HFileLinks after the split, but found a non-link store file: " | ||
| + sf.getPath()); | ||
| linkFiles++; | ||
| } | ||
| } | ||
| } | ||
| assertTrue(linkFiles >= 2, | ||
| "Expected at least two HFileLink files across the daughter regions, found " + linkFiles); | ||
| } | ||
|
|
||
| private void assertClonedSplitParentHasNoDaughters() throws IOException { | ||
| RegionStates regionStates = | ||
| TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates(); | ||
| List<RegionInfo> splitParents = | ||
| regionStates.getRegionByStateOfTable(clonedTableName).get(RegionState.State.SPLIT); | ||
| assertNotNull(splitParents); | ||
| assertFalse(splitParents.isEmpty(), "The cloned table should contain a split parent region"); | ||
| for (RegionInfo splitParent : splitParents) { | ||
| Result result = MetaTableAccessor.getRegionResult(TEST_UTIL.getConnection(), splitParent); | ||
| PairOfSameType<RegionInfo> daughters = MetaTableAccessor.getDaughterRegions(result); | ||
| assertNull(daughters.getFirst(), | ||
| "Did not expect SPLITA to be recorded for an all-HFileLink clone"); | ||
| assertNull(daughters.getSecond(), | ||
| "Did not expect SPLITB to be recorded for an all-HFileLink clone"); | ||
| } | ||
| } | ||
|
|
||
| private void runHFileCleaner() throws IOException { | ||
| TEST_UTIL.getMiniHBaseCluster().getMaster().getHFileCleaner().choreForTesting(); | ||
| } | ||
| } | ||
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
41 changes: 41 additions & 0 deletions
41
.../apache/hadoop/hbase/client/TestCloneSnapshotFromClientAfterSplittingRegionWithLinks.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,41 @@ | ||
| /* | ||
| * 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.client; | ||
|
|
||
| import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; | ||
| import org.apache.hadoop.hbase.testclassification.ClientTests; | ||
| import org.apache.hadoop.hbase.testclassification.LargeTests; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Tag; | ||
|
|
||
| @Tag(LargeTests.TAG) | ||
| @Tag(ClientTests.TAG) | ||
| @HBaseParameterizedTestTemplate(name = "{index}: regionReplication={0}") | ||
| public class TestCloneSnapshotFromClientAfterSplittingRegionWithLinks | ||
| extends CloneSnapshotFromClientAfterSplittingRegionWithLinksTestBase { | ||
|
|
||
| public TestCloneSnapshotFromClientAfterSplittingRegionWithLinks(int numReplicas) { | ||
| super(numReplicas); | ||
| } | ||
|
|
||
| @BeforeAll | ||
| public static void setUpBeforeClass() throws Exception { | ||
| setupConfiguration(); | ||
| TEST_UTIL.startMiniCluster(3); | ||
| } | ||
| } |
70 changes: 70 additions & 0 deletions
70
...ache/hadoop/hbase/client/TestMobCloneSnapshotFromClientAfterSplittingRegionWithLinks.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,70 @@ | ||
| /* | ||
| * 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.client; | ||
|
|
||
| import java.io.IOException; | ||
| import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.mob.MobConstants; | ||
| import org.apache.hadoop.hbase.snapshot.MobSnapshotTestingUtils; | ||
| import org.apache.hadoop.hbase.testclassification.ClientTests; | ||
| import org.apache.hadoop.hbase.testclassification.LargeTests; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Tag; | ||
|
|
||
| @Tag(LargeTests.TAG) | ||
| @Tag(ClientTests.TAG) | ||
| @HBaseParameterizedTestTemplate(name = "{index}: regionReplication={0}") | ||
| public class TestMobCloneSnapshotFromClientAfterSplittingRegionWithLinks | ||
| extends CloneSnapshotFromClientAfterSplittingRegionWithLinksTestBase { | ||
|
|
||
| public TestMobCloneSnapshotFromClientAfterSplittingRegionWithLinks(int numReplicas) { | ||
| super(numReplicas); | ||
| } | ||
|
|
||
| protected static void setupConfiguration() { | ||
| CloneSnapshotFromClientAfterSplittingRegionWithLinksTestBase.setupConfiguration(); | ||
| TEST_UTIL.getConfiguration().setInt(MobConstants.MOB_FILE_CACHE_SIZE_KEY, 0); | ||
| } | ||
|
|
||
| @BeforeAll | ||
| public static void setUpBeforeClass() throws Exception { | ||
| setupConfiguration(); | ||
| TEST_UTIL.startMiniCluster(3); | ||
| } | ||
|
|
||
| @Override | ||
| protected void createTable() throws IOException, InterruptedException { | ||
| MobSnapshotTestingUtils.createMobTable(TEST_UTIL, tableName, new byte[0][], numReplicas, | ||
| FAMILY); | ||
| } | ||
|
|
||
| @Override | ||
| protected int countRows(Table table) throws IOException { | ||
| return MobSnapshotTestingUtils.countMobRows(table); | ||
| } | ||
|
|
||
| @Override | ||
| protected void verifyRowCount(final HBaseTestingUtil util, final TableName tableName, | ||
| long expectedRows) throws IOException { | ||
| // Read every cell value so the MOB files are actually resolved: the point of this test is that | ||
| // the MOB data is still readable after the source table and snapshot are removed. | ||
| MobSnapshotTestingUtils.verifyMobRowCount(util, tableName, expectedRows); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Here is the fix, we need to compact store files here