Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dynamodb): add option to skip waiting for global replication to finish #16983

Merged
merged 3 commits into from
Oct 15, 2021

Conversation

TheSPD
Copy link
Contributor

@TheSPD TheSPD commented Oct 14, 2021

Motivation - On large tables, replication takes long time to complete. CloudFormation has a hard timeout of 1 hour on the Custom Resources, to bypass this, we want to have the replication continue in background based on a property.

Fixes #16611


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Oct 14, 2021

@mergify
Copy link
Contributor

mergify bot commented Oct 14, 2021

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@TheSPD TheSPD changed the title feature(aws-dynamodb): delegate replica creation to background feat(aws-dynamodb): delegate replica creation to background Oct 14, 2021
@TheSPD TheSPD force-pushed the feature-dynamodb-background-replica branch from 98c73b8 to ca08007 Compare October 14, 2021 18:20
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @TheSPD! Looks fine overall, I have a couple of minor comments though.

Comment on lines 235 to 241
* Whether Asynchronous Replication is enabled. If enabled, the
* CloudFormation resource will not wait for replication operation to be
* completed.
* DO NOT USE this for adding multiple replication regions in one deployment,
* as CloudFormation only supports one region replication at a time.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These docs need some work I think.

  1. The first sentence doesn't really say anything.
  2. It doesn't mention that it's related to the replicationRegions property, and is ignored if that property is not set.
  3. Not sure I understand what you mean by the warning...? Each region gets its own Custom Resource, so what's the problem in enabling it with multiple regions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree on 1 and 2 will add that;

On 3
I'm referring to this.

the current code bypasses this by adding some CFnCondition magic over the replicas(if multiple).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's reword that section a little bit then, and link to that document.

*
* @default false
*/
readonly asynchronousReplicationEnabled?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I love the name. How about waitForReplicationToFinish?: boolean, default true?

@@ -49,12 +49,13 @@ export async function isCompleteHandler(event: IsCompleteRequest): Promise<IsCom
const replicas = data.Table?.Replicas ?? [];
const regionReplica = replicas.find(r => r.RegionName === event.ResourceProperties.Region);
const replicaActive = !!(regionReplica?.ReplicaStatus === 'ACTIVE');
const asynchronousReplicationEnabled = event.ResourceProperties.AsynchronousReplicationEnabled;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's turn this into a negative, so that it's not enabled by default. So, let's call the property something like SkipReplicationCompletedWait, and it will be false if undefined. Even better, let's make the false case explicit:

Suggested change
const asynchronousReplicationEnabled = event.ResourceProperties.AsynchronousReplicationEnabled;
const skipReplicationCompletedWait = event.ResourceProperties.SkipReplicationCompletedWait ?? false;

@@ -1524,6 +1535,7 @@ export class Table extends TableBase {
properties: {
TableName: this.tableName,
Region: region,
AsynchronousReplicationEnabled: asynchronousReplicationEnabled || false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not do any defaulting here. This way, the existing templates will be unchanged.

Suggested change
AsynchronousReplicationEnabled: asynchronousReplicationEnabled || false,
SkipReplicationCompletedWait: waitForReplicationToFinish === undefined ? undefined : !waitForReplicationToFinish,

@@ -2420,6 +2421,7 @@ describe('global', () => {
Ref: 'TableCD117FA1',
},
Region: 'eu-central-1',
AsynchronousReplicationEnabled: false,
},
Condition: 'TableStackRegionNotEqualseucentral199D46FC0',
}, ResourcePart.CompleteDefinition);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a new test here, passing waitForReplicationToFinish as false.

@@ -209,7 +209,8 @@
"TableName": {
"Ref": "TableCD117FA1"
},
"Region": "eu-west-2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you follow my advice from above, all of these changes can be reverted.

@skinny85 skinny85 changed the title feat(aws-dynamodb): delegate replica creation to background feat(dynamodb): add option to skip waiting for global replication to finish Oct 14, 2021
@TheSPD TheSPD force-pushed the feature-dynamodb-background-replica branch from ca08007 to 436fd2a Compare October 14, 2021 22:09
@mergify mergify bot dismissed skinny85’s stale review October 14, 2021 22:10

Pull request has been modified.

@TheSPD TheSPD force-pushed the feature-dynamodb-background-replica branch 2 times, most recently from d976eb4 to 4f6e696 Compare October 14, 2021 22:36
@TheSPD TheSPD force-pushed the feature-dynamodb-background-replica branch from 4f6e696 to 6633c39 Compare October 14, 2021 22:45
@TheSPD TheSPD requested a review from skinny85 October 15, 2021 00:02
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for the contribution @TheSPD!

@skinny85 skinny85 added the pr-linter/exempt-readme The PR linter will not require README changes label Oct 15, 2021
@mergify
Copy link
Contributor

mergify bot commented Oct 15, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 26387ea
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 254601f into aws:master Oct 15, 2021
@mergify
Copy link
Contributor

mergify bot commented Oct 15, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

skinny85 added a commit to skinny85/aws-cdk that referenced this pull request Dec 4, 2021
Our CFN Custom Resource for global DynamoDB Tables did not correctly handle changing the
`waitForReplicationToFinish` parameter introduced in aws#16983 -
adding it to an existing replica would error out by attempting to re-create the existing replica.
Fix this by adding a check in the Custom Resource whether a replica already exists.
mergify bot pushed a commit that referenced this pull request Dec 6, 2021
…#17842)

Our CFN Custom Resource for global DynamoDB Tables did not correctly handle changing the
`waitForReplicationToFinish` parameter introduced in #16983 -
adding it to an existing replica would error out by attempting to re-create the existing replica.
Fix this by adding a check in the Custom Resource whether a replica already exists.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
…finish (aws#16983)

Motivation - On large tables, replication takes long time to complete. CloudFormation has a hard timeout of 1 hour on the Custom Resources, to bypass this, we want to have the replication continue in background based on a property.

Fixes aws#16611 


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
…aws#17842)

Our CFN Custom Resource for global DynamoDB Tables did not correctly handle changing the
`waitForReplicationToFinish` parameter introduced in aws#16983 -
adding it to an existing replica would error out by attempting to re-create the existing replica.
Fix this by adding a check in the Custom Resource whether a replica already exists.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-linter/exempt-readme The PR linter will not require README changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-cdk/aws-dynamodb): Create table replica in background
3 participants