Skip to content

Commit cd2e44a

Browse files
committed
Remove table caching properties from operation specific configs.
1 parent e11b6e5 commit cd2e44a

File tree

4 files changed

+25
-114
lines changed

4 files changed

+25
-114
lines changed

sdk/src/Services/DynamoDBv2/Custom/DataModel/BaseOperationConfig.cs

-26
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,6 @@ public abstract class BaseOperationConfig
4141
/// </summary>
4242
public string TableNamePrefix { get; set; }
4343

44-
/// <summary>
45-
/// The object persistence model API relies on an internal cache of the DynamoDB table's metadata to
46-
/// construct and validate requests. This controls how the cache key is derived, which influences
47-
/// when the SDK will call DescribeTable internally to populate the cache.
48-
/// </summary>
49-
/// <remarks>
50-
/// For <see cref="MetadataCachingMode.Default"/> the cache key will be a combination of the table name, credentials, region and service URL.
51-
/// For <see cref="MetadataCachingMode.TableNameOnly"/> the cache key will only consist of the table name. This reduces cache misses in contexts
52-
/// where you are accessing tables with identical structure but using different credentials or endpoints (such as a multi-tenant application).
53-
/// </remarks>
54-
public MetadataCachingMode? MetadataCachingMode { get; set; }
55-
56-
/// <summary>
57-
/// If true disables fetching table metadata automatically from DynamoDB. Table metadata must be
58-
/// defined by <see cref="DynamoDBAttribute"/> attributes and/or in <see cref = "AWSConfigsDynamoDB"/>.
59-
/// </summary>
60-
/// <remarks>
61-
/// Setting this to true can avoid latency and thread starvation due to blocking asynchronous
62-
/// DescribeTable calls that are used to populate the SDK's cache of table metadata.
63-
/// It requires that the table's index schema be accurately described via the above methods,
64-
/// otherwise exceptions may be thrown and/or the results of certain DynamoDB operations may change.
65-
/// </remarks>
66-
public bool? DisableFetchingTableMetadata { get; set; }
67-
6844
/// <summary>
6945
/// Specification which controls the conversion between .NET and DynamoDB types.
7046
/// </summary>
@@ -91,8 +67,6 @@ internal virtual DynamoDBOperationConfig ToDynamoDBOperationConfig()
9167
{
9268
OverrideTableName = OverrideTableName,
9369
TableNamePrefix = TableNamePrefix,
94-
MetadataCachingMode = MetadataCachingMode,
95-
DisableFetchingTableMetadata = DisableFetchingTableMetadata,
9670
Conversion = Conversion,
9771
IsEmptyStringValueEnabled = IsEmptyStringValueEnabled
9872
};

sdk/src/Services/DynamoDBv2/Custom/DataModel/Configs.cs

+7-30
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,6 @@ public class DynamoDBOperationConfig
191191
/// </summary>
192192
public string TableNamePrefix { get; set; }
193193

194-
/// <summary>
195-
/// The object persistence model API relies on an internal cache of the DynamoDB table's metadata to construct and validate
196-
/// requests. This controls how the cache key is derived, which influences when the SDK will call
197-
/// IAmazonDynamoDB.DescribeTable(string) internally to populate the cache.
198-
/// </summary>
199-
/// <remarks>
200-
/// For <see cref="MetadataCachingMode.Default"/> the cache key will be a combination of the table name, credentials, region and service URL.
201-
/// For <see cref="MetadataCachingMode.TableNameOnly"/> the cache key will only consist of the table name. This reduces cache misses in contexts
202-
/// where you are accessing tables with identical structure but using different credentials or endpoints (such as a multi-tenant application).
203-
/// </remarks>
204-
public MetadataCachingMode? MetadataCachingMode { get; set; }
205-
206194
/// <summary>
207195
/// Property that directs <see cref="DynamoDBContext"/> to ignore null values
208196
/// on attributes during a Save operation.
@@ -225,18 +213,6 @@ public class DynamoDBOperationConfig
225213
/// </summary>
226214
public DynamoDBEntryConversion Conversion { get; set; }
227215

228-
/// <summary>
229-
/// If true disables fetching table metadata automatically from DynamoDB. Table metadata must be
230-
/// defined by <see cref="DynamoDBAttribute"/> attributes and/or in <see cref = "AWSConfigsDynamoDB"/>.
231-
/// </summary>
232-
/// <remarks>
233-
/// Setting this to true can avoid latency and thread starvation due to blocking asynchronous
234-
/// IAmazonDynamoDB.DescribeTable(string) calls that are used to populate the SDK's cache of
235-
/// table metadata. It requires that the table's index schema be accurately described via the above methods,
236-
/// otherwise exceptions may be thrown and/or the results of certain DynamoDB operations may change.
237-
/// </remarks>
238-
public bool? DisableFetchingTableMetadata { get; set; }
239-
240216
/// <summary>
241217
/// If true, all <see cref="DateTime"/> properties are retrieved in UTC timezone while reading data from DynamoDB. Else, the local timezone is used.
242218
/// </summary>
@@ -425,8 +401,7 @@ internal class DynamoDBFlatConfig
425401
IndexName = null,
426402
ConditionalOperator = ConditionalOperatorValues.And,
427403
Conversion = null,
428-
IsEmptyStringValueEnabled = null,
429-
MetadataCachingMode = null
404+
IsEmptyStringValueEnabled = null
430405
};
431406
private static DynamoDBContextConfig _emptyContextConfig = new DynamoDBContextConfig
432407
{
@@ -450,20 +425,22 @@ public DynamoDBFlatConfig(DynamoDBOperationConfig operationConfig, DynamoDBConte
450425
bool consistentRead = operationConfig.ConsistentRead ?? contextConfig.ConsistentRead ?? false;
451426
bool skipVersionCheck = operationConfig.SkipVersionCheck ?? contextConfig.SkipVersionCheck ?? false;
452427
bool ignoreNullValues = operationConfig.IgnoreNullValues ?? contextConfig.IgnoreNullValues ?? false;
453-
bool disableFetchingTableMetadata = operationConfig.DisableFetchingTableMetadata ?? contextConfig.DisableFetchingTableMetadata ?? false;
454428
bool retrieveDateTimeInUtc = operationConfig.RetrieveDateTimeInUtc ?? contextConfig.RetrieveDateTimeInUtc ?? false;
455429
bool isEmptyStringValueEnabled = operationConfig.IsEmptyStringValueEnabled ?? contextConfig.IsEmptyStringValueEnabled ?? false;
456430
DynamoDBEntryConversion conversion = operationConfig.Conversion ?? contextConfig.Conversion ?? DynamoDBEntryConversion.CurrentConversion;
457-
MetadataCachingMode metadataCachingMode = operationConfig.MetadataCachingMode ?? contextConfig.MetadataCachingMode ?? DynamoDBv2.MetadataCachingMode.Default;
458-
459431
string tableNamePrefix =
460432
!string.IsNullOrEmpty(operationConfig.TableNamePrefix) ? operationConfig.TableNamePrefix :
461433
!string.IsNullOrEmpty(contextConfig.TableNamePrefix) ? contextConfig.TableNamePrefix : string.Empty;
462434

463-
// These properties can only be set at the operation level, most are related to querying or scanning.
435+
// These properties can only be set at the operation level
436+
bool disableFetchingTableMetadata = contextConfig.DisableFetchingTableMetadata ?? false;
437+
MetadataCachingMode metadataCachingMode = contextConfig.MetadataCachingMode ?? DynamoDBv2.MetadataCachingMode.Default;
438+
464439
// We don't support overriding the table name at the context level, since a context object can be used with multiple tables.
465440
string overrideTableName =
466441
!string.IsNullOrEmpty(operationConfig.OverrideTableName) ? operationConfig.OverrideTableName : string.Empty;
442+
443+
// The rest are related to querying or scanning, so only operation level
467444
bool backwardQuery = operationConfig.BackwardQuery ?? false;
468445
string indexName =
469446
!string.IsNullOrEmpty(operationConfig.IndexName) ? operationConfig.IndexName : DefaultIndexName;

sdk/test/Services/DynamoDBv2/UnitTests/Custom/DataModelOperationSpecificConfigTests.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ public void BaseOperationConfig()
2121
{
2222
// If this fails because you've added a property, be sure to add it to
2323
// `ToDynamoDBOperationConfig` before updating this unit test
24-
Assert.AreEqual(6, typeof(BaseOperationConfig).GetProperties().Length);
24+
Assert.AreEqual(4, typeof(BaseOperationConfig).GetProperties().Length);
2525
}
2626

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

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

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

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

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

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

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

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

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

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

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

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

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

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

409409
[DynamoDBTable("TableName")]

sdk/test/Services/DynamoDBv2/UnitTests/Custom/DynamoDBTests.cs

+3-43
Original file line numberDiff line numberDiff line change
@@ -451,17 +451,16 @@ public void DisableFetchingTableMetadata_QueryWithMissingHashKey_ThrowsException
451451
[TestCategory("DynamoDBv2")]
452452
public void DisableFetchingTableMetadata_QueryWithMissingRangeKey_ThrowsException()
453453
{
454-
// For variety, use the operation-level override
455-
var config = new DynamoDBOperationConfig()
454+
var config = new DynamoDBContextConfig()
456455
{
457456
DisableFetchingTableMetadata = true
458457
};
459458

460-
var context = new DynamoDBContext(new Mock<IAmazonDynamoDB>().Object);
459+
var context = new DynamoDBContext(new Mock<IAmazonDynamoDB>().Object, config);
461460

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

466465
// This is a GSI's range key, which is not attributed
467466
Assert.ThrowsException<InvalidOperationException>(() =>
@@ -755,44 +754,5 @@ public class DataModelWithMixedAccessibility
755754

756755
public string PublicAccessToProtected => _protected;
757756
}
758-
759-
/// <summary>
760-
/// Verifies that specifing an TableName on the operation-level config overrides
761-
/// the table name from the data model
762-
/// </summary>
763-
[TestMethod]
764-
public void OperationConfig_CanOverrideTableName()
765-
{
766-
var client = new Mock<IAmazonDynamoDB>();
767-
client.Setup(client => client.DescribeTable(It.IsAny<DescribeTableRequest>()))
768-
.Returns(new DescribeTableResponse { Table = new TableDescription
769-
{
770-
KeySchema = new List<KeySchemaElement>
771-
{
772-
new KeySchemaElement("Name", KeyType.HASH),
773-
new KeySchemaElement("Age", KeyType.RANGE)
774-
},
775-
AttributeDefinitions = new List<AttributeDefinition>()
776-
{
777-
new AttributeDefinition("Name", ScalarAttributeType.S),
778-
new AttributeDefinition("Age", ScalarAttributeType.S)
779-
}
780-
}});
781-
client.Setup(client => client.Query(It.IsAny<QueryRequest>())).Returns(new QueryResponse { Items = new() });
782-
783-
var config = new DynamoDBOperationConfig
784-
{
785-
OverrideTableName = "OverrideTableName"
786-
};
787-
788-
var context = new DynamoDBContext(client.Object, config);
789-
790-
var query = context.Query<Employee>("123", config);
791-
var objects = query.ToList();
792-
793-
client.Verify(client => client.DescribeTable(It.Is<DescribeTableRequest>(request => request.TableName == "OverrideTableName")), Times.Once());
794-
client.Verify(client => client.Query(It.Is<QueryRequest>(request => request.TableName == "OverrideTableName")), Times.Once());
795-
client.VerifyNoOtherCalls();
796-
}
797757
}
798758
}

0 commit comments

Comments
 (0)