3434#include " common/status.h"
3535#include " gutil/port.h"
3636#include " inverted_index_fs_directory.h"
37+ #include " io/cache/block_file_cache.h"
38+ #include " io/cache/block_file_cache_factory.h"
3739#include " io/fs/file_system.h"
3840#include " io/fs/file_writer.h"
3941#include " io/fs/local_file_system.h"
@@ -196,7 +198,7 @@ Status SegmentWriter::init(const std::vector<uint32_t>& col_ids, bool has_key) {
196198 if (_opts.compression_type == UNKNOWN_COMPRESSION ) {
197199 _opts.compression_type = _tablet_schema->compression_type ();
198200 }
199- auto create_column_writer = [&](uint32_t cid, const auto & column) -> auto {
201+ auto create_column_writer = [&](uint32_t cid, const auto & column) -> auto {
200202 ColumnWriterOptions opts;
201203 opts.meta = _footer.add_columns ();
202204
@@ -1113,6 +1115,7 @@ Status SegmentWriter::finalize(uint64_t* segment_file_size, uint64_t* index_size
11131115 }
11141116 // write data
11151117 RETURN_IF_ERROR (finalize_columns_data ());
1118+ uint64_t index_start = _file_writer->bytes_appended ();
11161119 // write index
11171120 RETURN_IF_ERROR (finalize_columns_index (index_size));
11181121 // write footer
@@ -1122,6 +1125,19 @@ Status SegmentWriter::finalize(uint64_t* segment_file_size, uint64_t* index_size
11221125 LOG (INFO ) << " segment flush consumes a lot time_ns " << timer.elapsed_time ()
11231126 << " , segmemt_size " << *segment_file_size;
11241127 }
1128+ // change cache time to index
1129+ if (config::is_cloud_mode ()) {
1130+ // TODO(): check if the expiration time is 0, 只修改normal的cache 别的都不修改
1131+ // Use path to calculate the Cache Hash
1132+ auto cache_key = io::BlockFileCache::hash (_file_writer->path ().filename ().native ());
1133+ auto * cache = io::FileCacheFactory::instance ()->get_by_path (cache_key);
1134+ io::CacheContext ctx;
1135+ ctx.cache_type = io::FileCacheType::NORMAL ;
1136+ auto holder = cache->get_or_set (cache_key, index_start, *index_size, ctx);
1137+ for (auto & segment : holder.file_blocks ) {
1138+ static_cast <void >(segment->change_cache_type_self (io::FileCacheType::INDEX ));
1139+ }
1140+ }
11251141 return Status::OK ();
11261142}
11271143
0 commit comments