dataroaring commented on code in PR #57770:
URL: https://github.com/apache/doris/pull/57770#discussion_r2511990000


##########
be/src/io/fs/merge_file_manager.h:
##########
@@ -0,0 +1,155 @@
+// 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.
+
+#pragma once
+
+#include <butil/macros.h>
+#include <gen_cpp/cloud.pb.h>
+#include <glog/logging.h>
+
+#include <atomic>
+#include <condition_variable>
+#include <map>
+#include <memory>
+#include <mutex>
+#include <string>
+#include <thread>
+#include <unordered_map>
+#include <vector>
+
+#include "common/status.h"
+#include "io/fs/file_system.h"
+#include "io/fs/file_writer.h"
+#include "io/fs/path.h"
+#include "util/slice.h"
+
+namespace doris::io {
+
+struct MergeFileSegmentIndex {
+    std::string merge_file_path;
+    int64_t offset;
+    int64_t size;
+};
+
+// Global object that manages merging small files into large files for S3 
optimization
+class MergeFileManager {
+public:
+    static MergeFileManager* instance();
+
+    // Initialize manager state; file system will be resolved lazily
+    Status init();
+
+    // Write a small file to the current merge file
+    Status append(const std::string& path, const Slice& data);
+
+    // Block until the small file's merge file is uploaded to S3
+    Status wait_write_done(const std::string& path);
+
+    // Get merge file index information for a small file
+    Status get_merge_file_index(const std::string& path, 
MergeFileSegmentIndex* index);
+
+    // Start the background management thread
+    void start_background_manager();
+
+    // Stop the background management thread
+    void stop_background_manager();
+
+    // Mark current merge file for upload and create new one
+    Status mark_current_merge_file_for_upload();
+
+    // Internal helper; expects caller holds _current_merge_file_mutex
+    Status mark_current_merge_file_for_upload_locked();
+
+private:
+    MergeFileManager() = default;
+    ~MergeFileManager();
+
+    DISALLOW_COPY_AND_ASSIGN(MergeFileManager);
+
+    // Background thread function for managing merge file lifecycle
+    void background_manager();
+
+    // Upload merge file to S3 and update meta service
+    Status upload_merge_file(const std::string& merge_file_path, FileWriter* 
writer);
+
+    // Update meta service with merge file information
+    Status update_meta_service(const std::string& merge_file_path,
+                               const cloud::MergedFileInfoPB& merge_file_info);
+
+    // Process uploading files
+    void process_uploading_files();
+
+    // Clean up expired data
+    void cleanup_expired_data();
+
+    // Internal structure to track merge file state
+    enum class MergeFileStateEnum {

Review Comment:
   MergeFileLifecycyleState



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to