ElastiCache 集群模式轉換 — Cluster Mode Modification (CMD to CME migration)

ElastiCache 提供的新功能,允許使用者直接轉換 Cluster mode 從 Disabled 轉換到 Enabled,在這個功能上線前,只能透過備份後重建的方式,來達到這個目的。

Jerry’s Notes
What’s next?
4 min readMay 19, 2023

--

如果您不清楚 Cluster mode Enabled 跟 Disabled 的差別,請先閱讀: Redis cluster mode and Key distribution

[+] Modifying cluster mode — https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/modify-cluster-mode.html

Cluster mode enabled (CME) and cluster mode disabled (CMD). In CME, Redis works as a distributed database with multiple shards and nodes, while in CMD, Redis works as a single node.

Modify Cluster Configuration to cluster mode compatible — In this mode, there will be a single shard deployed, and ElastiCache for Redis will work as a single node but also as a single shard cluster. Compatible mode means the client application can use either protocol to communicate with the cluster. In this mode, applications must be reconfigured to start using Redis Cluster protocol and configuration endpoint.

優點

1) 在 cluster-mode = compatible 模式下,同時提供 configuration endpoint 及 primary/reader endpoint。
2) Redis Client 可以在 compatible 模式下,去調整代碼改在 cluster-mode,並且不影響當前的連行。
3) 當 Redis Client 完成代碼調整後,再去調整 cluster-mode = enabled 後,再報增加 shards 數量,來滿足效能需求。

限制與功能

1) 功能: 同時支援 CMD | CMD Redis client。

  • Applications must use a Redis client that is capable of using Cluster protocol and use a configuration endpoint.

2) 功能: 同時提供 primary | reader endpoint | 也提供 configuration endpoint。

3) 限制: 只能有一個 db0 (Redis Cluster 原生的限制)。

  • The cluster may only have keys in database 0 only.

[+] Redis cluster specification | Redis:
https://redis.io/docs/reference/cluster-spec/

Redis Cluster does not support multiple databases like the standalone version of Redis. We only support database 0; the SELECT command is not allowed.

4) 限制: Auto-failover 必需開啟,代表至少要有1個從節點。

  • Auto-failover must be enabled on the cluster with a minimum of 1 replica.

Single node Redis cluster, or auto-failover disable.

$ aws elasticache modify-replication-group — replication-group-id cmd — cluster-mode compatible — apply-immediately

Cluster mode updates are not supported for clusters without replicas or with auto-failover disabled.

5) 限制: Redis 7 以上的版本才支援。

  • The minimum Redis engine version required for migration is 7.0.

$ aws elasticache modify-replication-group — replication-group-id cmd — cluster-mode compatible — apply-immediately

An error occurred (InvalidParameterValue) when calling the ModifyReplicationGroup operation: Modifying cluster mode is available when using Redis version 6.0 and above.

6) 限制: 只能從 Cluster mode disable (CMD) 轉換至 Cluster mode disable (CME),反過來不行。

  • Cluster mode configuration can only be changed from cluster mode disabled to cluster mode enabled. Reverting this configuration is not possible.
  • CME → CMD (x)
  • CMD → CME (yes)

7) 限制: 調成 CME — Cluster Mode Enabled 後,不能轉回到 compatible。

$ aws elasticache modify-replication-group — replication-group-id cmd — cluster-mode compatible — apply-immediately

An error occurred (InvalidParameterValue) when calling the ModifyReplicationGroup operation: Disabling cluster mode is not supported

8) 限制:不能直接轉成 “cluster-mode enabled” 的狀態,必需先轉成 cluster-mode compatible,才能轉成 enabled,轉換的動作要兩次。

$ aws elasticache modify-replication-group — replication-group-id cmd — cluster-mode enabled — apply-immediately

An error occurred (InvalidParameterValue) when calling the ModifyReplicationGroup operation: Cluster mode must first be set to ‘compatible’

9) 限制: 只能有一個 shard
!!! 在 compatible 狀態下,加 shard 會失敗。

$ aws elasticache modify-replication-group-shard-configuration \
— replication-group-id cmd \
— node-group-count 2 \
— apply-immediately

An error occurred (InvalidParameterValue) when calling the ModifyReplicationGroupShardConfiguration operation: Operation is only applicable for cluster mode enabled replication groups

10) ElastiCache Console & AWS CLI : modify-replication-group

  • ElastiCache Console 上的畫面。
  • AWS CLI : modify-replication-group

[+] modify-replication-group — https://docs.aws.amazon.com/cli/latest/reference/elasticache/modify-replication-group.html
— cluster-mode compatible

— replication-group-id
— cluster-mode disabled | compatible | enabled ←- !!!
— cache-parameter-group-name
— no-verify-ssl
— apply-immediately
— endpoint-url

$ aws elasticache modify-replication-group — replication-group-id cmd — cluster-mode enabled — apply-immediately
>> Primary endpoint and Reader endpoint 會被清掉。

$ aws elasticache modify-replication-group — replication-group-id cmd — cluster-mode compatible — apply-immediately
An error occurred (InvalidParameterValue) when calling the ModifyReplicationGroup operation: Disabling cluster mode is not supported
>> 調成 CME 後,不能轉回到 compatible。

--

--

Jerry’s Notes
What’s next?

An cloud support engineer focus on troubleshooting with customer reported issue ,and cloud solution architecture.