Help Center/ Distributed Cache Service/ API Reference/ Examples/ Common Issues of Creating DCS Instances Using an API
Updated on 2024-03-05 GMT+08:00

Common Issues of Creating DCS Instances Using an API

This topic describes common issues that may occur when you create DCS instances using APIs.

Table 1 Common issues of creating DCS instances

Issue

Solution

Setting the Replica Quantity When Purchasing an Instance Using an API

If an instance is purchased using an API, its replica quantity is determined by the spec_code parameter specified during the purchase. The replica quantity is the value of replica_count in the example response provided in Querying Product Flavors.

Obtaining the Subnet ID

Use an API to obtain the correct subnet ID when creating an instance.

Insufficient AZ Resources During Instance Purchase

If resources in an AZ are insufficient, instance creation in the AZ will fail. You can use the value of flavors_available_zones.az_codes to ensure that the AZ you use has sufficient resources, as shown in the example response in Querying Product Flavors.

Querying Resource Quotas

Call the API described in Querying the Tenant Quotas. The value of quota indicates the maximum number of instances that can be created and the maximum allowed total memory.

Setting the Replica Quantity When Purchasing an Instance Using an API

If an instance is purchased using an API, its replica quantity is determined by the spec_code parameter specified during the purchase. The number of replicas is the value of replica_count in the example response of the Querying Product Flavors API.

Example request:

GET https://{dcs_endpoint}/v2/flavors?cache_mode={cache_mode}&engine={engine}&engine_version={engine_version}&cpu_type={cpu_type}&capacity={capacity}

Example response:

{
 "flavors": [
  {
   "dec": false,
   "spec_code": "redis.ha.xu1.large.r4.2",
   "cloud_service_type_code": "hws.service.type.dcs",
   "cloud_resource_type_code": "hws.resource.type.dcs3",
   "cache_mode": "ha",
   "engine": "redis",
   "engine_version": "4.0;5.0",
   "product_type": "generic",
   "cpu_type": "x86_64",
   "storage_type": "DRAM",
   "capacity": [
    "2"
   ],
   "billing_mode": [
    "Hourly",
    "Monthly",
    "Yearly"
   ],
   "tenant_ip_count": 4,
   "pricing_type": "normal",
   "is_dec": false,
   "attrs": [
    {
     "capacity": "2",
     "name": "max_memory",
     "value": "2"
    },
    {
     "capacity": "2",
     "name": "max_connections",
     "value": "50000"
    },
    {
     "capacity": "2",
     "name": "sharding_num",
     "value": "1"
    },
    {
     "capacity": "2",
     "name": "proxy_num",
     "value": "0"
    },
    {
     "capacity": "2",
     "name": "db_number",
     "value": "256"
    },
    {
     "capacity": "2",
     "name": "max_clients",
     "value": "10000"
    },
    {
     "capacity": "2",
     "name": "max_bandwidth",
     "value": "128"
    }
   ],
   "flavors_available_zones": [
    {
     "capacity": "2",
     "unit": "GB",
     "available_zones": [
      "a0865121f83b41cbafce65930a22a6e8",
      "15dcd3f789cb4fc088dbdece9c5eb547",
      "2dcb154ac2724a6d92e9bcc859657c1e",
      "effdcbc7d4d64a02aa1fa26b42f56533"
     ],
     "az_codes": [
      "xx-xx-xx1",
      "xx-xx-xx2",
      "xx-xx-xx3",
      "xx-xx-xx4"
     ]
    }
   ],
   "replica_count": 4,
   "inquery_spec_code": null
  }
 ]
}

When purchasing an instance, ensure that the value of spec_code corresponds to the value of capacity.

Obtaining the Subnet ID

When purchasing an instance, configure the correct subnet ID so that you can successfully connect to the instance. You can obtain the subnet ID using GET /v1/{project_id}/subnets?{vpc_id}. vpc_id can be obtained using the GET /v1/{project_id}/vpcs API.

Example request for obtaining vpc_id:

GET https://{vpc_endpoint}/v1/7d80ae32f57b499eb8781f9a9f57c538/vpcs

To obtain the value of {vpc_endpoint}, see Regions and Endpoints.

Example response for obtaining vpc_id:

{
	"vpcs": [{
		"id": "743bf021-2c2d-4511-aeac-85bd48c06af7",
		"name": "vpc-d2d4",
		"description": "",
		"cidr": "192.168.0.0/16",
		"status": "OK",
		"routes": [],
		"enterprise_project_id": "0"
	}]
}

Example request for obtaining the subnet ID:

GET https://{vpc_endpoint}/v1/7d80ae32f57b499eb8781f9a9f57c538/subnets?vpc_id=743bf021-2c2d-4511-aeac-85bd48c06af7

Example response for obtaining the subnet ID:

{
	"subnets": [{
		"id": "b0d6e0ac-fcce-4e11-a4a6-707e851ae1c3",
		"name": "subnet-d2e4",
		"description": "",
		"cidr": "192.168.0.0/24",
		"dnsList": ["100.125.1.250",
		"100.125.129.250"],
		"status": "ACTIVE",
		"vpc_id": "743bf021-2c2d-4511-aeac-85bd48c06af7",
		"ipv6_enable": false,
		"gateway_ip": "192.168.0.1",
		"dhcp_enable": true,
		"primary_dns": "100.125.1.250",
		"secondary_dns": "100.125.129.250",
		"availability_zone": "xxxxxx",
		"neutron_network_id": "b0d6e0ac-fcce-4e11-a4a6-707e851ae1c3",
		"neutron_subnet_id": "3d4ccce0-cadc-4af4-8c21-14d2857ffe5e",
		"extra_dhcp_opts": []
	}]
}

Insufficient AZ Resources During Instance Purchase

When purchasing an instance, if you want to check whether resources of a flavor are sufficient in an AZ, you can call the API described in Querying Product Flavors to view details about the AZs where the flavor is available and determine the AZs that can be used based on the value of flavors_available_zones.

The following is an example request for querying AZs with sufficient resources for flavor redis.ha.xu1.large.r2.2 in a region:

https://{dcs_endpoint}/v2/05041fffa40025702f6dc009cc6f8f33/flavors?spec_code=redis.ha.xu1.large.r2.2

Example response:

{
 "flavors": [
  {
   "dec": false,
   "spec_code": "redis.ha.xu1.large.r2.2",
   "cloud_service_type_code": "hws.service.type.dcs",
   "cloud_resource_type_code": "hws.resource.type.dcs3",
   "cache_mode": "ha",
   "engine": "redis",
   "engine_version": "4.0;5.0",
   "product_type": "generic",
   "cpu_type": "x86_64",
   "storage_type": "DRAM",
   "capacity": [
    "2"
   ],
   "billing_mode": [
    "Hourly",
    "Monthly",
    "Yearly"
   ],
   "tenant_ip_count": 2,
   "pricing_type": "normal",
   "is_dec": false,
   "attrs": [
    {
     "capacity": "2",
     "name": "max_memory",
     "value": "2"
    },
    {
     "capacity": "2",
     "name": "max_connections",
     "value": "50000"
    },
    {
     "capacity": "2",
     "name": "sharding_num",
     "value": "1"
    },
    {
     "capacity": "2",
     "name": "proxy_num",
     "value": "0"
    },
    {
     "capacity": "2",
     "name": "db_number",
     "value": "256"
    },
    {
     "capacity": "2",
     "name": "max_clients",
     "value": "10000"
    },
    {
     "capacity": "2",
     "name": "max_bandwidth",
     "value": "128"
    }
   ],
   "flavors_available_zones": [
    {
     "capacity": "2",
     "unit": "GB",
     "available_zones": [
      "a0865121f83b41cbafce65930a22a6e8",
      "15dcd3f789cb4fc088dbdece9c5eb547",
      "2dcb154ac2724a6d92e9bcc859657c1e",
      "effdcbc7d4d64a02aa1fa26b42f56533"
     ],
     "az_codes": [
      "xx-xx-xx1",
      "xx-xx-xx2",
      "xx-xx-xx3",
      "xx-xx-xx4"
     ]
    }
   ],
   "replica_count": 2,
   "inquery_spec_code": null
  }
 ]
}

flavors_available_zones indicates the AZs with sufficient resources for the flavor.

Querying Resource Quotas

To query the resource quotas of the current account, including the used quotas, call the API described in Querying the Tenant Quotas.

Example request:

GET https://{dcs_endpoint}/v2/05041fffa40025702f6dc009cc6f8f33/quota

Example response:

{
 "quotas": {
  "resources": [
   {
    "quota": 160,
    "used": 1,
    "type": "instance",
    "min": 0,
    "max": 2147483647,
    "unit": null
   },
   {
    "quota": 64000,
    "used": 0,
    "type": "ram",
    "min": 0,
    "max": 1048576,
    "unit": "GB"
   }
  ]
 }
}
  • When type is set to instance, max and min indicate the maximum and minimum instance quotas that can be applied for, respectively.
  • When type is set to ram, max and min indicate the maximum and minimum memory quotas that can be applied for, respectively.
  • quota is the maximum number of instances that can be created and the maximum allowed total memory.
  • used is the number of created instances and used memory.