This topic describes how to add a tenant replica by using obshell-sdk-go. You can add multiple tenant replicas at a time.
Note
We recommend that you first read Get started with obshell-sdk-go to learn how to use obshell-sdk-go.
Considerations
Make sure that obshell is running.
Make sure that the tenant exists and is in the NORMAL state.
The node corresponding to the client for the request must be in an initialized cluster.
Sample code
package main
import (
"fmt"
"github.com/oceanbase/obshell-sdk-go/services"
"github.com/oceanbase/obshell-sdk-go/services/v1"
)
func main() {
// Create a client instance with the IP address of the node as '10.10.10.1' and the port as 2886.
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
if err != nil {
fmt.Print(err)
return
}
req := client.V1().NewScaleOutReplicasRequest("t1", []v1.ZoneParam{
{
Name: "zone2",
ReplicaType: "FULL",
UnitConfigName: "s1",
UnitNum: 1,
},
{
Name: "zone3",
ReplicaType: "READONLY",
UnitConfigName: "s1",
UnitNum: 1,
},
})
if _, err = client.V1().ScaleOutReplicasSyncWithRequest(req); err != nil {
fmt.Print(err)
return
}
}
package main
import (
"fmt"
"github.com/oceanbase/obshell-sdk-go/services"
"github.com/oceanbase/obshell-sdk-go/services/v1"
)
func main() {
// Create a client instance with the IP address of the node as '10.10.10.1' and the port as 2886.
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
if err != nil {
fmt.Print(err)
return
}
req := client.V1().NewScaleOutReplicasRequest("t1", []v1.ZoneParam{
{
Name: "zone2",
ReplicaType: "FULL",
UnitConfigName: "s1",
UnitNum: 1,
},
{
Name: "zone3",
ReplicaType: "READONLY",
UnitConfigName: "s1",
UnitNum: 1,
},
})
dag, err := client.V1().ScaleOutReplicasWithRequest(req)
if err != nil {
fmt.Print(err)
return
}
// Wait for the task to succeed.
if _, err = client.V1().WaitDagSucceed(dag.GenericID); err != nil {
fmt.Print(err)
return
}
}
References
For more information about the API for adding a tenant replica, see Add a tenant replica.
For more information about how to request API methods by using obshell-sdk-python, see Add a tenant replica.