Skip to content

Commit

Permalink
issue #221: HomeStore to report capacity stats (#222)
Browse files Browse the repository at this point in the history
* issue #221: HomeStore to report capacity stats
1. total used capacity
2. total capacity
  • Loading branch information
yamingk authored Nov 9, 2023
1 parent 3911682 commit f8f2fa8
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class HomestoreConan(ConanFile):
name = "homestore"
version = "4.5.10"
version = "4.6.1"

homepage = "https://github.com/eBay/Homestore"
description = "HomeStore Storage Engine"
Expand Down
4 changes: 4 additions & 0 deletions src/include/homestore/blkdata_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ class BlkDataService {
*/
void start();

uint64_t get_total_capacity() const;

uint64_t get_used_capacity() const;

private:
/**
* @brief Initializes the block data service.
Expand Down
5 changes: 5 additions & 0 deletions src/include/homestore/homestore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ struct hs_vdev_context {

using hs_before_services_starting_cb_t = std::function< void(void) >;

struct hs_stats {
uint64_t total_capacity{0ul};
uint64_t used_capacity{0ul};
};

struct HS_SERVICE {
static constexpr uint32_t META = 1 << 0;
static constexpr uint32_t LOG_REPLICATED = 1 << 1;
Expand Down
5 changes: 5 additions & 0 deletions src/include/homestore/replication_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ VENUM(ReplServiceError, int32_t,

class ReplDev;
class ReplDevListener;
struct hs_stats;

template < typename V, typename E >
using Result = folly::Expected< V, E >;
Expand Down Expand Up @@ -84,5 +85,9 @@ class ReplicationService {
/// @brief Iterate over all repl devs and then call the callback provided
/// @param cb Callback with repl dev
virtual void iterate_repl_devs(std::function< void(cshared< ReplDev >&) > const& cb) = 0;

/// @brief get the capacity stats form underlying backend;
/// @return the capacity stats;
virtual hs_stats get_cap_stats() const = 0;
};
} // namespace homestore
4 changes: 4 additions & 0 deletions src/lib/blkdata_svc/blkdata_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,8 @@ void BlkDataService::start() {
std::move(std::make_unique< DataSvcCPCallbacks >(m_vdev)));
}

uint64_t BlkDataService::get_total_capacity() const { return m_vdev->size(); }

uint64_t BlkDataService::get_used_capacity() const { return m_vdev->used_size(); }

} // namespace homestore
10 changes: 10 additions & 0 deletions src/lib/replication/service/repl_service_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "common/homestore_assert.hpp"
#include "replication/service/repl_service_impl.h"
#include "replication/repl_dev/solo_repl_dev.h"
#include "homestore/blkdata_service.hpp"
#include "homestore/homestore.hpp"

namespace homestore {
ReplicationService& repl_service() { return hs()->repl_service(); }
Expand Down Expand Up @@ -46,6 +48,14 @@ void ReplicationServiceImpl::stop() {
m_rd_map.clear();
}

hs_stats ReplicationServiceImpl::get_cap_stats() const {
hs_stats stats;

stats.total_capacity = data_service().get_total_capacity();
stats.used_capacity = data_service().get_used_capacity();
return stats;
}

AsyncReplResult< shared< ReplDev > >
ReplicationServiceImpl::create_repl_dev(uuid_t group_id, std::set< std::string, std::less<> >&& members,
std::unique_ptr< ReplDevListener > listener) {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/replication/service/repl_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class ReplicationServiceImpl : public ReplicationService {

folly::Future< ReplServiceError > replace_member(uuid_t group_id, std::string const& member_out,
std::string const& member_in) const override;
hs_stats get_cap_stats() const override;


private:
shared< ReplDev > create_repl_dev_instance(superblk< repl_dev_superblk > const& rd_sb, bool load_existing);
Expand Down
7 changes: 7 additions & 0 deletions src/tests/test_solo_repl_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ class SoloReplDevTest : public testing::Test {
}

auto& rdev = (rand() % 2) ? m_repl_dev1 : m_repl_dev2;

auto const cap = hs()->repl_service().get_cap_stats();
LOGDEBUG("Before write, cap stats: used={} total={}", cap.used_capacity, cap.total_capacity);

rdev->async_alloc_write(*req->header, req->key ? *req->key : sisl::blob{}, req->write_sgs, req);
}

Expand Down Expand Up @@ -285,6 +289,9 @@ class SoloReplDevTest : public testing::Test {
if (req->write_sgs.size != 0) {
req->read_sgs = HSTestHelper::create_sgs(req->write_sgs.size, g_block_size, req->write_sgs.size);

auto const cap = hs()->repl_service().get_cap_stats();
LOGDEBUG("Write complete with cap stats: used={} total={}", cap.used_capacity, cap.total_capacity);

rdev.async_read(req->written_blkids, req->read_sgs, req->read_sgs.size)
.thenValue([this, &rdev, req](auto&& err) {
RELEASE_ASSERT(!err, "Error during async_read");
Expand Down

0 comments on commit f8f2fa8

Please sign in to comment.