Skip to content

Commit

Permalink
Remove table caching properties from operation specific configs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashovlin committed Aug 10, 2024
1 parent f478a1b commit 295e52e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,6 @@ public abstract class BaseOperationConfig
/// </summary>
public string TableNamePrefix { get; set; }

/// <summary>
/// The object persistence model API relies on an internal cache of the DynamoDB table's metadata to
/// construct and validate requests. This controls how the cache key is derived, which influences
/// when the SDK will call DescribeTable internally to populate the cache.
/// </summary>
/// <remarks>
/// For <see cref="MetadataCachingMode.Default"/> the cache key will be a combination of the table name, credentials, region and service URL.
/// For <see cref="MetadataCachingMode.TableNameOnly"/> the cache key will only consist of the table name. This reduces cache misses in contexts
/// where you are accessing tables with identical structure but using different credentials or endpoints (such as a multi-tenant application).
/// </remarks>
public MetadataCachingMode? MetadataCachingMode { get; set; }

/// <summary>
/// If true disables fetching table metadata automatically from DynamoDB. Table metadata must be
/// defined by <see cref="DynamoDBAttribute"/> attributes and/or in <see cref = "AWSConfigsDynamoDB"/>.
/// </summary>
/// <remarks>
/// Setting this to true can avoid latency and thread starvation due to blocking asynchronous
/// DescribeTable calls that are used to populate the SDK's cache of table metadata.
/// It requires that the table's index schema be accurately described via the above methods,
/// otherwise exceptions may be thrown and/or the results of certain DynamoDB operations may change.
/// </remarks>
public bool? DisableFetchingTableMetadata { get; set; }

/// <summary>
/// Specification which controls the conversion between .NET and DynamoDB types.
/// </summary>
Expand All @@ -91,8 +67,6 @@ internal virtual DynamoDBOperationConfig ToDynamoDBOperationConfig()
{
OverrideTableName = OverrideTableName,
TableNamePrefix = TableNamePrefix,
MetadataCachingMode = MetadataCachingMode,
DisableFetchingTableMetadata = DisableFetchingTableMetadata,
Conversion = Conversion,
IsEmptyStringValueEnabled = IsEmptyStringValueEnabled
};
Expand Down
37 changes: 7 additions & 30 deletions sdk/src/Services/DynamoDBv2/Custom/DataModel/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,6 @@ public class DynamoDBOperationConfig
/// </summary>
public string TableNamePrefix { get; set; }

/// <summary>
/// The object persistence model API relies on an internal cache of the DynamoDB table's metadata to construct and validate
/// requests. This controls how the cache key is derived, which influences when the SDK will call
/// IAmazonDynamoDB.DescribeTable(string) internally to populate the cache.
/// </summary>
/// <remarks>
/// For <see cref="MetadataCachingMode.Default"/> the cache key will be a combination of the table name, credentials, region and service URL.
/// For <see cref="MetadataCachingMode.TableNameOnly"/> the cache key will only consist of the table name. This reduces cache misses in contexts
/// where you are accessing tables with identical structure but using different credentials or endpoints (such as a multi-tenant application).
/// </remarks>
public MetadataCachingMode? MetadataCachingMode { get; set; }

/// <summary>
/// Property that directs <see cref="DynamoDBContext"/> to ignore null values
/// on attributes during a Save operation.
Expand All @@ -225,18 +213,6 @@ public class DynamoDBOperationConfig
/// </summary>
public DynamoDBEntryConversion Conversion { get; set; }

/// <summary>
/// If true disables fetching table metadata automatically from DynamoDB. Table metadata must be
/// defined by <see cref="DynamoDBAttribute"/> attributes and/or in <see cref = "AWSConfigsDynamoDB"/>.
/// </summary>
/// <remarks>
/// Setting this to true can avoid latency and thread starvation due to blocking asynchronous
/// IAmazonDynamoDB.DescribeTable(string) calls that are used to populate the SDK's cache of
/// table metadata. It requires that the table's index schema be accurately described via the above methods,
/// otherwise exceptions may be thrown and/or the results of certain DynamoDB operations may change.
/// </remarks>
public bool? DisableFetchingTableMetadata { get; set; }

/// <summary>
/// If true, all <see cref="DateTime"/> properties are retrieved in UTC timezone while reading data from DynamoDB. Else, the local timezone is used.
/// </summary>
Expand Down Expand Up @@ -425,8 +401,7 @@ internal class DynamoDBFlatConfig
IndexName = null,
ConditionalOperator = ConditionalOperatorValues.And,
Conversion = null,
IsEmptyStringValueEnabled = null,
MetadataCachingMode = null
IsEmptyStringValueEnabled = null
};
private static DynamoDBContextConfig _emptyContextConfig = new DynamoDBContextConfig
{
Expand All @@ -450,20 +425,22 @@ public DynamoDBFlatConfig(DynamoDBOperationConfig operationConfig, DynamoDBConte
bool consistentRead = operationConfig.ConsistentRead ?? contextConfig.ConsistentRead ?? false;
bool skipVersionCheck = operationConfig.SkipVersionCheck ?? contextConfig.SkipVersionCheck ?? false;
bool ignoreNullValues = operationConfig.IgnoreNullValues ?? contextConfig.IgnoreNullValues ?? false;
bool disableFetchingTableMetadata = operationConfig.DisableFetchingTableMetadata ?? contextConfig.DisableFetchingTableMetadata ?? false;
bool retrieveDateTimeInUtc = operationConfig.RetrieveDateTimeInUtc ?? contextConfig.RetrieveDateTimeInUtc ?? false;
bool isEmptyStringValueEnabled = operationConfig.IsEmptyStringValueEnabled ?? contextConfig.IsEmptyStringValueEnabled ?? false;
DynamoDBEntryConversion conversion = operationConfig.Conversion ?? contextConfig.Conversion ?? DynamoDBEntryConversion.CurrentConversion;
MetadataCachingMode metadataCachingMode = operationConfig.MetadataCachingMode ?? contextConfig.MetadataCachingMode ?? DynamoDBv2.MetadataCachingMode.Default;

string tableNamePrefix =
!string.IsNullOrEmpty(operationConfig.TableNamePrefix) ? operationConfig.TableNamePrefix :
!string.IsNullOrEmpty(contextConfig.TableNamePrefix) ? contextConfig.TableNamePrefix : string.Empty;

// These properties can only be set at the operation level, most are related to querying or scanning.
// These properties can only be set at the operation level
bool disableFetchingTableMetadata = contextConfig.DisableFetchingTableMetadata ?? false;
MetadataCachingMode metadataCachingMode = contextConfig.MetadataCachingMode ?? DynamoDBv2.MetadataCachingMode.Default;

// We don't support overriding the table name at the context level, since a context object can be used with multiple tables.
string overrideTableName =
!string.IsNullOrEmpty(operationConfig.OverrideTableName) ? operationConfig.OverrideTableName : string.Empty;

// The rest are related to querying or scanning, so only operation level
bool backwardQuery = operationConfig.BackwardQuery ?? false;
string indexName =
!string.IsNullOrEmpty(operationConfig.IndexName) ? operationConfig.IndexName : DefaultIndexName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public void BaseOperationConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(6, typeof(BaseOperationConfig).GetProperties().Length);
Assert.AreEqual(4, typeof(BaseOperationConfig).GetProperties().Length);
}

[TestMethod]
public void BatchGetConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(8, typeof(BatchGetConfig).GetProperties().Length);
Assert.AreEqual(6, typeof(BatchGetConfig).GetProperties().Length);
}

[TestMethod]
Expand Down Expand Up @@ -62,7 +62,7 @@ public void BatchWriteConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(8, typeof(BatchWriteConfig).GetProperties().Length);
Assert.AreEqual(6, typeof(BatchWriteConfig).GetProperties().Length);
}

[TestMethod]
Expand Down Expand Up @@ -95,7 +95,7 @@ public void TransactGetConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(7, typeof(TransactGetConfig).GetProperties().Length);
Assert.AreEqual(5, typeof(TransactGetConfig).GetProperties().Length);
}

[TestMethod]
Expand Down Expand Up @@ -128,7 +128,7 @@ public void TransactWriteConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(7, typeof(TransactWriteConfig).GetProperties().Length);
Assert.AreEqual(5, typeof(TransactWriteConfig).GetProperties().Length);
}

[TestMethod]
Expand Down Expand Up @@ -161,7 +161,7 @@ public void QueryConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(12, typeof(QueryConfig).GetProperties().Length);
Assert.AreEqual(10, typeof(QueryConfig).GetProperties().Length);
}

[TestMethod]
Expand Down Expand Up @@ -193,7 +193,7 @@ public void FromQueryConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(7, typeof(FromQueryConfig).GetProperties().Length);
Assert.AreEqual(5, typeof(FromQueryConfig).GetProperties().Length);
}

[TestMethod]
Expand Down Expand Up @@ -230,7 +230,7 @@ public void ScanConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(11, typeof(ScanConfig).GetProperties().Length);
Assert.AreEqual(9, typeof(ScanConfig).GetProperties().Length);
}

[TestMethod]
Expand Down Expand Up @@ -262,7 +262,7 @@ public void FromScanConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(7, typeof(FromScanConfig).GetProperties().Length);
Assert.AreEqual(5, typeof(FromScanConfig).GetProperties().Length);
}

[TestMethod]
Expand Down Expand Up @@ -294,7 +294,7 @@ public void DeleteConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(7, typeof(DeleteConfig).GetProperties().Length);
Assert.AreEqual(5, typeof(DeleteConfig).GetProperties().Length);
}

[TestMethod]
Expand Down Expand Up @@ -325,7 +325,7 @@ public void SaveConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(8, typeof(SaveConfig).GetProperties().Length);
Assert.AreEqual(6, typeof(SaveConfig).GetProperties().Length);
}

[TestMethod]
Expand Down Expand Up @@ -356,7 +356,7 @@ public void LoadConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(8, typeof(LoadConfig).GetProperties().Length);
Assert.AreEqual(6, typeof(LoadConfig).GetProperties().Length);
}

[TestMethod]
Expand Down Expand Up @@ -387,23 +387,23 @@ public void ToDocumentConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(7, typeof(ToDocumentConfig).GetProperties().Length);
Assert.AreEqual(5, typeof(ToDocumentConfig).GetProperties().Length);
}

[TestMethod]
public void FromDocumentConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(7, typeof(FromDocumentConfig).GetProperties().Length);
Assert.AreEqual(5, typeof(FromDocumentConfig).GetProperties().Length);
}

[TestMethod]
public void GetTargetTableConfig()
{
// If this fails because you've added a property, be sure to add it to
// `ToDynamoDBOperationConfig` before updating this unit test
Assert.AreEqual(6, typeof(GetTargetTableConfig).GetProperties().Length);
Assert.AreEqual(4, typeof(GetTargetTableConfig).GetProperties().Length);
}

[DynamoDBTable("TableName")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,17 +451,16 @@ public void DisableFetchingTableMetadata_QueryWithMissingHashKey_ThrowsException
[TestCategory("DynamoDBv2")]
public void DisableFetchingTableMetadata_QueryWithMissingRangeKey_ThrowsException()
{
// For variety, use the operation-level override
var config = new DynamoDBOperationConfig()
var config = new DynamoDBContextConfig()
{
DisableFetchingTableMetadata = true
};

var context = new DynamoDBContext(new Mock<IAmazonDynamoDB>().Object);
var context = new DynamoDBContext(new Mock<IAmazonDynamoDB>().Object, config);

// This is the table's range key, which is not attributed
Assert.ThrowsException<InvalidOperationException>(() =>
context.Query<EmployeeMissingRangeKeys>("123", QueryOperator.GreaterThan, 5, config));
context.Query<EmployeeMissingRangeKeys>("123", QueryOperator.GreaterThan, 5));

// This is a GSI's range key, which is not attributed
Assert.ThrowsException<InvalidOperationException>(() =>
Expand Down

0 comments on commit 295e52e

Please sign in to comment.