You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "adutra (via GitHub)" <gi...@apache.org> on 2024/12/21 10:09:49 UTC
[PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
adutra opened a new pull request, #11844:
URL: https://github.com/apache/iceberg/pull/11844
3rd PR for the Auth Manager API. Previous ones:
* #11809
* #11769
This PR introduces the `OAuth2Manager` along with session caching and credentials refreshing. It is still "unplugged" though. Most of the `OAuth2Manager` code reflects one-to-one what's currently hard-coded in `RESTSessionCatalog` (and it's still there).
\cc @nastra @danielcweeks
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks merged PR #11844:
URL: https://github.com/apache/iceberg/pull/11844
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1917315859
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+import org.apache.iceberg.relocated.com.google.common.util.concurrent.ThreadFactoryBuilder;
+import org.apache.iceberg.relocated.com.google.common.util.concurrent.Uninterruptibles;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuthSessionCache.class);
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param name a distinctive name for the cache.
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(String name, Duration sessionTimeout) {
+ this(name, sessionTimeout, null, null);
+ }
+
+ /**
+ * Creates a new cache with the given session timeout, executor, and nano time supplier. This
+ * method is useful for testing mostly.
+ *
+ * @param name a distinctive name for the cache.
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ * @param executor the executor to use for eviction tasks; if null, the cache will create a
+ * default executor. The executor will be closed when this cache is closed.
+ * @param nanoTimeSupplier the supplier for nano time; if null, the cache will use {@link
+ * System#nanoTime()}.
+ */
+ AuthSessionCache(
+ String name,
+ Duration sessionTimeout,
+ @Nullable Executor executor,
+ @Nullable LongSupplier nanoTimeSupplier) {
+ this.sessionTimeout = sessionTimeout;
+ this.executor = executor == null ? createExecutor(name) : executor;
+ this.nanoTimeSupplier = nanoTimeSupplier;
+ }
+
+ private static Executor createExecutor(String name) {
+ ThreadFactory threadFactory =
+ new ThreadFactoryBuilder()
+ .setNameFormat(name + "-auth-session-evict-%d")
+ .setDaemon(true)
+ .build();
+ return Executors.newCachedThreadPool(threadFactory);
Review Comment:
We should be using a dedicated pool from our `ThreadPools` utility. I would suggest: `ThreadPools::newExitingWorkerPool(String namePrefix, int poolSize)` with a named pool like we had previously.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1917092295
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+import org.apache.iceberg.relocated.com.google.common.util.concurrent.ThreadFactoryBuilder;
+import org.apache.iceberg.relocated.com.google.common.util.concurrent.Uninterruptibles;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuthSessionCache.class);
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param name a distinctive name for the cache.
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(String name, Duration sessionTimeout) {
+ this(name, sessionTimeout, null, null);
+ }
+
+ /**
+ * Creates a new cache with the given session timeout, executor, and nano time supplier. This
+ * method is useful for testing mostly.
+ *
+ * @param name a distinctive name for the cache.
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ * @param executor the executor to use for eviction tasks; if null, the cache will create a
+ * default executor. The executor will be closed when this cache is closed.
+ * @param nanoTimeSupplier the supplier for nano time; if null, the cache will use {@link
+ * System#nanoTime()}.
+ */
+ AuthSessionCache(
+ String name,
+ Duration sessionTimeout,
+ @Nullable Executor executor,
+ @Nullable LongSupplier nanoTimeSupplier) {
+ this.sessionTimeout = sessionTimeout;
+ this.executor = executor == null ? createExecutor(name) : executor;
+ this.nanoTimeSupplier = nanoTimeSupplier;
+ }
+
+ private static Executor createExecutor(String name) {
+ ThreadFactory threadFactory =
+ new ThreadFactoryBuilder()
+ .setNameFormat(name + "-auth-session-evict-%d")
+ .setDaemon(true)
+ .build();
+ return Executors.newCachedThreadPool(threadFactory);
Review Comment:
I think this is the best executor for this kind of task, as we don't want a core thread kept alive if there isn't anything to do.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1910677023
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
Review Comment:
It looks like we should also make this package private. The other issue is that we shouldn't be using the common pool by default. This should probably be provided by the `OAuth2Manager` or if we expect there to be only one per manager, then just create a named pool for handling refreshes. We definitely don't want to rely on or possibly tie up the common pool.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1901735545
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthManagers.java:
##########
@@ -42,6 +57,9 @@ public static AuthManager loadAuthManager(String name, Map<String, String> prope
case AuthProperties.AUTH_TYPE_BASIC:
impl = AuthProperties.AUTH_MANAGER_IMPL_BASIC;
break;
+ case AuthProperties.AUTH_TYPE_OAUTH2:
+ impl = AuthProperties.AUTH_MANAGER_IMPL_OAUTH2;
+ break;
default:
impl = authType;
Review Comment:
There will be aliases for built-in managers, e.g. you can activate the built-in oauth2 manager with either:
```
rest.auth.type = oauth2
rest.auth.type = org.apache.iceberg.rest.auth.OAuth2Manager
```
But for custom ones, you must provide the FQDN of your implementation.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1912976403
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
Review Comment:
@danielcweeks I searched for all `Caffeine` caches in Iceberg's repo and found 25 occurrences. Only one occurrence sets the executor, the one in `CachingCatalog`:
https://github.com/apache/iceberg/blob/f7d40f07131894719c7ad9f99fda7c6cb7aec932/core/src/main/java/org/apache/iceberg/CachingCatalog.java#L112
Consequently, all the others are using the common pool for asynchronous tasks such as eviction.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1917090457
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
Review Comment:
This is not about token refresh, this is about auth session eviction.
But fair enough. I'll do it.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "johnnysohn (via GitHub)" <gi...@apache.org>.
johnnysohn commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1898846838
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthManagers.java:
##########
@@ -42,6 +57,9 @@ public static AuthManager loadAuthManager(String name, Map<String, String> prope
case AuthProperties.AUTH_TYPE_BASIC:
impl = AuthProperties.AUTH_MANAGER_IMPL_BASIC;
break;
+ case AuthProperties.AUTH_TYPE_OAUTH2:
+ impl = AuthProperties.AUTH_MANAGER_IMPL_OAUTH2;
+ break;
default:
impl = authType;
Review Comment:
can we also define something like `AUTH_IMPL = "rest.auth.type";` that could be used here for any custom auth manager/provider we want to bring in?
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1910786713
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
Review Comment:
Re: turning this constructor package-private: this won't fly, as SigV4 will also need to create caches, so this constructor needs to be 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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1910233419
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthConfig.java:
##########
@@ -21,15 +21,16 @@
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.iceberg.rest.ResourcePaths;
+import org.apache.iceberg.util.PropertyUtil;
import org.immutables.value.Value;
/**
- * The purpose of this class is to hold configuration options for {@link
- * org.apache.iceberg.rest.auth.OAuth2Util.AuthSession}.
+ * The purpose of this class is to hold OAuth configuration options for {@link
Review Comment:
we can't rename it without breaking the API unfortunately, so I'd say let's stick with the name
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
+ this(sessionTimeout, null, null);
+ }
+
+ /**
+ * Creates a new cache with the given session timeout, executor, and nano time supplier. This
+ * method is useful for testing mostly.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ * @param executor the executor to use for eviction tasks; if null, the cache will use the
+ * {@linkplain ForkJoinPool#commonPool() common pool}. The executor will not be closed when
+ * this cache is closed.
+ * @param nanoTimeSupplier the supplier for nano time; if null, the cache will use {@link
Review Comment:
+1
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1917015969
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
Review Comment:
Yes, we previously had refresh in a [dedicated threadpool](https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java#L730), so I don't think the other caffeine examples are what we should point to.
Also, we don't want to rely on the common pool for something important like token refresh. If something ties up the thread pool, we may miss the window to refresh. Also, we don't want to tie up the thread pool with refresh threads if something goes wrong.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1917315859
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+import org.apache.iceberg.relocated.com.google.common.util.concurrent.ThreadFactoryBuilder;
+import org.apache.iceberg.relocated.com.google.common.util.concurrent.Uninterruptibles;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuthSessionCache.class);
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param name a distinctive name for the cache.
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(String name, Duration sessionTimeout) {
+ this(name, sessionTimeout, null, null);
+ }
+
+ /**
+ * Creates a new cache with the given session timeout, executor, and nano time supplier. This
+ * method is useful for testing mostly.
+ *
+ * @param name a distinctive name for the cache.
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ * @param executor the executor to use for eviction tasks; if null, the cache will create a
+ * default executor. The executor will be closed when this cache is closed.
+ * @param nanoTimeSupplier the supplier for nano time; if null, the cache will use {@link
+ * System#nanoTime()}.
+ */
+ AuthSessionCache(
+ String name,
+ Duration sessionTimeout,
+ @Nullable Executor executor,
+ @Nullable LongSupplier nanoTimeSupplier) {
+ this.sessionTimeout = sessionTimeout;
+ this.executor = executor == null ? createExecutor(name) : executor;
+ this.nanoTimeSupplier = nanoTimeSupplier;
+ }
+
+ private static Executor createExecutor(String name) {
+ ThreadFactory threadFactory =
+ new ThreadFactoryBuilder()
+ .setNameFormat(name + "-auth-session-evict-%d")
+ .setDaemon(true)
+ .build();
+ return Executors.newCachedThreadPool(threadFactory);
Review Comment:
We should be using a dedicated pool from our `ThreadPools` utility. I would suggest: `ThreadPools::newExitingWorkerPool(String namePrefix, int poolSize)` like we had previously.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1910657206
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthConfig.java:
##########
@@ -21,15 +21,16 @@
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.iceberg.rest.ResourcePaths;
+import org.apache.iceberg.util.PropertyUtil;
import org.immutables.value.Value;
/**
- * The purpose of this class is to hold configuration options for {@link
- * org.apache.iceberg.rest.auth.OAuth2Util.AuthSession}.
+ * The purpose of this class is to hold OAuth configuration options for {@link
Review Comment:
Sounds good. I wasn't sure if this was entirely new or if there were prior dependencies. Maybe something to clean up for the future, but I'm good with this.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1909453326
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthConfig.java:
##########
@@ -21,15 +21,16 @@
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.iceberg.rest.ResourcePaths;
+import org.apache.iceberg.util.PropertyUtil;
import org.immutables.value.Value;
/**
- * The purpose of this class is to hold configuration options for {@link
- * org.apache.iceberg.rest.auth.OAuth2Util.AuthSession}.
+ * The purpose of this class is to hold OAuth configuration options for {@link
Review Comment:
If this is specific to OAuth (which it appears to be), should we call if OAuth2Config?
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1910776037
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
Review Comment:
@danielcweeks we are already using the common pool. The session cache currently is created as follows:
https://github.com/apache/iceberg/blob/a2b8008da7bc26e03248a35eeee60d1cc7e8499d/core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java#L1144-L1154
As you can see, we are not providing an executor explicitly, so evictions are being done on the common pool.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1916787886
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
Review Comment:
@danielcweeks do you maintain that you want me to use a different pool here?
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "johnnysohn (via GitHub)" <gi...@apache.org>.
johnnysohn commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1901683532
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthManagers.java:
##########
@@ -42,6 +57,9 @@ public static AuthManager loadAuthManager(String name, Map<String, String> prope
case AuthProperties.AUTH_TYPE_BASIC:
impl = AuthProperties.AUTH_MANAGER_IMPL_BASIC;
break;
+ case AuthProperties.AUTH_TYPE_OAUTH2:
+ impl = AuthProperties.AUTH_MANAGER_IMPL_OAUTH2;
+ break;
default:
impl = authType;
Review Comment:
Yes that works! I wasn't sure whether you were planning on having authType for as a name of the type
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1910192769
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
+ this(sessionTimeout, null, null);
+ }
+
+ /**
+ * Creates a new cache with the given session timeout, executor, and nano time supplier. This
+ * method is useful for testing mostly.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ * @param executor the executor to use for eviction tasks; if null, the cache will use the
+ * {@linkplain ForkJoinPool#commonPool() common pool}. The executor will not be closed when
+ * this cache is closed.
+ * @param nanoTimeSupplier the supplier for nano time; if null, the cache will use {@link
Review Comment:
No, not really, I can turn this constructor into package-private. It's meant only for tests.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1918180693
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,158 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+import org.apache.iceberg.relocated.com.google.common.util.concurrent.ThreadFactoryBuilder;
+import org.apache.iceberg.relocated.com.google.common.util.concurrent.Uninterruptibles;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private static final Logger LOG = LoggerFactory.getLogger(AuthSessionCache.class);
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param name a distinctive name for the cache.
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(String name, Duration sessionTimeout) {
+ this(name, sessionTimeout, null, null);
+ }
+
+ /**
+ * Creates a new cache with the given session timeout, executor, and nano time supplier. This
+ * method is useful for testing mostly.
+ *
+ * @param name a distinctive name for the cache.
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ * @param executor the executor to use for eviction tasks; if null, the cache will create a
+ * default executor. The executor will be closed when this cache is closed.
+ * @param nanoTimeSupplier the supplier for nano time; if null, the cache will use {@link
+ * System#nanoTime()}.
+ */
+ AuthSessionCache(
+ String name,
+ Duration sessionTimeout,
+ @Nullable Executor executor,
+ @Nullable LongSupplier nanoTimeSupplier) {
+ this.sessionTimeout = sessionTimeout;
+ this.executor = executor == null ? createExecutor(name) : executor;
+ this.nanoTimeSupplier = nanoTimeSupplier;
+ }
+
+ private static Executor createExecutor(String name) {
+ ThreadFactory threadFactory =
+ new ThreadFactoryBuilder()
+ .setNameFormat(name + "-auth-session-evict-%d")
+ .setDaemon(true)
+ .build();
+ return Executors.newCachedThreadPool(threadFactory);
Review Comment:
OK, switched to `ThreadPools.newExitingWorkerPool`.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1916787886
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
Review Comment:
@danielcweeks do you maintain that we want me to use a different pool here?
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1898887643
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthManagers.java:
##########
@@ -42,6 +57,9 @@ public static AuthManager loadAuthManager(String name, Map<String, String> prope
case AuthProperties.AUTH_TYPE_BASIC:
impl = AuthProperties.AUTH_MANAGER_IMPL_BASIC;
break;
+ case AuthProperties.AUTH_TYPE_OAUTH2:
+ impl = AuthProperties.AUTH_MANAGER_IMPL_OAUTH2;
+ break;
default:
impl = authType;
Review Comment:
That's precisely the intent here; if you have a custom manager, you would activate it with `rest.auth.type=my.custom.AuthManager`. Is that OK for you?
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#issuecomment-2583299516
@adutra Just one last comment on the thread pool, but other than that this look good to go.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "adutra (via GitHub)" <gi...@apache.org>.
adutra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1910190967
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthConfig.java:
##########
@@ -21,15 +21,16 @@
import java.util.Map;
import javax.annotation.Nullable;
import org.apache.iceberg.rest.ResourcePaths;
+import org.apache.iceberg.util.PropertyUtil;
import org.immutables.value.Value;
/**
- * The purpose of this class is to hold configuration options for {@link
- * org.apache.iceberg.rest.auth.OAuth2Util.AuthSession}.
+ * The purpose of this class is to hold OAuth configuration options for {@link
Review Comment:
Yes this is specific to OAuth, but changing its name would in principle be a breaking change. Are we OK with that?
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1909181281
##########
core/src/main/java/org/apache/iceberg/rest/auth/RefreshingAuthManager.java:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import java.util.List;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import javax.annotation.Nullable;
+import org.apache.iceberg.util.ThreadPools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * An {@link AuthManager} that provides machinery for refreshing authentication data asynchronously,
+ * using a background thread pool.
+ */
+public abstract class RefreshingAuthManager implements AuthManager {
+
+ private static final Logger LOG = LoggerFactory.getLogger(RefreshingAuthManager.class);
+
+ private final String executorNamePrefix;
+ private boolean keepRefreshed = true;
+ private volatile ScheduledExecutorService refreshExecutor;
+
+ protected RefreshingAuthManager(String executorNamePrefix) {
+ this.executorNamePrefix = executorNamePrefix;
+ }
+
+ public void keepRefreshed(boolean keep) {
+ this.keepRefreshed = keep;
+ }
+
+ @Override
+ public void close() {
+ ScheduledExecutorService service = refreshExecutor;
+ this.refreshExecutor = null;
+ if (service != null) {
+ List<Runnable> tasks = service.shutdownNow();
+ tasks.forEach(
+ task -> {
+ if (task instanceof Future) {
+ ((Future<?>) task).cancel(true);
+ }
+ });
+
+ try {
+ if (!service.awaitTermination(1, TimeUnit.MINUTES)) {
+ LOG.warn("Timed out waiting for refresh executor to terminate");
+ }
+ } catch (InterruptedException e) {
+ LOG.warn("Interrupted while waiting for refresh executor to terminate", e);
+ Thread.currentThread().interrupt();
+ }
+ }
+ }
+
+ @Nullable
+ protected ScheduledExecutorService refreshExecutor() {
+ if (!keepRefreshed) {
+ return null;
+ }
+ if (refreshExecutor == null) {
+ synchronized (this) {
+ if (refreshExecutor == null) {
+ this.refreshExecutor = ThreadPools.newScheduledPool(executorNamePrefix, 1);
+ }
+ }
+ }
Review Comment:
newline here and a few lines above
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthConfig.java:
##########
@@ -69,4 +70,42 @@ default String oauth2ServerUri() {
static ImmutableAuthConfig.Builder builder() {
return ImmutableAuthConfig.builder();
}
+
+ static AuthConfig fromProperties(Map<String, String> properties) {
+ return builder()
+ .credential(properties.get(OAuth2Properties.CREDENTIAL))
+ .token(properties.get(OAuth2Properties.TOKEN))
+ .scope(properties.getOrDefault(OAuth2Properties.SCOPE, OAuth2Properties.CATALOG_SCOPE))
+ .oauth2ServerUri(
+ properties.getOrDefault(OAuth2Properties.OAUTH2_SERVER_URI, ResourcePaths.tokens()))
+ .optionalOAuthParams(OAuth2Util.buildOptionalParam(properties))
+ .keepRefreshed(
+ PropertyUtil.propertyAsBoolean(
+ properties,
+ OAuth2Properties.TOKEN_REFRESH_ENABLED,
+ OAuth2Properties.TOKEN_REFRESH_ENABLED_DEFAULT))
+ .expiresAtMillis(expiresAtMillis(properties))
+ .build();
+ }
+
+ private static Long expiresAtMillis(Map<String, String> props) {
+ Long expiresAtMillis = null;
+
+ if (props.containsKey(OAuth2Properties.TOKEN)) {
+ expiresAtMillis = OAuth2Util.expiresAtMillis(props.get(OAuth2Properties.TOKEN));
+ }
+
+ if (expiresAtMillis == null) {
Review Comment:
both ifs can be combined
##########
core/src/test/java/org/apache/iceberg/rest/auth/TestAuthSessionCache.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+
+import java.time.Duration;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Function;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+class TestAuthSessionCache {
+
+ @Test
+ void cachedHitsAndMisses() {
+ AuthSessionCache cache =
+ new AuthSessionCache(Duration.ofHours(1), Runnable::run, System::nanoTime);
+ AuthSession session1 = Mockito.mock(AuthSession.class);
+ AuthSession session2 = Mockito.mock(AuthSession.class);
+
+ @SuppressWarnings("unchecked")
+ Function<String, AuthSession> loader = Mockito.mock(Function.class);
+ Mockito.when(loader.apply("key1")).thenReturn(session1);
+ Mockito.when(loader.apply("key2")).thenReturn(session2);
+
+ AuthSession session = cache.cachedSession("key1", loader);
+ assertThat(session).isNotNull().isSameAs(session1);
+
+ session = cache.cachedSession("key1", loader);
+ assertThat(session).isNotNull().isSameAs(session1);
+
+ session = cache.cachedSession("key2", loader);
+ assertThat(session).isNotNull().isSameAs(session2);
+
+ session = cache.cachedSession("key2", loader);
+ assertThat(session).isNotNull().isSameAs(session2);
+
+ Mockito.verify(loader, times(1)).apply("key1");
+ Mockito.verify(loader, times(1)).apply("key2");
+
+ assertThat(cache.sessionCache().asMap()).hasSize(2);
+ cache.close();
+ assertThat(cache.sessionCache().asMap()).isEmpty();
+
+ Mockito.verify(session1).close();
+ Mockito.verify(session2).close();
+ }
+
+ @Test
+ void cacheEviction() {
+ AtomicLong ticker = new AtomicLong(0);
+ AuthSessionCache cache = new AuthSessionCache(Duration.ofHours(1), Runnable::run, ticker::get);
+ AuthSession session1 = Mockito.mock(AuthSession.class);
+
+ @SuppressWarnings("unchecked")
Review Comment:
we typically add this to the enclosing method
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
+ this(sessionTimeout, null, null);
+ }
+
+ /**
+ * Creates a new cache with the given session timeout, executor, and nano time supplier. This
+ * method is useful for testing mostly.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ * @param executor the executor to use for eviction tasks; if null, the cache will use the
+ * {@linkplain ForkJoinPool#commonPool() common pool}. The executor will not be closed when
+ * this cache is closed.
+ * @param nanoTimeSupplier the supplier for nano time; if null, the cache will use {@link
+ * System#nanoTime()}.
+ */
+ public AuthSessionCache(
+ Duration sessionTimeout,
+ @Nullable Executor executor,
+ @Nullable LongSupplier nanoTimeSupplier) {
+ this.sessionTimeout = sessionTimeout;
+ this.executor = executor;
+ this.nanoTimeSupplier = nanoTimeSupplier;
+ }
+
+ /**
+ * Returns a cached session for the given key, loading it with the given loader if it is not
+ * already cached.
+ *
+ * @param key the key to use for the session.
+ * @param loader the loader to use to load the session if it is not already cached.
+ * @param <T> the type of the session.
+ * @return the cached session.
+ */
+ @SuppressWarnings("unchecked")
+ public <T extends AuthSession> T cachedSession(String key, Function<String, T> loader) {
+ return (T) sessionCache().get(key, loader);
+ }
+
+ @Override
+ public void close() {
+ Cache<String, AuthSession> cache = sessionCache;
+ this.sessionCache = null;
+ if (cache != null) {
+ cache.invalidateAll();
+ cache.cleanUp();
+ }
+ }
+
+ @VisibleForTesting
+ Cache<String, AuthSession> sessionCache() {
+ if (sessionCache == null) {
+ synchronized (this) {
+ if (sessionCache == null) {
+ this.sessionCache = newSessionCache(sessionTimeout, executor, nanoTimeSupplier);
+ }
+ }
+ }
+ return sessionCache;
Review Comment:
nit: newline after } here and in the method further below
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Auth Manager API part 3: OAuth2 Manager [iceberg]
Posted by "danielcweeks (via GitHub)" <gi...@apache.org>.
danielcweeks commented on code in PR #11844:
URL: https://github.com/apache/iceberg/pull/11844#discussion_r1909568642
##########
core/src/main/java/org/apache/iceberg/rest/auth/AuthSessionCache.java:
##########
@@ -0,0 +1,127 @@
+/*
+ * 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.iceberg.rest.auth;
+
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+import java.time.Duration;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ForkJoinPool;
+import java.util.function.Function;
+import java.util.function.LongSupplier;
+import javax.annotation.Nullable;
+import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
+
+/** A cache for {@link AuthSession} instances. */
+public class AuthSessionCache implements AutoCloseable {
+
+ private final Duration sessionTimeout;
+ private final Executor executor;
+ private final LongSupplier nanoTimeSupplier;
+
+ private volatile Cache<String, AuthSession> sessionCache;
+
+ /**
+ * Creates a new cache with the given session timeout, and with default executor and nano time
+ * supplier for eviction tasks.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ */
+ public AuthSessionCache(Duration sessionTimeout) {
+ this(sessionTimeout, null, null);
+ }
+
+ /**
+ * Creates a new cache with the given session timeout, executor, and nano time supplier. This
+ * method is useful for testing mostly.
+ *
+ * @param sessionTimeout the session timeout. Sessions will become eligible for eviction after
+ * this duration of inactivity.
+ * @param executor the executor to use for eviction tasks; if null, the cache will use the
+ * {@linkplain ForkJoinPool#commonPool() common pool}. The executor will not be closed when
+ * this cache is closed.
+ * @param nanoTimeSupplier the supplier for nano time; if null, the cache will use {@link
Review Comment:
Is there a reason we would need to expose this?
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org