-
Notifications
You must be signed in to change notification settings - Fork 496
Fix Production readiness for Persistence #1707
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,53 @@ | ||||
| /* | ||||
| * Licensed to the Apache Software Foundation (ASF) under one | ||||
| * or more contributor license agreements. See the NOTICE file | ||||
| * distributed with this work for additional information | ||||
| * regarding copyright ownership. The ASF licenses this file | ||||
| * to you under the Apache License, Version 2.0 (the | ||||
| * "License"); you may not use this file except in compliance | ||||
| * with the License. You may obtain a copy of the License at | ||||
| * | ||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||
| * | ||||
| * Unless required by applicable law or agreed to in writing, | ||||
| * software distributed under the License is distributed on an | ||||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||
| * KIND, either express or implied. See the License for the | ||||
| * specific language governing permissions and limitations | ||||
| * under the License. | ||||
| */ | ||||
|
|
||||
| package org.apache.polaris.extension.persistence.relational.jdbc; | ||||
|
|
||||
| import io.smallrye.common.annotation.Identifier; | ||||
| import jakarta.enterprise.context.ApplicationScoped; | ||||
| import jakarta.enterprise.inject.Any; | ||||
| import jakarta.enterprise.inject.Instance; | ||||
| import jakarta.enterprise.inject.Produces; | ||||
| import java.util.Optional; | ||||
| import org.apache.polaris.core.config.ProductionReadinessCheck; | ||||
| import org.apache.polaris.core.persistence.MetaStoreManagerFactory; | ||||
| import org.eclipse.microprofile.config.inject.ConfigProperty; | ||||
|
|
||||
| @ApplicationScoped | ||||
| public class RelationalJdbcProductionReadinessChecks { | ||||
| @Produces | ||||
| public ProductionReadinessCheck checkRelationalJdbc( | ||||
| @ConfigProperty(name = "quarkus.datasource.jdbc.url") Optional<String> jdbcUrl, | ||||
| @ConfigProperty(name = "polaris.persistence.type") String persistenceType, | ||||
| @Any Instance<MetaStoreManagerFactory> metaStoreManagerFactories) { | ||||
| // This check should only be applicable when persistence uses RelationalJdbc. | ||||
| if (!(metaStoreManagerFactories.select(Identifier.Literal.of(persistenceType)).get() | ||||
| instanceof JdbcMetaStoreManagerFactory)) { | ||||
| return ProductionReadinessCheck.OK; | ||||
| } | ||||
|
|
||||
| if (jdbcUrl.isPresent() && jdbcUrl.get().startsWith("jdbc:h2")) { | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be more reliable, plus it's in sync with actual persistence usage: Line 119 in 2a69415
The EclipseLink side is good to merge, IMHO, so if you prefer we could move this to a separate PR.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not mind adding this:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good, tbh i think the h2 check is fine, though one thing i realized doing this will also check the connection is properly made to the DB and if its not then we simply fail early that your DB is misconfigured correct it ! let me make the change should be small IMHO
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point about connections. Although, I would not fail the startup in that case, maybe just produce a warning check?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, connection checks should be part of the "readiness" check.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, though i prefer failing as without persistence we can't use the application at all, let me know if you feel strongly otherwise. |
||||
| return ProductionReadinessCheck.of( | ||||
| ProductionReadinessCheck.Error.of( | ||||
| "The current persistence (jdbc:h2) is intended for tests only.", | ||||
| "quarkus.datasource.jdbc.url")); | ||||
| } | ||||
| return ProductionReadinessCheck.OK; | ||||
| } | ||||
| } | ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to
.select()here? The usual producer should normally yield a value if we just declaredMetaStoreManagerFactoryfor injection, I think.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because both @Inject as a member of this class as well as using @Any Instance and then doing .get() letter was giving ambigous bean, I wonder if these checks run before the bean is actually created from QuarkusProducers, this is the only approach worked for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, this WFM :)
Output:
AAA: class org.apache.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory_ClientProxyUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤦♂️ I didn't try just passing it in the parameter without an Annotation. i though like anyother producer it would need one, I can confirm your suggestion works, though any explanation why even with
@Producesannotation we don;t need any annotation ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quarkus CDI is able to figure out bean dependencies. When a producer method is needed for a bean, its inputs are automatically injected, I suppose.