mcvsubbu commented on a change in pull request #4560: Refactor
toggleInstanceState API
URL: https://github.com/apache/incubator-pinot/pull/4560#discussion_r317853198
##########
File path:
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/PinotHelixResourceManager.java
##########
@@ -2142,48 +2142,59 @@ public PinotResourceManagerResponse
dropInstance(String instanceName) {
* @param timeOutInSeconds: Time-out for setting ideal-state.
* @return
*/
- public PinotResourceManagerResponse toggleInstance(String instanceName,
boolean toggle, int timeOutInSeconds) {
+ private PinotResourceManagerResponse toggleInstance(String instanceName,
boolean toggle, int timeOutInSeconds) {
if (!instanceExists(instanceName)) {
return PinotResourceManagerResponse.failure("Instance " + instanceName +
" not found");
}
_helixAdmin.enableInstance(_helixClusterName, instanceName, toggle);
long deadline = System.currentTimeMillis() + 1000 * timeOutInSeconds;
- boolean toggleSucceed = false;
- String beforeToggleStates =
- (toggle) ? SegmentOnlineOfflineStateModel.OFFLINE :
SegmentOnlineOfflineStateModel.ONLINE;
+ boolean toggleSucceed;
+ String offlineState = SegmentOnlineOfflineStateModel.OFFLINE;
while (System.currentTimeMillis() < deadline) {
toggleSucceed = true;
PropertyKey liveInstanceKey = _keyBuilder.liveInstance(instanceName);
LiveInstance liveInstance =
_helixDataAccessor.getProperty(liveInstanceKey);
if (liveInstance == null) {
- return toggle ? PinotResourceManagerResponse.FAILURE :
PinotResourceManagerResponse.SUCCESS;
- }
- PropertyKey instanceCurrentStatesKey =
_keyBuilder.currentStates(instanceName, liveInstance.getSessionId());
- List<CurrentState> instanceCurrentStates =
_helixDataAccessor.getChildValues(instanceCurrentStatesKey);
- if (instanceCurrentStates == null) {
- return PinotResourceManagerResponse.SUCCESS;
+ if (!toggle) {
+ // If we disable the instance, we actually don't care whether live
instance being null. Thus, returning success should be good.
+ // Otherwise, wait for at most 10 seconds.
+ return PinotResourceManagerResponse.SUCCESS;
+ }
} else {
- for (CurrentState currentState : instanceCurrentStates) {
- for (String state : currentState.getPartitionStateMap().values()) {
- if (beforeToggleStates.equals(state)) {
- toggleSucceed = false;
+ // Checks all the current states fall into the target states
+ PropertyKey instanceCurrentStatesKey =
_keyBuilder.currentStates(instanceName, liveInstance.getSessionId());
+ List<CurrentState> instanceCurrentStates =
_helixDataAccessor.getChildValues(instanceCurrentStatesKey);
+ if (instanceCurrentStates == null) {
+ return PinotResourceManagerResponse.SUCCESS;
Review comment:
Not sure if instanceCurrentStates can be null while we are enabling an
instance (say, if it has no resource assigned to it). Can you verify? My guess
is that the instanceCurrentStates is not null, but the individual resource
current states can be null.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]