This topic describes how to add an OBServer node to an uninitialized 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
Before adding an OBServer node to an uninitialized OceanBase cluster, take note of the following considerations:
Make sure that the node corresponding to the client instance that you use is in the cluster to be initialized, unless the node itself is to be added.
Make sure that the node to be added has not joined any cluster.
When you add the node corresponding to the client instance that you use, make sure that the node has not joined any cluster and OceanBase Shell (obshell) on the node runs normally.
Sample code
The following code joins the node with the IP address of 10.10.10.1 as Master Agent and then joins another node with the IP address of 10.10.10.2 as Follower Agent.
package main
import (
"github.com/oceanbase/obshell-sdk-go/services"
)
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.
client, err := services.NewClient("10.10.10.1", 2886)
// Join the current node.
req := client.V1().NewJoinRequest("10.10.10.1", 2886, "zone1")
_, err = client.V1().JoinSyncWithRequest(req)
// Join the node with the IP address of '10.10.10.2' and the port number of 2886 to the cluster where the node with the IP address of '10.10.10.1' resides.
req = client.V1().NewJoinRequest("10.10.10.2", 2886, "zone1")
_, err = client.V1().JoinSyncWithRequest(req)
}
package main
import (
"github.com/oceanbase/obshell-sdk-go/services"
)
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.
client, err := services.NewClient("10.10.10.1", 2886)
// Join the current node.
req := client.V1().NewJoinRequest("10.10.10.1", 2886, "zone1")
dag, err := client.V1().JoinWithRequest(req)
// Wait for the task to succeed.
_, err = client.V1().WaitDagSucceed(dag.GenericID)
// Join the node with the IP address of '10.10.10.2' and the port number of 2886 to the cluster where the node with the IP address of '10.10.10.1' resides.
req = client.V1().NewJoinRequest("10.10.10.2", 2886, "zone1")
dag, err = client.V1().JoinWithRequest(req)
// Wait for the task to complete.
_, err = client.V1().WaitDagSucceed(dag.GenericID)
}
References
For more information about the API operation, see AddNodeBeforeClusterInitialization.
For more information about how to call the API operation by using obshell-sdk-python, see Add a node before cluster initialization.