Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Curve
Commits
5ae26185
Commit
5ae26185
authored
3 years ago
by
Wine93
Committed by
xuchaojie
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
snapshotcloneserver: fixed cancel task lost
parent
c3418be3
master
No related merge requests found
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
src/snapshotcloneserver/common/snapshotclone_meta_store.h
+14
-0
src/snapshotcloneserver/common/snapshotclone_meta_store.h
src/snapshotcloneserver/common/snapshotclone_meta_store_etcd.cpp
+29
-0
...pshotcloneserver/common/snapshotclone_meta_store_etcd.cpp
src/snapshotcloneserver/common/snapshotclone_meta_store_etcd.h
+2
-0
...napshotcloneserver/common/snapshotclone_meta_store_etcd.h
src/snapshotcloneserver/snapshot/snapshot_core.cpp
+46
-24
src/snapshotcloneserver/snapshot/snapshot_core.cpp
src/snapshotcloneserver/snapshot/snapshot_core.h
+13
-0
src/snapshotcloneserver/snapshot/snapshot_core.h
src/snapshotcloneserver/snapshot/snapshot_task_manager.cpp
+1
-5
src/snapshotcloneserver/snapshot/snapshot_task_manager.cpp
test/integration/snapshotcloneserver/fake_snapshotclone_meta_store.cpp
+17
-0
...ion/snapshotcloneserver/fake_snapshotclone_meta_store.cpp
test/integration/snapshotcloneserver/fake_snapshotclone_meta_store.h
+1
-0
...ation/snapshotcloneserver/fake_snapshotclone_meta_store.h
test/integration/snapshotcloneserver/snapshotcloneserver_concurrent_test.cpp
+1
-1
...apshotcloneserver/snapshotcloneserver_concurrent_test.cpp
test/snapshotcloneserver/mock_snapshot_server.h
+4
-0
test/snapshotcloneserver/mock_snapshot_server.h
test/snapshotcloneserver/test_snapshot_core.cpp
+53
-43
test/snapshotcloneserver/test_snapshot_core.cpp
test/snapshotcloneserver/test_snapshot_service_manager.cpp
+18
-0
test/snapshotcloneserver/test_snapshot_service_manager.cpp
test/snapshotcloneserver/test_snapshotclone_meta_store_etcd.cpp
+110
-0
...napshotcloneserver/test_snapshotclone_meta_store_etcd.cpp
with
309 additions
and
73 deletions
+309
-73
src/snapshotcloneserver/common/snapshotclone_meta_store.h
+
14
-
0
View file @
5ae26185
...
...
@@ -37,6 +37,8 @@
namespace
curve
{
namespace
snapshotcloneserver
{
using
CASFunc
=
std
::
function
<
SnapshotInfo
*
(
SnapshotInfo
*
)
>
;
class
SnapshotCloneMetaStore
{
public:
SnapshotCloneMetaStore
()
{}
...
...
@@ -60,6 +62,18 @@ class SnapshotCloneMetaStore {
* @return: 0 更新成功/ -1 更新失败
*/
virtual
int
UpdateSnapshot
(
const
SnapshotInfo
&
snapinfo
)
=
0
;
/**
* @brief Compare and set snapshot
* @param[in] uuid the uuid for snapshot
* @param[in] cas the function for compare and set snapshot,
* return nullptr if not needed to set snapshot,
* else return the pointer of snapshot to set
* @return 0 if set snapshot success or not needed to set snapshot,
* else return -1
*/
virtual
int
CASSnapshot
(
const
UUID
&
uuid
,
CASFunc
cas
)
=
0
;
/**
* 获取指定快照的快照信息
* @param 快照的uuid
...
...
This diff is collapsed.
Click to expand it.
src/snapshotcloneserver/common/snapshotclone_meta_store_etcd.cpp
+
29
-
0
View file @
5ae26185
...
...
@@ -106,6 +106,35 @@ int SnapshotCloneMetaStoreEtcd::UpdateSnapshot(const SnapshotInfo &info) {
return
0
;
}
int
SnapshotCloneMetaStoreEtcd
::
CASSnapshot
(
const
UUID
&
uuid
,
CASFunc
cas
)
{
WriteLockGuard
guard
(
snapInfos_mutex
);
auto
iter
=
snapInfos_
.
find
(
uuid
);
auto
info
=
cas
(
iter
==
snapInfos_
.
end
()
?
nullptr
:
&
(
iter
->
second
));
if
(
nullptr
==
info
)
{
// Not needed to update snapshot
return
0
;
}
int
retCode
;
std
::
string
value
;
auto
key
=
codec_
->
EncodeSnapshotKey
(
uuid
);
if
(
!
codec_
->
EncodeSnapshotData
(
*
info
,
&
value
))
{
LOG
(
ERROR
)
<<
"EncodeSnapshotData failed, snapshotInfo: "
<<
*
info
;
return
-
1
;
}
else
if
((
retCode
=
client_
->
Put
(
key
,
value
))
!=
EtcdErrCode
::
EtcdOK
)
{
LOG
(
ERROR
)
<<
"Put snapshotInfo into etcd failed"
<<
", errCode: "
<<
retCode
<<
", snapshotInfo: "
<<
*
info
;
return
-
1
;
}
if
(
iter
!=
snapInfos_
.
end
())
{
iter
->
second
=
*
info
;
}
else
{
snapInfos_
.
emplace
(
uuid
,
*
info
);
}
return
0
;
}
int
SnapshotCloneMetaStoreEtcd
::
GetSnapshotInfo
(
const
UUID
&
uuid
,
SnapshotInfo
*
info
)
{
ReadLockGuard
guard
(
snapInfos_mutex
);
...
...
This diff is collapsed.
Click to expand it.
src/snapshotcloneserver/common/snapshotclone_meta_store_etcd.h
+
2
-
0
View file @
5ae26185
...
...
@@ -57,6 +57,8 @@ class SnapshotCloneMetaStoreEtcd : public SnapshotCloneMetaStore {
int
UpdateSnapshot
(
const
SnapshotInfo
&
info
)
override
;
int
CASSnapshot
(
const
UUID
&
uuid
,
CASFunc
cas
)
override
;
int
GetSnapshotInfo
(
const
UUID
&
uuid
,
SnapshotInfo
*
info
)
override
;
int
GetSnapshotList
(
const
std
::
string
&
filename
,
...
...
This diff is collapsed.
Click to expand it.
src/snapshotcloneserver/snapshot/snapshot_core.cpp
+
46
-
24
View file @
5ae26185
...
...
@@ -173,7 +173,7 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask(
UUID
uuid
=
task
->
GetUuid
();
uint64_t
seqNum
=
info
->
GetSeqNum
();
bool
existIndexData
=
false
;
if
(
kUnInitializeSeqNum
==
seqNum
)
{
if
(
kUnInitializeSeqNum
==
seqNum
)
{
ret
=
CreateSnapshotOnCurvefs
(
fileName
,
info
,
task
);
if
(
ret
<
0
)
{
LOG
(
ERROR
)
<<
"CreateSnapshotOnCurvefs error, "
...
...
@@ -212,11 +212,7 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask(
task
->
SetProgress
(
kProgressCreateSnapshotOnCurvefsComplete
);
task
->
UpdateMetric
();
if
(
task
->
IsCanceled
())
{
ret
=
StartCancel
(
task
);
if
(
kErrCodeSuccess
==
ret
)
{
CancelAfterCreateSnapshotOnCurvefs
(
task
);
}
return
;
return
CancelAfterCreateSnapshotOnCurvefs
(
task
);
}
ChunkIndexData
indexData
;
...
...
@@ -270,11 +266,7 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask(
}
if
(
task
->
IsCanceled
())
{
ret
=
StartCancel
(
task
);
if
(
kErrCodeSuccess
==
ret
)
{
CancelAfterCreateChunkIndexData
(
task
);
}
return
;
return
CancelAfterCreateChunkIndexData
(
task
);
}
FileSnapMap
fileSnapshotMap
;
...
...
@@ -320,11 +312,8 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask(
task
->
UpdateMetric
();
if
(
task
->
IsCanceled
())
{
ret
=
StartCancel
(
task
);
if
(
kErrCodeSuccess
==
ret
)
{
CancelAfterTransferSnapshotData
(
task
,
indexData
,
fileSnapshotMap
);
}
return
;
return
CancelAfterTransferSnapshotData
(
task
,
indexData
,
fileSnapshotMap
);
}
ret
=
DeleteSnapshotOnCurvefs
(
*
info
);
...
...
@@ -337,12 +326,8 @@ void SnapshotCoreImpl::HandleCreateSnapshotTask(
LockGuard
lockGuard
(
task
->
GetLockRef
());
if
(
task
->
IsCanceled
())
{
// Cancel的逻辑与前面一致
ret
=
StartCancel
(
task
);
if
(
kErrCodeSuccess
==
ret
)
{
CancelAfterTransferSnapshotData
(
task
,
indexData
,
fileSnapshotMap
);
}
return
;
return
CancelAfterTransferSnapshotData
(
task
,
indexData
,
fileSnapshotMap
);
}
HandleCreateSnapshotSuccess
(
task
);
...
...
@@ -572,9 +557,20 @@ int SnapshotCoreImpl::CreateSnapshotOnCurvefs(
info
->
SetStripeCount
(
snapInfo
.
stripeCount
);
info
->
SetCreateTime
(
snapInfo
.
ctime
);
ret
=
metaStore_
->
UpdateSnapshot
(
*
info
);
auto
compareAndSet
=
[
&
](
SnapshotInfo
*
snapinfo
)
{
if
(
nullptr
!=
snapinfo
)
{
auto
status
=
snapinfo
->
GetStatus
();
if
(
info
->
GetStatus
()
!=
status
)
{
info
->
SetStatus
(
status
);
}
}
return
info
;
};
auto
uuid
=
info
->
GetUuid
();
ret
=
metaStore_
->
CASSnapshot
(
uuid
,
compareAndSet
);
if
(
ret
<
0
)
{
LOG
(
ERROR
)
<<
"
Update
Snapshot error, "
LOG
(
ERROR
)
<<
"
CAS
Snapshot error, "
<<
" ret = "
<<
ret
<<
", fileName = "
<<
fileName
<<
", uuid = "
<<
task
->
GetUuid
();
...
...
@@ -1159,6 +1155,32 @@ int SnapshotCoreImpl::HandleCancelUnSchduledSnapshotTask(
return
kErrCodeSuccess
;
}
int
SnapshotCoreImpl
::
HandleCancelScheduledSnapshotTask
(
std
::
shared_ptr
<
SnapshotTaskInfo
>
task
)
{
LockGuard
lockGuard
(
task
->
GetLockRef
());
if
(
task
->
IsFinish
())
{
return
kErrCodeCannotCancelFinished
;
}
auto
ret
=
StartCancel
(
task
);
if
(
kErrCodeSuccess
==
ret
)
{
task
->
Cancel
();
}
else
{
auto
&
snapInfo
=
task
->
GetSnapshotInfo
();
LOG
(
ERROR
)
<<
"HandleCancelSchduledSnapshotTask failed: "
<<
", ret = "
<<
ret
<<
", uuid = "
<<
snapInfo
.
GetUuid
()
<<
", fileName = "
<<
snapInfo
.
GetFileName
()
<<
", snapshotName = "
<<
snapInfo
.
GetSnapshotName
()
<<
", seqNum = "
<<
snapInfo
.
GetSeqNum
()
<<
", createTime = "
<<
snapInfo
.
GetCreateTime
();
}
return
ret
;
}
}
// namespace snapshotcloneserver
}
// namespace curve
This diff is collapsed.
Click to expand it.
src/snapshotcloneserver/snapshot/snapshot_core.h
+
13
-
0
View file @
5ae26185
...
...
@@ -156,6 +156,16 @@ class SnapshotCore {
virtual
int
HandleCancelUnSchduledSnapshotTask
(
std
::
shared_ptr
<
SnapshotTaskInfo
>
task
)
=
0
;
/**
* @brief Handle cancel snapshot task which is scheduled
* @param[in] task pointer to snapshot task
* @return kErrCodeCannotCancelFinished if task has finished,
* kErrCodeSuccess if cancel success,
* else return kErrCodeInternalError
*/
virtual
int
HandleCancelScheduledSnapshotTask
(
std
::
shared_ptr
<
SnapshotTaskInfo
>
task
)
=
0
;
};
class
SnapshotCoreImpl
:
public
SnapshotCore
{
...
...
@@ -224,6 +234,9 @@ class SnapshotCoreImpl : public SnapshotCore {
int
HandleCancelUnSchduledSnapshotTask
(
std
::
shared_ptr
<
SnapshotTaskInfo
>
task
)
override
;
int
HandleCancelScheduledSnapshotTask
(
std
::
shared_ptr
<
SnapshotTaskInfo
>
task
)
override
;
private:
/**
* @brief 构建快照文件映射
...
...
This diff is collapsed.
Click to expand it.
src/snapshotcloneserver/snapshot/snapshot_task_manager.cpp
+
1
-
5
View file @
5ae26185
...
...
@@ -114,11 +114,7 @@ int SnapshotTaskManager::CancelTask(const TaskIdType &taskId) {
auto
it
=
taskMap_
.
find
(
taskId
);
if
(
it
!=
taskMap_
.
end
())
{
auto
taskInfo
=
it
->
second
->
GetTaskInfo
();
LockGuard
lockGuard
(
taskInfo
->
GetLockRef
());
if
(
!
taskInfo
->
IsFinish
())
{
taskInfo
->
Cancel
();
return
kErrCodeSuccess
;
}
return
core_
->
HandleCancelScheduledSnapshotTask
(
taskInfo
);
}
return
kErrCodeCannotCancelFinished
;
}
...
...
This diff is collapsed.
Click to expand it.
test/integration/snapshotcloneserver/fake_snapshotclone_meta_store.cpp
+
17
-
0
View file @
5ae26185
...
...
@@ -62,6 +62,23 @@ int FakeSnapshotCloneMetaStore::UpdateSnapshot(const SnapshotInfo &info) {
return
0
;
}
int
FakeSnapshotCloneMetaStore
::
CASSnapshot
(
const
UUID
&
uuid
,
CASFunc
cas
)
{
fiu_return_on
(
"test/integration/snapshotcloneserver/FakeSnapshotCloneMetaStore.UpdateSnapshot"
,
-
1
);
// NOLINT
std
::
lock_guard
<
std
::
mutex
>
guard
(
snapInfos_mutex
);
auto
iter
=
snapInfos_
.
find
(
uuid
);
if
(
iter
==
snapInfos_
.
end
())
{
return
-
1
;
}
auto
info
=
cas
(
&
(
iter
->
second
));
if
(
nullptr
!=
info
)
{
iter
->
second
=
*
info
;
}
return
0
;
}
int
FakeSnapshotCloneMetaStore
::
GetSnapshotInfo
(
const
UUID
&
uuid
,
SnapshotInfo
*
info
)
{
std
::
lock_guard
<
std
::
mutex
>
guard
(
snapInfos_mutex
);
...
...
This diff is collapsed.
Click to expand it.
test/integration/snapshotcloneserver/fake_snapshotclone_meta_store.h
+
1
-
0
View file @
5ae26185
...
...
@@ -37,6 +37,7 @@ class FakeSnapshotCloneMetaStore : public SnapshotCloneMetaStore {
int
AddSnapshot
(
const
SnapshotInfo
&
snapinfo
)
override
;
int
DeleteSnapshot
(
const
UUID
&
uuid
)
override
;
int
UpdateSnapshot
(
const
SnapshotInfo
&
snapinfo
)
override
;
int
CASSnapshot
(
const
UUID
&
uuid
,
CASFunc
cas
)
override
;
int
GetSnapshotInfo
(
const
UUID
&
uuid
,
SnapshotInfo
*
info
)
override
;
int
GetSnapshotList
(
const
std
::
string
&
filename
,
std
::
vector
<
SnapshotInfo
>
*
v
)
override
;
...
...
This diff is collapsed.
Click to expand it.
test/integration/snapshotcloneserver/snapshotcloneserver_concurrent_test.cpp
+
1
-
1
View file @
5ae26185
...
...
@@ -530,7 +530,7 @@ TEST_F(SnapshotCloneServerTest, TestCancelAndMakeSnaphotConcurrent) {
CancelSnapshot
(
testUser1_
,
testFile1_
,
uuid1
);
isCancel
=
true
;
}
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milli
seconds
(
30
00
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
30
));
continue
;
}
else
if
(
info1
.
GetSnapshotInfo
().
GetStatus
()
==
Status
::
done
)
{
success1
=
false
;
...
...
This diff is collapsed.
Click to expand it.
test/snapshotcloneserver/mock_snapshot_server.h
+
4
-
0
View file @
5ae26185
...
...
@@ -79,6 +79,9 @@ class MockSnapshotCore : public SnapshotCore {
MOCK_METHOD1
(
HandleCancelUnSchduledSnapshotTask
,
int
(
std
::
shared_ptr
<
SnapshotTaskInfo
>
task
));
MOCK_METHOD1
(
HandleCancelScheduledSnapshotTask
,
int
(
std
::
shared_ptr
<
SnapshotTaskInfo
>
task
));
};
class
MockSnapshotCloneMetaStore
:
public
SnapshotCloneMetaStore
{
...
...
@@ -86,6 +89,7 @@ class MockSnapshotCloneMetaStore : public SnapshotCloneMetaStore {
MOCK_METHOD1
(
AddSnapshot
,
int
(
const
SnapshotInfo
&
snapinfo
));
MOCK_METHOD1
(
DeleteSnapshot
,
int
(
const
UUID
&
uuid
));
MOCK_METHOD1
(
UpdateSnapshot
,
int
(
const
SnapshotInfo
&
snapinfo
));
MOCK_METHOD2
(
CASSnapshot
,
int
(
const
UUID
&
,
CASFunc
));
MOCK_METHOD2
(
GetSnapshotInfo
,
int
(
const
UUID
&
uuid
,
SnapshotInfo
*
info
));
MOCK_METHOD2
(
GetSnapshotList
,
...
...
This diff is collapsed.
Click to expand it.
test/snapshotcloneserver/test_snapshot_core.cpp
+
53
-
43
View file @
5ae26185
...
...
@@ -394,9 +394,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -613,9 +614,9 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeInternalError
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillOnce
(
Return
(
kErrCodeInternalError
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
core_
->
HandleCreateSnapshotTask
(
task
);
...
...
@@ -655,9 +656,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeInternalError
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeInternalError
));
.
WillOnce
(
Return
(
kErrCodeInternalError
));
core_
->
HandleCreateSnapshotTask
(
task
);
...
...
@@ -698,9 +700,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
client_
,
GetSnapshotSegmentInfo
(
fileName
,
user
,
...
...
@@ -747,9 +750,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -831,9 +835,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -921,9 +926,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -1037,9 +1043,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -1168,9 +1175,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -1306,9 +1314,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -1449,9 +1458,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -1594,9 +1604,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -1742,9 +1753,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -1890,9 +1902,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -2604,9 +2617,8 @@ TEST_F(TestSnapshotCoreImpl, TestHandleCreateSnapshotTaskCancelSuccess) {
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -2775,13 +2787,11 @@ TEST_F(TestSnapshotCoreImpl,
// 此处捕获task,设置cancel
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Invoke
([
task
](
const
SnapshotInfo
&
snapinfo
){
task
->
Cancel
();
return
kErrCodeSuccess
;
}));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Invoke
([
task
](
const
UUID
&
uuid
,
CASFunc
cas
)
{
task
->
Cancel
();
return
kErrCodeSuccess
;
}));
// 进入cancel
EXPECT_CALL
(
*
client_
,
DeleteSnapshot
(
fileName
,
user
,
seqNum
))
...
...
@@ -2830,9 +2840,8 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
2
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
@@ -2938,9 +2947,10 @@ TEST_F(TestSnapshotCoreImpl,
Return
(
LIBCURVE_ERROR
::
OK
)));
EXPECT_CALL
(
*
metaStore_
,
CASSnapshot
(
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
EXPECT_CALL
(
*
metaStore_
,
UpdateSnapshot
(
_
))
.
Times
(
3
)
.
WillRepeatedly
(
Return
(
kErrCodeSuccess
));
.
WillOnce
(
Return
(
kErrCodeSuccess
));
LogicPoolID
lpid1
=
1
;
CopysetID
cpid1
=
1
;
...
...
This diff is collapsed.
Click to expand it.
test/snapshotcloneserver/test_snapshot_service_manager.cpp
+
18
-
0
View file @
5ae26185
...
...
@@ -468,6 +468,15 @@ TEST_F(TestSnapshotServiceManager, TestDeleteSnapshotByCancelSuccess) {
EXPECT_CALL
(
*
core_
,
DeleteSnapshotPre
(
uuid
,
user
,
_
,
_
))
.
WillOnce
(
Return
(
kErrCodeSnapshotCannotDeleteUnfinished
));
// Cancel scheduled snapshot task
auto
callback
=
[](
std
::
shared_ptr
<
SnapshotTaskInfo
>
task
)
{
task
->
Cancel
();
return
kErrCodeSuccess
;
};
EXPECT_CALL
(
*
core_
,
HandleCancelScheduledSnapshotTask
(
_
))
.
WillOnce
(
Invoke
(
callback
));
ret
=
manager_
->
DeleteSnapshot
(
uuid
,
user
,
file
);
ASSERT_EQ
(
kErrCodeSuccess
,
ret
);
...
...
@@ -1081,6 +1090,15 @@ TEST_F(TestSnapshotServiceManager,
EXPECT_CALL
(
*
core_
,
HandleCancelUnSchduledSnapshotTask
(
_
))
.
WillOnce
(
Return
(
kErrCodeSuccess
));
// Cancel scheduled snapshot task
auto
callback
=
[](
std
::
shared_ptr
<
SnapshotTaskInfo
>
task
)
{
task
->
Cancel
();
return
kErrCodeSuccess
;
};
EXPECT_CALL
(
*
core_
,
HandleCancelScheduledSnapshotTask
(
_
))
.
WillOnce
(
Invoke
(
callback
));
int
ret
=
manager_
->
CreateSnapshot
(
file
,
user
,
...
...
This diff is collapsed.
Click to expand it.
test/snapshotcloneserver/test_snapshotclone_meta_store_etcd.cpp
+
110
-
0
View file @
5ae26185
...
...
@@ -256,6 +256,116 @@ TEST_F(TestSnapshotCloneMetaStoreEtcd,
ASSERT_TRUE
(
JudgeSnapshotInfoEqual
(
snapInfo
,
outInfo
));
}
TEST_F
(
TestSnapshotCloneMetaStoreEtcd
,
TestCASSnapshot
)
{
SnapshotInfo
snapInfo
(
"uuid"
,
"user"
,
""
,
""
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
Status
::
pending
);
auto
setUp
=
[
&
]()
{
EXPECT_CALL
(
*
kvStorageClient_
,
Put
(
_
,
_
))
.
WillOnce
(
Return
(
EtcdErrCode
::
EtcdOK
));
ASSERT_EQ
(
metaStore_
->
AddSnapshot
(
snapInfo
),
0
);
};
auto
tearDown
=
[
&
]()
{
ASSERT_EQ
(
metaStore_
->
DeleteSnapshot
(
"uuid"
),
0
);
};
// CASE 1: Etcd put failed -> CASSnapshot failed
{
setUp
();
auto
cas
=
[](
SnapshotInfo
*
snapinfo
)
->
SnapshotInfo
*
{
return
snapinfo
;
};
EXPECT_CALL
(
*
kvStorageClient_
,
Put
(
_
,
_
))
.
WillOnce
(
Return
(
EtcdErrCode
::
EtcdUnknown
));
ASSERT_EQ
(
metaStore_
->
CASSnapshot
(
"uuid"
,
cas
),
-
1
);
tearDown
();
}
// CASE 2: Set snapshot success
{
setUp
();
SnapshotInfo
setInfo
(
"uuid"
,
"user1"
,
""
,
""
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
Status
::
done
);
auto
cas
=
[
&
setInfo
](
SnapshotInfo
*
snapinfo
)
->
SnapshotInfo
*
{
return
&
setInfo
;
};
EXPECT_CALL
(
*
kvStorageClient_
,
Put
(
_
,
_
))
.
WillOnce
(
Return
(
EtcdErrCode
::
EtcdOK
));
ASSERT_EQ
(
metaStore_
->
CASSnapshot
(
"uuid"
,
cas
),
0
);
SnapshotInfo
retInfo
;
ASSERT_EQ
(
metaStore_
->
GetSnapshotInfo
(
"uuid"
,
&
retInfo
),
0
);
ASSERT_TRUE
(
JudgeSnapshotInfoEqual
(
retInfo
,
setInfo
));
tearDown
();
}
// CASE 3: Set snapshot success without origin snapshot
{
auto
cas
=
[
&
snapInfo
](
SnapshotInfo
*
snapinfo
)
->
SnapshotInfo
*
{
return
&
snapInfo
;
};
EXPECT_CALL
(
*
kvStorageClient_
,
Put
(
_
,
_
))
.
WillOnce
(
Return
(
EtcdErrCode
::
EtcdOK
));
ASSERT_EQ
(
metaStore_
->
CASSnapshot
(
"uuid"
,
cas
),
0
);
SnapshotInfo
retInfo
;
ASSERT_EQ
(
metaStore_
->
GetSnapshotInfo
(
"uuid"
,
&
retInfo
),
0
);
ASSERT_TRUE
(
JudgeSnapshotInfoEqual
(
retInfo
,
snapInfo
));
tearDown
();
}
// CASE 4: Not needed to set snapshot
{
setUp
();
auto
cas
=
[](
SnapshotInfo
*
snapinfo
)
->
SnapshotInfo
*
{
return
nullptr
;
};
EXPECT_CALL
(
*
kvStorageClient_
,
Put
(
_
,
_
))
.
Times
(
0
);
ASSERT_EQ
(
metaStore_
->
CASSnapshot
(
"uuid"
,
cas
),
0
);
SnapshotInfo
retInfo
;
ASSERT_EQ
(
metaStore_
->
GetSnapshotInfo
(
"uuid"
,
&
retInfo
),
0
);
ASSERT_TRUE
(
JudgeSnapshotInfoEqual
(
retInfo
,
snapInfo
));
tearDown
();
}
// CASE 5: Set snapshot and keep status
{
setUp
();
SnapshotInfo
setInfo
(
"uuid"
,
"user1"
,
""
,
""
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
Status
::
done
);
auto
cas
=
[
&
setInfo
](
SnapshotInfo
*
snapInfo
)
->
SnapshotInfo
*
{
setInfo
.
SetStatus
(
snapInfo
->
GetStatus
());
return
&
setInfo
;
};
EXPECT_CALL
(
*
kvStorageClient_
,
Put
(
_
,
_
))
.
WillOnce
(
Return
(
EtcdErrCode
::
EtcdOK
));
ASSERT_EQ
(
metaStore_
->
CASSnapshot
(
"uuid"
,
cas
),
0
);
SnapshotInfo
retInfo
;
ASSERT_EQ
(
metaStore_
->
GetSnapshotInfo
(
"uuid"
,
&
retInfo
),
0
);
ASSERT_TRUE
(
JudgeSnapshotInfoEqual
(
retInfo
,
setInfo
));
ASSERT_EQ
(
retInfo
.
GetStatus
(),
Status
::
pending
);
tearDown
();
}
}
TEST_F
(
TestSnapshotCloneMetaStoreEtcd
,
TestGetSnapshotInfoFail
)
{
SnapshotInfo
outInfo
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help