-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
HBASE-26245 Store region server list in master local region #4136
Merged
Merged
Changes from all commits
Commits
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 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
111 changes: 111 additions & 0 deletions
111
hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRegionServerList.java
This file contains 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,111 @@ | ||
/** | ||
* 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 java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.apache.hadoop.hbase.Abortable; | ||
import org.apache.hadoop.hbase.HConstants; | ||
import org.apache.hadoop.hbase.ServerName; | ||
import org.apache.hadoop.hbase.client.Delete; | ||
import org.apache.hadoop.hbase.client.Put; | ||
import org.apache.hadoop.hbase.client.Result; | ||
import org.apache.hadoop.hbase.client.ResultScanner; | ||
import org.apache.hadoop.hbase.client.Scan; | ||
import org.apache.hadoop.hbase.log.HBaseMarkers; | ||
import org.apache.hadoop.hbase.master.assignment.ServerState; | ||
import org.apache.hadoop.hbase.master.region.MasterRegion; | ||
import org.apache.hadoop.hbase.master.region.MasterRegionFactory; | ||
import org.apache.hadoop.hbase.util.Bytes; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* {@link MasterRegion} based {@link RegionServerList}. | ||
* <p/> | ||
* This is useful when we want to restart a cluster with only the data on file system, as when | ||
* restarting, we need to get the previous live region servers for scheduling SCP. Before we have | ||
* this class, we need to scan the WAL directory on WAL file system to find out the previous live | ||
* region servers, which means we can not restart a cluster without the previous WAL file system, | ||
* even if we have flushed all the data. | ||
* <p/> | ||
* Please see HBASE-26245 for more details. | ||
*/ | ||
@InterfaceAudience.Private | ||
public class MasterRegionServerList implements RegionServerList { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(MasterRegionServerList.class); | ||
|
||
private final MasterRegion region; | ||
|
||
private final Abortable abortable; | ||
|
||
public MasterRegionServerList(MasterRegion region, Abortable abortable) { | ||
this.region = region; | ||
this.abortable = abortable; | ||
} | ||
|
||
@Override | ||
public void started(ServerName sn) { | ||
Put put = | ||
new Put(Bytes.toBytes(sn.getServerName())).addColumn(MasterRegionFactory.REGION_SERVER_FAMILY, | ||
HConstants.STATE_QUALIFIER, Bytes.toBytes(ServerState.ONLINE.name())); | ||
try { | ||
region.update(r -> r.put(put)); | ||
} catch (IOException e) { | ||
LOG.error(HBaseMarkers.FATAL, "Failed to record region server {} as started, aborting...", sn, | ||
e); | ||
abortable.abort("Failed to record region server as started"); | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public void expired(ServerName sn) { | ||
Delete delete = new Delete(Bytes.toBytes(sn.getServerName())) | ||
.addFamily(MasterRegionFactory.REGION_SERVER_FAMILY); | ||
try { | ||
region.update(r -> r.delete(delete)); | ||
} catch (IOException e) { | ||
LOG.error(HBaseMarkers.FATAL, "Failed to record region server {} as expired, aborting...", sn, | ||
e); | ||
abortable.abort("Failed to record region server as expired"); | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public Set<ServerName> getAll() throws IOException { | ||
Set<ServerName> rsList = new HashSet<>(); | ||
try (ResultScanner scanner = | ||
region.getScanner(new Scan().addFamily(MasterRegionFactory.REGION_SERVER_FAMILY))) { | ||
for (;;) { | ||
Result result = scanner.next(); | ||
if (result == null) { | ||
break; | ||
} | ||
rsList.add(ServerName.valueOf(Bytes.toString(result.getRow()))); | ||
} | ||
} | ||
return rsList; | ||
} | ||
|
||
} |
This file contains 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
47 changes: 47 additions & 0 deletions
47
hbase-server/src/main/java/org/apache/hadoop/hbase/master/RegionServerList.java
This file contains 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,47 @@ | ||
/** | ||
* 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 java.io.IOException; | ||
import java.util.Set; | ||
import org.apache.hadoop.hbase.ServerName; | ||
import org.apache.yetus.audience.InterfaceAudience; | ||
|
||
/** | ||
* For storing the region server list. | ||
* <p/> | ||
* Mainly be used when restarting master, to load the previous active region server list. | ||
*/ | ||
@InterfaceAudience.Private | ||
public interface RegionServerList { | ||
|
||
/** | ||
* Called when a region server join the cluster. | ||
*/ | ||
void started(ServerName sn); | ||
|
||
/** | ||
* Called when a region server is dead. | ||
*/ | ||
void expired(ServerName sn); | ||
|
||
/** | ||
* Get all live region servers. | ||
*/ | ||
Set<ServerName> getAll() throws IOException; | ||
} |
This file contains 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
This file contains 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
This file contains 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
40 changes: 40 additions & 0 deletions
40
hbase-server/src/test/java/org/apache/hadoop/hbase/master/DummyRegionServerListStorage.java
This file contains 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,40 @@ | ||
/** | ||
* 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 java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import org.apache.hadoop.hbase.ServerName; | ||
|
||
public class DummyRegionServerListStorage implements RegionServerList { | ||
|
||
@Override | ||
public void started(ServerName sn) { | ||
} | ||
|
||
@Override | ||
public void expired(ServerName sn) { | ||
} | ||
|
||
@Override | ||
public Set<ServerName> getAll() throws IOException { | ||
return Collections.emptySet(); | ||
} | ||
|
||
} |
This file contains 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
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.
Do we still need to also track, and take a union here of, live servers via WALManager? Is the WALManager based live server stuff redundant now? Can we remove it?
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.
This is for rolling upgrading, where we have nothing in the master local region yet. I think we could remove the union in 4.0.0.
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.
There could be a migration step, and then taking the union is not necessary. The concern here is tracking by two mechanisms can cause issues or complicate troubleshooting if they get out of sync. It can be a follow up change if deemed important at some future time.
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 be a follow up. It is not easy as the WAL directory is not actually a 'storage', so the 'migration' is not an actual migration as the WAL directory is always there even after 'migration'...