-
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-27551 Add config options to delay assignment to retain last region location #4945
Changes from 2 commits
87fc143
69db293
d1c9ecb
20c454c
b5d21a0
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 |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
import org.apache.hadoop.hbase.client.RetriesExhaustedException; | ||
import org.apache.hadoop.hbase.master.MetricsAssignmentManager; | ||
import org.apache.hadoop.hbase.master.RegionState.State; | ||
import org.apache.hadoop.hbase.master.ServerManager; | ||
import org.apache.hadoop.hbase.master.procedure.AbstractStateMachineRegionProcedure; | ||
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; | ||
import org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure; | ||
|
@@ -107,6 +108,23 @@ public class TransitRegionStateProcedure | |
|
||
private static final Logger LOG = LoggerFactory.getLogger(TransitRegionStateProcedure.class); | ||
|
||
public static final String FORCE_REGION_RETAINMENT = "hbase.master.scp.retain.assignment.force"; | ||
|
||
public static final boolean DEFAULT_FORCE_REGION_RETAINMENT = false; | ||
|
||
/** The wait time in millis before checking again if the region's previous RS is back online*/ | ||
public static final String FORCE_REGION_RETAINMENT_WAIT = | ||
"hbase.master.scp.retain.assignment.force.wait"; | ||
|
||
/** The number of times to check if the region's previous RS is back online, before giving up | ||
* and proceeding with assignment on a new RS*/ | ||
public static final long DEFAULT_FORCE_REGION_RETAINMENT_WAIT = 500; | ||
|
||
public static final String FORCE_REGION_RETAINMENT_RETRIES = | ||
"hbase.master.scp.retain.assignment.force.retries"; | ||
|
||
public static final long DEFAULT_FORCE_REGION_RETAINMENT_RETRIES = 600; | ||
|
||
private TransitionType type; | ||
|
||
private RegionStateTransitionState initialState; | ||
|
@@ -126,6 +144,14 @@ public class TransitRegionStateProcedure | |
|
||
private boolean isSplit; | ||
|
||
private boolean forceRegionRetainment; | ||
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. All the below fields should not be stored here, when reloading we will use the default constructor to create a procedure and use deserialize method to restore the fields, so if you want to store them here, you need to serialize them, or you should implement the afterReplay method to initialize them... 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. Thanks for pointing this out. Since these are all config readings, decided to go with the 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. Looking at other configs in TRSP, I prefer we store these configs in AssignmentManager, just like
|
||
|
||
private ServerManager serverManager; | ||
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. ServerManager can be gotten from MasterProcedureEnv, so we do not need to store it here. 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. Problem here is that we don't keep any MasterProcedureEnv ref as class attribute. 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. When executing you will always have a MasterProcedureEnv... |
||
|
||
private long forceRegionRetainmentWait; | ||
|
||
private long forceRegionRetainmentRetries; | ||
|
||
public TransitRegionStateProcedure() { | ||
} | ||
|
||
|
@@ -163,6 +189,17 @@ protected TransitRegionStateProcedure(MasterProcedureEnv env, RegionInfo hri, | |
} | ||
evictCache = | ||
env.getMasterConfiguration().getBoolean(EVICT_BLOCKS_ON_CLOSE_KEY, DEFAULT_EVICT_ON_CLOSE); | ||
|
||
forceRegionRetainment = env.getMasterConfiguration().getBoolean(FORCE_REGION_RETAINMENT, | ||
DEFAULT_FORCE_REGION_RETAINMENT); | ||
|
||
forceRegionRetainmentWait = env.getMasterConfiguration().getLong(FORCE_REGION_RETAINMENT_WAIT, | ||
DEFAULT_FORCE_REGION_RETAINMENT_WAIT); | ||
|
||
forceRegionRetainmentRetries = env.getMasterConfiguration() | ||
.getLong(FORCE_REGION_RETAINMENT_RETRIES, DEFAULT_FORCE_REGION_RETAINMENT_RETRIES); | ||
|
||
serverManager = env.getMasterServices().getServerManager(); | ||
} | ||
|
||
protected TransitRegionStateProcedure(MasterProcedureEnv env, RegionInfo hri, | ||
|
@@ -188,6 +225,25 @@ protected boolean waitInitialized(MasterProcedureEnv env) { | |
return am.waitMetaLoaded(this) || am.waitMetaAssigned(this, getRegion()); | ||
} | ||
|
||
private void checkAndWaitForOriginalServer(ServerName lastHost) | ||
throws ProcedureSuspendedException { | ||
boolean isOnline = serverManager.findServerWithSameHostnamePortWithLock(lastHost) != null; | ||
long retries = 0; | ||
while (!isOnline && retries < forceRegionRetainmentRetries) { | ||
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. In this way the procedure will hang here for a very long time without releasing the procedure worker. Better suspend the procedure and reschedule it again later. 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. Yes. Thanks for the suggestion, I had changed this in the last commit. |
||
try { | ||
Thread.sleep(forceRegionRetainmentWait); | ||
} catch (InterruptedException e) { | ||
throw new ProcedureSuspendedException(); | ||
} | ||
retries++; | ||
isOnline = serverManager.findServerWithSameHostnamePortWithLock(lastHost) != null; | ||
} | ||
LOG.info( | ||
Apache9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"{} is true. We waited {} ms for host {} to come back online. " | ||
+ "Did host come back online? {}", | ||
FORCE_REGION_RETAINMENT, (retries * forceRegionRetainmentRetries), lastHost, isOnline); | ||
} | ||
|
||
private void queueAssign(MasterProcedureEnv env, RegionStateNode regionNode) | ||
throws ProcedureSuspendedException { | ||
boolean retain = false; | ||
|
@@ -200,9 +256,15 @@ private void queueAssign(MasterProcedureEnv env, RegionStateNode regionNode) | |
regionNode.setRegionLocation(assignCandidate); | ||
} else if (regionNode.getLastHost() != null) { | ||
retain = true; | ||
LOG.info("Setting lastHost as the region location {}", regionNode.getLastHost()); | ||
LOG.info("Setting lastHost {} as the location for region {}", regionNode.getLastHost(), | ||
regionNode.getRegionInfo().getEncodedName()); | ||
regionNode.setRegionLocation(regionNode.getLastHost()); | ||
} | ||
if (regionNode.getRegionLocation() != null && forceRegionRetainment) { | ||
LOG.warn("{} is set to true. This may delay regions re-assignment " | ||
+ "upon RegionServers crashes or restarts.", FORCE_REGION_RETAINMENT); | ||
checkAndWaitForOriginalServer(regionNode.getRegionLocation()); | ||
} | ||
} | ||
LOG.info("Starting {}; {}; forceNewPlan={}, retain={}", this, regionNode.toShortString(), | ||
forceNewPlan, retain); | ||
|
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 first read this config as how long we should wait for this server to come online. However, the code uses this config to sleep for this period between checks, so the overall wait time is FORCE_REGION_RETAINMENT_WAIT * FORCE_REGION_RETAINMENT_RETRIES.
From the operator's perspective, I think it is better to manage this with overall wait 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.
A single overall wait time would be less efficient, we would forcibly wait for the whole of the given timeout, even if the RS comes back online much sooner than that. Maybe better leave as this, but put comments on this constant to avoid confusion?
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.
Documentation/comment is definitely good to have here. Is it costly to check the RS's availability? Maybe hbase.master.scp.retain.assignment.force.wait can be set to a small value so configuring it might not be that important.