@@ -150,6 +150,8 @@ Status PackedFileManager::create_new_packed_file_context(
150150 // Create file writer for the packed file
151151 FileWriterPtr new_writer;
152152 FileWriterOptions opts;
153+ // enable write file cache for packed file
154+ opts.write_file_cache = true ;
153155 RETURN_IF_ERROR (
154156 packed_file_ctx->file_system ->create_file (Path (relative_path), &new_writer, &opts));
155157 packed_file_ctx->writer = std::move (new_writer);
@@ -256,6 +258,7 @@ Status PackedFileManager::append_small_file(const std::string& path, const Slice
256258 location.packed_file_path = active_state->packed_file_path ;
257259 location.offset = active_state->current_offset ;
258260 location.size = data.get_size ();
261+ location.create_time = std::time (nullptr );
259262 location.tablet_id = info.tablet_id ;
260263 location.rowset_id = info.rowset_id ;
261264 location.resource_id = info.resource_id ;
@@ -609,6 +612,15 @@ void PackedFileManager::process_uploading_packed_files() {
609612 first_slice = false ;
610613 slices_stream << small_file_path << " (txn=" << index.txn_id
611614 << " , offset=" << index.offset << " , size=" << index.size << " )" ;
615+
616+ // Update packed_file_size in global index
617+ {
618+ std::lock_guard<std::mutex> global_lock (_global_index_mutex);
619+ auto it = _global_slice_locations.find (small_file_path);
620+ if (it != _global_slice_locations.end ()) {
621+ it->second .packed_file_size = packed_file->total_size ;
622+ }
623+ }
612624 }
613625 LOG (INFO) << " Packed file " << packed_file->packed_file_path
614626 << " uploaded; slices=" << packed_file->slice_locations .size ()
@@ -809,30 +821,12 @@ void PackedFileManager::cleanup_expired_data() {
809821
810822 // Clean up expired global index entries
811823 {
812- std::unordered_set<std::string> active_packed_files;
813- {
814- std::lock_guard<std::timed_mutex> current_lock (_current_packed_file_mutex);
815- for (const auto & [resource_id, state] : _current_packed_files) {
816- if (state) {
817- active_packed_files.insert (state->packed_file_path );
818- }
819- }
820- }
821- {
822- std::lock_guard<std::mutex> merge_lock (_packed_files_mutex);
823- for (const auto & [path, state] : _uploading_packed_files) {
824- active_packed_files.insert (path);
825- }
826- for (const auto & [path, state] : _uploaded_packed_files) {
827- active_packed_files.insert (path);
828- }
829- }
830-
831824 std::lock_guard<std::mutex> global_lock (_global_index_mutex);
832825 auto it = _global_slice_locations.begin ();
833826 while (it != _global_slice_locations.end ()) {
834827 const auto & index = it->second ;
835- if (active_packed_files.find (index.packed_file_path ) == active_packed_files.end ()) {
828+ if (index.create_time > 0 &&
829+ current_time - index.create_time > config::uploaded_file_retention_seconds) {
836830 it = _global_slice_locations.erase (it);
837831 } else {
838832 ++it;
0 commit comments