dimas-b commented on code in PR #3960: URL: https://github.com/apache/polaris/pull/3960#discussion_r2907236152
########## persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DataSourceResolver.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.persistence.relational.jdbc; + +import java.util.Set; +import javax.sql.DataSource; + +/** + * Service to resolve the correct {@link DataSource} for a given realm and store + * type. + * This enables isolating different workloads (e.g., entity metadata vs metrics + * vs events) + * into different physical databases or connection pools. + */ +public interface DataSourceResolver { + + String STORE_TYPE_MAIN = "main"; Review Comment: Maybe an `enum`? ########## persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DefaultDataSourceResolver.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.persistence.relational.jdbc; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Instance; +import jakarta.inject.Inject; +import java.util.HashSet; +import java.util.Set; +import javax.sql.DataSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Default implementation of {@link DataSourceResolver} that routes all realms + * and store types to a + * single default {@link DataSource}. This serves as both the production default + * and the base for + * multi-datasource extensions. + * + * <p> + * To enable per-realm or per-store datasource routing, this class can be + * extended or replaced + * with a custom implementation that resolves named datasources based on + * configuration. + */ +@ApplicationScoped +public class DefaultDataSourceResolver implements DataSourceResolver { + + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultDataSourceResolver.class); + + private final Instance<DataSource> defaultDataSource; Review Comment: Does this have to be an `Instance`? Why not use the plain `DataSource` as type here? ########## persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DefaultDataSourceResolver.java: ########## @@ -0,0 +1,67 @@ +/* + * 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.persistence.relational.jdbc; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Instance; +import jakarta.inject.Inject; +import java.util.HashSet; +import java.util.Set; +import javax.sql.DataSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Default implementation of {@link DataSourceResolver} that routes all realms + * and store types to a + * single default {@link DataSource}. This serves as both the production default + * and the base for + * multi-datasource extensions. + * + * <p> + * To enable per-realm or per-store datasource routing, this class can be + * extended or replaced + * with a custom implementation that resolves named datasources based on + * configuration. + */ +@ApplicationScoped +public class DefaultDataSourceResolver implements DataSourceResolver { Review Comment: I wonder whether this class should "live" in `runtime/services` instead 🤔 Basically, the idea is that JDBC Persistence should not "worry" about how the DataSource is resolved. It's the concern of the "runtime" code. ########## persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/DataSourceResolver.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.persistence.relational.jdbc; + +import java.util.Set; +import javax.sql.DataSource; + +/** + * Service to resolve the correct {@link DataSource} for a given realm and store + * type. + * This enables isolating different workloads (e.g., entity metadata vs metrics + * vs events) + * into different physical databases or connection pools. + */ +public interface DataSourceResolver { + + String STORE_TYPE_MAIN = "main"; + String STORE_TYPE_METRICS = "metrics"; + String STORE_TYPE_EVENTS = "events"; + + /** + * Resolves the DataSource for a given realm and store type. + * + * @param realmId the realm identifier + * @param storeType the type of store (e.g., main, metrics, events) + * @return the resolved DataSource + */ + DataSource resolve(String realmId, String storeType); + + /** + * Returns all unique DataSources managed by this resolver. + * This is useful for global operations like schema initialization against all + * data sources. + * + * @return a set of all DataSources + */ + Set<DataSource> getAllUniqueDataSources(); Review Comment: It's fine to have the "list all" method, but I tend to think it needs a separate interface because it's a different use case. Specifically, providing a DataSource per realm does not have to be co-location with the code to list all data sources. The former is a Server runtime concerns, the later is more of an Admin tool concern. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
