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

Fix MetadataProvider initialization in Hot Reload and remove duplicate Query Executor reloading #2428

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

aaronburtle
Copy link
Contributor

@aaronburtle aaronburtle commented Oct 15, 2024

Why make this change?

Closes #2426
Closes #2427

What is this change?

Properly create and initialize a new set of SqlMetadataProviders as part of the hot-reload process of the SqlMetadataProviderFactory, by utilizing the initiaizeAsync() function. This guarantees a correctly configured set of meta data providers for the factory.

Remove the event handling to hot-reload the QueryExecutors classes specifically, since this is already handled during the hot-reload process of the QueryManagerFactory. That process creates new and up to date QueryExecutors as part of a hot-reload.

With the correct initialization of the meta data providers, we can remove the code that saves the DefaultDataSourceName to be passed along the hot-reloaded configs. With all of the data structures we initialized on new meta data providers, we do not need to save the data source name and hot-reloading will be more resilient.

How was this tested?

Manually ran to verify hot reload works and requests work before and after hot reloads.

Sample Request(s)

Any rest request should work.

eg:

https://localhost:5001/rest/Book

@aaronburtle aaronburtle self-assigned this Oct 15, 2024
@aaronburtle aaronburtle added bug Something isn't working 🔥Hot Reload Tasks related to DAB's Hot Reload feature proposal labels Oct 15, 2024
@aaronburtle aaronburtle added this to the 1.3 milestone Oct 15, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add more detail in pr description for how you manually tested these changes. Use
#2417 and #2414 as examples via the "test scenarios" sections

Copy link
Contributor

Choose a reason for hiding this comment

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

can you add more details to the PR description for why we need to change how dataSourceName is used: using the passed in argument versus using the "default" data source name.

Comment on lines -29 to -32
{ QUERY_EXECUTOR_ON_CONFIG_CHANGED, null },
{ MSSQL_QUERY_EXECUTOR_ON_CONFIG_CHANGED, null },
{ MYSQL_QUERY_EXECUTOR_ON_CONFIG_CHANGED, null },
{ POSTGRESQL_QUERY_EXECUTOR_ON_CONFIG_CHANGED, null },
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add comment surrounding QUERY_MANAGER_FACTORY_ON_CONFIG_CHANGED here that describes how the "query executors since those are already being correctly refreshed already by the query manager factory reload process."

@@ -17,7 +17,7 @@ namespace Azure.DataApiBuilder.Core.Services.MetadataProviders
/// <inheritdoc />
public class MetadataProviderFactory : IMetadataProviderFactory
{
private readonly IDictionary<string, ISqlMetadataProvider> _metadataProviders;
private IDictionary<string, ISqlMetadataProvider> _metadataProviders;
Copy link
Contributor

Choose a reason for hiding this comment

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

just for new allocation, we shouldn't change its access modifier

@@ -62,7 +62,10 @@ private void ConfigureMetadataProviders()

public void OnConfigChanged(object? sender, HotReloadEventArgs args)
{
_metadataProviders = new Dictionary<string, ISqlMetadataProvider>();
Copy link
Contributor

Choose a reason for hiding this comment

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

better to clear() because it avoids re-allocating the _metadataProviders dictionary every time the OnConfigChanged method is called. it is more efficient in terms of memory and performance.

I'll address it in my PR. so you can remove revert this

@@ -97,7 +93,6 @@ public static bool TryParseConfig(string json,
ILogger? logger = null,
string? connectionString = null,
bool replaceEnvVar = false,
string dataSourceName = "",
Copy link

Choose a reason for hiding this comment

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

string dataSourceName = "",
If this has been removed, we should modify the doc string

@@ -133,7 +122,7 @@ public static bool TryParseConfig(string json,
}
Copy link

Choose a reason for hiding this comment

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

We should put Dictionary<string, string>? datasourceNameToConnectionString = new Dictionary<string, string>(); in the function defination itself instead of putting null there and then checking and replacing it with new object here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 🔥Hot Reload Tasks related to DAB's Hot Reload feature proposal
Projects
None yet
4 participants