-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
server: add fault injection in write path #117
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a35a4a9
pegasus_server: refine write process
qinzuoyan e56c031
smallfix
qinzuoyan 1450243
smallfix
qinzuoyan bdc2a05
smallfix
qinzuoyan 99cca7e
further refinement
14832bb
Merge branch 'master' of https://github.com/XiaoMi/pegasus
02dacfe
add test for fail_point
bccecb1
Merge branch 'master' of https://github.com/XiaoMi/pegasus
50abba9
Merge branch 'master' of https://github.com/XiaoMi/pegasus
cd9d9e0
add pegasus_server_write_test
ece4812
fix rdsn
815b619
Merge branch 'master' of https://github.com/XiaoMi/pegasus
3e1f8ef
fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule rdsn
updated
3 files
+10 −2 | include/dsn/cpp/rpc_holder.h | |
+2 −0 | include/dsn/utility/defer.h | |
+21 −0 | src/core/tests/rpc_holder_test.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright (c) 2017, Xiaomi, Inc. All rights reserved. | ||
// This source code is licensed under the Apache License Version 2.0, which | ||
// can be found in the LICENSE file in the root directory of this source tree. | ||
|
||
#include "pegasus_server_test_base.h" | ||
#include "message_utils.h" | ||
#include "server/pegasus_server_write.h" | ||
#include "server/pegasus_write_service_impl.h" | ||
#include "base/pegasus_key_schema.h" | ||
|
||
#include <dsn/utility/fail_point.h> | ||
#include <dsn/utility/defer.h> | ||
|
||
namespace pegasus { | ||
namespace server { | ||
|
||
class pegasus_server_write_test : public pegasus_server_test_base | ||
{ | ||
std::unique_ptr<pegasus_server_write> _server_write; | ||
|
||
public: | ||
pegasus_server_write_test() : pegasus_server_test_base() | ||
{ | ||
_server_write = dsn::make_unique<pegasus_server_write>(_server.get(), true); | ||
} | ||
|
||
void test_batch_writes() | ||
{ | ||
dsn::fail::setup(); | ||
|
||
dsn::fail::cfg("db_write_batch_put", "10%return()"); | ||
dsn::fail::cfg("db_write_batch_remove", "10%return()"); | ||
dsn::fail::cfg("db_write", "10%return()"); | ||
|
||
for (int decree = 1; decree <= 1000; decree++) { | ||
RPC_MOCKING(put_rpc) RPC_MOCKING(remove_rpc) | ||
{ | ||
dsn::blob key; | ||
pegasus_generate_key(key, std::string("hash"), std::string("sort")); | ||
dsn::apps::update_request req; | ||
req.key = key; | ||
req.value.assign("value", 0, 5); | ||
|
||
int put_rpc_cnt = dsn_random32(1, 10); | ||
int remove_rpc_cnt = dsn_random32(1, 10); | ||
int total_rpc_cnt = put_rpc_cnt + remove_rpc_cnt; | ||
auto writes = new dsn_message_t[total_rpc_cnt]; | ||
for (int i = 0; i < put_rpc_cnt; i++) { | ||
writes[i] = pegasus::create_put_request(req); | ||
} | ||
for (int i = put_rpc_cnt; i < total_rpc_cnt; i++) { | ||
writes[i] = pegasus::create_remove_request(key); | ||
} | ||
auto cleanup = dsn::defer([=]() { | ||
for (int i = 0; i < total_rpc_cnt; i++) { | ||
dsn_msg_release_ref(writes[i]); | ||
} | ||
delete writes; | ||
}); | ||
|
||
int err = | ||
_server_write->on_batched_write_requests(writes, total_rpc_cnt, decree, 0); | ||
switch (err) { | ||
case FAIL_DB_WRITE_BATCH_PUT: | ||
case FAIL_DB_WRITE_BATCH_DELETE: | ||
case FAIL_DB_WRITE: | ||
case 0: | ||
break; | ||
default: | ||
ASSERT_TRUE(false) << "unacceptable error: " << err; | ||
} | ||
|
||
// make sure everything is cleanup after batch write. | ||
ASSERT_TRUE(_server_write->_put_rpc_batch.empty()); | ||
ASSERT_TRUE(_server_write->_remove_rpc_batch.empty()); | ||
ASSERT_TRUE(_server_write->_write_svc->_batch_qps_perfcounters.empty()); | ||
ASSERT_TRUE(_server_write->_write_svc->_batch_latency_perfcounters.empty()); | ||
ASSERT_EQ(_server_write->_write_svc->_batch_start_time, 0); | ||
ASSERT_EQ(_server_write->_write_svc->_impl->_batch.Count(), 0); | ||
ASSERT_EQ(_server_write->_write_svc->_impl->_update_responses.size(), 0); | ||
|
||
ASSERT_EQ(put_rpc::mail_box().size(), put_rpc_cnt); | ||
ASSERT_EQ(remove_rpc::mail_box().size(), remove_rpc_cnt); | ||
for (auto &rpc : put_rpc::mail_box()) { | ||
verify_response(rpc.response(), err, decree); | ||
} | ||
for (auto &rpc : remove_rpc::mail_box()) { | ||
verify_response(rpc.response(), err, decree); | ||
} | ||
} | ||
} | ||
|
||
dsn::fail::teardown(); | ||
} | ||
|
||
void verify_response(const dsn::apps::update_response &response, int err, int64_t decree) | ||
{ | ||
ASSERT_EQ(response.error, err); | ||
ASSERT_EQ(response.app_id, _gpid.get_app_id()); | ||
ASSERT_EQ(response.partition_index, _gpid.get_partition_index()); | ||
ASSERT_EQ(response.decree, decree); | ||
ASSERT_EQ(response.server, _server_write->_write_svc->_impl->_primary_address); | ||
} | ||
}; | ||
|
||
TEST_F(pegasus_server_write_test, batch_writes) { test_batch_writes(); } | ||
|
||
} // namespace server | ||
} // namespace pegasus | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add new endline at end