-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLAT-14787] Implement a master tablet lb api for YW
Summary: An API that returns if the master tablet load balancer is disabled, enabled & idle or enabled & running. If running, an estimate of the time to go back to idle is provided if it is possible to get such an estimate. ``` $ '/usr/bin/curl' '-s' '--insecure' '-H' 'X-AUTH-TOKEN: xxxxx' '-X' 'GET' 'http://localhost:9000/api/v1/customers/f33e3c9b-75ab-4c30-80ad-cba85646ea39/universes/180f069f-adf3-49b9-86ab-7a4fb4bc5d3e/master_lb_state' {"isEnabled":false} {"isEnabled":true, "isIdle": true} {"isEnabled":true, "isIdle": false, "estTimeToBalanceSecs":987} ``` Also added the relevant metrics used here on the metrics page. Test Plan: 1. Turn off the master lb with `tserver/bin/yb-admin --init_master_addrs=10.9.207.233 set_load_balancer_enabled 0`, verify the response is ``` {"isEnabled":false} ``` 2. Turn back the master lb on with `tserver/bin/yb-admin --init_master_addrs=10.9.207.233 set_load_balancer_enabled 1`, verify the response is ``` {"isEnabled":true,"isIdle":true} ``` 3. Verify lb progress is reflected correctly. Create some tables with lot of tablets ``` seq 1 10 | while read i; do tserver/bin/ysqlsh -h /tmp/.yb.10.9.207.233\:5433/ -c "create table foo$i(id int) split into 150 tablets; insert into foo$i (select * from generate_series(1,1000));"; done ``` and slow down the master LB by setting master gflag `load_balancer_max_concurrent_moves to 1`. Then trigger the master lb by leader blacklisting one of the tservers `tserver/bin/yb-admin --init_master_addrs=10.9.207.233 change_leader_blacklist ADD 10.9.142.7`. Verify that the master LB is now running via ``` tserver/bin/yb-admin --init_master_addrs=10.9.207.233 get_is_load_balancer_idle Idle = 0 ``` and that the API response matches this ``` {"isEnabled":true,"isIdle":false} ``` After all the moves are complete, verify that the response returns to ``` {"isEnabled":true,"isIdle":true} ``` Reviewers: cwang, yshchetinin Reviewed By: cwang, yshchetinin Subscribers: yugaware Differential Revision: https://phorge.dev.yugabyte.com/D36164
- Loading branch information
Showing
32 changed files
with
743 additions
and
166 deletions.
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
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
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
67 changes: 67 additions & 0 deletions
67
java/yb-client/src/main/java/org/yb/client/GetLoadBalancerStateRequest.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,67 @@ | ||
// Copyright (c) YugaByte, Inc. | ||
// | ||
// Licensed 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.yb.client; | ||
|
||
import com.google.protobuf.Message; | ||
import io.netty.buffer.ByteBuf; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.yb.annotations.InterfaceAudience; | ||
import org.yb.master.MasterClusterOuterClass; | ||
import org.yb.master.MasterClusterOuterClass.GetLoadBalancerStateRequestPB; | ||
import org.yb.util.Pair; | ||
|
||
@InterfaceAudience.Public | ||
public class GetLoadBalancerStateRequest extends YRpc<GetLoadBalancerStateResponse> { | ||
|
||
public static final Logger LOG = LoggerFactory.getLogger(GetLoadBalancerStateRequest.class); | ||
|
||
public GetLoadBalancerStateRequest(YBTable table) { | ||
// The passed table will be a master table from AsyncYBClient since this service is registered | ||
// on master. | ||
super(table); | ||
} | ||
|
||
@Override | ||
ByteBuf serialize(Message header) { | ||
assert header.isInitialized(); | ||
final GetLoadBalancerStateRequestPB.Builder builder = | ||
GetLoadBalancerStateRequestPB.newBuilder(); | ||
return toChannelBuffer(header, builder.build()); | ||
} | ||
|
||
@Override | ||
String serviceName() { | ||
return MASTER_SERVICE_NAME; | ||
} | ||
|
||
@Override | ||
String method() { | ||
return "GetLoadBalancerState"; | ||
} | ||
|
||
@Override | ||
Pair<GetLoadBalancerStateResponse, Object> deserialize(CallResponse callResponse, String uuid) | ||
throws Exception { | ||
final MasterClusterOuterClass.GetLoadBalancerStateResponsePB.Builder respBuilder = | ||
MasterClusterOuterClass.GetLoadBalancerStateResponsePB.newBuilder(); | ||
readProtobuf(callResponse.getPBMessage(), respBuilder); | ||
|
||
GetLoadBalancerStateResponse response = | ||
new GetLoadBalancerStateResponse( | ||
deadlineTracker.getElapsedMillis(), uuid, respBuilder.build()); | ||
return new Pair<GetLoadBalancerStateResponse, Object>( | ||
response, respBuilder.hasError() ? respBuilder.getError() : null); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
java/yb-client/src/main/java/org/yb/client/GetLoadBalancerStateResponse.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,54 @@ | ||
// Copyright (c) YugaByte, Inc. | ||
// | ||
// Licensed 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.yb.client; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.yb.annotations.InterfaceAudience; | ||
import org.yb.master.MasterClusterOuterClass.GetLoadBalancerStateResponsePB; | ||
import org.yb.master.MasterTypes.MasterErrorPB; | ||
|
||
@InterfaceAudience.Public | ||
public class GetLoadBalancerStateResponse extends YRpcResponse { | ||
|
||
public static final Logger LOG = LoggerFactory.getLogger(GetLoadBalancerStateResponse.class); | ||
|
||
private GetLoadBalancerStateResponsePB masterLBState; | ||
|
||
public GetLoadBalancerStateResponse( | ||
long elapsedMillis, String uuid, GetLoadBalancerStateResponsePB response) { | ||
super(elapsedMillis, uuid); | ||
this.masterLBState = response; | ||
} | ||
|
||
public MasterErrorPB getServerError() { | ||
return masterLBState.getError(); | ||
} | ||
|
||
public boolean hasError() { | ||
return masterLBState.hasError(); | ||
} | ||
|
||
public String errorMessage() { | ||
return masterLBState.hasError() ? masterLBState.getError().getStatus().getMessage() : null; | ||
} | ||
|
||
public boolean hasIsEnabled() { | ||
return masterLBState.hasIsEnabled(); | ||
} | ||
|
||
public boolean isEnabled() { | ||
return masterLBState.getIsEnabled(); | ||
} | ||
} |
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
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
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
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
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
32 changes: 32 additions & 0 deletions
32
managed/src/main/java/com/yugabyte/yw/controllers/apiModels/MasterLBStateResponse.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,32 @@ | ||
/* | ||
* Copyright 2024 YugaByte, Inc. and Contributors | ||
* | ||
* Licensed under the Polyform Free Trial License 1.0.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://github.com/YugaByte/yugabyte-db/blob/master/licenses/POLYFORM-FREE-TRIAL-LICENSE-1.0.0.txt | ||
*/ | ||
package com.yugabyte.yw.controllers.apiModels; | ||
|
||
import io.swagger.annotations.ApiModel; | ||
import io.swagger.annotations.ApiModelProperty; | ||
|
||
@ApiModel(description = "Master tablet load balancer status") | ||
public class MasterLBStateResponse { | ||
@ApiModelProperty( | ||
required = true, | ||
value = "YbaApi Internal Whether master tablet load balancer is enabled") | ||
public Boolean isEnabled; | ||
|
||
@ApiModelProperty( | ||
required = false, | ||
value = "YbaApi Internal Whether master tablet load balancer is inactive") | ||
public Boolean isIdle; | ||
|
||
@ApiModelProperty( | ||
required = false, | ||
value = | ||
"YbaApi Internal Estimate of time for which master tablet load balancer will be active") | ||
public Long estTimeToBalanceSecs; | ||
} |
Oops, something went wrong.