This topic describes how to remove specified nodes from a cluster by using the obshell-sdk-go.
Note
Before you proceed, we recommend that you read the Getting Started with obshell-sdk-go topic to learn how to use obshell-sdk-go.
Considerations
Before you scale in a cluster, make sure that the following conditions are met:
The client node is in the cluster to be scaled in and cannot be the node to be deleted. In other words, the node cannot remove itself from the cluster.
obshell is running normally.
Sample code
package main
import (
"github.com/oceanbase/obshell-sdk-go/services"
)
func main() {
// Create a client instance. The node address is '10.10.10.1', and the port is 2886.
// The root@sys password of the cluster is '****'.
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
if err != nil {
panic(err)
}
// Remove the node '10.10.10.3:2886' from the cluster.
req := client.V1().NewScaleInRequest("10.10.10.3", 2886)
if _, err = client.V1().ScaleInSyncWithRequest(req); err != nil {
panic(err)
}
}
package main
import (
"github.com/oceanbase/obshell-sdk-go/services"
)
func main() {
// Create a client instance. The node address is '10.10.10.1', and the port is 2886.
// The root@sys password of the cluster is '****'.
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
if err != nil {
panic(err)
}
// Remove the node '10.10.10.3:2886' from the cluster.
req := client.V1().NewScaleInRequest("10.10.10.3", 2886)
dag, err := client.V1().ScaleInWithRequest(req)
if err != nil {
panic(err)
}
// Wait for the task to succeed.
if dag != nil && dag.GenericDTO != nil {
if _, err = client.V1().WaitDagSucceed(dag.GenericID); err != nil {
panic(err)
}
}
}
References
For more information about the API for cluster scale-in, see Cluster scale-in.
For more information about how to request the API by using obshell-sdk-python, see Cluster scale-in.