Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDSTOR-12187 : PartitionUtilization Endpoint (multi volume version) #277

Merged
merged 1 commit into from
Jan 19, 2024
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: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class HomestoreConan(ConanFile):
name = "homestore"
version = "3.6.13"
version = "3.6.14"

homepage = "https://github.corp.ebay.com/SDS/homestore"
description = "HomeStore"
Expand Down
2 changes: 1 addition & 1 deletion src/api/vol_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ class VolInterface {

virtual const char* get_name(const VolumePtr& vol) = 0;
virtual uint64_t get_size(const VolumePtr& vol) = 0;
virtual uint64_t get_used_size(const VolumePtr& vol) = 0;
virtual std::map<boost::uuids::uuid, uint64_t> get_used_size(const VolumePtr& vol) = 0;
virtual uint64_t get_page_size(const VolumePtr& vol) = 0;
virtual boost::uuids::uuid get_uuid(std::shared_ptr< Volume > vol) = 0;
virtual sisl::blob at_offset(const boost::intrusive_ptr< BlkBuffer >& buf, uint32_t offset) = 0;
Expand Down
16 changes: 14 additions & 2 deletions src/homeblks/home_blks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,21 @@ bool HomeBlks::verify_index_bm() {
return true;
}

uint64_t HomeBlks::get_used_size(const VolumePtr& vol) {
std::map<boost::uuids::uuid, uint64_t> HomeBlks::get_used_size(const VolumePtr& vol) {
/* Update per volume status */
return vol->get_used_size().used_total_size;
std::map<boost::uuids::uuid, uint64_t> utils_map;
std::unique_lock< std::recursive_mutex > lg(m_vol_lock);
if (vol == nullptr){
auto it{m_volume_map.begin()};
while (it != m_volume_map.end()) {
const VolumePtr& vol{it->second};
utils_map[it->first] = vol->get_used_size().used_total_size;
++it;
}
} else {
utils_map[vol->get_uuid()] = vol->get_used_size().used_total_size;
}
return utils_map;
}

sisl::status_response HomeBlks::get_status(const sisl::status_request& request) {
Expand Down
2 changes: 1 addition & 1 deletion src/homeblks/home_blks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class HomeBlks : public VolInterface, public HomeStore< BLKSTORE_BUFFER_TYPE > {
virtual const char* get_name(const VolumePtr& vol) override;
virtual uint64_t get_page_size(const VolumePtr& vol) override;
virtual uint64_t get_size(const VolumePtr& vol) override;
virtual uint64_t get_used_size(const VolumePtr& vol) override;
virtual std::map<boost::uuids::uuid, uint64_t> get_used_size(const VolumePtr& vol) override;
virtual boost::uuids::uuid get_uuid(VolumePtr vol) override;
virtual sisl::blob at_offset(const blk_buf_t& buf, uint32_t offset) override;

Expand Down
33 changes: 18 additions & 15 deletions src/homeblks/homeblks_http_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ void HomeBlksHttpServer::setup_routes() {
Routes::bind(&HomeBlksHttpServer::get_status, this));
http_server_ptr->setup_route(Http::Method::Get, "/api/v1/utilization/:volumeUUID",
Routes::bind(&HomeBlksHttpServer::get_utilization, this));
http_server_ptr->setup_route(Http::Method::Get, "/api/v1/utilization",
Routes::bind(&HomeBlksHttpServer::get_utilization, this));
http_server_ptr->setup_route(Http::Method::Get, "/api/v1/verifyBitmap",
Routes::bind(&HomeBlksHttpServer::verify_bitmap, this), iomgr::url_t::localhost);
http_server_ptr->setup_route(Http::Method::Get, "/api/v1/dumpDiskMetaBlks",
Expand Down Expand Up @@ -155,23 +157,24 @@ void HomeBlksHttpServer::set_log_level(const Pistache::Rest::Request& request,
}
void HomeBlksHttpServer::get_utilization(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response)
{
const std::string vol_uuid{request.param(":volumeUUID").as<std::string>()};
if (vol_uuid.length() == 0) {
response.send(Pistache::Http::Code::Bad_Request, "empty vol_uuid!");
return;
}

boost::uuids::string_generator gen;
boost::uuids::uuid uuid = gen(vol_uuid);
const auto vol = VolInterface::get_instance()->lookup_volume(uuid);
if (!vol) {
response.send(Pistache::Http::Code::Bad_Request, "vol not found!");
return;
const std::string vol_uuid = request.hasParam(":volumeUUID") ? request.param(":volumeUUID").as<std::string>():"";

VolumePtr vol = nullptr;
if (vol_uuid.length() != 0) {
boost::uuids::string_generator gen;
boost::uuids::uuid uuid = gen(vol_uuid);
vol = VolInterface::get_instance()->lookup_volume(uuid);
if (!vol) {
response.send(Pistache::Http::Code::Bad_Request, "vol not found!");
return;
}
}
nlohmann::json resp;
const auto total_data_size = VolInterface::get_instance()->get_system_capacity().initial_total_data_meta_size;
const auto vol_used = VolInterface::get_instance()->get_used_size(vol);
auto resp = std::to_string(static_cast<double> (vol_used) / total_data_size);
response.send(Pistache::Http::Code::Ok, resp);
for (auto [uuid, vol_used] : VolInterface::get_instance()->get_used_size(vol)) {
resp[boost::uuids::to_string(uuid)] = std::to_string(static_cast<double> (vol_used)/ total_data_size);
}
response.send(Pistache::Http::Code::Ok, resp.dump());
}
void HomeBlksHttpServer::get_log_level(const Pistache::Rest::Request& request,
Pistache::Http::ResponseWriter response) {
Expand Down