-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-29272 When Spark reads an HBase snapshot, it always read empty … #6947
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
5d66c94
5154ecf
2d55b76
124d879
191c69d
5aed8c9
b949655
f501f83
1232348
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 |
|---|---|---|
|
|
@@ -94,10 +94,17 @@ public TableSnapshotRegionSplit(TableSnapshotInputFormatImpl.InputSplit delegate | |
| this.delegate = delegate; | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated since 4.0.0. Use | ||
| * {@link #TableSnapshotRegionSplit(TableSnapshotInputFormatImpl.InputSplit)}. This | ||
| * constructor will be removed in a future. | ||
| * @see <a href="https://issues.apache.org/jira/browse/HBASE-29272">HBASE-29272</a> | ||
| */ | ||
| @Deprecated | ||
| public TableSnapshotRegionSplit(TableDescriptor htd, RegionInfo regionInfo, | ||
|
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. The class is marked as IA.Public, so you can not delete a public method from it directly. You need to make it deprecated for a whole major release cycle before deleteing. |
||
| List<String> locations, Scan scan, Path restoreDir) { | ||
| this.delegate = | ||
| new TableSnapshotInputFormatImpl.InputSplit(htd, regionInfo, locations, scan, restoreDir); | ||
| this.delegate = new TableSnapshotInputFormatImpl.InputSplit(htd, regionInfo, locations, scan, | ||
| restoreDir, 1); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * 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.snapshot; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.hbase.snapshot.SnapshotInfo.SnapshotStats; | ||
| import org.apache.hadoop.hbase.util.CommonFSUtils; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos; | ||
|
|
||
| /** | ||
| * Utility class to calculate the size of each region in a snapshot. | ||
| */ | ||
| @InterfaceAudience.Private | ||
| public class SnapshotRegionSizeCalculator { | ||
Apache9 marked this conversation as resolved.
Show resolved
Hide resolved
Apache9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Calculate the size of each region in the snapshot. | ||
| * @return A map of region encoded names to their total size in bytes. | ||
| * @throws IOException If an error occurs during calculation. | ||
| */ | ||
| public static Map<String, Long> calculateRegionSizes(Configuration conf, | ||
| SnapshotManifest manifest) throws IOException { | ||
| FileSystem fs = FileSystem.get(CommonFSUtils.getRootDir(conf).toUri(), conf); | ||
| SnapshotProtos.SnapshotDescription snapshot = | ||
| SnapshotDescriptionUtils.readSnapshotInfo(fs, manifest.getSnapshotDir()); | ||
| SnapshotStats stats = SnapshotInfo.getSnapshotStats(conf, snapshot, null); | ||
| return stats.getRegionSizeMap(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* | ||
| * 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.snapshot; | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.client.Admin; | ||
| import org.apache.hadoop.hbase.testclassification.SmallTests; | ||
| import org.apache.hadoop.hbase.util.Bytes; | ||
| import org.apache.hadoop.hbase.util.CommonFSUtils; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
|
|
||
| import org.apache.hadoop.hbase.shaded.protobuf.generated.SnapshotProtos; | ||
|
|
||
| @Category(SmallTests.class) | ||
| public class TestSnapshotRegionSizeCalculator { | ||
|
|
||
| @ClassRule | ||
| public static final HBaseClassTestRule CLASS_RULE = | ||
| HBaseClassTestRule.forClass(TestSnapshotRegionSizeCalculator.class); | ||
|
|
||
| private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); | ||
| private static FileSystem fs; | ||
| private static Path rootDir; | ||
| private static Path snapshotDir; | ||
| private static SnapshotProtos.SnapshotDescription snapshotDesc; | ||
| private static SnapshotManifest manifest; | ||
| private static Admin admin; | ||
| private static Configuration conf; | ||
|
|
||
| @BeforeClass | ||
| public static void setupCluster() throws Exception { | ||
| TEST_UTIL.startMiniCluster(3); | ||
| conf = TEST_UTIL.getConfiguration(); | ||
| fs = TEST_UTIL.getTestFileSystem(); | ||
| rootDir = TEST_UTIL.getDataTestDir("TestSnapshotRegionSizeCalculator"); | ||
| CommonFSUtils.setRootDir(conf, rootDir); | ||
| admin = TEST_UTIL.getAdmin(); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDown() throws Exception { | ||
| fs.delete(rootDir, true); | ||
| TEST_UTIL.shutdownMiniCluster(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCalculateRegionSize() throws IOException { | ||
| TableName tableName = TableName.valueOf("test_table"); | ||
| String snapshotName = "test_snapshot"; | ||
|
|
||
| // table has no data | ||
| TEST_UTIL.createTable(tableName, Bytes.toBytes("info")); | ||
| admin = TEST_UTIL.getConnection().getAdmin(); | ||
| admin.snapshot(snapshotName, tableName); | ||
| Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, | ||
| TEST_UTIL.getDefaultRootDirPath()); | ||
| SnapshotProtos.SnapshotDescription snapshotDesc = | ||
| SnapshotDescriptionUtils.readSnapshotInfo(TEST_UTIL.getTestFileSystem(), snapshotDir); | ||
| SnapshotManifest manifest = SnapshotManifest.open(TEST_UTIL.getConfiguration(), | ||
| TEST_UTIL.getTestFileSystem(), snapshotDir, snapshotDesc); | ||
|
|
||
| Map<String, Long> regionSizes = | ||
| SnapshotRegionSizeCalculator.calculateRegionSizes(TEST_UTIL.getConfiguration(), manifest); | ||
|
|
||
| for (Map.Entry<String, Long> entry : regionSizes.entrySet()) { | ||
| assertTrue("Region size should be 0.", entry.getValue() == 0); | ||
| } | ||
|
|
||
| admin.deleteSnapshot(snapshotName); | ||
|
|
||
| // table has some data | ||
| TEST_UTIL.loadTable(admin.getConnection().getTable(tableName), Bytes.toBytes("info")); | ||
| admin.snapshot(snapshotName, tableName); | ||
| snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, | ||
| TEST_UTIL.getDefaultRootDirPath()); | ||
| snapshotDesc = | ||
| SnapshotDescriptionUtils.readSnapshotInfo(TEST_UTIL.getTestFileSystem(), snapshotDir); | ||
| manifest = SnapshotManifest.open(TEST_UTIL.getConfiguration(), TEST_UTIL.getTestFileSystem(), | ||
| snapshotDir, snapshotDesc); | ||
| regionSizes = | ||
| SnapshotRegionSizeCalculator.calculateRegionSizes(TEST_UTIL.getConfiguration(), manifest); | ||
| for (Map.Entry<String, Long> entry : regionSizes.entrySet()) { | ||
| assertTrue("Region size should be greater than 0.", entry.getValue() > 0); | ||
| } | ||
|
|
||
| TEST_UTIL.deleteTable(tableName); | ||
| admin.deleteSnapshot(snapshotName); | ||
| } | ||
| } | ||
|
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. Hello @guluo2016 , I have seen your comments. I don't know why the test case didn't pass a few days ago, busy resolving it😭... Now it is okay, please review the latest changes, let the test case for two scenarios:
|
||
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.
Please add javadoc and deprecated tag to specify the life cycle for these APIs. You can find some examples in the current code base. And please also add some docs to explain why it is deprecated.