This topic describes how to stop an OceanBase cluster by using obshell-sdk-go.
Note
We recommend that you read Quick start for a better understanding of how to use obshell-sdk-go.
Considerations
Make sure that OceanBase Shell (obshell) runs normally.
Make sure that the node corresponding to the client instance that you use belongs to the cluster to be stopped.
Sample code
package main
import (
"github.com/oceanbase/obshell-sdk-go/services"
"github.com/oceanbase/obshell-sdk-go/services/v1"
)
func main() {
var err error // Handle errors in the production environment.
// Create a client instance, with the IP address of "10.10.10.1" and the port number of 2886.
// Enter the root@sys password "****" for the cluster.
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "***")
// Stop all OBServer nodes in the cluster forcibly.
req := client.V1().NewStopRequest(v1.SCOPE_GLOBAL).SetForce()
_, err = client.V1().StopSyncWithRequest(req)
}
package main
import (
"github.com/oceanbase/obshell-sdk-go/services"
"github.com/oceanbase/obshell-sdk-go/services/v1"
)
func main() {
var err error // Handle errors in the production environment.
// Create a client instance, with the IP address of "10.10.10.1" and the port number of 2886.
// Enter the root@sys password "****" for the cluster.
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "***")
// Stop all OBServer nodes in the cluster forcibly.
req := client.V1().NewStopRequest(v1.SCOPE_GLOBAL).SetForce()
dag, err := client.V1().StopWithRequest(req)
// Wait for the task to complete.
_, err = client.V1().WaitDagSucceed(dag.GenericID)
}
References
For more information about the API operation, see StopCluster.
For more information about how to call the API operation by using obshell-sdk-python, see Stop a cluster.