-
Notifications
You must be signed in to change notification settings - Fork 467
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,28 @@ public void testSetEnablePriorityLeaseAssignment() { | |
assertThat(resolvedConfiguration.leaseManagementConfig.enablePriorityLeaseAssignment(), equalTo(false)); | ||
} | ||
|
||
@Test | ||
public void testSetLeaseTableDeletionProtectionEnabled() { | ||
MultiLangDaemonConfiguration configuration = baseConfiguration(); | ||
configuration.setLeaseTableDeletionProtectionEnabled(true); | ||
|
||
MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration = | ||
configuration.resolvedConfiguration(shardRecordProcessorFactory); | ||
|
||
assertThat(resolvedConfiguration.leaseManagementConfig.leaseTableDeletionProtectionEnabled(), equalTo(true)); | ||
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. minor nit, but this could just be assertTrue(...) 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. Fixed |
||
} | ||
|
||
@Test | ||
public void testSetLeaseTablePitrEnabled() { | ||
MultiLangDaemonConfiguration configuration = baseConfiguration(); | ||
configuration.setLeaseTablePitrEnabled(true); | ||
|
||
MultiLangDaemonConfiguration.ResolvedConfiguration resolvedConfiguration = | ||
configuration.resolvedConfiguration(shardRecordProcessorFactory); | ||
|
||
assertThat(resolvedConfiguration.leaseManagementConfig.leaseTablePitrEnabled(), equalTo(true)); | ||
} | ||
|
||
@Test | ||
public void testDefaultRetrievalConfig() { | ||
MultiLangDaemonConfiguration configuration = baseConfiguration(); | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -40,6 +40,7 @@ | |||||||||
import software.amazon.awssdk.services.dynamodb.model.GetItemRequest; | ||||||||||
import software.amazon.awssdk.services.dynamodb.model.GetItemResponse; | ||||||||||
import software.amazon.awssdk.services.dynamodb.model.LimitExceededException; | ||||||||||
import software.amazon.awssdk.services.dynamodb.model.PointInTimeRecoverySpecification; | ||||||||||
import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughput; | ||||||||||
import software.amazon.awssdk.services.dynamodb.model.ProvisionedThroughputExceededException; | ||||||||||
import software.amazon.awssdk.services.dynamodb.model.PutItemRequest; | ||||||||||
|
@@ -49,6 +50,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 +83,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 +162,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 +210,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 +254,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 +264,7 @@ public DynamoDBLeaseRefresher( | |||||||||
this.dynamoDbRequestTimeout = dynamoDbRequestTimeout; | ||||||||||
this.billingMode = billingMode; | ||||||||||
this.leaseTableDeletionProtectionEnabled = leaseTableDeletionProtectionEnabled; | ||||||||||
this.leaseTablePitrEnabled = leaseTablePitrEnabled; | ||||||||||
this.tags = tags; | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -252,7 +292,35 @@ 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(PointInTimeRecoverySpecification.builder() | ||||||||||
.pointInTimeRecoveryEnabled(true) | ||||||||||
.build()) | ||||||||||
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. Instead of passing in a PointInTimeRecoverySpecification, you can pass in a Consumer<PointInTimeRecoverySpecification.Builder> like so:
Suggested change
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 shorthand, did not know about it. Updated |
||||||||||
.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) | ||||||||||
|
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