collado-mike commented on code in PR #493: URL: https://github.com/apache/polaris/pull/493#discussion_r1870177342
########## polaris-service/src/main/java/org/apache/polaris/service/context/RealmScopeContext.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.context; + +import jakarta.inject.Singleton; +import java.lang.annotation.Annotation; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.polaris.core.context.CallContext; +import org.apache.polaris.core.context.RealmContext; +import org.apache.polaris.core.context.RealmScope; +import org.glassfish.hk2.api.ActiveDescriptor; +import org.glassfish.hk2.api.Context; +import org.glassfish.hk2.api.ServiceHandle; + +@Singleton +public class RealmScopeContext implements Context<RealmScope> { Review Comment: The concern is not whether the `RealmContext` is recreated, but the items that are supposed to be scoped to a realm and reused across requests. Some examples off the top of my head are * EntityCache * Threadpools for background work * HTTP clients for remote caches or token validation * DB Connection pools There are a lot of good reasons to want to reuse resources across requests (e.g., https connections are expensive and we want to reuse them as much as possible), but it's important that these resources are scoped to specific realms (we don't want to look up `server_admin` from one realm when processing a request for another). I do get the concern about subtle bugs, though. That's one reason I added an explicit test to validate the entity cache is scoped to the realm and reused across requests. More tests and validation would be good for comfort. We could wrap all the realm-scoped stuff in factories with hash maps, like the `MetaStoreManagerFactory`, but... it just means we have to write factories for all those things. And then, as I commented to Dmitri, the intention becomes less clear - if readers believe a bean is request-scoped, but is actually supplied from a cache and reused across requests, it may be unclear if the object is safe for concurrent modification. -- 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]
