Skip to content

Commit

Permalink
Merge pull request facebook#5 from pikiwidb/feat/update_sst_cache_whe…
Browse files Browse the repository at this point in the history
…n_write

feat: update sst_file_cache when writablefile closes
  • Loading branch information
baixin01 authored May 29, 2024
2 parents 8516b36 + b4805d4 commit ff691a0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cloud/cloud_file_system_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ class CloudFileSystemImpl : public CloudFileSystem {
IOStatus RollNewEpoch(const std::string& local_dbname);

// helper methods to access the file cache
void FileCacheAccess(const std::string& fname);
void FileCacheInsert(const std::string& fname, uint64_t filesize);
void FileCacheAccess(const std::string& fname) override;
void FileCacheInsert(const std::string& fname, uint64_t filesize) override;

// The dbid of the source database that is cloned
std::string src_dbid_;
Expand Down
12 changes: 11 additions & 1 deletion cloud/cloud_storage_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ IOStatus CloudStorageWritableFileImpl::Close(const IOOptions& opts,
"[%s] CloudWritableFile closing %s", Name(), fname_.c_str());
assert(status_.ok());

uint64_t f_size = local_file_->GetFileSize(opts, dbg);

// close local file
auto st = local_file_->Close(opts, dbg);
if (!st.ok()) {
Expand All @@ -185,8 +187,16 @@ IOStatus CloudStorageWritableFileImpl::Close(const IOOptions& opts,
return status_;
}

// flush and compaction will reopen newly generated file,
// so we add newly writablefile to sst_file_cache to reduce once s3 io
bool delete_local_file = true;
if (cfs_->GetCloudFileSystemOptions().sst_file_cache) {
cfs_->FileCacheInsert(fname_, f_size);
delete_local_file = false;
}

// delete local file
if (!cfs_->GetCloudFileSystemOptions().keep_local_sst_files) {
if (!cfs_->GetCloudFileSystemOptions().keep_local_sst_files && delete_local_file) {
status_ = cfs_->GetBaseFileSystem()->DeleteFile(fname_, opts, dbg);
if (!status_.ok()) {
Log(InfoLogLevel::ERROR_LEVEL, cfs_->GetLogger(),
Expand Down
4 changes: 4 additions & 0 deletions include/rocksdb/cloud/cloud_file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,10 @@ class CloudFileSystem : public FileSystem {
virtual IOStatus DeleteCloudObject(const std::string& bucket,
const std::string& objectpath) = 0;

// helper methods to access the file cache
virtual void FileCacheAccess(const std::string& fname) {}
virtual void FileCacheInsert(const std::string& fname, uint64_t filesize) {}

Logger* GetLogger() const { return info_log_.get(); }
const std::shared_ptr<CloudStorageProvider>& GetStorageProvider() const {
return cloud_fs_options.storage_provider;
Expand Down

0 comments on commit ff691a0

Please sign in to comment.