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
[AWS:DynamoDB] Explicit setting for UseProvisionedThroughput
#6328
Merged
sergeybykov
merged 1 commit into
dotnet:master
from
icanhasjonas:explicitsettingforprovisionedthroughput
Feb 22, 2020
Merged
[AWS:DynamoDB] Explicit setting for UseProvisionedThroughput
#6328
sergeybykov
merged 1 commit into
dotnet:master
from
icanhasjonas:explicitsettingforprovisionedthroughput
Feb 22, 2020
Conversation
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
Defaults to `true`, not changing existing behaviour diff --git a/src/AWS/Orleans.Persistence.DynamoDB/Options/DynamoDBStorageOptions.cs b/src/AWS/Orleans.Persistence.DynamoDB/Options/DynamoDBStorageOptions.cs old mode 100644 new mode 100755 index 8d895bcbb..ccfc85475 --- a/src/AWS/Orleans.Persistence.DynamoDB/Options/DynamoDBStorageOptions.cs +++ b/src/AWS/Orleans.Persistence.DynamoDB/Options/DynamoDBStorageOptions.cs @@ -25,10 +25,15 @@ public class DynamoDBStorageOptions public string SecretKey { get; set; } /// <summary> - /// DynamoDB Service name + /// DynamoDB Service name /// </summary> public string Service { get; set; } + /// <summary> + /// Use Provisioned Throughput for tables + /// </summary> + public bool UseProvisionedThroughput { get; set; } = true; + /// <summary> /// Read capacity unit for DynamoDB storage /// </summary> @@ -94,13 +99,16 @@ public void ValidateConfiguration() throw new OrleansConfigurationException( $"Configuration for DynamoDBGrainStorage {this.name} is invalid. {nameof(this.options.TableName)} is not valid."); - if (this.options.ReadCapacityUnits == 0) - throw new OrleansConfigurationException( - $"Configuration for DynamoDBGrainStorage {this.name} is invalid. {nameof(this.options.ReadCapacityUnits)} is not valid."); + if (this.options.UseProvisionedThroughput) + { + if (this.options.ReadCapacityUnits == 0) + throw new OrleansConfigurationException( + $"Configuration for DynamoDBGrainStorage {this.name} is invalid. {nameof(this.options.ReadCapacityUnits)} is not valid."); - if (this.options.WriteCapacityUnits == 0) - throw new OrleansConfigurationException( - $"Configuration for DynamoDBGrainStorage {this.name} is invalid. {nameof(this.options.WriteCapacityUnits)} is not valid."); + if (this.options.WriteCapacityUnits == 0) + throw new OrleansConfigurationException( + $"Configuration for DynamoDBGrainStorage {this.name} is invalid. {nameof(this.options.WriteCapacityUnits)} is not valid."); + } } } } diff --git a/src/AWS/Orleans.Persistence.DynamoDB/Provider/DynamoDBGrainStorage.cs b/src/AWS/Orleans.Persistence.DynamoDB/Provider/DynamoDBGrainStorage.cs old mode 100644 new mode 100755 index a39e62ebf..a85b83ed3 --- a/src/AWS/Orleans.Persistence.DynamoDB/Provider/DynamoDBGrainStorage.cs +++ b/src/AWS/Orleans.Persistence.DynamoDB/Provider/DynamoDBGrainStorage.cs @@ -83,7 +83,7 @@ public async Task Init(CancellationToken ct) this.logger.LogInformation((int)ErrorCode.StorageProviderBase, $"AWS DynamoDB Grain Storage {this.name} is initializing: {initMsg}"); this.storage = new DynamoDBStorage(this.loggerFactory, this.options.Service, this.options.AccessKey, this.options.SecretKey, - this.options.ReadCapacityUnits, this.options.WriteCapacityUnits); + this.options.ReadCapacityUnits, this.options.WriteCapacityUnits, this.options.UseProvisionedThroughput); await storage.InitializeTable(this.options.TableName, new List<KeySchemaElement> @@ -187,7 +187,7 @@ private async Task WriteStateInternal(IGrainState grainState, GrainStateRecord r { var fields = new Dictionary<string, AttributeValue>(); if (this.options.TimeToLive.HasValue) - { + { fields.Add(GRAIN_TTL_PROPERTY_NAME, new AttributeValue { N = ((DateTimeOffset)DateTime.UtcNow.Add(this.options.TimeToLive.Value)).ToUnixTimeSeconds().ToString() }); } diff --git a/src/AWS/Shared/Storage/DynamoDBStorage.cs b/src/AWS/Shared/Storage/DynamoDBStorage.cs index 4425211a9..82a5570e4 100644 --- a/src/AWS/Shared/Storage/DynamoDBStorage.cs +++ b/src/AWS/Shared/Storage/DynamoDBStorage.cs @@ -38,6 +38,7 @@ internal class DynamoDBStorage public const int DefaultWriteCapacityUnits = 5; private int readCapacityUnits = DefaultReadCapacityUnits; private int writeCapacityUnits = DefaultWriteCapacityUnits; + private readonly bool useProvisionedThroughput; private AmazonDynamoDBClient ddbClient; private ILogger Logger; @@ -50,10 +51,12 @@ internal class DynamoDBStorage /// <param name="service"></param> /// <param name="readCapacityUnits"></param> /// <param name="writeCapacityUnits"></param> + /// <param name="useProvisionedThroughput"></param> public DynamoDBStorage(ILoggerFactory loggerFactory, string service, string accessKey = "", string secretKey = "", int readCapacityUnits = DefaultReadCapacityUnits, - int writeCapacityUnits = DefaultWriteCapacityUnits) + int writeCapacityUnits = DefaultWriteCapacityUnits, + bool useProvisionedThroughput = true) { if (service == null) throw new ArgumentNullException(nameof(service)); this.accessKey = accessKey; @@ -61,6 +64,7 @@ internal class DynamoDBStorage this.service = service; this.readCapacityUnits = readCapacityUnits; this.writeCapacityUnits = writeCapacityUnits; + this.useProvisionedThroughput = useProvisionedThroughput; Logger = loggerFactory.CreateLogger<DynamoDBStorage>(); CreateClient(); } @@ -127,14 +131,13 @@ private async Task<TableDescription> GetTableDescription(string tableName) private async Task CreateTable(string tableName, List<KeySchemaElement> keys, List<AttributeDefinition> attributes, List<GlobalSecondaryIndex> secondaryIndexes = null, string ttlAttributeName = null) { - var useProvisionedThroughput = readCapacityUnits > 0 && writeCapacityUnits > 0; var request = new CreateTableRequest { TableName = tableName, AttributeDefinitions = attributes, KeySchema = keys, - BillingMode = useProvisionedThroughput ? BillingMode.PROVISIONED : BillingMode.PAY_PER_REQUEST, - ProvisionedThroughput = useProvisionedThroughput ? new ProvisionedThroughput + BillingMode = this.useProvisionedThroughput ? BillingMode.PROVISIONED : BillingMode.PAY_PER_REQUEST, + ProvisionedThroughput = this.useProvisionedThroughput ? new ProvisionedThroughput { ReadCapacityUnits = readCapacityUnits, WriteCapacityUnits = writeCapacityUnits @@ -143,7 +146,7 @@ private async Task CreateTable(string tableName, List<KeySchemaElement> keys, Li if (secondaryIndexes != null && secondaryIndexes.Count > 0) { - if (useProvisionedThroughput) + if (this.useProvisionedThroughput) { var indexThroughput = new ProvisionedThroughput {ReadCapacityUnits = readCapacityUnits, WriteCapacityUnits = writeCapacityUnits}; secondaryIndexes.ForEach(i =>
icanhasjonas
changed the title
Explicit setting for
[AWS:DynamoDB] Explicit setting for Feb 22, 2020
UseProvisionedThroughput
UseProvisionedThroughput
Thank you, @icanhasjonas! |
sergeybykov
pushed a commit
that referenced
this pull request
Feb 22, 2020
(cherry picked from commit 38e1e86)
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This fixes a previous issue where a Read/Write capacity of
0
would imply a non-provisioned strategy. SettingUseProvisionedThroughput
tofalse
now changes theBILLING_MODE
toPAY_PER_REQUEST
as expected.Defaults are kept (
UseProvisionedThroughput = true
) to not change or break existing behavior.