snazy commented on code in PR #3411: URL: https://github.com/apache/polaris/pull/3411#discussion_r2685180602
########## runtime/service/src/main/java/org/apache/polaris/service/config/Bootstrapper.java: ########## @@ -0,0 +1,82 @@ +/* + * 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.service.config; + +import io.smallrye.common.annotation.Identifier; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.control.ActivateRequestContext; +import jakarta.inject.Inject; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import org.apache.polaris.core.persistence.MetaStoreManagerFactory; +import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; +import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult; +import org.apache.polaris.service.context.catalog.RealmContextHolder; + +/** Utility class for running per-realm bootstrap tasks each in a fresh Request Context. */ +@ApplicationScoped +public class Bootstrapper { + @Inject private RealmContextHolder realmContextHolder; + @Inject private MetaStoreManagerFactory factory; + + // Note: this executor is expected to NOT propagate CDI contexts to tasks. + @Inject + @Identifier("task-executor") + private ExecutorService executor; Review Comment: ```suggestion AsyncExec executor; ``` Would prevent a dependency from bootstrapping to the current tasks implementation. ########## runtime/service/src/main/java/org/apache/polaris/service/config/Bootstrapper.java: ########## @@ -0,0 +1,82 @@ +/* + * 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.service.config; + +import io.smallrye.common.annotation.Identifier; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.control.ActivateRequestContext; +import jakarta.inject.Inject; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import org.apache.polaris.core.persistence.MetaStoreManagerFactory; +import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; +import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult; +import org.apache.polaris.service.context.catalog.RealmContextHolder; + +/** Utility class for running per-realm bootstrap tasks each in a fresh Request Context. */ +@ApplicationScoped +public class Bootstrapper { + @Inject private RealmContextHolder realmContextHolder; + @Inject private MetaStoreManagerFactory factory; + + // Note: this executor is expected to NOT propagate CDI contexts to tasks. + @Inject + @Identifier("task-executor") + private ExecutorService executor; + + Map<String, PrincipalSecretsResult> bootstrapRealms( + Iterable<String> realmIds, RootCredentialsSet rootCredentialsSet) { + HashMap<String, PrincipalSecretsResult> result = new HashMap<>(); + for (String realmId : realmIds) { + Task t = new Task(realmContextHolder, realmId, rootCredentialsSet, factory); Review Comment: ```suggestion Task t = new Task(realmId, rootCredentialsSet); ``` ########## runtime/service/src/main/java/org/apache/polaris/service/config/Bootstrapper.java: ########## @@ -0,0 +1,82 @@ +/* + * 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.service.config; + +import io.smallrye.common.annotation.Identifier; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.control.ActivateRequestContext; +import jakarta.inject.Inject; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import org.apache.polaris.core.persistence.MetaStoreManagerFactory; +import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; +import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult; +import org.apache.polaris.service.context.catalog.RealmContextHolder; + +/** Utility class for running per-realm bootstrap tasks each in a fresh Request Context. */ +@ApplicationScoped +public class Bootstrapper { Review Comment: ```suggestion class Bootstrapper { ``` Don't think this type should be used from other packages. ########## runtime/service/src/main/java/org/apache/polaris/service/config/Bootstrapper.java: ########## @@ -0,0 +1,82 @@ +/* + * 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.service.config; + +import io.smallrye.common.annotation.Identifier; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.control.ActivateRequestContext; +import jakarta.inject.Inject; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import org.apache.polaris.core.persistence.MetaStoreManagerFactory; +import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; +import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult; +import org.apache.polaris.service.context.catalog.RealmContextHolder; + +/** Utility class for running per-realm bootstrap tasks each in a fresh Request Context. */ +@ApplicationScoped +public class Bootstrapper { + @Inject private RealmContextHolder realmContextHolder; + @Inject private MetaStoreManagerFactory factory; + + // Note: this executor is expected to NOT propagate CDI contexts to tasks. + @Inject + @Identifier("task-executor") + private ExecutorService executor; + + Map<String, PrincipalSecretsResult> bootstrapRealms( + Iterable<String> realmIds, RootCredentialsSet rootCredentialsSet) { + HashMap<String, PrincipalSecretsResult> result = new HashMap<>(); + for (String realmId : realmIds) { + Task t = new Task(realmContextHolder, realmId, rootCredentialsSet, factory); + try { + // Submit an async task per realm to ensure it runs in a fresh RequestContext. + // Note: simultaneous bootstrap of multiple realms is an edge case - no need + // to optimize for fast concurrent completion. + result.putAll(executor.submit(t).get(2, TimeUnit.MINUTES)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + return result; + } + + private record Task( + RealmContextHolder realmContextHolder, + String realmId, + RootCredentialsSet rootCredentialsSet, + MetaStoreManagerFactory factory) Review Comment: ```suggestion String realmId, RootCredentialsSet rootCredentialsSet) ``` ########## runtime/service/src/main/java/org/apache/polaris/service/config/Bootstrapper.java: ########## @@ -0,0 +1,82 @@ +/* + * 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.service.config; + +import io.smallrye.common.annotation.Identifier; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.control.ActivateRequestContext; +import jakarta.inject.Inject; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import org.apache.polaris.core.persistence.MetaStoreManagerFactory; +import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; +import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult; +import org.apache.polaris.service.context.catalog.RealmContextHolder; + +/** Utility class for running per-realm bootstrap tasks each in a fresh Request Context. */ +@ApplicationScoped +public class Bootstrapper { + @Inject private RealmContextHolder realmContextHolder; + @Inject private MetaStoreManagerFactory factory; Review Comment: ```suggestion @Inject RealmContextHolder realmContextHolder; @Inject MetaStoreManagerFactory factory; ``` [Less work](https://quarkus.io/guides/cdi-reference#quarkus-arc_quarkus-arc-transform-private-injected-fields) for DI instrumentation in Quarkus, and potentially nicer for Weld. ########## runtime/service/src/main/java/org/apache/polaris/service/config/Bootstrapper.java: ########## @@ -0,0 +1,82 @@ +/* + * 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.service.config; + +import io.smallrye.common.annotation.Identifier; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.context.control.ActivateRequestContext; +import jakarta.inject.Inject; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; +import org.apache.polaris.core.persistence.MetaStoreManagerFactory; +import org.apache.polaris.core.persistence.bootstrap.RootCredentialsSet; +import org.apache.polaris.core.persistence.dao.entity.PrincipalSecretsResult; +import org.apache.polaris.service.context.catalog.RealmContextHolder; + +/** Utility class for running per-realm bootstrap tasks each in a fresh Request Context. */ +@ApplicationScoped +public class Bootstrapper { + @Inject private RealmContextHolder realmContextHolder; + @Inject private MetaStoreManagerFactory factory; + + // Note: this executor is expected to NOT propagate CDI contexts to tasks. + @Inject + @Identifier("task-executor") + private ExecutorService executor; Review Comment: ```suggestion ExecutorService executor; ``` -- 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]
