Skip to content

Commit

Permalink
mds:fix updatechunkserverstat bug & add some logs
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-chaojie committed Nov 29, 2023
1 parent ee0b0bb commit b436c94
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/chunkserver/chunkserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,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.";

Expand Down
2 changes: 1 addition & 1 deletion src/chunkserver/datastore/chunkserver_chunkfile_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ CSErrorCode CSChunkFile_V2::Delete(SequenceNum sn) {
if (ret < 0)
return CSErrorCode::InternalError;

DVLOG(9) << "Chunk deleted."
LOG(INFO) << "Chunk deleted."
<< "ChunkID: " << chunkId_
<< ", request sn: " << sn
<< ", chunk sn: " << metaPage_.sn;
Expand Down
5 changes: 0 additions & 5 deletions src/chunkserver/datastore/file_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ bool FilePool::ScanInternal() {
}
}

currentState_.capacity = tmpvec.size();
currentState_.preallocatedChunksLeft = tmpvec.size();

std::unique_lock<std::mutex> lk(mtx_);
Expand All @@ -539,10 +538,6 @@ size_t FilePool::Size() {
return tmpChunkvec_.size();
}

size_t FilePool::Capacity() {
return currentState_.capacity;
}

FilePoolState FilePool::GetState() const {
return currentState_;
}
Expand Down
4 changes: 0 additions & 4 deletions src/chunkserver/datastore/file_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ struct FilePoolState {
uint32_t metaPageSize = 0;
// io alignment
uint32_t blockSize = 0;
// filepool Capacity
uint64_t capacity = 0;
};

struct FilePoolMeta {
Expand Down Expand Up @@ -173,8 +171,6 @@ class CURVE_CACHELINE_ALIGNMENT FilePool {
*/
virtual size_t Size();

virtual size_t Capacity();

/**
* Get the allocation status of FilePool
*/
Expand Down
16 changes: 11 additions & 5 deletions src/chunkserver/heartbeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions src/chunkserver/heartbeat.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct HeartbeatOptions {
uint32_t port;
uint32_t intervalSec;
uint32_t timeout;
bool useChunkFilePoolAsWalPool;
CopysetNodeManager* copysetNodeManager;

std::shared_ptr<LocalFileSystem> fs;
Expand Down
6 changes: 5 additions & 1 deletion src/fs/ext4_filesystem_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 4 additions & 7 deletions src/mds/topology/topology_service_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion src/mds/topology/topology_stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ void TopologyStatImpl::UpdateChunkServerStat(ChunkServerIdType csId,
int64_t diffUsed = stat.chunkSizeUsedBytes -
it->second.chunkSizeUsedBytes;
physicalPoolStats_[belongPhysicalPoolId].chunkFilePoolUsed += diffUsed;

VLOG(3) << "UpdateChunkServerStat, chunkserver stat update,"
<< " chunkserverId = "
<< csId
<< ", chunkFilePoolSize = "
<< stat.chunkFilepoolSize
<< ", chunkFilePoolUsed = "
<< stat.chunkSizeUsedBytes
<< ", diff = "
<< diff
<< ", diffUsed = "
<< diffUsed;
if (chunkFilePoolAllocHelp_->GetUseChunkFilepool()) {
if (stat.chunkSizeUsedBytes >
(stat.chunkFilepoolSize * available / 100)) {
Expand Down

0 comments on commit b436c94

Please sign in to comment.