Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Spanner expose databaseId provider bean #1530

Merged
merged 10 commits into from
Mar 15, 2019
Merged

Conversation

ChengyuanZhao
Copy link
Contributor

related #1525
allows bean for Database ID provider to support multiple instances or databases

*
* @since 1.2
*/
public interface DatabaseUtilityProvider<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks identical to java.util.function.Supplier except for the name. Why not just use Supplier in its place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea I actually prefer using those general "functional" classes. Will change.

[source,java]
----
@Bean
public DatabaseUtilityProvider<DatabaseId> databaseIdProvider() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we discussed and agreed on using something like DatabaseClientProvider. It's more flexible in a sense that it allows the app to connect to Spanner instances even in different projects.
You can always implement a DatabaseClientProvider that works with DatabaseId.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@meltsufin , so there is a provider bean for DatabaseClient exposed. However the way DatabaseClients receive their instance/database/project id is via the DatabaseId class. furthermore there is a DatabaseAdminClient that also uses the DatabaseId
so it made sense to also make a provider bean available for DatabaseId
(emphasizing that DatabaseClient provider bean is also exposed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the refdoc to emphasize that a bean for Supplier of DatabaseClient is also available and an option to set.

Speaking of Suppliers, should we go back and remove CredentialProvider and ProjectIDProvider and just use Suppler of Credentials and Supplier of ProjectID ?

@meltsufin meltsufin requested a review from dzou March 15, 2019 15:26
Copy link
Contributor

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

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

Some more review.

* @param <U> the type of objects this provider bases its products on.
* @author Chengyuan Zhao
*/
public class CachingDatabaseUtilityProvider<T, U> implements Supplier<T> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is too generic. The specificity of the name of the class does not reflect its function. What it does seems very generic and not specific to "Database".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed a type parameter, PTAL

*/
public SpannerDatabaseAdminTemplate(DatabaseAdminClient databaseAdminClient,
DatabaseClient databaseClient,
DatabaseId databaseId) {
Supplier<DatabaseClient> databaseClientProvider,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why would you need this, if you can compute it from the databaseIdProvider?

Copy link
Contributor Author

@ChengyuanZhao ChengyuanZhao Mar 15, 2019

Choose a reason for hiding this comment

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

If the user had chosen to provide his own DatabaseClient supplier then that wouldn't be right (for example if he sets things that aren't in DatabaseId). Also if we just use the DAtabaseIdProvider we would need to create new instances of DatabaseClient in here (instead of using existing ones) and also have a Spanner.class on hand.

@codecov
Copy link

codecov bot commented Mar 15, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@5c6ac41). Click here to learn what that means.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1530   +/-   ##
=========================================
  Coverage          ?   69.22%           
  Complexity        ?     1633           
=========================================
  Files             ?      238           
  Lines             ?     6281           
  Branches          ?      647           
=========================================
  Hits              ?     4348           
  Misses            ?     1648           
  Partials          ?      285
Flag Coverage Δ Complexity Δ
#unittests 69.22% <94.44%> (?) 1633 <10> (?)
Impacted Files Coverage Δ Complexity Δ
...nner/core/ReadWriteTransactionSpannerTemplate.java 70% <ø> (ø) 4 <0> (?)
...anner/core/ReadOnlyTransactionSpannerTemplate.java 55.55% <ø> (ø) 3 <0> (?)
...anner/core/admin/SpannerDatabaseAdminTemplate.java 83.07% <100%> (ø) 20 <3> (?)
...configure/spanner/GcpSpannerAutoConfiguration.java 70.9% <100%> (ø) 1 <0> (?)
...nner/core/admin/CachingDatabaseClientProvider.java 100% <100%> (ø) 2 <2> (?)
...er/SpannerTransactionManagerAutoConfiguration.java 80% <100%> (ø) 1 <0> (?)
...p/data/spanner/core/SpannerTransactionManager.java 69.69% <100%> (ø) 13 <1> (?)
...k/cloud/gcp/data/spanner/core/SpannerTemplate.java 73.07% <81.81%> (ø) 73 <4> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c6ac41...166b8c8. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 15, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@5c6ac41). Click here to learn what that means.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1530   +/-   ##
=========================================
  Coverage          ?   69.22%           
  Complexity        ?     1633           
=========================================
  Files             ?      238           
  Lines             ?     6281           
  Branches          ?      647           
=========================================
  Hits              ?     4348           
  Misses            ?     1648           
  Partials          ?      285
Flag Coverage Δ Complexity Δ
#unittests 69.22% <94.44%> (?) 1633 <10> (?)
Impacted Files Coverage Δ Complexity Δ
...nner/core/ReadWriteTransactionSpannerTemplate.java 70% <ø> (ø) 4 <0> (?)
...anner/core/ReadOnlyTransactionSpannerTemplate.java 55.55% <ø> (ø) 3 <0> (?)
...a/spanner/core/admin/CachingComposingSupplier.java 100% <100%> (ø) 2 <2> (?)
...anner/core/admin/SpannerDatabaseAdminTemplate.java 83.07% <100%> (ø) 20 <3> (?)
...configure/spanner/GcpSpannerAutoConfiguration.java 70.9% <100%> (ø) 1 <0> (?)
...er/SpannerTransactionManagerAutoConfiguration.java 80% <100%> (ø) 1 <0> (?)
...p/data/spanner/core/SpannerTransactionManager.java 69.69% <100%> (ø) 13 <1> (?)
...k/cloud/gcp/data/spanner/core/SpannerTemplate.java 73.07% <81.81%> (ø) 73 <4> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c6ac41...1eaf40c. Read the comment docs.

* @param <U> the type of objects this provider bases its products on.
* @author Chengyuan Zhao
*/
public class CachingDatabaseClientProvider<U> implements Supplier<DatabaseClient> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there's much value in this U type parameter either.
I would just call this class DatabaseIdBasedDatabaseClientProvider and it doesn't need any generics at all. It just needs the DatabaseIdProvider and a Spanner instance.
Why does this class even need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think there's a reason to make it that restrictive. There's no reason U can't be the Spanner object in another use-case or a just a string specifying the instance ID.
I don't think we gain any simplification by being more restrictive here, actually.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case, you might be better off going back to the most generic design as you had before, and just renaming this class to CachingSupplier<INPUT, OUTPUT> implements Supplier<OUTPUT>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good! changes made

docs/src/main/asciidoc/spanner.adoc Outdated Show resolved Hide resolved
*
* @since 1.2
*/
public interface DatabaseIdProvider extends Supplier<DatabaseId> {
Copy link
Contributor

Choose a reason for hiding this comment

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

What was the reason for creating this wrapper around Supplier<DatabaseId>? Is it better to just use Supplier<DatabaseId> in the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See a comment further up from Mike :P

Copy link
Contributor

@dmitry-s dmitry-s left a comment

Choose a reason for hiding this comment

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

We probably should add an example or integration test for this feature.

@ChengyuanZhao
Copy link
Contributor Author

@dmitry-s Done !! PTAL

Copy link
Contributor

@dmitry-s dmitry-s left a comment

Choose a reason for hiding this comment

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

Looks good!

@ChengyuanZhao ChengyuanZhao merged commit 16f9aad into master Mar 15, 2019
@ChengyuanZhao ChengyuanZhao deleted the spanner-template-provider branch March 15, 2019 19:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

4 participants