diff --git a/src/hpfs/hpfs_mount.cpp b/src/hpfs/hpfs_mount.cpp index caace69e..3617e654 100644 --- a/src/hpfs/hpfs_mount.cpp +++ b/src/hpfs/hpfs_mount.cpp @@ -412,4 +412,22 @@ namespace hpfs return 0; } + /** + * Invoke log file and hpfs index file starting from the given sequence number. This function is a blocking call. + * @param seq_no Sequence number to start truncation from. + * @return Returns -1 on error and 0 on success. + */ + int hpfs_mount::truncate_log_file(const uint64_t seq_no) + { + const std::string file_path = mount_dir + INDEX_UPDATE + "." + std::to_string(seq_no); + // File /hpfs::index. is truncated to invoke log file truncation in hpfs. + // This call waits until any running RW or RO sessions stop. + if (truncate(file_path.c_str(), 0) == -1) + { + LOG_ERROR << errno << ": Error truncating log file for seq_no: " << std::to_string(seq_no); + return -1; + } + return 0; + } + } // namespace hpfs \ No newline at end of file diff --git a/src/hpfs/hpfs_mount.hpp b/src/hpfs/hpfs_mount.hpp index 18bea158..61113f88 100644 --- a/src/hpfs/hpfs_mount.hpp +++ b/src/hpfs/hpfs_mount.hpp @@ -68,6 +68,7 @@ namespace hpfs const util::h32 get_parent_hash(const std::string &parent_vpath); void set_parent_hash(const std::string &parent_vpath, const util::h32 new_state); int update_hpfs_log_index(); + int truncate_log_file(const uint64_t seq_no); }; } // namespace hpfs diff --git a/test/bin/hpfs b/test/bin/hpfs index e25f415b..3a37b7a0 100755 Binary files a/test/bin/hpfs and b/test/bin/hpfs differ