Skip to content

Commit

Permalink
fix mds test bug
Browse files Browse the repository at this point in the history
Change-Id: If55d87364abbb06e77098a529d44bb50dfac2ec8
  • Loading branch information
hzchenwei7 committed Jun 19, 2019
1 parent bebe265 commit c1f10eb
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 6 deletions.
2 changes: 1 addition & 1 deletion curve_robot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ create file less than 10g
#[Setup] file init
${rc} create libcurve file less than 10g with normal user
${new_fd} Convert To Integer ${rc}
${expect_rc} evaluate int(-17)
${expect_rc} evaluate int(-24)
should be equal ${rc} ${expect_rc}
[Teardown] file clean ${new_fd}

Expand Down
2 changes: 2 additions & 0 deletions proto/nameserver2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ enum StatusCode {
kFileIdNotMatch = 130;
// 文件在删除中
kFileUnderDeleting = 131;
// 文件长度不符合要求
kFileLengthNotSupported = 132;
// 元数据存储错误
kStorageError = 501;
// 内部错误
Expand Down
2 changes: 2 additions & 0 deletions src/client/libcurve_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ enum LIBCURVE_ERROR {
NOT_ALIGNED = 22,
// 文件正在被关闭,fd不可用
BAD_FD = 23,
// 文件长度不满足要求
LENGTH_NOT_SUPPORT = 24,
// 未知错误
UNKNOWN = 100
};
Expand Down
3 changes: 3 additions & 0 deletions src/client/mds_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,9 @@ void MDSClient::MDSStatusCode2LibcurveError(const curve::mds::StatusCode& status
case ::curve::mds::StatusCode::kStorageError:
*errcode = LIBCURVE_ERROR::INTERNAL_ERROR;
break;
case ::curve::mds::StatusCode::kFileLengthNotSupported:
*errcode = LIBCURVE_ERROR::LENGTH_NOT_SUPPORT;
break;
default:
*errcode = LIBCURVE_ERROR::UNKNOWN;
break;
Expand Down
2 changes: 2 additions & 0 deletions src/mds/common/mds_define.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ typedef uint64_t SeqNum;
const uint64_t kKB = 1024;
const uint64_t kMB = 1024*kKB;
const uint64_t kGB = 1024*kMB;
const uint64_t kTB = 1024*kGB;

const uint64_t DefaultChunkSize = 16 * kMB;
const uint64_t DefaultSegmentSize = kGB * 1;
const uint64_t kMiniFileLength = DefaultSegmentSize * 10;
const uint64_t kMaxFileLength = 4 * kTB;

// curve默认root目录&inodeid
const InodeID ROOTINODEID = 0;
Expand Down
24 changes: 22 additions & 2 deletions src/mds/nameserver2/curvefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,18 @@ StatusCode CurveFS::CreateFile(const std::string & fileName,
}

// check param
// TODO(tom) : paramerror细化
if (filetype == FileType::INODE_PAGEFILE) {
if (length < kMiniFileLength) {
LOG(ERROR) << "file Length < MinFileLength " << kMiniFileLength
<< ", length = " << length;
return StatusCode::kParaError;
return StatusCode::kFileLengthNotSupported;
}

if (length > kMaxFileLength) {
LOG(ERROR) << "CreateFile file length > maxFileLength, fileName = "
<< fileName << ", length = " << length
<< ", maxFileLength = " << kMaxFileLength;
return StatusCode::kFileLengthNotSupported;
}
}

Expand Down Expand Up @@ -629,6 +635,13 @@ StatusCode CurveFS::ExtendFile(const std::string &filename,
return StatusCode::kNotSupported;
}

if (newLength > kMaxFileLength) {
LOG(ERROR) << "ExtendFile newLength > maxFileLength, fileName = "
<< filename << ", newLength = " << newLength
<< ", maxFileLength = " << kMaxFileLength;
return StatusCode::kFileLengthNotSupported;
}

if (newLength < fileInfo.length()) {
LOG(INFO) << "newLength = " << newLength
<< ", smaller than file length " << fileInfo.length();
Expand Down Expand Up @@ -1088,6 +1101,13 @@ StatusCode CurveFS::OpenFile(const std::string &fileName,
return ret;
}

if (fileInfo->filetype() != FileType::INODE_PAGEFILE) {
LOG(ERROR) << "OpenFile file type not support, fileName = " << fileName
<< ", clientIP = " << clientIP
<< ", filetype = " << fileInfo->filetype();
return StatusCode::kNotSupported;
}

ret = sessionManager_->InsertSession(fileName, clientIP, protoSession);
if (ret == StatusCode::kFileOccupied) {
LOG(WARNING) << "OpenFile file occupied, fileName = " << fileName
Expand Down
4 changes: 2 additions & 2 deletions src/mds/nameserver2/namespace_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ void NameSpaceService::RefreshSession(
return;
}

LOG(INFO) << "logid = " << cntl->log_id()
DVLOG(6) << "logid = " << cntl->log_id()
<< ", RefreshSession request, filename = " << request->filename()
<< ", sessionid = " << request->sessionid()
<< ", date = " << request->date()
Expand Down Expand Up @@ -1068,7 +1068,7 @@ void NameSpaceService::RefreshSession(
response->set_sessionid(request->sessionid());
response->set_allocated_fileinfo(fileInfo);
response->set_statuscode(StatusCode::kOK);
LOG(INFO) << "logid = " << cntl->log_id()
DVLOG(6) << "logid = " << cntl->log_id()
<< ", RefreshSession ok, filename = " << request->filename()
<< ", sessionid = " << request->sessionid()
<< ", date = " << request->date()
Expand Down
44 changes: 43 additions & 1 deletion test/mds/nameserver2/curvefs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ class CurveFSTest: public ::testing::Test {
TEST_F(CurveFSTest, testCreateFile1) {
// test parm error
ASSERT_EQ(curvefs_->CreateFile("/file1", "owner1", FileType::INODE_PAGEFILE,
kMiniFileLength-1), StatusCode::kParaError);
kMiniFileLength - 1), StatusCode::kFileLengthNotSupported);

ASSERT_EQ(curvefs_->CreateFile("/file1", "owner1", FileType::INODE_PAGEFILE,
kMaxFileLength + 1), StatusCode::kFileLengthNotSupported);

ASSERT_EQ(curvefs_->CreateFile("/", "", FileType::INODE_DIRECTORY, 0),
StatusCode::kFileExists);
Expand Down Expand Up @@ -1057,6 +1060,27 @@ TEST_F(CurveFSTest, testExtendFile) {
2 * kMiniFileLength), StatusCode::kOK);
}

// test size over maxsize
{
FileInfo fileInfo1;
fileInfo1.set_filetype(FileType::INODE_DIRECTORY);

FileInfo fileInfo2;
fileInfo2.set_filetype(FileType::INODE_PAGEFILE);
fileInfo2.set_length(kMiniFileLength);
fileInfo2.set_segmentsize(DefaultSegmentSize);

EXPECT_CALL(*storage_, GetFile(_, _, _))
.Times(2)
.WillOnce(DoAll(SetArgPointee<2>(fileInfo1),
Return(StoreStatus::OK)))
.WillOnce(DoAll(SetArgPointee<2>(fileInfo2),
Return(StoreStatus::OK)));

ASSERT_EQ(curvefs_->ExtendFile("/user1/file1",
2 * kMaxFileLength), StatusCode::kFileLengthNotSupported);
}

// file not exist
{
FileInfo fileInfo1;
Expand Down Expand Up @@ -2203,6 +2227,7 @@ TEST_F(CurveFSTest, testOpenFile) {
{
ProtoSession protoSession;
FileInfo fileInfo;
fileInfo.set_filetype(FileType::INODE_PAGEFILE);
EXPECT_CALL(*storage_, GetFile(_, _, _))
.Times(1)
.WillOnce(Return(StoreStatus::KeyNotExist));
Expand All @@ -2211,10 +2236,24 @@ TEST_F(CurveFSTest, testOpenFile) {
StatusCode::kFileNotExists);
}

// open目录
{
ProtoSession protoSession;
FileInfo fileInfo;
fileInfo.set_filetype(FileType::INODE_DIRECTORY);
EXPECT_CALL(*storage_, GetFile(_, _, _))
.Times(1)
.WillOnce(Return(StoreStatus::OK));
ASSERT_EQ(curvefs_->OpenFile("/file1", "127.0.0.1",
&protoSession, &fileInfo),
StatusCode::kNotSupported);
}

// 插入session失败
{
ProtoSession protoSession;
FileInfo fileInfo;
fileInfo.set_filetype(FileType::INODE_PAGEFILE);
EXPECT_CALL(*storage_, GetFile(_, _, _))
.Times(1)
.WillOnce(Return(StoreStatus::OK));
Expand All @@ -2232,6 +2271,7 @@ TEST_F(CurveFSTest, testOpenFile) {
{
ProtoSession protoSession;
FileInfo fileInfo;
fileInfo.set_filetype(FileType::INODE_PAGEFILE);
EXPECT_CALL(*storage_, GetFile(_, _, _))
.Times(1)
.WillOnce(Return(StoreStatus::OK));
Expand All @@ -2257,6 +2297,7 @@ TEST_F(CurveFSTest, testOpenFile) {
TEST_F(CurveFSTest, testCloseFile) {
ProtoSession protoSession;
FileInfo fileInfo;
fileInfo.set_filetype(FileType::INODE_PAGEFILE);

// 先插入session
EXPECT_CALL(*storage_, GetFile(_, _, _))
Expand Down Expand Up @@ -2313,6 +2354,7 @@ TEST_F(CurveFSTest, testCloseFile) {
TEST_F(CurveFSTest, testRefreshSession) {
ProtoSession protoSession;
FileInfo fileInfo;
fileInfo.set_filetype(FileType::INODE_PAGEFILE);

// 先插入session
EXPECT_CALL(*storage_, GetFile(_, _, _))
Expand Down
24 changes: 24 additions & 0 deletions test/mds/nameserver2/namespace_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,30 @@ TEST_F(NameSpaceServiceTest, deletefiletests) {
ASSERT_TRUE(false);
}

while (1) {
cntl.Reset();
CheckSnapShotStatusRequest checkRequest;
CheckSnapShotStatusResponse checkResponse;
checkRequest.set_filename("/file1");
checkRequest.set_owner("owner");
checkRequest.set_date(TimeUtility::GetTimeofDayUs());
checkRequest.set_seq(1);
stub.CheckSnapShotStatus(&cntl, &checkRequest, &checkResponse, NULL);
if (!cntl.Failed()) {
if (checkResponse.statuscode() ==
StatusCode::kSnapshotFileNotExists) {
break;
} else {
ASSERT_EQ(checkResponse.statuscode(), StatusCode::kOK);
sleep(1);
}
} else {
ASSERT_TRUE(false);
break;
}
}


// 3 如果目录下有文件,那么删除目录返回kDirNotEmpty
cntl.Reset();
request3.set_filename("/dir1");
Expand Down

0 comments on commit c1f10eb

Please sign in to comment.