-
Notifications
You must be signed in to change notification settings - Fork 466
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
Add config to enable PITR #1365
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
import software.amazon.awssdk.services.dynamodb.model.ScanResponse; | ||
import software.amazon.awssdk.services.dynamodb.model.TableStatus; | ||
import software.amazon.awssdk.services.dynamodb.model.Tag; | ||
import software.amazon.awssdk.services.dynamodb.model.UpdateContinuousBackupsRequest; | ||
import software.amazon.awssdk.services.dynamodb.model.UpdateItemRequest; | ||
import software.amazon.awssdk.utils.CollectionUtils; | ||
import software.amazon.kinesis.annotations.KinesisClientInternalApi; | ||
|
@@ -81,6 +82,7 @@ public class DynamoDBLeaseRefresher implements LeaseRefresher { | |
private final Duration dynamoDbRequestTimeout; | ||
private final BillingMode billingMode; | ||
private final boolean leaseTableDeletionProtectionEnabled; | ||
private final boolean leaseTablePitrEnabled; | ||
private final Collection<Tag> tags; | ||
|
||
private boolean newTableCreated = false; | ||
|
@@ -159,7 +161,7 @@ public DynamoDBLeaseRefresher( | |
tableCreatorCallback, | ||
dynamoDbRequestTimeout, | ||
BillingMode.PAY_PER_REQUEST, | ||
false); | ||
LeaseManagementConfig.DEFAULT_LEASE_TABLE_DELETION_PROTECTION_ENABLED); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for this. |
||
} | ||
|
||
/** | ||
|
@@ -207,6 +209,41 @@ public DynamoDBLeaseRefresher( | |
* @param leaseTableDeletionProtectionEnabled | ||
* @param tags | ||
*/ | ||
@Deprecated | ||
public DynamoDBLeaseRefresher( | ||
final String table, | ||
final DynamoDbAsyncClient dynamoDBClient, | ||
final LeaseSerializer serializer, | ||
final boolean consistentReads, | ||
@NonNull final TableCreatorCallback tableCreatorCallback, | ||
Duration dynamoDbRequestTimeout, | ||
final BillingMode billingMode, | ||
final boolean leaseTableDeletionProtectionEnabled, | ||
final Collection<Tag> tags) { | ||
this( | ||
table, | ||
dynamoDBClient, | ||
serializer, | ||
consistentReads, | ||
tableCreatorCallback, | ||
dynamoDbRequestTimeout, | ||
billingMode, | ||
leaseTableDeletionProtectionEnabled, | ||
LeaseManagementConfig.DEFAULT_LEASE_TABLE_PITR_ENABLED, | ||
tags); | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* @param table | ||
* @param dynamoDBClient | ||
* @param serializer | ||
* @param consistentReads | ||
* @param tableCreatorCallback | ||
* @param dynamoDbRequestTimeout | ||
* @param billingMode | ||
* @param leaseTableDeletionProtectionEnabled | ||
*/ | ||
public DynamoDBLeaseRefresher( | ||
final String table, | ||
final DynamoDbAsyncClient dynamoDBClient, | ||
|
@@ -216,6 +253,7 @@ public DynamoDBLeaseRefresher( | |
Duration dynamoDbRequestTimeout, | ||
final BillingMode billingMode, | ||
final boolean leaseTableDeletionProtectionEnabled, | ||
final boolean leaseTablePitrEnabled, | ||
final Collection<Tag> tags) { | ||
this.table = table; | ||
this.dynamoDBClient = dynamoDBClient; | ||
|
@@ -225,6 +263,7 @@ public DynamoDBLeaseRefresher( | |
this.dynamoDbRequestTimeout = dynamoDbRequestTimeout; | ||
this.billingMode = billingMode; | ||
this.leaseTableDeletionProtectionEnabled = leaseTableDeletionProtectionEnabled; | ||
this.leaseTablePitrEnabled = leaseTablePitrEnabled; | ||
this.tags = tags; | ||
} | ||
|
||
|
@@ -252,7 +291,33 @@ public boolean createLeaseTableIfNotExists(@NonNull final Long readCapacity, @No | |
public boolean createLeaseTableIfNotExists() throws ProvisionedThroughputException, DependencyException { | ||
final CreateTableRequest request = createTableRequestBuilder().build(); | ||
|
||
return createTableIfNotExists(request); | ||
boolean tableExists = createTableIfNotExists(request); | ||
|
||
if (leaseTablePitrEnabled) { | ||
enablePitr(); | ||
log.info("Enabled PITR on table {}", table); | ||
} | ||
|
||
return tableExists; | ||
} | ||
|
||
private void enablePitr() throws DependencyException { | ||
final UpdateContinuousBackupsRequest request = UpdateContinuousBackupsRequest.builder() | ||
.tableName(table) | ||
.pointInTimeRecoverySpecification(builder -> builder.pointInTimeRecoveryEnabled(true)) | ||
.build(); | ||
|
||
final AWSExceptionManager exceptionManager = createExceptionManager(); | ||
exceptionManager.add(ResourceNotFoundException.class, t -> t); | ||
exceptionManager.add(ProvisionedThroughputExceededException.class, t -> t); | ||
|
||
try { | ||
FutureUtils.resolveOrCancelFuture(dynamoDBClient.updateContinuousBackups(request), dynamoDbRequestTimeout); | ||
} catch (ExecutionException e) { | ||
throw exceptionManager.apply(e.getCause()); | ||
} catch (InterruptedException | DynamoDbException | TimeoutException e) { | ||
throw new DependencyException(e); | ||
} | ||
} | ||
|
||
private boolean createTableIfNotExists(CreateTableRequest request) | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We check that leaseTableDeletionProtectionEnabled() and leaseTablePitrEnabled() equal true, but this will give a false positive if the default changes to true and setLeaseTable...Enabled() methods break.
This is a bit of a nit since it appears this methodology was repeated with other tests. Just including it for consideration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I've added two more tests to set the false value as well