-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-25393 Support split and merge region with direct insert into CF… #3488
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7ae88da
HBASE-25393 Support split and merge region with direct insert into CF…
c53e542
fixing some UTs; Removing unnecessary logging...
1a221ca
Added merge strategy info to MergeTableRegionsProcedure serialization…
831eb83
missed the proto file in previous commit
adb648a
addressing Josh review suggestions
017625a
Changes to load strategy to use from table configuration
5e79151
Removing restricted API annotation.
56284fc
Fixing some javadoc
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
105 changes: 105 additions & 0 deletions
105
.../main/java/org/apache/hadoop/hbase/master/assignment/DirectStoreMergeRegionsStrategy.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,105 @@ | ||
| /** | ||
| * 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 org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; | ||
| import org.apache.hadoop.hbase.client.RegionInfo; | ||
| import org.apache.hadoop.hbase.client.TableDescriptor; | ||
| import org.apache.hadoop.hbase.io.hfile.CacheConfig; | ||
| import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; | ||
| import org.apache.hadoop.hbase.regionserver.HRegionFileSystem; | ||
| import org.apache.hadoop.hbase.regionserver.HStoreFile; | ||
| import org.apache.hadoop.hbase.regionserver.StoreFileInfo; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Collection; | ||
|
|
||
| /** | ||
| * <code></code>MergeRegionStrategy</code> implementation to be used in combination with | ||
| * <code>PersistedStoreEngine</code> to avoid renames when merging regions. | ||
| * | ||
| * To use it, define the following properties under master configuration: | ||
| * 1) <property> | ||
| * <name>hbase.hregion.file.write.strategy</name> | ||
| * <value>org.apache.hadoop.hbase.regionserver.DirectStoreFSWriteStrategy</value> | ||
| * </property> | ||
| * 2) <property> | ||
| * <name>hbase.hregion.merge.strategy</name> | ||
| * <value>org.apache.hadoop.hbase.master.assignment.DirectStoreMergeRegionsStrategy</value> | ||
| * </property> | ||
| * | ||
| * This will create the resulting merging region directory straight under the table dir, instead of | ||
| * creating it under the temporary ".merges" dir as done by the default implementation. | ||
| * | ||
| * | ||
| */ | ||
| @InterfaceAudience.Private | ||
| public class DirectStoreMergeRegionsStrategy extends MergeRegionsStrategy { | ||
|
|
||
| /** | ||
| * Inner logic of creating a merging region, this relies on DirectStoreMergeRegionsStrategy to | ||
| * return the actual paths where to create the new region (avoiding temp dirs and subsequent | ||
| * renames). | ||
| * @param env the MasterProcedureEnv wrapping several meta information required. | ||
| * @param fs the FileSystem instance to write the region directory. | ||
| * @param regionsToMerge array of RegionInfo representing the regions being merged. | ||
| * @param tableDir Path instance for the table dir. | ||
| * @param mergedRegion the resulting merging region. | ||
| * @return HRegionFileSystem for the resulting merging region. | ||
| * @throws IOException if any error occurs while creating the region dir. | ||
| */ | ||
| @Override | ||
| public HRegionFileSystem innerMergeRegions(MasterProcedureEnv env, FileSystem fs, | ||
| RegionInfo[] regionsToMerge, Path tableDir, RegionInfo mergedRegion) throws IOException { | ||
| //creates the resulting merge region dir directly under the table directory, instead of | ||
| //the temp ".merges" dir | ||
| HRegionFileSystem mergeRegionFs = HRegionFileSystem.createRegionOnFileSystem( | ||
| env.getMasterConfiguration(), fs, tableDir, mergedRegion); | ||
| mergeRegionFs.createMergesDir(); | ||
| for (RegionInfo ri: regionsToMerge) { | ||
| HRegionFileSystem regionFs = HRegionFileSystem.openRegionFromFileSystem( | ||
| env.getMasterConfiguration(), fs, tableDir, ri, false); | ||
| mergeStoreFiles(env, regionFs, mergeRegionFs, mergedRegion); | ||
| } | ||
| return mergeRegionFs; | ||
| } | ||
|
|
||
| private void mergeStoreFiles(MasterProcedureEnv env, HRegionFileSystem regionFs, | ||
| HRegionFileSystem mergeRegionFs, RegionInfo mergedRegion) throws IOException { | ||
| final TableDescriptor htd = env.getMasterServices().getTableDescriptors() | ||
| .get(mergedRegion.getTable()); | ||
| for (ColumnFamilyDescriptor hcd : htd.getColumnFamilies()) { | ||
| String family = hcd.getNameAsString(); | ||
| final Collection<StoreFileInfo> storeFiles = regionFs.getStoreFiles(family); | ||
| if (storeFiles != null && storeFiles.size() > 0) { | ||
| for (StoreFileInfo storeFileInfo : storeFiles) { | ||
| // Create reference file(s) to parent region file here in mergedDir. | ||
| // As this procedure is running on master, use CacheConfig.DISABLED means | ||
| // don't cache any block. | ||
| mergeRegionFs.mergeStoreFile(regionFs.getRegionInfo(), family, | ||
| new HStoreFile(storeFileInfo, hcd.getBloomFilterType(), CacheConfig.DISABLED), | ||
| mergeRegionFs.getMergesDir()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
99 changes: 99 additions & 0 deletions
99
...-server/src/main/java/org/apache/hadoop/hbase/master/assignment/MergeRegionsStrategy.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,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.assignment; | ||
|
|
||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.client.RegionInfo; | ||
| import org.apache.hadoop.hbase.master.MasterFileSystem; | ||
| import org.apache.hadoop.hbase.master.RegionState; | ||
| import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; | ||
| import org.apache.hadoop.hbase.regionserver.HRegionFileSystem; | ||
| import org.apache.hadoop.hbase.util.CommonFSUtils; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Region merge directory creation strategy to decouple create dir logic from | ||
| * <code></code>MergeTableRegionsProcedure</code> and allow for plugable behaviour. | ||
| */ | ||
| @InterfaceAudience.Private | ||
| public abstract class MergeRegionsStrategy { | ||
|
|
||
| /** | ||
| * Creates the resulting merging region dir and files in the file system, then updates | ||
| * meta table information for the given region. Specific logic on where in the files system to | ||
| * create the region structure is delegated to <method>innerMergeRegions</method> and the | ||
| * actual <code>HRegionFileSystemWriteStrategy</code> implementation. | ||
| * @param env the MasterProcedureEnv wrapping several meta information required. | ||
| * @param regionsToMerge array of RegionInfo representing the regions being merged. | ||
| * @param mergedRegion the resulting merging region. | ||
| * @throws IOException if any error occurs while creating the region dir. | ||
| */ | ||
| public void createMergedRegion(MasterProcedureEnv env, RegionInfo[] regionsToMerge, | ||
| RegionInfo mergedRegion) throws IOException { | ||
| final MasterFileSystem mfs = env.getMasterServices().getMasterFileSystem(); | ||
| final Path tabledir = CommonFSUtils.getTableDir(mfs.getRootDir(), regionsToMerge[0].getTable()); | ||
| final FileSystem fs = mfs.getFileSystem(); | ||
| HRegionFileSystem mergeRegionFs = innerMergeRegions(env, fs, regionsToMerge, | ||
| tabledir, mergedRegion); | ||
| assert mergeRegionFs != null; | ||
| mergeRegionFs.commitMergedRegion(mergedRegion); | ||
| // Prepare to create merged regions | ||
| env.getAssignmentManager().getRegionStates(). | ||
| getOrCreateRegionStateNode(mergedRegion).setState(RegionState.State.MERGING_NEW); | ||
| } | ||
|
|
||
| /** | ||
| * Should define specific logic about where in the file system the region structure should be | ||
| * created. | ||
| * @param env the MasterProcedureEnv wrapping several meta information required. | ||
| * @param fs the FileSystem instance to write the region directory. | ||
| * @param regionsToMerge array of RegionInfo representing the regions being merged. | ||
| * @param tableDir Path instance for the table dir. | ||
| * @param mergedRegion the resulting merging region. | ||
| * @return HRegionFileSystem for the resulting merging region. | ||
| * @throws IOException if any error occurs while creating the region dir. | ||
| */ | ||
| abstract protected HRegionFileSystem innerMergeRegions(MasterProcedureEnv env, FileSystem fs, | ||
| RegionInfo[] regionsToMerge, Path tableDir, RegionInfo mergedRegion) throws IOException; | ||
|
||
|
|
||
|
|
||
| /** | ||
| * Clean up a merged region on rollback after failure. | ||
| * @param env the MasterProcedureEnv wrapping several meta information required. | ||
| * @param regionsToMerge array of RegionInfo representing the regions being merged. | ||
| * @param mergedRegion the resulting merging region. | ||
| * @throws IOException if any error occurs while creating the region dir. | ||
| */ | ||
| public void cleanupMergedRegion(MasterProcedureEnv env, RegionInfo[] regionsToMerge, | ||
| RegionInfo mergedRegion) throws IOException { | ||
| final MasterFileSystem mfs = env.getMasterServices().getMasterFileSystem(); | ||
| TableName tn = regionsToMerge[0].getTable(); | ||
| final Path tableDir = CommonFSUtils.getTableDir(mfs.getRootDir(), tn); | ||
| final FileSystem fs = mfs.getFileSystem(); | ||
| // See createMergedRegion above where we specify the merge dir as being in the | ||
| // FIRST merge parent region. | ||
| HRegionFileSystem regionFs = HRegionFileSystem.openRegionFromFileSystem( | ||
| env.getMasterConfiguration(), fs, tableDir, regionsToMerge[0], false); | ||
| regionFs.cleanupMergedRegion(mergedRegion); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
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.
I do not think this should be a master level config? Since different region could have different StoreEngine implementations(though I do not think we should have a PersistedStoreEngine but that's another story), we can not use the same merge strategy for them at master side?
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 point. Let me modify this. I guess for consistency, maybe table level configuration, rather then family level.
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.
Should be family level?
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.
Could cause confusion/inconsistencies, no? Same region splitting using different approaches to different stores?
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.
Changed to load both mergestrategy and write strategy from the table config.