This is an automated email from the ASF dual-hosted git repository.

adutra pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git


The following commit(s) were added to refs/heads/main by this push:
     new febe4e83 Copy RealmId when passing it to TaskExecutorImpl (#879)
febe4e83 is described below

commit febe4e83c53c6864fa42114d25aff56786b2057a
Author: Alexandre Dutra <[email protected]>
AuthorDate: Mon Jan 27 15:00:03 2025 +0100

    Copy RealmId when passing it to TaskExecutorImpl (#879)
    
    Realm id is a request-scoped component, so we need to copy it to ensure it 
is available when
    the task is executed, even if the original realm id is no longer available 
because the
    request has completed.
---
 .../src/main/java/org/apache/polaris/core/context/RealmId.java       | 4 ++++
 .../main/java/org/apache/polaris/service/task/TaskExecutorImpl.java  | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git 
a/polaris-core/src/main/java/org/apache/polaris/core/context/RealmId.java 
b/polaris-core/src/main/java/org/apache/polaris/core/context/RealmId.java
index 98e58bb5..56bedbd3 100644
--- a/polaris-core/src/main/java/org/apache/polaris/core/context/RealmId.java
+++ b/polaris-core/src/main/java/org/apache/polaris/core/context/RealmId.java
@@ -37,6 +37,10 @@ public interface RealmId {
     return ImmutableRealmId.of(id);
   }
 
+  static RealmId copyOf(RealmId realmId) {
+    return ImmutableRealmId.copyOf(realmId);
+  }
+
   @Value.Parameter
   @JsonValue
   String id();
diff --git 
a/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java
 
b/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java
index 04472dec..68be1b45 100644
--- 
a/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java
+++ 
b/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java
@@ -97,7 +97,10 @@ public class TaskExecutorImpl implements TaskExecutor {
    */
   @Override
   public void addTaskHandlerContext(long taskEntityId, RealmId realmId) {
-    tryHandleTask(taskEntityId, realmId, null, 1);
+    // Realm id is a request-scoped component, so we need to copy it to ensure 
it is available when
+    // the task is executed, even if the original realm id is no longer 
available because the
+    // request has completed.
+    tryHandleTask(taskEntityId, RealmId.copyOf(realmId), null, 1);
   }
 
   private @Nonnull CompletableFuture<Void> tryHandleTask(

Reply via email to