From 339182287f48aa3df86b7733e2dd1c1d7dd11909 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Fri, 24 Nov 2023 17:58:56 +0300 Subject: [PATCH] s3/client: Cache stats on readable_file S3-based sstables components are immutable, so every time stat is called there's no need to ping server again. But the main intention of this patch is to provide stats for read calls in the next patch. Signed-off-by: Pavel Emelyanov --- utils/s3/client.cc | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/utils/s3/client.cc b/utils/s3/client.cc index 6fa31b0ac7..66f80fa184 100644 --- a/utils/s3/client.cc +++ b/utils/s3/client.cc @@ -850,11 +850,23 @@ data_sink client::make_upload_jumbo_sink(sstring object_name, std::optional _client; sstring _object_name; + std::optional _stats; [[noreturn]] void unsupported() { throw_with_backtrace("unsupported operation on s3 readable file"); } + future<> maybe_update_stats() { + if (_stats) { + return make_ready_future<>(); + } + + return _client->get_object_stats(_object_name).then([this] (auto st) { + _stats = std::move(st); + return make_ready_future<>(); + }); + } + public: readable_file(shared_ptr cln, sstring object_name) : _client(std::move(cln)) @@ -899,16 +911,16 @@ public: } virtual future stat(void) override { - auto object_stats = co_await _client->get_object_stats(_object_name); + co_await maybe_update_stats(); struct stat ret {}; ret.st_nlink = 1; ret.st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; - ret.st_size = object_stats.size; + ret.st_size = _stats->size; ret.st_blksize = 1 << 10; // huh? - ret.st_blocks = object_stats.size >> 9; + ret.st_blocks = _stats->size >> 9; // objects are immutable on S3, therefore we can use Last-Modified to set both st_mtime and st_ctime - ret.st_mtime = object_stats.last_modified; - ret.st_ctime = object_stats.last_modified; + ret.st_mtime = _stats->last_modified; + ret.st_ctime = _stats->last_modified; co_return ret; }