Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
rgw/sfs: update bucket stats
Browse files Browse the repository at this point in the history
Signed-off-by: Joao Eduardo Luis <[email protected]>
  • Loading branch information
jecluis committed Jun 3, 2023
1 parent 3db8861 commit 6158fc8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/rgw/driver/sfs/bucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,36 @@ int SFSBucket::sync_user_stats(
) {
return 0;
}

int SFSBucket::update_container_stats(const DoutPrefixProvider* dpp) {
lsfs_dout(dpp, 10) << fmt::format(
"update bucket {} (id {}) stats", get_name(),
get_bucket_id()
)
<< dendl;
sfs::sqlite::SQLiteBuckets bucketdb(store->db_conn);
auto stats = bucketdb.get_stats(get_bucket_id());

if (!stats.has_value()) {
lsfs_dout(dpp, 10) << fmt::format(
"unable to obtain stats for bucket {} (id {}) -- "
"no such bucket!",
get_name(), get_bucket_id()
)
<< dendl;
return -ERR_NO_SUCH_BUCKET;
}

lsfs_dout(dpp, 10) << fmt::format(
"bucket {} stats: size: {}, obj_cnt: {}",
get_name(), stats->size, stats->obj_count
)
<< dendl;
ent.size = ent.size_rounded = stats->size;
ent.count = stats->obj_count;
return 0;
}

int SFSBucket::check_bucket_shards(const DoutPrefixProvider* dpp) {
ldpp_dout(dpp, 10) << __func__ << ": TODO" << dendl;
return -ENOTSUP;
Expand Down
38 changes: 38 additions & 0 deletions src/rgw/driver/sfs/sqlite/sqlite_buckets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,42 @@ std::vector<std::string> SQLiteBuckets::get_deleted_buckets_ids() const {
);
}

const std::optional<SQLiteBucketStats> SQLiteBuckets::get_stats(
const std::string& bucket_id
) const {
auto storage = conn->get_storage();
std::optional<SQLiteBucketStats> stats;
storage.transaction([&]() mutable {
// ensure bucket exists
auto tmp = storage.get_all<DBBucket>(
where(is_equal(&DBBucket::bucket_id, bucket_id))
);
if (tmp.size() == 0) {
return false;
}
ceph_assert(tmp.size() == 1);

stats = SQLiteBucketStats();
stats->obj_count = storage.count<DBOPObjectInfo>(
where(is_equal(&DBOPObjectInfo::bucket_id, bucket_id))
);

auto res = storage.sum(
&DBVersionedObject::size,
left_join<DBOPObjectInfo>(
on(is_equal(&DBOPObjectInfo::uuid, &DBVersionedObject::object_id))
),
where(is_equal(&DBOPObjectInfo::bucket_id, bucket_id))
);

if (res) {
stats->size = *res;
}

return true;
});

return stats;
}

} // namespace rgw::sal::sfs::sqlite
8 changes: 8 additions & 0 deletions src/rgw/driver/sfs/sqlite/sqlite_buckets.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

namespace rgw::sal::sfs::sqlite {

struct SQLiteBucketStats {
size_t size;
uint64_t obj_count;
};

class SQLiteBuckets {
DBConnRef conn;

Expand All @@ -42,6 +47,9 @@ class SQLiteBuckets {
std::vector<DBOPBucketInfo> get_buckets(const std::string& user_id) const;

std::vector<std::string> get_deleted_buckets_ids() const;

const std::optional<SQLiteBucketStats> get_stats(const std::string& bucket_id
) const;
};

} // namespace rgw::sal::sfs::sqlite

0 comments on commit 6158fc8

Please sign in to comment.