dimas-b commented on code in PR #1482: URL: https://github.com/apache/polaris/pull/1482#discussion_r2064033081
########## extension/persistence/relational-jdbc/src/main/java/org/apache/polaris/extension/persistence/relational/jdbc/JdbcDatasource.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 JdbcDatasource { Review Comment: nit: Maybe `DataSourceSupplier`? ########## extension/persistence/relational-jdbc/src/main/java/org/apache/polaris/extension/persistence/relational/jdbc/JdbcBasePersistenceImpl.java: ########## @@ -304,6 +304,9 @@ private PolarisBaseEntity getPolarisBaseEntity(String query) { return results.getFirst(); } } catch (SQLException e) { + if (e.getSQLState().equals("42P01")) { Review Comment: This logic should probably be in `DatabaseType` ########## quarkus/admin/src/main/java/org/apache/polaris/admintool/config/QuarkusJdbcDataSource.java: ########## @@ -0,0 +1,59 @@ +/* + * 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.admintool.config; + +import io.quarkus.arc.InstanceHandle; +import java.util.List; +import javax.sql.DataSource; +import org.apache.polaris.extension.persistence.relational.jdbc.JdbcDatasource; +import org.postgresql.shaded.com.ongres.scram.common.util.Preconditions; + +public class QuarkusJdbcDataSource implements JdbcDatasource { + private final List<InstanceHandle<DataSource>> dataSources; + private final String realmIsolationType; + + public static final String DEFAULT_DATA_SOURCE_NAME = "<default>"; + public static final String REALM_ISOLATION_TYPE_DB = "db"; + + public QuarkusJdbcDataSource(String realmIsolationType, List<InstanceHandle<DataSource>> dataSources) { + this.realmIsolationType = realmIsolationType; + this.dataSources = dataSources; + } + + @Override + public DataSource fromRealmId(String realmId) { + Preconditions.checkNotNull(REALM_ISOLATION_TYPE_DB.equals(realmIsolationType) && dataSources.size() == 1, "Misconfigured datasources as per realm requirements"); + for (InstanceHandle<DataSource> handle : dataSources) { + String name = handle.getBean().getName(); + name = name == null ? DEFAULT_DATA_SOURCE_NAME : unquoteDataSourceName(name); + // if realm isolation is DB then there should be only one DS configured. + if (name.equals(realmId) || (REALM_ISOLATION_TYPE_DB.equals(realmIsolationType) && name.equals(DEFAULT_DATA_SOURCE_NAME))) { + return handle.get(); + } + } + throw new IllegalStateException("No datasource configured with name: " + realmId); + } + + public static String unquoteDataSourceName(String dataSourceName) { + if (dataSourceName.startsWith("\"") && dataSourceName.endsWith("\"")) { Review Comment: It might be best to define a config `Map` for translating realm ID to DS names (cf. `RealmContextConfiguration`), defaulting to 1:1 association when not configured. ########## quarkus/test-commons/src/main/java/org/apache/polaris/test/commons/PostgresRelationalJdbcLifeCycleManagement.java: ########## @@ -53,19 +56,40 @@ 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"); + + if (separateDs) { Review Comment: is this really useful for this class, which manages the database container? Would it not be clearer for it to have the list of databases to pre-configure? ########## 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\".db-kind=pgsql Review Comment: Is this for testing? ########## quarkus/admin/src/main/java/org/apache/polaris/admintool/config/QuarkusProducers.java: ########## @@ -76,4 +81,9 @@ public PolarisConfigurationStore configurationStore() { // A configuration store is not required when running the admin tool. return new PolarisConfigurationStore() {}; } + + @Produces + public JdbcDatasource jdbcDatasource(@ConfigProperty(name = "polaris.persistence.realm.isolation.type") String realmIsolationType, @All List<InstanceHandle<DataSource>> dataSources) { Review Comment: What is the purpose of the `polaris.persistence.realm.isolation.type` config? Considering that there could be many Polaris servers, each running with different config, this settings is rather confusion IMHO. A given Polaris server merely needs a way to find a DataSource for each Realm ID. -- 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