You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Shawnsuun (via GitHub)" <gi...@apache.org> on 2024/12/22 10:26:08 UTC

[PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Shawnsuun opened a new pull request, #25838:
URL: https://github.com/apache/flink/pull/25838

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   Currently, when a Flink job finishes, it writes an archive as a single file that maps paths to JSON files. Flink History Server (FHS) job archives are pulled locally to where the FHS is running. This process creates a local directory structure that scales inefficiently as the number of jobs increases.
   
   ### Key Problems
   - **High inode usage** in the file system due to nested directories for job archives.
   - **Slower data retrieval** and bottlenecks in job archive navigation at scale.
   - Challenges due to limited file system scalability.
   
   ### Proposed Solution
   Integrating **RocksDB**, a high-performance embedded database, as an alternative storage backend for job archives. RocksDB provides:
   - **Faster job data retrieval.**
   - **Reduced inode consumption.**
   - **Enhanced scalability**, especially in containerized environments.
   
   The integration of RocksDB is implemented as a pluggable backend. The current file system storage remains intact, while RocksDB serves as an optional alternative for efficient storage and retrieval of job archives.
   
   ---
   
   ## Brief Change Log
   
   ### 1. KVStore Interface
   - Introduced `KVStore` as an abstraction for key-value storage systems to enable flexible storage backends.
   - Added basic CRUD operations and advanced capabilities for managing job archives.
   
   ### 2. RocksDB Integration
   - Implemented `HistoryServerRocksDBKVStore` as the RocksDB-based implementation of the `KVStore` interface.
   - Mapped the hierarchical file-based job archive structure into key-value pairs for efficient storage and retrieval.
   
   ### 3. ArchiveFetcher Abstraction and Improvements
   - Introduced `ArchiveFetcher` as an abstract class to support multiple backends for job archive fetching.
   - Updated `HistoryServerArchiveFetcher` for file-based systems.
   - Created `HistoryServerKVStoreArchiveFetcher` to fetch job archives using RocksDB.
   
   ### 4. ServerHandler Abstraction and Improvements
   - Designed `HistoryServerServerHandler` as an abstract base class for handling HTTP requests, supporting pluggable backends.
   - Updated `HistoryServerStaticFileServerHandler` for file-based job archive serving.
   - Implemented `HistoryServerKVStoreServerHandler` to serve job data from RocksDB via REST APIs.
   
   ### 5. HistoryServer Updates
   - Modified `HistoryServer` to integrate the `KVStore` interface and support RocksDB as a pluggable backend.
   - Added configuration options in `HistoryServerOptions` to toggle between file-based and RocksDB storagen:
   - Add the following configuration options in your flink-conf.yaml file to enable RocksDB as the storage backend for the History Server.
     ```yaml
     historyserver.storage.backend: kvstore
     ```
   
   ---
   
   
   ## Verifying this change
   
   This change added tests and can be verified as follows:
   
   ### 1. Testing
   - **Unit Tests**:
     - Added `FhsRocksDBKVStoreTest` to validate CRUD operations and resource cleanup for RocksDB.
     - Added `HistoryServerKVStoreArchiveFetcherTest` to ensure correct fetching and processing of job archives from RocksDB.
   
   - **Integration Tests**:
     - Built a Flink binary and configured `flink-conf.yaml` to test both file-based and RocksDB backends.
     - Verified archive retrieval via the History Server web UI and ensured backward compatibility with the file-based backend.
   
   - **End-to-End Tests**:
     - Conducted tests in a Kubernetes cluster with both RocksDB and file-based storage backends.
     - Verified correct behavior of the History Server in processing and displaying job archives for both storage backends in a real-world setup.
   
   ### 2. Performance Enhancements
   - **Faster Archive Retrieval**: Achieved a 4.25x improvement in fetching and processing archives with RocksDB compared to the traditional file system (tested in a production environment).
     - File system: 17 minutes for 100 archives.
     - RocksDB: 4 minutes for 100 archives.
   - **Reduced Inode Usage**: Reduced inode consumption by over 99.99%.
     - File system: Over 20 million inodes.
     - RocksDB: Only 79 inodes.
   - **Lower Storage Usage**: Achieved a 95.6% reduction in storage usage.
     - File system: 48 GB for 100 archives.
     - RocksDB: 2.1 GB for 100 archives.
   
   These enhancements significantly improve scalability, reduce resource overhead, and make the History Server more responsive for large-scale deployments.
   
   ---
   
   ## Does this pull request potentially affect one of the following parts:
   
   - **Dependencies**: No (using existing RocksDB dependency).
   - **Public API**: No.
   - **Serializers**: No.
   - **Performance-sensitive code paths**: Yes (job archive storage and retrieval).
   - **Deployment or recovery**: Yes (affects FHS deployment with the RocksDB backend option).
   - **File system connectors**: No.
   
   ---
   
   ## Documentation
     - Does this pull request introduce a new feature? (yes)
     - If yes, how is the feature documented? (not documented)
   


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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "venkata91 (via GitHub)" <gi...@apache.org>.
venkata91 commented on PR #25838:
URL: https://github.com/apache/flink/pull/25838#issuecomment-2558560788

   Thanks @Shawnsuun for adding pluggable storage backend and a new RocksDB storage backend support. This is a great addition.
   
   At scale, we also see the current set of issues with the file/directory based storage backend for the HistoryServer especially with respect to the quick exhaustion of inodes. 
   
   Flink OSS has a formal process called FLIP - Flink Improvement proposals where any new designs are vetted by the community and goes for a voting process. See [FLIP improvement proposals wiki](https://cwiki.apache.org/confluence/display/Flink/Flink+Improvement+Proposals) to know more.
   
   I am happy to help with reviewing this code. Thanks again!


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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "Shawnsuun (via GitHub)" <gi...@apache.org>.
Shawnsuun commented on PR #25838:
URL: https://github.com/apache/flink/pull/25838#issuecomment-2580522373

   > Thanks @Shawnsuun for adding pluggable storage backend and a new RocksDB storage backend support. This is a great addition.
   > 
   > At scale, we also see the current set of issues with the file/directory based storage backend for the HistoryServer especially with respect to the quick exhaustion of inodes.
   > 
   > Flink OSS has a formal process called FLIP - Flink Improvement proposals where any new designs are vetted by the community and goes for a voting process. See [FLIP improvement proposals wiki](https://cwiki.apache.org/confluence/display/Flink/Flink+Improvement+Proposals) to know more.
   > 
   > I am happy to help with reviewing this code. Thanks again!
   
   @venkata91 Thanks for reviewing! I’m in progress on opening an Apache account to start the FLIP proposal for this, and I’ll be sure to keep you updated. Appreciate your support!


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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25838:
URL: https://github.com/apache/flink/pull/25838#issuecomment-2986786703

   This PR has been closed since it has not had any activity in 120 days. 
   If you feel like this was a mistake, or you would like to continue working on it, 
   please feel free to re-open the PR and ask for a review.


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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "venkata91 (via GitHub)" <gi...@apache.org>.
venkata91 commented on PR #25838:
URL: https://github.com/apache/flink/pull/25838#issuecomment-2560253701

   @Shawnsuun There are test failures, can you please take a look?


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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #25838:
URL: https://github.com/apache/flink/pull/25838#discussion_r1908973583


##########
flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/history/ArchiveFetcher.java:
##########
@@ -0,0 +1,265 @@
+/*
+ * 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.flink.runtime.webmonitor.history;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.JobStatus;
+import org.apache.flink.core.fs.FileStatus;
+import org.apache.flink.core.fs.FileSystem;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.messages.webmonitor.JobDetails;
+import org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails;
+import org.apache.flink.util.jackson.JacksonMapperFactory;
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Consumer;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * The {@code ArchiveFetcher} class is an abstract class that defines the basic structure for
+ * fetching job archives in the Flink History Server. Implementations of this class should provide
+ * the logic for retrieving and processing job archives.
+ *
+ * <p>This class may be extended by specific implementations to support different storage backends
+ * for job archives, such as local file systems or key-value stores.
+ */
+public abstract class ArchiveFetcher {
+
+    /** Possible job archive operations in history-server. */
+    public enum ArchiveEventType {
+        /** Job archive was found in one refresh location and created in history server. */
+        CREATED,
+        /**
+         * Job archive was deleted from one of refresh locations and deleted from history server.
+         */
+        DELETED
+    }
+
+    /** Representation of job archive event. */
+    public static class ArchiveEvent {
+        private final String jobID;
+        private final ArchiveFetcher.ArchiveEventType operation;
+
+        ArchiveEvent(String jobID, ArchiveFetcher.ArchiveEventType operation) {
+            this.jobID = jobID;
+            this.operation = operation;
+        }
+
+        public String getJobID() {
+            return jobID;
+        }
+
+        public ArchiveFetcher.ArchiveEventType getType() {
+            return operation;
+        }
+    }
+
+    protected static final Logger LOG = LoggerFactory.getLogger(ArchiveFetcher.class);
+
+    protected static final ObjectMapper MAPPER = JacksonMapperFactory.createObjectMapper();
+
+    protected final List<HistoryServer.RefreshLocation> refreshDirs;
+    protected final Consumer<ArchiveEvent> jobArchiveEventListener;
+    protected final boolean processExpiredArchiveDeletion;
+    protected final boolean processBeyondLimitArchiveDeletion;
+    protected final int maxHistorySize;
+
+    /** Cache of all available jobs identified by their id. */
+    protected final Map<Path, Set<String>> cachedArchivesPerRefreshDirectory;
+
+    protected ArchiveFetcher(
+            List<HistoryServer.RefreshLocation> refreshDirs,
+            Consumer<ArchiveEvent> jobArchiveEventListener,
+            boolean cleanupExpiredArchives,
+            int maxHistorySize) {
+        this.refreshDirs = checkNotNull(refreshDirs);
+        this.jobArchiveEventListener = jobArchiveEventListener;
+        this.processExpiredArchiveDeletion = cleanupExpiredArchives;
+        this.maxHistorySize = maxHistorySize;
+        this.processBeyondLimitArchiveDeletion = this.maxHistorySize > 0;
+        this.cachedArchivesPerRefreshDirectory = new HashMap<>();
+        for (HistoryServer.RefreshLocation refreshDir : refreshDirs) {
+            cachedArchivesPerRefreshDirectory.put(refreshDir.getPath(), new HashSet<>());
+        }
+    }
+
+    abstract void fetchArchives();
+
+    static FileStatus[] listArchives(FileSystem refreshFS, Path refreshDir) throws IOException {
+        // contents of /:refreshDir
+        FileStatus[] jobArchives = refreshFS.listStatus(refreshDir);
+        if (jobArchives == null) {
+            // the entire refreshDirectory was removed
+            return new FileStatus[0];
+        }
+
+        Arrays.sort(
+                jobArchives, Comparator.comparingLong(FileStatus::getModificationTime).reversed());
+
+        return jobArchives;
+    }
+
+    static boolean isValidJobID(String jobId, Path refreshDir) {
+        try {
+            JobID.fromHexString(jobId);
+            return true;
+        } catch (IllegalArgumentException iae) {
+            LOG.debug(
+                    "Archive directory {} contained file with unexpected name {}. Ignoring file.",
+                    refreshDir,
+                    jobId,
+                    iae);
+            return false;
+        }
+    }
+
+    abstract void processArchive(String jobID, Path jobArchivePath) throws IOException;
+
+    List<ArchiveFetcher.ArchiveEvent> cleanupJobsBeyondSizeLimit(
+            Map<Path, Set<Path>> jobArchivesToRemove) {
+        Map<Path, Set<String>> allJobIdsToRemoveFromOverview = new HashMap<>();
+
+        for (Map.Entry<Path, Set<Path>> pathSetEntry : jobArchivesToRemove.entrySet()) {
+            HashSet<String> jobIdsToRemoveFromOverview = new HashSet<>();
+
+            for (Path archive : pathSetEntry.getValue()) {
+                jobIdsToRemoveFromOverview.add(archive.getName());
+                try {
+                    archive.getFileSystem().delete(archive, false);
+                } catch (IOException ioe) {
+                    LOG.warn("Could not delete old archive " + archive, ioe);
+                }
+            }
+            allJobIdsToRemoveFromOverview.put(pathSetEntry.getKey(), jobIdsToRemoveFromOverview);
+        }
+
+        return cleanupExpiredJobs(allJobIdsToRemoveFromOverview);
+    }
+
+    List<ArchiveFetcher.ArchiveEvent> cleanupExpiredJobs(Map<Path, Set<String>> jobsToRemove) {
+
+        List<ArchiveFetcher.ArchiveEvent> deleteLog = new ArrayList<>();
+        LOG.info("Archive directories for jobs {} were deleted.", jobsToRemove);
+
+        jobsToRemove.forEach(
+                (refreshDir, archivesToRemove) -> {
+                    cachedArchivesPerRefreshDirectory.get(refreshDir).removeAll(archivesToRemove);
+                });
+        jobsToRemove.values().stream()
+                .flatMap(Set::stream)
+                .forEach(
+                        removedJobID -> {
+                            deleteJobFiles(removedJobID);
+                            deleteLog.add(
+                                    new ArchiveFetcher.ArchiveEvent(
+                                            removedJobID, ArchiveFetcher.ArchiveEventType.DELETED));
+                        });
+
+        return deleteLog;
+    }
+
+    abstract void deleteJobFiles(String jobID);
+
+    static String convertLegacyJobOverview(String legacyOverview) throws IOException {

Review Comment:
   I this javadoc would be helpful here, including the definition of a legacy server and the expected output. 
   
   I thin all the methods would benefit from javadoc.
   



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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on PR #25838:
URL: https://github.com/apache/flink/pull/25838#issuecomment-2583060608

   Reviewed by Chi on 09/01/2025 Go back to the submitter with review comments.


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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "Shawnsuun (via GitHub)" <gi...@apache.org>.
Shawnsuun closed pull request #25838: [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB
URL: https://github.com/apache/flink/pull/25838


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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #25838:
URL: https://github.com/apache/flink/pull/25838#issuecomment-2558408367

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "026a9756641272c5df243ec1e55c5205c860f6c1",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "026a9756641272c5df243ec1e55c5205c860f6c1",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 026a9756641272c5df243ec1e55c5205c860f6c1 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #25838:
URL: https://github.com/apache/flink/pull/25838#discussion_r1908973583


##########
flink-runtime-web/src/main/java/org/apache/flink/runtime/webmonitor/history/ArchiveFetcher.java:
##########
@@ -0,0 +1,265 @@
+/*
+ * 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.flink.runtime.webmonitor.history;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.JobStatus;
+import org.apache.flink.core.fs.FileStatus;
+import org.apache.flink.core.fs.FileSystem;
+import org.apache.flink.core.fs.Path;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.messages.webmonitor.JobDetails;
+import org.apache.flink.runtime.messages.webmonitor.MultipleJobsDetails;
+import org.apache.flink.util.jackson.JacksonMapperFactory;
+
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode;
+import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Consumer;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * The {@code ArchiveFetcher} class is an abstract class that defines the basic structure for
+ * fetching job archives in the Flink History Server. Implementations of this class should provide
+ * the logic for retrieving and processing job archives.
+ *
+ * <p>This class may be extended by specific implementations to support different storage backends
+ * for job archives, such as local file systems or key-value stores.
+ */
+public abstract class ArchiveFetcher {
+
+    /** Possible job archive operations in history-server. */
+    public enum ArchiveEventType {
+        /** Job archive was found in one refresh location and created in history server. */
+        CREATED,
+        /**
+         * Job archive was deleted from one of refresh locations and deleted from history server.
+         */
+        DELETED
+    }
+
+    /** Representation of job archive event. */
+    public static class ArchiveEvent {
+        private final String jobID;
+        private final ArchiveFetcher.ArchiveEventType operation;
+
+        ArchiveEvent(String jobID, ArchiveFetcher.ArchiveEventType operation) {
+            this.jobID = jobID;
+            this.operation = operation;
+        }
+
+        public String getJobID() {
+            return jobID;
+        }
+
+        public ArchiveFetcher.ArchiveEventType getType() {
+            return operation;
+        }
+    }
+
+    protected static final Logger LOG = LoggerFactory.getLogger(ArchiveFetcher.class);
+
+    protected static final ObjectMapper MAPPER = JacksonMapperFactory.createObjectMapper();
+
+    protected final List<HistoryServer.RefreshLocation> refreshDirs;
+    protected final Consumer<ArchiveEvent> jobArchiveEventListener;
+    protected final boolean processExpiredArchiveDeletion;
+    protected final boolean processBeyondLimitArchiveDeletion;
+    protected final int maxHistorySize;
+
+    /** Cache of all available jobs identified by their id. */
+    protected final Map<Path, Set<String>> cachedArchivesPerRefreshDirectory;
+
+    protected ArchiveFetcher(
+            List<HistoryServer.RefreshLocation> refreshDirs,
+            Consumer<ArchiveEvent> jobArchiveEventListener,
+            boolean cleanupExpiredArchives,
+            int maxHistorySize) {
+        this.refreshDirs = checkNotNull(refreshDirs);
+        this.jobArchiveEventListener = jobArchiveEventListener;
+        this.processExpiredArchiveDeletion = cleanupExpiredArchives;
+        this.maxHistorySize = maxHistorySize;
+        this.processBeyondLimitArchiveDeletion = this.maxHistorySize > 0;
+        this.cachedArchivesPerRefreshDirectory = new HashMap<>();
+        for (HistoryServer.RefreshLocation refreshDir : refreshDirs) {
+            cachedArchivesPerRefreshDirectory.put(refreshDir.getPath(), new HashSet<>());
+        }
+    }
+
+    abstract void fetchArchives();
+
+    static FileStatus[] listArchives(FileSystem refreshFS, Path refreshDir) throws IOException {
+        // contents of /:refreshDir
+        FileStatus[] jobArchives = refreshFS.listStatus(refreshDir);
+        if (jobArchives == null) {
+            // the entire refreshDirectory was removed
+            return new FileStatus[0];
+        }
+
+        Arrays.sort(
+                jobArchives, Comparator.comparingLong(FileStatus::getModificationTime).reversed());
+
+        return jobArchives;
+    }
+
+    static boolean isValidJobID(String jobId, Path refreshDir) {
+        try {
+            JobID.fromHexString(jobId);
+            return true;
+        } catch (IllegalArgumentException iae) {
+            LOG.debug(
+                    "Archive directory {} contained file with unexpected name {}. Ignoring file.",
+                    refreshDir,
+                    jobId,
+                    iae);
+            return false;
+        }
+    }
+
+    abstract void processArchive(String jobID, Path jobArchivePath) throws IOException;
+
+    List<ArchiveFetcher.ArchiveEvent> cleanupJobsBeyondSizeLimit(
+            Map<Path, Set<Path>> jobArchivesToRemove) {
+        Map<Path, Set<String>> allJobIdsToRemoveFromOverview = new HashMap<>();
+
+        for (Map.Entry<Path, Set<Path>> pathSetEntry : jobArchivesToRemove.entrySet()) {
+            HashSet<String> jobIdsToRemoveFromOverview = new HashSet<>();
+
+            for (Path archive : pathSetEntry.getValue()) {
+                jobIdsToRemoveFromOverview.add(archive.getName());
+                try {
+                    archive.getFileSystem().delete(archive, false);
+                } catch (IOException ioe) {
+                    LOG.warn("Could not delete old archive " + archive, ioe);
+                }
+            }
+            allJobIdsToRemoveFromOverview.put(pathSetEntry.getKey(), jobIdsToRemoveFromOverview);
+        }
+
+        return cleanupExpiredJobs(allJobIdsToRemoveFromOverview);
+    }
+
+    List<ArchiveFetcher.ArchiveEvent> cleanupExpiredJobs(Map<Path, Set<String>> jobsToRemove) {
+
+        List<ArchiveFetcher.ArchiveEvent> deleteLog = new ArrayList<>();
+        LOG.info("Archive directories for jobs {} were deleted.", jobsToRemove);
+
+        jobsToRemove.forEach(
+                (refreshDir, archivesToRemove) -> {
+                    cachedArchivesPerRefreshDirectory.get(refreshDir).removeAll(archivesToRemove);
+                });
+        jobsToRemove.values().stream()
+                .flatMap(Set::stream)
+                .forEach(
+                        removedJobID -> {
+                            deleteJobFiles(removedJobID);
+                            deleteLog.add(
+                                    new ArchiveFetcher.ArchiveEvent(
+                                            removedJobID, ArchiveFetcher.ArchiveEventType.DELETED));
+                        });
+
+        return deleteLog;
+    }
+
+    abstract void deleteJobFiles(String jobID);
+
+    static String convertLegacyJobOverview(String legacyOverview) throws IOException {

Review Comment:
   I this java doc would be helpful here, including the definition of a legacy server and the expected output. 



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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #25838:
URL: https://github.com/apache/flink/pull/25838#discussion_r1908982644


##########
flink-core/src/main/java/org/apache/flink/configuration/HistoryServerOptions.java:
##########
@@ -143,5 +143,20 @@ public class HistoryServerOptions {
                                             code("IllegalConfigurationException"))
                                     .build());
 
+    public static final ConfigOption<String> HISTORY_SERVER_STORAGE_BACKEND =

Review Comment:
   I suggest adding something to the documentation around this new option in [https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/deployment/advanced/historyserver/](https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/deployment/advanced/historyserver/). The docs could include details on how to extend ArchiveFetcher - as per the javadoc at the top of that class.



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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #25838: [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB
URL: https://github.com/apache/flink/pull/25838


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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #25838:
URL: https://github.com/apache/flink/pull/25838#issuecomment-2889766351

   This PR is being marked as stale since it has not had any activity in the last 90 days. 
   If you would like to keep this PR alive, please leave a comment asking for a review. 
   If the PR has merge conflicts, update it with the latest from the base branch.
   
   If you are having difficulty finding a reviewer, please reach out to the 
   community, contact details can be found here: https://flink.apache.org/what-is-flink/community/
   
   If this PR is no longer valid or desired, please feel free to close it. 
   If no activity occurs in the next 30 days, it will be automatically closed.


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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "Shawnsuun (via GitHub)" <gi...@apache.org>.
Shawnsuun commented on PR #25838:
URL: https://github.com/apache/flink/pull/25838#issuecomment-2661664038

   > ## CI report:
   > * [026a975](https://github.com/apache/flink/commit/026a9756641272c5df243ec1e55c5205c860f6c1) UNKNOWN
   > * [b17c658](https://github.com/apache/flink/commit/b17c6589a0fc38b71c900ce68114c6802049fc57) Azure: [FAILURE](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=66072)
   > 
   > Bot commands
   > The @flinkbot bot supports the following commands:
   > * `@flinkbot run azure` re-run the last Azure build
   
   @flinkbot run azure


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

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


Re: [PR] [FLINK-36429] [runtime-web] Enhancing Flink History Server File Storage and Retrieval with RocksDB [flink]

Posted by "davidradl (via GitHub)" <gi...@apache.org>.
davidradl commented on code in PR #25838:
URL: https://github.com/apache/flink/pull/25838#discussion_r1908982644


##########
flink-core/src/main/java/org/apache/flink/configuration/HistoryServerOptions.java:
##########
@@ -143,5 +143,20 @@ public class HistoryServerOptions {
                                             code("IllegalConfigurationException"))
                                     .build());
 
+    public static final ConfigOption<String> HISTORY_SERVER_STORAGE_BACKEND =

Review Comment:
   I suggest adding something to the documentation around this new option in [https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/deployment/advanced/historyserver/](https://nightlies.apache.org/flink/flink-docs-release-1.20/docs/deployment/advanced/historyserver/). It would be good to indicate the pos and cons of file vs kv servers.
   
   The docs could include details on how to extend ArchiveFetcher - as per the javadoc at the top of that class.



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

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