Managing cluster shards
You can add and remove cluster shards, request a list of shards in the selected cluster, and rebalance your cluster.
Warning
You can only manage shards in sharded clusters.
You can create a sharded cluster or enable sharding in an existing non-sharded cluster.
Listing shards in a cluster
- In the management console
, select the folder with the cluster you need. - Select Managed Service for Redis.
- Click the name of the cluster you need and select the Shards tab.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To get a list of shards in a cluster, run the following command:
yc managed-redis shards list --cluster-name <cluster_name>
Result:
+--------------+
| NAME |
+--------------+
| test-shard-1 |
| test-shard-2 |
| test-shard-3 |
+--------------+
To get a list of cluster shards, use the listShards REST API method for the Cluster resource or the ClusterService/ListShards gRPC API call and provide the cluster ID in the clusterId
request parameter.
You can request the cluster ID and name with a list of clusters in the folder.
Getting detailed information about a shard
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To get information about a shard, run the following command:
yc managed-redis shards get <shard_name> --cluster-name <cluster_name>
To get shard details, use the getShard REST API method for the Cluster resource or the ClusterService/GetShard gRPC API call and provide the following in the request:
- Cluster ID in the
clusterId
parameter. - Shard name in the
shardName
parameter.
You can request the shard name with a list of cluster shards and the cluster name with a list of clusters in a folder.
Creating a shard
For clusters with the local-ssd disk type, the minimum allowed number of hosts per shard is two.
To add a shard:
- Go to the folder page
and select Managed Service for Redis. - Click the cluster name and go to the Shards tab.
- Click Create shard.
- Specify Shard name.
- Under Hosts:
- (Optional) Edit the host settings.
- Click Add host.
- In the Availability zone field, choose the availability zone, select Subnet, and enable the Public access option.
- Click Create shard.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
View a description of the CLI command for adding a shard:
yc managed-redis shards add --help
To create a shard of two hosts, one with public access and the other with a host priority of 50
, run this command:
yc managed-redis shards add --name=<new_shard_name> \
--cluster-name=<cluster_name> \
--host zone-id=<availability_zone>,`
`subnet-name=<subnet_name>,`
`assign-public-ip=true \
--host zone-id=<availability_zone>,`
`subnet-name=<subnet_name>,`
`replica-priority=50
To add a shard:
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Add the required number of
host
sections to the Managed Service for Redis cluster description and specify the shard name in theshard_name
parameter:resource "yandex_mdb_redis_cluster" "<cluster_name>" { ... host { zone = "<availability_zone>" subnet_id = <subnet_ID> assign_public_ip = <public_access> replica_priority = <host_priority> shard_name = "<shard_name>" } }
Where
assign_public_ip
is public access to the host,true
orfalse
. -
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
Time limits
A Terraform provider sets the timeout for Managed Service for Redis cluster operations:
- Creating a cluster, including by restoring one from a backup: 15 minutes.
- Editing a cluster: 60 minutes.
- Deleting a cluster: 15 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
resource "yandex_mdb_redis_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
To create a shard, use the addShard REST API method for the Cluster resource or the ClusterService/AddShard gRPC API call and provide the following in the request:
- Cluster ID in the
clusterId
parameter. - Shard name in the
shardName
parameter. - Shard host configuration in the array of
hostSpecs
parameters.
You can request the shard name with a list of cluster shards and the cluster name with a list of clusters in a folder.
To be able to place data in the new shard, start rebalancing the Managed Service for Redis cluster.
Deleting a shard
Alert
- All the shard hosts are deleted with the shard.
- If a cluster has two or three shards, use the CLI, Terraform, or API to delete a shard.
- In the management console
, go to the folder containing the cluster to delete the shard from. - Select Managed Service for Redis.
- Click the cluster name and open the Shards tab.
- In the line with the shard, click
and select Delete. - In the window that opens, click Remove.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To delete a shard from the cluster, run:
yc managed-redis shards delete <shard_name> \
--cluster-name=<cluster_name>
You can request the shard name with a list of cluster shards and the cluster name with a list of clusters in a folder.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Delete all shard-related
host
blocks from the Managed Service for Redis cluster description. -
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Type
yes
and press Enter.-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
Time limits
A Terraform provider sets the timeout for Managed Service for Redis cluster operations:
- Creating a cluster, including by restoring one from a backup: 15 minutes.
- Editing a cluster: 60 minutes.
- Deleting a cluster: 15 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
resource "yandex_mdb_redis_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
To delete a shard, use the deleteShard REST API method for the Cluster resource or the ClusterService/DeleteShard gRPC API call and provide the following in the request:
- Cluster ID in the
clusterId
parameter. - Name of the shard you are deleting in the
shardName
parameter.
You can request the shard name with a list of cluster shards and the cluster name with a list of clusters in a folder.
Rebalancing a cluster
New shards are created without hash slots and can't accept data. To begin populating a new shard with data, rebalance the cluster to allocate some of its hash slots to the new shard. The cluster will move the data in the reassigned hash slots to the appropriate shard. Rebalancing can be performed on a running cluster and does not affect data availability or integrity.
For more information, see Scalability.
To rebalance a cluster:
- In the management console
, select the folder with the cluster you need. - Select Managed Service for Redis.
- Click the cluster name.
- In the Overview tab, click Rebalance.
Tip
You can also rebalance a cluster using the Rebalance cluster button on the Shards tab.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To rebalance a cluster, run the command below:
yc managed-redis cluster rebalance \
--name=<cluster_name>
You can request the cluster name with the list of clusters in the folder.
To rebalance a cluster, use the rebalance REST API method for the Cluster resource or the ClusterService/Rebalance gRPC API call.