Skip to content

Commit

Permalink
fix cpplint problem & ut failed
Browse files Browse the repository at this point in the history
  • Loading branch information
xu-chaojie committed Nov 23, 2023
1 parent 4317ff8 commit eebd988
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 79 deletions.
3 changes: 2 additions & 1 deletion src/chunkserver/copyset_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ uint64_t CopysetNode::GetHashCode(const ChunkRequest* request) {
hashcode = std::hash<uint64_t>{} (request->fileid());
break;
}
} else { // has no originfileId it is the origin file just use the fileid
// has no originfileId it is the origin file just use the fileid
} else {
switch (request->optype()) {
case CHUNK_OP_DELETE:
case CHUNK_OP_WRITE:
Expand Down
30 changes: 17 additions & 13 deletions src/chunkserver/datastore/chunkserver_chunkfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace chunkserver {
ChunkFileMetaPage::ChunkFileMetaPage(const ChunkFileMetaPage& metaPage) {
version = metaPage.version;
sn = metaPage.sn;
if (version <= curve::common::kBaseFileVersion) { //old version metaPage
if (version <= curve::common::kBaseFileVersion) { // old version metaPage
correctedSn = metaPage.correctedSn;
location = metaPage.location;
} else {
Expand All @@ -43,7 +43,7 @@ ChunkFileMetaPage::ChunkFileMetaPage(const ChunkFileMetaPage& metaPage) {
virtualId = metaPage.virtualId;
fileId = metaPage.fileId;
}

if (metaPage.bitmap != nullptr) {
bitmap = std::make_shared<Bitmap>(metaPage.bitmap->Size(),
metaPage.bitmap->GetBitmap());
Expand All @@ -58,7 +58,7 @@ ChunkFileMetaPage& ChunkFileMetaPage::operator =(
return *this;
version = metaPage.version;
sn = metaPage.sn;
if (version <= curve::common::kBaseFileVersion) { //old version metaPage
if (version <= curve::common::kBaseFileVersion) { // old version metaPage
correctedSn = metaPage.correctedSn;
location = metaPage.location;
} else {
Expand All @@ -81,7 +81,8 @@ ChunkFileMetaPage& ChunkFileMetaPage::operator =(
void ChunkFileMetaPage::encode(char* buf) {
size_t len = 0;

if (version <= uint8_t (curve::common::kBaseFileVersion)) { //old version metaPage
if (version <= uint8_t(curve::common::kBaseFileVersion)) {
// old version metaPage
memcpy(buf, &version, sizeof(version));
len += sizeof(version);
memcpy(buf + len, &sn, sizeof(sn));
Expand All @@ -91,7 +92,8 @@ void ChunkFileMetaPage::encode(char* buf) {
size_t loc_size = location.size();
memcpy(buf + len, &loc_size, sizeof(loc_size));
len += sizeof(loc_size);
// CloneChunk need serialized location information and bitmap information
// CloneChunk need serialized location information
// and bitmap information
if (loc_size > 0) {
memcpy(buf + len, location.c_str(), loc_size);
len += loc_size;
Expand All @@ -102,7 +104,8 @@ void ChunkFileMetaPage::encode(char* buf) {
memcpy(buf + len, bitmap->GetBitmap(), bitmapBytes);
len += bitmapBytes;
}
} else { //new version metaPage
} else {
// new version metaPage
memcpy(buf, &version, sizeof(version));
len += sizeof(version);
memcpy(buf + len, &sn, sizeof(sn));
Expand All @@ -114,7 +117,8 @@ void ChunkFileMetaPage::encode(char* buf) {
memcpy(buf + len, &fileId, sizeof(fileId));
len += sizeof(fileId);

// CloneChunk need serialized location information and bitmap information
// CloneChunk need serialized location information
// and bitmap information
if (cloneNo > 0) {
int32_t bMark = 0;
if (nullptr == bitmap) {
Expand Down Expand Up @@ -145,7 +149,7 @@ CSErrorCode ChunkFileMetaPage::decode(const char* buf) {
memcpy(&version, buf, sizeof(version));
len += sizeof(version);

if (version <= uint8_t (curve::common::kBaseFileVersion)) {
if (version <= uint8_t(curve::common::kBaseFileVersion)) {
memcpy(&sn, buf + len, sizeof(sn));
len += sizeof(sn);
memcpy(&correctedSn, buf + len, sizeof(correctedSn));
Expand Down Expand Up @@ -211,7 +215,8 @@ CSErrorCode ChunkFileMetaPage::decode(const char* buf) {

// TODO(yyk) check version compatibility, currrent simple error handing,
// need detailed implementation later
if (version > FORMAT_VERSION) { // version bigger than FORMAT_VERSION, some error happened
if (version > FORMAT_VERSION) {
// version bigger than FORMAT_VERSION, some error happened
LOG(ERROR) << "File format version incompatible."
<< "file version: "
<< static_cast<uint32_t>(version)
Expand Down Expand Up @@ -244,7 +249,7 @@ CSChunkFile::CSChunkFile(std::shared_ptr<LocalFileSystem> lfs,
enableOdsyncWhenOpenChunkFile_(options.enableOdsyncWhenOpenChunkFile) {
CHECK(!baseDir_.empty()) << "Create chunk file failed";
CHECK(lfs_ != nullptr) << "Create chunk file failed";
metaPage_.version = uint8_t (curve::common::kBaseFileVersion);
metaPage_.version = uint8_t(curve::common::kBaseFileVersion);
metaPage_.sn = options.sn;
metaPage_.correctedSn = options.correctedSn;
metaPage_.location = options.location;
Expand Down Expand Up @@ -288,7 +293,6 @@ CSChunkFile::~CSChunkFile() {
*/
int CSChunkFile::getVersion(std::shared_ptr<LocalFileSystem> lfs,
std::string dir, SequenceNum id) {

uint8_t version = 0;
std::string path = dir + "/" +
FileNameOperator::GenerateChunkFileName(id);
Expand All @@ -301,7 +305,7 @@ int CSChunkFile::getVersion(std::shared_ptr<LocalFileSystem> lfs,
}

int rc = 0;
rc = lfs->Read(fd, (char*)&version, 0, 1);
rc = lfs->Read(fd, reinterpret_cast<char*>(&version), 0, 1);
if (rc < 0) {
LOG(ERROR) << "read chunkfile version failed, path = " << path
<< ", errcode = " << rc;
Expand Down Expand Up @@ -777,7 +781,7 @@ CSErrorCode CSChunkFile::Delete(SequenceNum sn) {
return CSErrorCode::Success;
}

CSErrorCode CSChunkFile::DeleteSnapshot(SequenceNum correctedSn,
CSErrorCode CSChunkFile::DeleteSnapshot(SequenceNum correctedSn,
std::shared_ptr<SnapContext> ctx) {
return DeleteSnapshotOrCorrectSn(correctedSn);
}
Expand Down
25 changes: 13 additions & 12 deletions src/chunkserver/datastore/chunkserver_chunkfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ struct CloneInfos {
};

// The CloneContext structure is used to store the clone context information
// of the clone chunk, used by client to tell chunkserver the clone and snapshot tree
// of the clone chunk, used by client to
// tell chunkserver the clone and snapshot tree
// structure of the clone chunk
// the @rootId is the fileid of the root file
// the @cloneNo is the fileid of the clone file
Expand Down Expand Up @@ -290,7 +291,7 @@ class CSChunkFile {
CSDataStore* datastore) {
// flattenWrite not supported in this version
LOG(ERROR) << "flattenWrite not supported in this version";
return CSErrorCode::IncompatibleError;
return CSErrorCode::IncompatibleError;
}
/**
* Write the data of the clone chunk
Expand All @@ -316,7 +317,7 @@ class CSChunkFile {
// cloneWrite not supported in this version
LOG(ERROR) << "cloneWrite not supported in this version";
return CSErrorCode::IncompatibleError;
};
}

CSErrorCode Sync();

Expand Down Expand Up @@ -381,21 +382,21 @@ class CSChunkFile {
* delete
* @param ctx: snapshot context
*/
virtual CSErrorCode DeleteSnapshot(SequenceNum correctedSn,
virtual CSErrorCode DeleteSnapshot(SequenceNum correctedSn,
std::shared_ptr<SnapContext> ctx);
/* In order to call the v2 DivideObjInfoByIndex
* to find the chunkfile has which data in the range,
* to find the chunkfile has which data in the range,
* the data in the range but not in the chunkfile
* are put into the notInRanges
* @param sn: The sequence number of the chunk that needs
* @param sn: The sequence number of the chunk that needs
* @param range: the range of the data to find
* @param notInRanges: the range of the data not in the chunkfile
* @param objInfos: the data in the chunkfile
*/
virtual bool DivideObjInfoByIndex(SequenceNum sn,
std::vector<BitRange>& range, // NOLINT
std::vector<BitRange>& notInRanges, // NOLINT
std::vector<ObjectInfo>& objInfos) {
std::vector<ObjectInfo>& objInfos) { // NOLINT
return false;
}
/* In order to call the v2 DivideObjInfoByIndex without lock
Expand All @@ -407,7 +408,7 @@ class CSChunkFile {
virtual bool DivideObjInfoByIndexLockless(SequenceNum sn,
std::vector<BitRange>& range, // NOLINT
std::vector<BitRange>& notInRanges, // NOLINT
std::vector<ObjectInfo>& objInfos) {
std::vector<ObjectInfo>& objInfos) { // NOLINT
return false;
}
/**
Expand All @@ -420,7 +421,7 @@ class CSChunkFile {
virtual bool DivideSnapshotObjInfoByIndex(SequenceNum sn,
std::vector<BitRange>& range, // NOLINT
std::vector<BitRange>& notInRanges, // NOLINT
std::vector<ObjectInfo>& objInfos) {
std::vector<ObjectInfo>& objInfos) { // NOLINT
return false;
}
/**
Expand Down Expand Up @@ -498,7 +499,7 @@ class CSChunkFile {
* Load metapage into memory
*/
CSErrorCode loadMetaPage();

inline int readMetaPage(char* buf) {
return lfs_->Read(fd_, buf, 0, metaPageSize_);
}
Expand Down Expand Up @@ -589,7 +590,7 @@ class CSChunkFile {
return syncChunkLimits_;
}

private: //options of snapshot
private: // options of snapshot
/**
* Determine whether you need to create a new snapshot
* @param sn: write request sequence number
Expand Down Expand Up @@ -645,7 +646,7 @@ class CSChunkFile {
// enable O_DSYNC When Open ChunkFile
bool enableOdsyncWhenOpenChunkFile_;

private: //options of snapshot
private: // options of snapshot
// Snapshot file pointer
CSSnapshot* snapshot_;
};
Expand Down
35 changes: 20 additions & 15 deletions src/chunkserver/datastore/chunkserver_chunkfile_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* File Created: Thursday, 6th September 2018 10:49:53 am
* Author: yangyaokai
*/

#include "src/chunkserver/datastore/chunkserver_chunkfile_v2.h"

#include <fcntl.h>
#include <algorithm>
#include <memory>
Expand Down Expand Up @@ -61,7 +64,8 @@ CSChunkFile_V2::CSChunkFile_V2(std::shared_ptr<LocalFileSystem> lfs,
}

snapshots_ = std::make_shared<CSSnapshots>(options.blockSize);
metaPage_.version = uint8_t (curve::common::kSupportLocalSnapshotFileVersion);
metaPage_.version = uint8_t(
curve::common::kSupportLocalSnapshotFileVersion);
metaPage_.sn = options.sn;
metaPage_.correctedSn = 0;
metaPage_.location = "";
Expand Down Expand Up @@ -341,8 +345,8 @@ CSErrorCode CSChunkFile_V2::writeSnapData(SequenceNum sn,

// Find the OBJ need to read from Parent
// and update the objInfos
// <offset, length>
// if OBJ is on the left of <offset, length> need read
// <offset, length>
// if OBJ is on the left of <offset, length> need read
// if OBJ is in the middle of <offset, length>
// if OBJ is on the right of <offset, length> need read
// @param objIns: the objInfos of the clone file
Expand Down Expand Up @@ -417,10 +421,11 @@ int CSChunkFile_V2::FindExtraReadFromParent(
// Merge the address adjacent OBJS of diffent Parents together
// for example the <0, 64KB> in snapshot 1 and <64KB, 64KB> in snapshot 2
// can get <0, 128KB> --> <1, 0, 64KB> and <2, 64KB, 64KB>
// @param objmap: the output merge map of the objs
// @param objmap: the output merge map of the objs
// @param objIns: the input objInfos of the clone file
void CSChunkFile_V2::MergeObjectForRead(std::map<int32_t, Offset_InfoPtr>& objmap,
std::vector<File_ObjectInfoPtr>& objIns) {
void CSChunkFile_V2::MergeObjectForRead(
std::map<int32_t, Offset_InfoPtr>& objmap,
std::vector<File_ObjectInfoPtr>& objIns) {
for (auto& tmpo : objIns) {
if (tmpo->fileptr.get() != this) {
for (auto& tmpi : tmpo->obj_infos) {
Expand Down Expand Up @@ -542,7 +547,7 @@ bool CSChunkFile_V2::isAlignWithObjSize(off_t offset, size_t length) {
return false;
}

// Snapshot or clone OBJ_SIZE is maybe different from write block size
// Snapshot or clone OBJ_SIZE is maybe different from write block size
// OBJ_SIZE maybe 64KB, block size maybe 4KB / 512B
// OBJ_SIZE alreadys bigger than block size
// MergeParentAndWrite is used for read the parent obj and merge with
Expand All @@ -553,7 +558,6 @@ CSErrorCode CSChunkFile_V2::MergeParentAndWrite(SequenceNum sn,
size_t length,
const std::unique_ptr<CloneContext>& cloneCtx,
CSDataStore* datastore) {

CSErrorCode errorCode = CSErrorCode::Success;

// Judge that the clonefile has the data in <beginIndex, endIndex>
Expand All @@ -572,13 +576,13 @@ CSErrorCode CSChunkFile_V2::MergeParentAndWrite(SequenceNum sn,
<< ",chunk sn: " << metaPage_.sn
<< ", rc = " << rc;
return CSErrorCode::InternalError;
}
}
return errorCode;
}

uint32_t beginIndex = offset >> OBJ_SIZE_SHIFT;
uint32_t endIndex = (offset + length - 1) >> OBJ_SIZE_SHIFT;
off_t offsetHeader = offset;
off_t offsetHeader = offset;
size_t realLength = length;
bool needHeader = false;
bool needTail = false;
Expand All @@ -601,14 +605,16 @@ CSErrorCode CSChunkFile_V2::MergeParentAndWrite(SequenceNum sn,
cloneCtx, datastore, true);
auto objHeader = objIns.begin();
fileobjHeader = std::move(*objHeader);
if (fileobjHeader->fileptr.get() != this) {//need read from parent
if (fileobjHeader->fileptr.get() != this) {
// need read from parent
offsetHeader = beginIndex << OBJ_SIZE_SHIFT;
needHeader = true;
}
}
}

if (endIndex == beginIndex) {// have only one object
if (endIndex == beginIndex) {
// have only one object
if (true == needHeader) {
realLength = OBJ_SIZE;
} else {
Expand All @@ -621,7 +627,8 @@ CSErrorCode CSChunkFile_V2::MergeParentAndWrite(SequenceNum sn,
cloneCtx, datastore, true);
auto objTail = objInsTail.begin();
fileobjTail = std::move(*objTail);
if (fileobjTail->fileptr.get() != this) {//need read from parent
if (fileobjTail->fileptr.get() != this) {
// need read from parent
realLength = ((endIndex + 1) << OBJ_SIZE_SHIFT) - offsetHeader;
needTail = true;
}
Expand Down Expand Up @@ -707,7 +714,6 @@ CSErrorCode CSChunkFile_V2::flattenWriteInternal(SequenceNum sn,
size_t length,
const std::unique_ptr<CloneContext>& cloneCtx,
CSDataStore* datastore) {

CSErrorCode errorCode = CSErrorCode::Success;

// Judge that the clonefile has the data in <beginIndex, endIndex>
Expand Down Expand Up @@ -1002,7 +1008,6 @@ CSErrorCode CSChunkFile_V2::flattenWrite(SequenceNum sn,
}

CSErrorCode CSChunkFile_V2::createSnapshot(SequenceNum sn) {

if (snapshots_->contains(sn)) {
return CSErrorCode::Success;
}
Expand Down
Loading

0 comments on commit eebd988

Please sign in to comment.