danielhumanmod commented on code in PR #2003:
URL: https://github.com/apache/polaris/pull/2003#discussion_r2187883542


##########
service/common/src/main/java/org/apache/polaris/service/task/TaskRecoveryManager.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.task;
+
+import jakarta.annotation.Nonnull;
+import java.time.Clock;
+import java.time.ZoneId;
+import java.util.Iterator;
+import java.util.Map;
+import org.apache.polaris.core.PolarisCallContext;
+import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
+import org.apache.polaris.core.config.PolarisConfigurationStore;
+import org.apache.polaris.core.context.CallContext;
+import org.apache.polaris.core.context.RealmContext;
+import org.apache.polaris.core.entity.TaskEntity;
+import org.apache.polaris.core.persistence.BasePersistence;
+import org.apache.polaris.core.persistence.MetaStoreManagerFactory;
+import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
+import org.apache.polaris.core.persistence.dao.entity.BaseResult;
+import org.apache.polaris.core.persistence.dao.entity.EntitiesResult;
+import org.apache.polaris.core.persistence.pagination.PageToken;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TaskRecoveryManager {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(TaskRecoveryManager.class);
+
+  public static void recoverPendingTasks(
+      MetaStoreManagerFactory metaStoreManagerFactory,
+      String executorId,
+      TaskExecutor taskExecutor) {
+    recoverPendingTasks(
+        metaStoreManagerFactory,
+        executorId,
+        taskExecutor,
+        new PolarisConfigurationStore() {},
+        Clock.system(ZoneId.systemDefault()));
+  }
+
+  public static void recoverPendingTasks(
+      @Nonnull MetaStoreManagerFactory metaStoreManagerFactory,
+      @Nonnull String executorId,
+      @Nonnull TaskExecutor taskExecutor,
+      @Nonnull PolarisConfigurationStore configurationStore,
+      @Nonnull Clock clock) {
+    for (Iterator<Map.Entry<String, PolarisMetaStoreManager>> it =
+            metaStoreManagerFactory.getMetaStoreManagerMap();
+        it.hasNext(); ) {
+      Map.Entry<String, PolarisMetaStoreManager> entry = it.next();
+      RealmContext realmContext = entry::getKey;
+      PolarisMetaStoreManager metaStoreManager = entry.getValue();
+      BasePersistence metastore =
+          
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get();
+      PolarisCallContext polarisCallContext =
+          new PolarisCallContext(
+              realmContext,
+              metastore,
+              new PolarisDefaultDiagServiceImpl(),
+              configurationStore,
+              clock);
+      EntitiesResult entitiesResult =
+          metaStoreManager.loadTasks(polarisCallContext, executorId, 
PageToken.readEverything());

Review Comment:
   @adnanhemani continue [previous 
comment](https://github.com/apache/polaris/pull/1585/files#r2122779304) here: 
   
   > I'm not sure I'm understanding the logic here: we are asking for 20 tasks 
here - but what if there are more than 20 tasks that need recovery?
   
   Good catch, we should update to read all pending tasks



-- 
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-unsubscr...@polaris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to