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

rgw/sfs: update bucket stats #152

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions qa/rgw/store/sfs/tests/fixtures/s3tr_excuses.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ test_atomic_dual_conditional_write_1mb;https://github.com/aquarist-labs/s3gw/iss
test_bucket_create_exists_nonowner;https://github.com/aquarist-labs/s3gw/issues/617;BUG
test_bucket_create_special_key_names;https://github.com/aquarist-labs/s3gw/issues/516;BUG
test_bucket_get_location;https://github.com/aquarist-labs/s3gw/issues/676;BUG
test_bucket_head_extended;https://github.com/aquarist-labs/s3gw/issues/196;WIP, RGW Extension
test_bucket_list_delimiter_not_skip_special;https://github.com/aquarist-labs/s3gw/issues/691;BUG
test_bucket_list_delimiter_prefix_underscore;https://github.com/aquarist-labs/s3gw/issues/691;BUG
test_bucket_listv2_delimiter_prefix_underscore;https://github.com/aquarist-labs/s3gw/issues/691;BUG
Expand All @@ -22,7 +21,6 @@ test_bucket_recreate_new_acl;https://github.com/aquarist-labs/s3gw/issues/617;BU
test_bucket_recreate_overwrite_acl;https://github.com/aquarist-labs/s3gw/issues/617;BUG
test_delete_tags_obj_public;https://github.com/aquarist-labs/s3gw/issues/675;BUG
test_get_tags_acl_public;https://github.com/aquarist-labs/s3gw/issues/675;BUG
test_head_bucket_usage;https://github.com/aquarist-labs/s3gw/issues/92;Unsupported RGW Extension
test_lifecycle_expiration_header_head;https://github.com/aquarist-labs/s3gw/issues/695;BUG
test_lifecycle_expiration_header_tags_head;https://github.com/aquarist-labs/s3gw/issues/695;BUG
test_logging_toggle;https://tracker.ceph.com/issues/984;Not supported by RGW
Expand Down
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
Loading