Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating Redis to AWS Elasticache with minimal downtime

Let's start by listing some facts:

  • Elasticache can't be a slave of my existing Redis setup. Real shame, that would be so much more efficent.
  • I have only one Redis server to migrate, with roughly 3gb of data.
  • Downtime must be less than 10 mins. I assume the usual "stop the site, stop redis, provision cluster with snapshot" will take longer than this.

Similar to this question: How do I set an elasticache redis cluster as a slave?

One idea on how this might work:

  1. Set Redis to use an AOF and trigger BGSAVE at the same time.
  2. When BGSAVE finishes, provision the Elasticache cluster with RDB seed.
  3. Stop the site and shut down my local Redis instance.
  4. Use an aof-replay tool to replay the AOF into Elasticache.
  5. Start the site again, pointed at the Elasticache cluster.

My questions:

  1. How can I guarantee that my AOF file begins at exactly the point the RDB file ends, and that no data will be written in between?
  2. Is there an AOF tool supported by the maintainers of Redis, or are they all third-party solutions, and therefore (potentially) of questionable reliability?*

* No offence intended to any authors of such tools, I'm sure they're great, I just feel much more confident using a tool written by the same team as the product to avoid potential compatibility bugs.

like image 451
arrtchiu Avatar asked Jun 13 '16 10:06

arrtchiu


People also ask

How do I transfer Redis data to ElastiCache?

Navigate to the Amazon EC2 console and find the instance that is hosting your Redis cluster. Copy the Private IPs value and save it for the next step. Navigate to the ElastiCache console to begin your online migration. Choose your ElastiCache cluster, and then choose Migrate Data from Endpoint in the Actions dropdown.

Is ElastiCache High Availability?

With the growth of business-critical, real-time use cases on Redis, ensuring availability becomes an important consideration. To provide high availability, Amazon ElastiCache for Redis supports Redis Cluster configuration, which delivers superior scalability and availability.

What is the benefit of enabling multi AZ with auto failover in ElastiCache Redis?

Using ElastiCache for Redis replication together with Multi-AZ and automatic failover provides increased availability and fault tolerance. If automatic failover is turned off, you can manually failover from one Availability Zone to another.

What happens when ElastiCache Redis runs out of memory?

ElastiCache for Redis implements the maxmemory-policy that's set for the cache node's parameter group when out of memory. The default value (volatile-lru) frees up memory by evicting keys with a set expiration time (TTL value). When a cache node doesn't have any keys with a TTL value, it returns an error instead.


2 Answers

ElastiCache has online migration support. You can use the start-migration API to start migration from self managed cluster to ElastiCache cluster.

aws elasticache start-migration --replication-group-id <ElastiCache Replication Group Id> --customer-node-endpoint-list "Address='<IP Address>',Port=<Port>"

The input to the API is your ElastiCache replication group id and the IP and port of the master of your self managed cluster. You need to ensure that the IP address is accessible from ElastiCache node. (An example IP address would be the private IP address of the master of your self managed cluster). This API will make the master node of the ElastiCache cluster call 'SLAVEOF' on the master of your self managed cluster. This will establish a replication stream and will start migrating data from self-managed cluster to ElastiCache cluster. During migration, the master of the ElastiCache cluster will stop accepting writes sent to it directly. You can start using ElastiCache cluster from your application for reads.

Once you have all your data in ElastiCache cluster, you can use the complete-migration API to stop the migration. This API will stop the replication from self managed cluster to ElastiCache cluster.

aws elasticache complete-migration --replication-group-id <ElastiCache Replication Group Id>

After this, the master of the ElastiCache cluster will start accepting writes. You can start using ElastiCache cluster from your application for both read and write.

The following limitations to be aware of for this migration method:

  • An existing or newly created ElastiCache deployment should meet the following requirements for migration:
  • It's cluster-mode disabled using Redis engine version 5.0.5 or higher.
  • It doesn't have either encryption in-transit or encryption at-rest enabled.
  • It has Multi-AZ with Auto-Failover enabled.
  • It has sufficient memory available to fit the data from your Redis on EC2 instance. To configure the right reserved memory settings, see Managing Reserved Memory.
like image 138
Gourav Roy Avatar answered Sep 18 '22 13:09

Gourav Roy


I have only one Redis server to migrate, with roughly 3gb of data

I would halt, save the REDIS to S3 and then upload it to a new cluster.

I'm guessing 10 mins to save the file and get it into s3.
10 minutes to just launch an elasticache cluster from that data. Leaves you ten extra minutes to configure and test.

But there is a simple way of knowing EXACTLY how long. Do a test migration of it.

  1. DONT stop your live system
  2. Run BGSAVE and get a dump of your Redis (leave everything running as normal)
  3. move the dump S3
  4. launch an elasticache cluster for it.

Take DETAILED notes, TIME each step, copy the commands to a notepad window.

Put a Word/excel document so you have a migration document. That way you know how long it takes and there are no surprises. Let us know how it goes.

like image 24
greg_diesel Avatar answered Sep 21 '22 13:09

greg_diesel