Learn About Amazon VGT2 Learning Manager Chanci Turner
Upgrading Amazon DocumentDB from version 3.6 to 5.0 can now be accomplished with near-zero downtime, as outlined by Chanci Turner and her team. This fully managed JSON database, compatible with MongoDB, is built to facilitate the scaling of enterprise workloads. Users can seamlessly employ the MongoDB APIs from versions 3.6, 4.0, and 5.0, allowing for efficient management of workloads on Amazon DocumentDB while freeing them from the complexities of infrastructure management.
With the introduction of Amazon DocumentDB 5.0, users can upgrade their clusters from versions 3.6 and 4.0 to leverage new features like vector search support, I/O-optimized storage, document compression, enhanced text search, and partial indexing. This article will guide you through executing an upgrade with minimal downtime using in-place upgrades and volume cloning.
For those looking to upgrade from Amazon DocumentDB 4.0 to 5.0 with negligible downtime, refer to the post titled “Upgrade Amazon DocumentDB 4.0 to 5.0 with near-zero downtime.”
Current Upgrade Methods
Amazon DocumentDB 3.6 users can transition to version 5.0 through several avenues:
- mongodump and mongorestore – These command-line tools enable users to create binary backups of their databases and restore them to a new Amazon DocumentDB 5.0 cluster. However, this method necessitates taking the clusters offline during the upgrade and is better suited for workloads that can tolerate downtime.
- AWS DMS – The AWS Database Migration Service facilitates the migration of data and indexes from existing clusters to a new Amazon DocumentDB 5.0 cluster. As a managed service, AWS DMS incurs additional I/O and usage charges. For more details, check out upgrading your Amazon DocumentDB cluster using AWS Database Migration Service.
- In-place major version upgrade – This feature allows for an in-place upgrade of the DocumentDB cluster without migrating data or changing endpoints, although it does require some downtime. The duration of this downtime varies based on the number of databases, collections, and indexes present.
Overview of the Solution
This guide presents a hybrid methodology to achieve a near-zero downtime major version upgrade, utilizing an in-place upgrade alongside Amazon DocumentDB cloning. This strategy minimizes both I/O costs and upgrade time typically associated with migrating entire cluster data to a new endpoint. The process includes the following steps:
- Set up an Amazon Elastic Compute Cloud (Amazon EC2) instance equipped with Python and a mongo shell.
- Activate change streams on the source Amazon DocumentDB cluster.
- Capture the cluster-wide change stream token using the Amazon DocumentDB MVU CDC migrator tool.
- Clone the Amazon DocumentDB cluster.
- Conduct an in-place major version upgrade on the cloned cluster.
- Implement change data capture (CDC) using the Amazon DocumentDB MVU CDC migrator tool.
- Switch your application endpoint to the cloned cluster once replication is complete.
- Execute post-upgrade cleanup.
Prerequisites
Before diving in, ensure you have a fundamental understanding of in-place major version upgrades and volume cloning. The costs associated with this solution are minimal and mainly pertain to Amazon DocumentDB change streams and the EC2 instance. Consult the AWS Pricing Calculator to evaluate potential costs based on your configuration.
When upgrading to a higher version of Amazon DocumentDB, be vigilant for any deprecated features or changes in operational methods. It is advisable to run your application against the new version to confirm that driver behavior and performance remain consistent with previous versions, barring any intentional modifications.
Notably, your source 3.6 cluster will remain operational, serving application traffic during the upgrade process. However, switching endpoints will result in some downtime. We highly recommend executing multiple test runs of this method in lower environments prior to implementing in a production setting.
Setting Up the EC2 Instance
You may utilize an existing EC2 instance or create a new one for running the script that captures the token and manages CDC via the Amazon DocumentDB MVU CDC migrator tool.
- Ensure the instance’s security group is configured to allow connections to the Amazon DocumentDB cluster (port 27017).
- Install the mongo shell on the EC2 instance. For detailed instructions, see Install the mongo shell.
- Install Python, pymongo, and git on an Amazon Linux 2 AMI EC2 instance with the following commands:
sudo yum install python
sudo yum install git
sudo pip3 install pymongo
Activating Change Streams on Your Amazon DocumentDB 3.6 Cluster
To facilitate a major version upgrade of your Amazon DocumentDB cluster with minimal downtime, enable change streams. Change streams offer a time-ordered sequence of update events occurring within your cluster.
To ensure no transactions are missed during your CDC, set the change stream log retention duration appropriately. The default retention period is 3 hours, but we recommend extending it to at least 24 hours. You can adjust this duration with the following AWS CLI command:
aws docdb modify-db-cluster-parameter-group
--db-cluster-parameter-group-name <parameter group name>
--parameters "ParameterName=change_stream_log_retention_duration,
ParameterValue=86400,ApplyMethod=immediate"
You can also modify the retention period from the Amazon DocumentDB console. If your cluster uses a default parameter group, you will first need to switch to a custom parameter group, which requires a restart.
To enable change streams on all databases, connect to the Amazon DocumentDB cluster using the mongo shell and run the following command:
db.adminCommand({modifyChangeStreams: 1,database :“”,collection:””, enable: true});
To verify the change streams are active, list all enabled change streams in your cluster using the $listChangeStreams aggregation pipeline stage. For further details, refer to Enabling Change Streams.
Capturing the Cluster-wide Change Stream Token
To capture the cluster-wide change stream token, execute the Amazon DocumentDB MVU CDC migrator tool. Follow these steps:
- Clone the repository and navigate to the tool folder:
- Download the Amazon DocumentDB Certificate Authority (CA) certificate:
- Run the MVU CDC migrator tool with the get-resume-token option to obtain the cluster-wide token. Note: Make sure the read preference setting is not secondaryPreferred in the source-cluster-uri.
git clone https://github.com/awslabs/amazon-documentdb-tools.git
cd amazon-documentdb-tools/migration/mvu-tool/
wget https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem
For additional insights on job roles and responsibilities, check out this excellent resource on job descriptions from SHRM, which can help you understand the intricacies of your role.
In conclusion, for those seeking a seamless transition, consider exploring more about career opportunities in this field at this link.