-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-22707 [HBCK2] MasterRpcServices assigns method should try to reload regions from meta if the passed regions isn't found under AssignmentManager RegionsStateStore #403
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
Changes from 4 commits
6965920
a42cf36
54e52c3
5a94343
fb54acc
f2e4ecb
688cb9e
57a8371
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 |
|---|---|---|
|
|
@@ -1383,51 +1383,76 @@ public void processOfflineRegions() { | |
| } | ||
| } | ||
|
|
||
| private void loadMeta() throws IOException { | ||
| // TODO: use a thread pool | ||
| regionStateStore.visitMeta(new RegionStateStore.RegionStateVisitor() { | ||
| @Override | ||
| public void visitRegionState(Result result, final RegionInfo regionInfo, final State state, | ||
| final ServerName regionLocation, final ServerName lastHost, final long openSeqNum) { | ||
| if (state == null && regionLocation == null && lastHost == null && | ||
| openSeqNum == SequenceId.NO_SEQUENCE_ID) { | ||
| // This is a row with nothing in it. | ||
| LOG.warn("Skipping empty row={}", result); | ||
| return; | ||
| } | ||
| State localState = state; | ||
| if (localState == null) { | ||
| // No region state column data in hbase:meta table! Are I doing a rolling upgrade from | ||
| // hbase1 to hbase2? Am I restoring a SNAPSHOT or otherwise adding a region to hbase:meta? | ||
| // In any of these cases, state is empty. For now, presume OFFLINE but there are probably | ||
| // cases where we need to probe more to be sure this correct; TODO informed by experience. | ||
| LOG.info(regionInfo.getEncodedName() + " regionState=null; presuming " + State.OFFLINE); | ||
| localState = State.OFFLINE; | ||
| } | ||
| RegionStateNode regionNode = regionStates.getOrCreateRegionStateNode(regionInfo); | ||
| // Do not need to lock on regionNode, as we can make sure that before we finish loading | ||
| // meta, all the related procedures can not be executed. The only exception is for meta | ||
| // region related operations, but here we do not load the informations for meta region. | ||
| regionNode.setState(localState); | ||
| regionNode.setLastHost(lastHost); | ||
| regionNode.setRegionLocation(regionLocation); | ||
| regionNode.setOpenSeqNum(openSeqNum); | ||
|
|
||
| // Note: keep consistent with other methods, see region(Opening|Opened|Closing) | ||
| // RIT/ServerCrash handling should take care of the transiting regions. | ||
| if (localState.matches(State.OPEN, State.OPENING, State.CLOSING, State.SPLITTING, | ||
| State.MERGING)) { | ||
| assert regionLocation != null : "found null region location for " + regionNode; | ||
| regionStates.addRegionToServer(regionNode); | ||
| } else if (localState == State.OFFLINE || regionInfo.isOffline()) { | ||
| regionStates.addToOfflineRegions(regionNode); | ||
| } | ||
| if (regionNode.getProcedure() != null) { | ||
| regionNode.getProcedure().stateLoaded(AssignmentManager.this, regionNode); | ||
| } | ||
| private class RegionMetaLoadingVisitor implements RegionStateStore.RegionStateVisitor { | ||
saintstack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public void visitRegionState(Result result, final RegionInfo regionInfo, final State state, | ||
| final ServerName regionLocation, final ServerName lastHost, final long openSeqNum) { | ||
| if (state == null && regionLocation == null && lastHost == null && | ||
| openSeqNum == SequenceId.NO_SEQUENCE_ID) { | ||
| // This is a row with nothing in it. | ||
| LOG.warn("Skipping empty row={}", result); | ||
| return; | ||
| } | ||
| }); | ||
| State localState = state; | ||
| if (localState == null) { | ||
| // No region state column data in hbase:meta table! Are I doing a rolling upgrade from | ||
| // hbase1 to hbase2? Am I restoring a SNAPSHOT or otherwise adding a region to hbase:meta? | ||
| // In any of these cases, state is empty. For now, presume OFFLINE but there are probably | ||
| // cases where we need to probe more to be sure this correct; TODO informed by experience. | ||
| LOG.info(regionInfo.getEncodedName() + " regionState=null; presuming " + State.OFFLINE); | ||
| localState = State.OFFLINE; | ||
| } | ||
| RegionStateNode regionNode = regionStates.getOrCreateRegionStateNode(regionInfo); | ||
| // Do not need to lock on regionNode, as we can make sure that before we finish loading | ||
| // meta, all the related procedures can not be executed. The only exception is for meta | ||
| // region related operations, but here we do not load the informations for meta region. | ||
| regionNode.setState(localState); | ||
| regionNode.setLastHost(lastHost); | ||
| regionNode.setRegionLocation(regionLocation); | ||
| regionNode.setOpenSeqNum(openSeqNum); | ||
|
|
||
| // Note: keep consistent with other methods, see region(Opening|Opened|Closing) | ||
| // RIT/ServerCrash handling should take care of the transiting regions. | ||
| if (localState.matches(State.OPEN, State.OPENING, State.CLOSING, State.SPLITTING, | ||
| State.MERGING)) { | ||
| assert regionLocation != null : "found null region location for " + regionNode; | ||
| regionStates.addRegionToServer(regionNode); | ||
| } else if (localState == State.OFFLINE || regionInfo.isOffline()) { | ||
| regionStates.addToOfflineRegions(regionNode); | ||
| } | ||
| if (regionNode.getProcedure() != null) { | ||
| regionNode.getProcedure().stateLoaded(AssignmentManager.this, regionNode); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Query META if the given <code>RegionInfo</code> exists, adding to | ||
| * <code>AssignmentManager.regionStateStore</code> cache if the region is found in META. | ||
| * @param regionEncodedName encoded name for the region to be loaded from META into | ||
| * <code>AssignmentManager.regionStateStore</code> cache | ||
| * @return <code>RegionInfo</code> instance for the given region if it is present in META | ||
| * and got successfully loaded into <code>AssignmentManager.regionStateStore</code> | ||
| * cache, <b>null</b> otherwise. | ||
| * @throws UnknownRegionException if any errors occur while querying meta. | ||
| */ | ||
| public RegionInfo loadRegionFromMeta(String regionEncodedName) throws UnknownRegionException { | ||
| try { | ||
| RegionMetaLoadingVisitor visitor = new RegionMetaLoadingVisitor(); | ||
| regionStateStore.visitMetaForRegion(regionEncodedName, visitor); | ||
| RegionInfo regionInfo = regionStates.getRegionState(regionEncodedName) == null ? null : | ||
| regionStates.getRegionState(regionEncodedName).getRegion(); | ||
| return regionInfo; | ||
|
||
| }catch(IOException e){ | ||
|
||
| LOG.error("Error trying to load region {} from META", regionEncodedName, e); | ||
| throw new UnknownRegionException("Error while trying load region from meta"); | ||
| } | ||
| } | ||
|
|
||
| private void loadMeta() throws IOException { | ||
| // TODO: use a thread pool | ||
| regionStateStore.visitMeta(new RegionMetaLoadingVisitor()); | ||
| // every assignment is blocked until meta is loaded. | ||
| wakeMetaLoadedEvent(); | ||
| } | ||
saintstack marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,23 @@ public boolean visit(final Result r) throws IOException { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Queries META table for the passed region encoded name, | ||
| * delegating action upon results to the <code>RegionStateVisitor</code> | ||
| * passed as second parameter. | ||
| * @param regionEncodedName encoded name for the Region we want to query META for. | ||
| * @param visitor The <code>RegionStateVisitor</code> instance to react over the query results. | ||
| * @throws IOException If some error occurs while querying META or parsing results. | ||
| */ | ||
| public void visitMetaForRegion(final String regionEncodedName, final RegionStateVisitor visitor) | ||
| throws IOException { | ||
| Result result = MetaTableAccessor. | ||
| scanByRegionEncodedName(master.getConnection(), regionEncodedName); | ||
| if(result != null) { | ||
|
||
| visitMetaEntry(visitor, result); | ||
| } | ||
| } | ||
|
|
||
| private void visitMetaEntry(final RegionStateVisitor visitor, final Result result) | ||
| throws IOException { | ||
| final RegionLocations rl = MetaTableAccessor.getRegionLocations(result); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.