Skip to content
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

Remove the Context/Operation Config Hierarchy, and Remove Table-level Configurations from DynamoDBOperationConfig #3422

Merged
merged 3 commits into from
Aug 14, 2024

Conversation

ashovlin
Copy link
Member

@ashovlin ashovlin commented Aug 5, 2024

Description

  1. This allows users to set OverrideTableName on the DynamoDBContextConfig, not just the DynamoDBOperationConfig
    • During review we decided against this.
  2. While I was here I noticed that I didn't follow the hierarchy when adding DisableFetchingTableMetadata last year, so backfilled that too.

New changes after PR feedback:

  1. Separate the hierarchy between DynamoDBContextConfig and DynamoDBOperationConfig, to remove the appearance that you can pass an operation config into the context. This came up several times with OverrideTableName.
  2. Removed two table-level configurations from DynamoDBOperationConfig (and thus all of the new operation-specific config objects). These control how the context object caches table metadata, and should be specified there instead of at the operation level.

Motivation and Context

We've gotten a few requests over the years for the ability to override the DynamoDB table name via the object-persistence context config, instead of needing to do so on every operation config.

This is complicated by the fact that DynamoDBOperationConfig inherits from DynamoDBContextConfig. One could be passing an operation config into the context constructor, thinking that OverrideTableName would apply.

public class DynamoDBOperationConfig : DynamoDBContextConfig

Testing

  1. Ran unit and integration tests in DynamoDBv2 sln locally.
  2. Dry-run in progress.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

@@ -152,12 +162,6 @@ public DynamoDBContextConfig()
#endif
public class DynamoDBOperationConfig : DynamoDBContextConfig
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we break this hierarchy while we're here?

We're discouraging the use of DynamoDBOperationConfig in V4 via [Obsolete] #3421, but this did lead to the confusion that this is addressing in the first place.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it make sense to break the hierarchy. I assume we would copy over the properties from DynamoDBContextConfig to DynamoDBOperationConfig that made sense at the operation level.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in f478a1b

/// If you specify this on <see cref="DynamoDBContextConfig"/>, then it will apply to all
/// objects/tables used with that <see cref="DynamoDBContext"/> object unless overriden by an operation-specific config.
/// </remarks>
public string OverrideTableName { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this property on the context's config doesn't make sense to me since the context works with multiple tables. I know you call that out in the doc that it replaces all table mappings. I'm thinking it was a failure in our response to the GitHub issues to not point out that could accomplish what they wanted using the AWSConfigsDynamoDB.Context.TypeMappings property. Here is how I configured one of my application to use the table that was created during deployment as part of CloudFormation with CloudFormation naming the table.

var tableName = System.Environment.GetEnvironmentVariable(ENV_TABLE_NAME_POLL_DEFINITION);
if (!string.IsNullOrEmpty(tableName))
{
    PollDefinitionTableName = tableName;
    AWSConfigsDynamoDB.Context.TypeMappings[typeof(PollDefinition)] = new Amazon.Util.TypeMapping(typeof(PollDefinition), tableName);
    Console.WriteLine($"Using table {tableName} for PollDefinition");
}

If we really want this capability on the context object I think we would have to make it a map of types to table names.

Copy link
Member Author

@ashovlin ashovlin Aug 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't too attached to this yet either, was mostly throwing it out there since there seems to be interest via the three issues. The only counterargument I can think of is if an application is only working with a single table, the current approach is simpler to override.

Should we just point users to AWSConfigsDynamoDB.Context.TypeMappings? and then break the hierarchy so it stops looking like you could be able to do this? Or maybe we can leave this PR out for a bit for feedback, I could go comment on the original issues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think we should point users to AWSConfigsDynamoDB.Context.TypeMappings. You are right that the single property would be useful in a single table design but then confusing in the other case. I don't have a feeling how common single table design is but I don't believe it would be the overwhelming majority to warrant putting in this confusing property for non single table users.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add a comment on the OverrideTableName for the operational config that if users want to make the override global they should use the AWSConfigsDynamoDB.Context.TypeMappings.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in f478a1b.

Plus as long as we do the breaking change to separate the hierarchy in V4, if we did want to add a context-level table mapping, that'd be an additive change in the future.

@@ -152,12 +162,6 @@ public DynamoDBContextConfig()
#endif
public class DynamoDBOperationConfig : DynamoDBContextConfig
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it make sense to break the hierarchy. I assume we would copy over the properties from DynamoDBContextConfig to DynamoDBOperationConfig that made sense at the operation level.

@ashovlin ashovlin changed the title fix: Honor an OverrideTableName and DisableFetchingTableMetadata when specified on a DynamoDBOperationConfig, instead of just on the DynamoDBContextConfig fix: Honor DisableFetchingTableMetadata when specified on a DynamoDBOperationConfig, and remove the Context/Operation Config Hierarchy Aug 10, 2024
@ashovlin ashovlin force-pushed the shovlia/ddb-context-level-table-1421 branch from 7236fff to f478a1b Compare August 10, 2024 00:19
@ashovlin ashovlin requested a review from normj August 10, 2024 00:21
Comment on lines +180 to +183
/// If you want to specify this globally instead of for each operation, you can use
/// the <see cref="TableAlias"/> or <see cref="TypeMapping"/> collections
/// on <see cref="AWSConfigsDynamoDB.Context"/>.
/// </remarks>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New note the suggests an alternative to the operation-level override.

/// 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; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make sense at the operational level? Since only one operation invoke is going to do the cache load for a table would a user even now when the load is happening or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that's why I left it off originally... Agreed that you wouldn't need to set this past the first one.

I can remove it again, especially in parallel with #3430

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 295e52e

/// 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; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like DisableFetchingTableMetadata this property doesn't make sense at the operational level.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 295e52e

@ashovlin ashovlin changed the title fix: Honor DisableFetchingTableMetadata when specified on a DynamoDBOperationConfig, and remove the Context/Operation Config Hierarchy Remove the Context/Operation Config Hierarchy, and Remove Table-level Configurations from DynamoDBOperationConfig Aug 10, 2024
@ashovlin ashovlin requested a review from normj August 10, 2024 02:18
@ashovlin ashovlin force-pushed the shovlia/ddb-context-level-table-1421 branch from 295e52e to cd2e44a Compare August 14, 2024 15:19
@ashovlin ashovlin merged commit 15a8661 into v4-development Aug 14, 2024
1 check passed
@ashovlin ashovlin deleted the shovlia/ddb-context-level-table-1421 branch August 14, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants