obshell supports expanding a tenant in the following two ways:
Call an API to expand a tenant.
Use obshell commands to expand a tenant.
This topic describes how to expand a tenant (from 3 replicas to 5 replicas) in an OceanBase cluster with obshell.
Note
In this topic, expanding a tenant refers to adding a tenant replica.
Prerequisites
The OceanBase cluster is managed by obshell. For more information, see Take over a non-obshell-deployed cluster.
All OBServer nodes of the OceanBase cluster and obshell are running.
Deployment mode
The following table describes the deployment mode of the three servers (obshell uses the default port 2886) in this example:
| Role | Server | Remarks |
|---|---|---|
| OBServer node | 10.10.10.1 | Zone 1 of OceanBase Database |
| OBServer node | 10.10.10.2 | Zone 2 of OceanBase Database |
| OBServer node | 10.10.10.3 | Zone 3 of OceanBase Database |
| OBServer node for expansion | 10.10.10.4 | Zone 4 of OceanBase Database |
| OBServer node for expansion | 10.10.10.5 | Zone 5 of OceanBase Database |
Expand a tenant by calling an API
Note
obshell performs security verification on the called API. Therefore, you must encrypt the request before you call the API and configure the encrypted request header (${request_headers}) and request body (${request_body}) in the curl command. For more information, see API hybrid encryption.
Step 1: Expand the cluster
Follow the steps in Expand an OceanBase cluster to expand 10.10.10.4 to zone4 and 10.10.10.5 to zone5.
Step 2: Add a tenant replica
Call the POST /api/v1/tenant/:name/replicas API of any obshell to expand the tenant1 tenant.
For more information about how to call this API, see Add a tenant replica. This API creates an asynchronous task. For more information about how to query the task progress, see Get task details. Wait for the task to complete, and then the expansion of the tenant replica is completed.
[admin@test001 ~]$ curl -H "Content-Type: application/json" -H 'X-OCS-Header:${request_headers}' -X POST -d '${request_body}' http://10.10.10.1:2886/api/v1/tenant/tenant1/replicas
The request body before encryption is as follows. unit_1 is the resource specification of the tenant1 tenant. If you want to create a new resource unit, see Step 1: Create a resource specification in Create a tenant.
{
"zone_list": [
{
"name": "zone4",
"unit_config_name": "unit_1",
"unit_num": 1
},
{
"name": "zone5",
"unit_config_name": "unit_1",
"unit_num": 1
}
]
}
For more information about how to request the API method, see Add a tenant replica.
...
client = ClientSet("10.10.10.1", 2886, PassswordAuth("****"))
client.v1.add_tenant_replica_sync("tenant1", [ZoneParam("zone4", 'unit_1', 1),
ZoneParam("zone5", 'unit_1', 1))
...
For more information about how to request the API method, see Add a tenant replica.
...
req := client.V1().NewScaleOutReplicasRequest("tenant1", []v1.ZoneParam{
{
Name: "zone4",
ReplicaType: "FULL",
UnitConfigName: "unit_1",
UnitNum: 1,
},
{
Name: "zone5",
ReplicaType: "FULL",
UnitConfigName: "unit_1",
UnitNum: 1,
},
})
if _, err = client.V1().ScaleOutReplicasSyncWithRequest(req); err != nil {
fmt.Print(err)
}
...
Step 3: Query tenant information
Call the GET /api/v1/tenant/:name API of any obshell to query the information of the expanded tenant.
For more information about how to call this API, see Query tenant information.
[admin@test001 ~]$ curl -H "Content-Type: application/json" -H 'X-OCS-Header:${request_headers}' -X GET http://10.10.10.1:2886/api/v1/tenant/tenant1
For more information about how to request the API method, see Query tenant information.
...
client = ClientSet("10.10.11", 2886, PasswordAuth("****"))
tenant_info = client.v1.get_tenant_info("tenant1")
...
For more information about how to request the API method, see Query tenant information.
...
client, err := services.NewClientWithPassword("10.10.10.1", 2886, "****")
tenant, err := client.V1().GetTenantInfo("tenant1")
...
Expand a tenant by using obshell commands
Step 1: Expand the cluster
Follow the steps in Expand an OceanBase cluster to expand 10.10.10.4 to zone4 and 10.10.10.5 to zone5.
Step 2: Add a tenant replica
Run the following command on any node to add a replica of the tenant1 tenant to zone4 and zone5. For more information about the command, see obshell tenant replica add.
[admin@test001 ~]$ /home/admin/oceanbase/bin/obshell tenant replica add tenant1 -z zone4,zone5 -u unit_1
In the preceding example, unit_1 is the resource specification of the tenant1 tenant. Configure it based on your actual situation. If you want to create a new resource unit, see Step 1: Create a resource specification in Create a tenant.
Step 3: Query tenant information
Run the following command on any node to query the information of the specified tenant. For more information about the command, see obshell tenant show.
[admin@test001 ~]$ /home/admin/oceanbase/bin/obshell tenant show tenant1