Skip to content

Don't use explicit Guice binding for config class#14039

Closed
ksobolew wants to merge 1 commit intotrinodb:masterfrom
ksobolew:kudi/dont-explicitly-bind-metastore-type-config
Closed

Don't use explicit Guice binding for config class#14039
ksobolew wants to merge 1 commit intotrinodb:masterfrom
ksobolew:kudi/dont-explicitly-bind-metastore-type-config

Conversation

@ksobolew
Copy link
Copy Markdown
Contributor

@ksobolew ksobolew commented Sep 7, 2022

Description

The binding is necessary because HiveMetadataFactory has an @Injected parameter MetastoreTypeConfig now. This means that it needs to be bound now in all code paths, even when the metastore is provided externally (which only happens when using HiveQueryRunner). But explicit binding is bad, because it is incompatible with bindings managed by io.airlift:configuration, specifically with buildConfigObject and anything that calls it.

This commit changes the binding to use a regular configBinder(); in order to prevent unexpected configuration "leaking" from the environment, the HiveQueryRunner now explicitly forbids setting the hive.metastore property.

Non-technical explanation

Fixes incorrect internal use of configuration management interfaces.

Release notes

(x) This is not user-visible and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Section
* Fix some things. ({issue}`issuenumber`)

The binding is necessary because `HiveMetadataFactory` has an
`@Inject`ed parameter `MetastoreTypeConfig` now. This means that it
needs to be bound now in all code paths, even when the metastore is
provided externally (which only happens when using `HiveQueryRunner`).
But explicit binding is bad, because it is incompatible with bindings
managed by io.airlift:configuration, specifically with
`buildConfigObject` and anything that calls it.

This commit changes the binding to use a regular `configBinder()`; in
order to prevent unexpected configuration "leaking" from the
environment, the `HiveQueryRunner` now explicitly forbids setting the
`hive.metastore` property.
@cla-bot cla-bot bot added the cla-signed label Sep 7, 2022
binder.bind(HiveMetastoreFactory.class).annotatedWith(RawHiveMetastoreFactory.class).toInstance(HiveMetastoreFactory.ofInstance(metastore.get()));
MetastoreTypeConfig metastoreTypeConfig = new MetastoreTypeConfig();
metastoreTypeConfig.setMetastoreType("provided");
binder.bind(MetastoreTypeConfig.class).toInstance(metastoreTypeConfig);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It was intentionally like this

metastoreTypeConfig.setMetastoreType("provided");
binder.bind(MetastoreTypeConfig.class).toInstance(metastoreTypeConfig);
configBinder(binder).bindConfigDefaults(MetastoreTypeConfig.class, config -> config.setMetastoreType("provided"));
configBinder(binder).bindConfig(MetastoreTypeConfig.class);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is wrong. Here the code intention is not to expose any configurable properties

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I talked with @homar about this and was under the impression that this was done this way because there was no better way. I kinda understand why it's like this, but the current way is wrong too :)

Here the code intention is not to expose any configurable properties

I get that. But this code path is only used when HiveQueryRunner is used, so I added an assertion there to prevent setting this property. I was hoping this would have the same effect 🤷

@findepi
Copy link
Copy Markdown
Member

findepi commented Sep 8, 2022

I posted #14059 as an alternative approach

@ksobolew
Copy link
Copy Markdown
Contributor Author

ksobolew commented Sep 8, 2022

Closing in favor of #14059

@ksobolew ksobolew closed this Sep 8, 2022
@ksobolew ksobolew deleted the kudi/dont-explicitly-bind-metastore-type-config branch September 8, 2022 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants