From 47a5267ddeec1ec24993d3e366233b2003747f13 Mon Sep 17 00:00:00 2001 From: xuchaojie Date: Tue, 28 Nov 2023 11:09:12 +0800 Subject: [PATCH] mds:fix updatechunkserverstat bug & add some logs Signed-off-by: Hanqing Wu --- src/chunkserver/chunkserver.cpp | 1 + src/chunkserver/datastore/file_pool.cpp | 5 ----- src/chunkserver/datastore/file_pool.h | 4 ---- src/chunkserver/heartbeat.cpp | 16 +++++++++++----- src/chunkserver/heartbeat.h | 1 + src/fs/ext4_filesystem_impl.cpp | 6 +++++- src/mds/topology/topology_service_manager.cpp | 11 ++++------- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/chunkserver/chunkserver.cpp b/src/chunkserver/chunkserver.cpp index c3f2726adb..5ccb305968 100644 --- a/src/chunkserver/chunkserver.cpp +++ b/src/chunkserver/chunkserver.cpp @@ -294,6 +294,7 @@ int ChunkServer::Run(int argc, char** argv) { heartbeatOptions.chunkFilePool = chunkfilePool; heartbeatOptions.chunkserverId = metadata.id(); heartbeatOptions.chunkserverToken = metadata.token(); + heartbeatOptions.useChunkFilePoolAsWalPool = useChunkFilePoolAsWalPool; LOG_IF(FATAL, heartbeat_.Init(heartbeatOptions) != 0) << "Failed to init Heartbeat manager."; diff --git a/src/chunkserver/datastore/file_pool.cpp b/src/chunkserver/datastore/file_pool.cpp index 4c7af601b2..8a4430b0c4 100644 --- a/src/chunkserver/datastore/file_pool.cpp +++ b/src/chunkserver/datastore/file_pool.cpp @@ -524,7 +524,6 @@ bool FilePool::ScanInternal() { } } - currentState_.capacity = tmpvec.size(); currentState_.preallocatedChunksLeft = tmpvec.size(); std::unique_lock lk(mtx_); @@ -539,10 +538,6 @@ size_t FilePool::Size() { return tmpChunkvec_.size(); } -size_t FilePool::Capacity() { - return currentState_.capacity; -} - FilePoolState FilePool::GetState() const { return currentState_; } diff --git a/src/chunkserver/datastore/file_pool.h b/src/chunkserver/datastore/file_pool.h index 4c2a2a8d7d..25c1662529 100644 --- a/src/chunkserver/datastore/file_pool.h +++ b/src/chunkserver/datastore/file_pool.h @@ -73,8 +73,6 @@ struct FilePoolState { uint32_t metaPageSize = 0; // io alignment uint32_t blockSize = 0; - // filepool Capacity - uint64_t capacity = 0; }; struct FilePoolMeta { @@ -173,8 +171,6 @@ class CURVE_CACHELINE_ALIGNMENT FilePool { */ virtual size_t Size(); - virtual size_t Capacity(); - /** * Get the allocation status of FilePool */ diff --git a/src/chunkserver/heartbeat.cpp b/src/chunkserver/heartbeat.cpp index efb5c1f423..41bfbd4f55 100644 --- a/src/chunkserver/heartbeat.cpp +++ b/src/chunkserver/heartbeat.cpp @@ -250,11 +250,17 @@ int Heartbeat::BuildRequest(HeartbeatRequest* req) { // leftWalSegmentSize will be 0 when CHUNK and WAL share file pool uint64_t leftWalSegmentSize = metric->GetWalSegmentLeftCount() * walSegmentFileSize; - uint64_t chunkPoolSize = options_.chunkFilePool->Capacity() * - options_.chunkFilePool->GetFilePoolOpt().fileSize; - stats->set_chunkfilepoolsize(chunkPoolSize); - stats->set_chunksizeusedbytes(usedChunkSize+usedWalSegmentSize); - stats->set_chunksizeleftbytes(leftChunkSize+leftWalSegmentSize); + // CHUNK and WAL share file pool + uint64_t totalSize = 0; + if (options_.useChunkFilePoolAsWalPool) { + totalSize = usedChunkSize + usedWalSegmentSize + + leftChunkSize + leftWalSegmentSize; + } else { + totalSize = usedChunkSize + leftChunkSize; + } + stats->set_chunkfilepoolsize(totalSize); + stats->set_chunksizeusedbytes(usedChunkSize + usedWalSegmentSize); + stats->set_chunksizeleftbytes(leftChunkSize + leftWalSegmentSize); stats->set_chunksizetrashedbytes(trashedChunkSize); req->set_allocated_stats(stats); diff --git a/src/chunkserver/heartbeat.h b/src/chunkserver/heartbeat.h index 2a047506fa..b4c30d0d9f 100644 --- a/src/chunkserver/heartbeat.h +++ b/src/chunkserver/heartbeat.h @@ -70,6 +70,7 @@ struct HeartbeatOptions { uint32_t port; uint32_t intervalSec; uint32_t timeout; + bool useChunkFilePoolAsWalPool; CopysetNodeManager* copysetNodeManager; std::shared_ptr fs; diff --git a/src/fs/ext4_filesystem_impl.cpp b/src/fs/ext4_filesystem_impl.cpp index 4116146f42..6ed6430a27 100644 --- a/src/fs/ext4_filesystem_impl.cpp +++ b/src/fs/ext4_filesystem_impl.cpp @@ -346,7 +346,11 @@ int Ext4FileSystemImpl::Write(int fd, continue; } LOG(ERROR) << "IOBuf::pcut_into_file_descriptor failed: " - << strerror(errno); + << strerror(errno) + << ", fd: " << fd + << ", offset: " << offset + << ", remainLength: " << remainLength + << ", length: " << length; return -errno; } diff --git a/src/mds/topology/topology_service_manager.cpp b/src/mds/topology/topology_service_manager.cpp index e648ff5a48..3fa0dd3fa1 100644 --- a/src/mds/topology/topology_service_manager.cpp +++ b/src/mds/topology/topology_service_manager.cpp @@ -82,13 +82,9 @@ void TopologyServiceManager::RegistChunkServer( std::string hostIp = request->hostip(); uint32_t port = request->port(); - ChunkServerStat stat; bool useChunkFilePoolAsWalPool = false; uint32_t useChunkFilePoolAsWalPoolReserve; bool useChunkFilepool = false; - if (request->has_chunkfilepoolsize()) { - stat.chunkFilepoolSize = request->chunkfilepoolsize(); - } if (request->has_usechunkfilepoolaswalpool()) { useChunkFilepool = true; useChunkFilePoolAsWalPool = request->usechunkfilepoolaswalpool(); @@ -135,7 +131,7 @@ void TopologyServiceManager::RegistChunkServer( response->set_statuscode(kTopoErrCodeSuccess); response->set_chunkserverid(cs.GetId()); response->set_token(cs.GetToken()); - topoStat_->UpdateChunkServerStat(cs.GetId(), stat); + topologyChunkAllocator_->UpdateChunkFilePoolAllocConfig( useChunkFilepool, useChunkFilePoolAsWalPool, useChunkFilePoolAsWalPoolReserve); @@ -172,8 +168,6 @@ void TopologyServiceManager::RegistChunkServer( response->set_statuscode(kTopoErrCodeSuccess); response->set_chunkserverid(cs.GetId()); response->set_token(cs.GetToken()); - topoStat_->UpdateChunkServerStat(cs.GetId(), - stat); topologyChunkAllocator_->UpdateChunkFilePoolAllocConfig( useChunkFilepool, useChunkFilePoolAsWalPool, useChunkFilePoolAsWalPoolReserve); @@ -253,6 +247,9 @@ void TopologyServiceManager::RegistChunkServer( response->set_token(chunkserver.GetToken()); ChunkServerStat stat; stat.chunkFilepoolSize = request->chunkfilepoolsize(); + stat.chunkSizeUsedBytes = 0; + stat.chunkSizeLeftBytes = stat.chunkFilepoolSize; + stat.chunkSizeTrashedBytes = 0; topoStat_->UpdateChunkServerStat(chunkserver.GetId(), stat); topologyChunkAllocator_->UpdateChunkFilePoolAllocConfig( useChunkFilepool, useChunkFilePoolAsWalPool,