This topic describes how to delete a zone and its nodes in an OceanBase cluster by using obshell-sdk-go.
Note
Before you proceed, we recommend that you read the Quick Start topic to get familiar with the usage of obshell-sdk-go.
Considerations
Before you scale down a cluster, make sure that the following conditions are met:
The client node must be in the cluster to be scaled down and cannot be in the zone to be deleted.
obshell must be running.
The zone to be deleted must not contain any units.
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)
}
// Delete zone3 from the cluster.
req := client.V1().NewDeleteZoneRequest("zone3")
if _, err := client.V1().DeleteZoneSyncWithRequest(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)
}
// Delete zone3 from the cluster.
req := client.V1().NewDeleteZoneRequest("zone3")
dag, err := client.V1().DeleteZoneWithRequest(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 deleting a zone, see Delete a zone.
For more information about how to call the API by using the obshell-sdk-python SDK, see Delete a zone.