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 Oct 13, 2023
1 parent 5a7aa0d commit 6cd689c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/rgw/driver/sfs/bucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,36 @@ int SFSBucket::sync_user_stats(
) {
return 0;
}
int SFSBucket::update_container_stats(const DoutPrefixProvider* /*dpp*/) {

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
32 changes: 32 additions & 0 deletions src/rgw/driver/sfs/sqlite/sqlite_buckets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,36 @@ std::optional<DBDeletedObjectItems> SQLiteBuckets::delete_bucket_transact(
return retry.run();
}

const std::optional<SQLiteBuckets::Stats> SQLiteBuckets::get_stats(
const std::string& bucket_id
) const {
auto storage = conn->get_storage();
std::optional<SQLiteBuckets::Stats> stats;

auto res = storage.select(
columns(
count(&DBVersionedObject::object_id), sum(&DBVersionedObject::size)
),
inner_join<DBObject>(
on(is_equal(&DBObject::uuid, &DBVersionedObject::object_id))
),
where(
is_equal(&DBObject::bucket_id, bucket_id) and
is_equal(&DBVersionedObject::object_state, ObjectState::COMMITTED)
)
);

if (res.size() > 0) {
ceph_assert(res.size() == 1);
stats = SQLiteBuckets::Stats();
stats->obj_count = std::get<0>(res[0]);
// We get a unique_ptr for SUM(), likely because of the underlying type of 'size'.
// Therefore we need to check whether it's a nullptr or not.
auto size = std::get<1>(res[0]).get();
stats->size = (size ? *size : 0);
}

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 @@ -28,6 +28,11 @@ class SQLiteBuckets {
SQLiteBuckets(const SQLiteBuckets&) = delete;
SQLiteBuckets& operator=(const SQLiteBuckets&) = delete;

struct Stats {
size_t size;
uint64_t obj_count;
};

std::optional<DBOPBucketInfo> get_bucket(const std::string& bucket_id) const;
std::vector<DBOPBucketInfo> get_bucket_by_name(const std::string& bucket_name
) const;
Expand All @@ -52,6 +57,9 @@ class SQLiteBuckets {
std::optional<DBDeletedObjectItems> delete_bucket_transact(
const std::string& bucket_id, uint max_objects, bool& bucket_deleted
) const;
const std::optional<SQLiteBuckets::Stats> get_stats(
const std::string& bucket_id
) const;
};

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

0 comments on commit 6cd689c

Please sign in to comment.