Skip to content

Commit

Permalink
fix logical capacity metric
Browse files Browse the repository at this point in the history
Signed-off-by: Hanqing Wu <wuhanqing@corp.netease.com>
  • Loading branch information
xu-chaojie authored and wu-hanqing committed Sep 26, 2023
1 parent cef01cd commit cf85cce
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/mds/server/mds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ void MDS::InitTopologyMetricService(const TopologyOption& option) {
topologyMetricService_ =
std::make_shared<TopologyMetricService>(topology_,
topologyStat_,
segmentAllocStatistic_);
segmentAllocStatistic_,
chunkFilePoolAllocHelp_);
LOG_IF(FATAL, topologyMetricService_->Init(option) < 0)
<< "init topologyMetricService fail.";
LOG(INFO) << "init topologyMetricService success.";
Expand Down Expand Up @@ -397,7 +398,7 @@ void MDS::InitCopysetOption(CopysetOption *copysetOption) {


void MDS::InitTopologyChunkAllocator(const TopologyOption& option) {
std::shared_ptr<ChunkFilePoolAllocHelp> chunkFilePoolAllocHelp_ =
chunkFilePoolAllocHelp_ =
std::make_shared<ChunkFilePoolAllocHelp>();
topologyChunkAllocator_ =
std::make_shared<TopologyChunkAllocatorImpl>(topology_,
Expand Down
1 change: 1 addition & 0 deletions src/mds/server/mds.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class MDS {
std::shared_ptr<NameServerStorage> nameServerStorage_;
std::shared_ptr<TopologyImpl> topology_;
std::shared_ptr<TopologyStatImpl> topologyStat_;
std::shared_ptr<ChunkFilePoolAllocHelp> chunkFilePoolAllocHelp_;
std::shared_ptr<TopologyChunkAllocator> topologyChunkAllocator_;
std::shared_ptr<TopologyMetricService> topologyMetricService_;
std::shared_ptr<TopologyServiceManager> topologyServiceManager_;
Expand Down
4 changes: 2 additions & 2 deletions src/mds/topology/topology_chunk_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ class TopologyChunkAllocatorImpl : public TopologyChunkAllocator {
TopologyChunkAllocatorImpl(std::shared_ptr<Topology> topology,
std::shared_ptr<AllocStatistic> allocStatistic,
std::shared_ptr<TopologyStat> topologyStat,
std::shared_ptr<ChunkFilePoolAllocHelp> ChunkFilePoolAllocHelp,
std::shared_ptr<ChunkFilePoolAllocHelp> chunkFilePoolAllocHelp,
const TopologyOption &option)
: topology_(topology),
allocStatistic_(allocStatistic),
topoStat_(topologyStat),
chunkFilePoolAllocHelp_(ChunkFilePoolAllocHelp),
chunkFilePoolAllocHelp_(chunkFilePoolAllocHelp),
available_(option.PoolUsagePercentLimit),
policy_(static_cast<ChoosePoolPolicy>(option.choosePoolPolicy)),
enableLogicalPoolStatus_(option.enableLogicalPoolStatus) {
Expand Down
14 changes: 12 additions & 2 deletions src/mds/topology/topology_metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,18 @@ void TopologyMetricService::UpdateTopologyMetrics() {
it->second->chunkSizeTrashedBytes.set_value(totalChunkSizeTrashedBytes);
it->second->chunkSizeTotalBytes.set_value(totalChunkSizeBytes);
if (pool.GetReplicaNum() != 0) {
it->second->logicalCapacity.set_value(
totalChunkSizeBytes / pool.GetReplicaNum());
if (chunkFilePoolAllocHelp_->GetUseChunkFilepool()) {
uint64_t diskCapacity = 0;
topoStat_->GetChunkPoolSize(pool.GetPhysicalPoolId(),
&diskCapacity);
diskCapacity = diskCapacity *
chunkFilePoolAllocHelp_->GetAvailable() / 100;
it->second->logicalCapacity.set_value(
diskCapacity / pool.GetReplicaNum());
} else {
it->second->logicalCapacity.set_value(
totalChunkSizeBytes / pool.GetReplicaNum());
}
}

uint64_t readRate = 0, writeRate = 0,
Expand Down
9 changes: 7 additions & 2 deletions src/mds/topology/topology_metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "src/mds/topology/topology_stat.h"
#include "src/mds/nameserver2/allocstatistic/alloc_statistic.h"
#include "src/common/interruptible_sleeper.h"
#include "src/mds/topology/topology_chunk_allocator.h"

using ::curve::common::InterruptibleSleeper;

Expand Down Expand Up @@ -389,11 +390,13 @@ class TopologyMetricService {

public:
TopologyMetricService(std::shared_ptr<Topology> topo,
std::shared_ptr<TopologyStat> topoStat,
std::shared_ptr<AllocStatistic> allocStatistic)
const std::shared_ptr<TopologyStat> &topoStat,
const std::shared_ptr<AllocStatistic> &allocStatistic,
const std::shared_ptr<ChunkFilePoolAllocHelp> &chunkFilePoolAllocHelp)
: topo_(topo),
topoStat_(topoStat),
allocStatistic_(allocStatistic),
chunkFilePoolAllocHelp_(chunkFilePoolAllocHelp),
isStop_(true) {}
~TopologyMetricService() {
Stop();
Expand Down Expand Up @@ -446,6 +449,8 @@ class TopologyMetricService {
* @brief allocation statistic module
*/
std::shared_ptr<AllocStatistic> allocStatistic_;

std::shared_ptr<ChunkFilePoolAllocHelp> chunkFilePoolAllocHelp_;
/**
* @brief backend thread
*/
Expand Down
5 changes: 4 additions & 1 deletion test/mds/topology/test_topology_metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@ class TestTopologyMetric : public ::testing::Test {
tokenGenerator_,
storage_);


std::shared_ptr<ChunkFilePoolAllocHelp> chunkFilePoolAllocHelp =
std::make_shared<ChunkFilePoolAllocHelp>();
topologyStat_ = std::make_shared<MockTopologyStat>();
allocStatistic_ = std::make_shared<MockAllocStatistic>();
testObj_ = std::make_shared<TopologyMetricService>(
topology_, topologyStat_, allocStatistic_);
topology_, topologyStat_, allocStatistic_, chunkFilePoolAllocHelp);
}

void TearDown() {
Expand Down

0 comments on commit cf85cce

Please sign in to comment.