dimas-b commented on code in PR #1482: URL: https://github.com/apache/polaris/pull/1482#discussion_r2067462025
########## quarkus/commons/src/main/java/org/apache/polaris/commons/PostgresRelationalJdbcLifeCycleManagement.java: ########## @@ -53,19 +60,42 @@ public Map<String, String> start() { context.containerNetworkId().ifPresent(postgres::withNetworkMode); postgres.start(); - return Map.of( - "polaris.persistence.type", - "relational-jdbc", - "quarkus.datasource.db-kind", - "pgsql", - "quarkus.datasource.jdbc.url", - postgres.getJdbcUrl(), - "quarkus.datasource.username", - postgres.getUsername(), - "quarkus.datasource.password", - postgres.getPassword(), - "quarkus.datasource.jdbc.initial-size", - "10"); + Map<String, String> props = new HashMap<>(); + props.put("polaris.persistence.type", "relational-jdbc"); + + if (!databases.isEmpty()) { + for (String database : databases) { + // polaris.relation.jdbc.datasource.realm=realm_ds + props.put(String.format("polaris.relation.jdbc.datasource.%s", database), database + "_ds"); + props.put(String.format("quarkus.datasource.%s.db-kind", database + "_ds"), "pgsql"); + props.put(String.format("quarkus.datasource.%s.active", database + "_ds"), "true"); + props.put( + String.format("quarkus.datasource.%s.jdbc.url", database + "_ds"), + postgres.getJdbcUrl().replace("realm1", database)); + props.put( + String.format("quarkus.datasource.%s.username", database + "_ds"), + postgres.getUsername()); + props.put( + String.format("quarkus.datasource.%s.password", database + "_ds"), + postgres.getPassword()); + } + } else { + return Map.of( + "polaris.persistence.type", + "relational-jdbc", + "quarkus.datasource.db-kind", + "pgsql", + "quarkus.datasource.jdbc.url", + postgres.getJdbcUrl(), + "quarkus.datasource.username", + postgres.getUsername(), + "quarkus.datasource.password", + postgres.getPassword(), + "quarkus.datasource.jdbc.initial-size", + "10"); + } + + return props; Review Comment: The code patterns of falling through to here from the main `if` branch, but not doing so from `else` look very odd to me from code maintenance POV. ########## quarkus/commons/src/main/java/org/apache/polaris/commons/QuarkusDatasourceSupplier.java: ########## @@ -0,0 +1,54 @@ +/* + * 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.commons; + +import io.quarkus.arc.InstanceHandle; +import java.util.List; +import javax.sql.DataSource; +import org.apache.polaris.extension.persistence.relational.jdbc.DatasourceSupplier; +import org.apache.polaris.extension.persistence.relational.jdbc.RelationalJdbcConfiguration; + +public class QuarkusDatasourceSupplier implements DatasourceSupplier { Review Comment: It looks like we mixing this production code with test code in the same module, same package... This is not nice :thinking: WDYT about keeping this class under `quarkus/service` (and keeping test code as before)? ########## quarkus/admin/src/main/java/org/apache/polaris/admintool/config/QuarkusProducers.java: ########## @@ -76,4 +83,11 @@ public PolarisConfigurationStore configurationStore() { // A configuration store is not required when running the admin tool. return new PolarisConfigurationStore() {}; } + + @Produces + public DatasourceSupplier datasourceSupplier( + @Any RelationalJdbcConfiguration relationalJdbcConfiguration, + @All List<InstanceHandle<DataSource>> datasources) { + return new QuarkusDatasourceSupplier(relationalJdbcConfiguration, datasources); Review Comment: If you add an injectable constructor (same params) to `QuarkusDatasourceSupplier` then producers will not be required. ########## quarkus/commons/src/main/java/org/apache/polaris/commons/QuarkusDatasourceSupplier.java: ########## @@ -0,0 +1,54 @@ +/* + * 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.commons; + +import io.quarkus.arc.InstanceHandle; +import java.util.List; +import javax.sql.DataSource; +import org.apache.polaris.extension.persistence.relational.jdbc.DatasourceSupplier; +import org.apache.polaris.extension.persistence.relational.jdbc.RelationalJdbcConfiguration; + +public class QuarkusDatasourceSupplier implements DatasourceSupplier { + private List<InstanceHandle<DataSource>> dataSources; + private RelationalJdbcConfiguration relationalJdbcConfiguration; Review Comment: pls make these fields `final` ########## quarkus/admin/src/main/resources/application.properties: ########## @@ -49,3 +49,21 @@ quarkus.index-dependency.guava.group-id=com.google.guava quarkus.index-dependency.guava.artifact-id=guava quarkus.index-dependency.protobuf.group-id=com.google.protobuf quarkus.index-dependency.protobuf.artifact-id=protobuf-java + +#quarkus.datasource.db-kind=pgsql +#quarkus.datasource.jdbc.url=polaris +#quarkus.datasource.username=polaris +#quarkus.datasource.password=polaris +quarkus.datasource.\"realm1_ds\".db-kind=pgsql Review Comment: I'm still not sure why we need the multitude of test-like datasource configs in the production sections of the admin tool properties :thinking: ########## extension/persistence/relational-jdbc/build.gradle.kts: ########## @@ -32,6 +32,7 @@ dependencies { compileOnly(libs.jakarta.inject.api) implementation(libs.smallrye.common.annotation) // @Identifier + compileOnly(libs.smallrye.config.core) Review Comment: Why do we need this? ########## extension/persistence/relational-jdbc/src/main/java/org/apache/polaris/extension/persistence/relational/jdbc/DatasourceSupplier.java: ########## @@ -0,0 +1,25 @@ +/* + * 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 javax.sql.DataSource; + +public interface DatasourceSupplier { Review Comment: It might be preferable to move this class to `polaris-core` to avoid service code depending on extensions. ########## extension/persistence/relational-jdbc/src/main/java/org/apache/polaris/extension/persistence/relational/jdbc/RelationalJdbcConfiguration.java: ########## @@ -0,0 +1,27 @@ +/* + * 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.config.ConfigMapping; +import java.util.Map; + +@ConfigMapping(prefix = "polaris.relation.jdbc") +public interface RelationalJdbcConfiguration { Review Comment: It is preferable to keep config interfaces used by more generic Polaris modules free from Quarkus dependencies, and them have a sub-interface (mostly empty) inside Quarkus modules with config annotations for build-time wiring. ########## extension/persistence/relational-jdbc/src/main/java/org/apache/polaris/extension/persistence/relational/jdbc/JdbcBasePersistenceImpl.java: ########## @@ -315,6 +315,12 @@ private PolarisBaseEntity getPolarisBaseEntity(String query) { return results.getFirst(); } } catch (SQLException e) { + // This look-up is used for checking if the realm is bootstrap or not. + // If we have 1 DB per realm it might happen that the realm is not boostrap + // at all. Review Comment: So why not throw an exception in that case? ########## quarkus/commons/src/main/java/org/apache/polaris/commons/QuarkusDatasourceSupplier.java: ########## @@ -0,0 +1,54 @@ +/* + * 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.commons; + +import io.quarkus.arc.InstanceHandle; +import java.util.List; +import javax.sql.DataSource; +import org.apache.polaris.extension.persistence.relational.jdbc.DatasourceSupplier; +import org.apache.polaris.extension.persistence.relational.jdbc.RelationalJdbcConfiguration; + +public class QuarkusDatasourceSupplier implements DatasourceSupplier { + private List<InstanceHandle<DataSource>> dataSources; + private RelationalJdbcConfiguration relationalJdbcConfiguration; + + public static final String DEFAULT_DATA_SOURCE_NAME = "<default>"; Review Comment: why `public`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@polaris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org