本文整理汇总了C++中session::write_cas方法的典型用法代码示例。如果您正苦于以下问题:C++ session::write_cas方法的具体用法?C++ session::write_cas怎么用?C++ session::write_cas使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类session
的用法示例。
在下文中一共展示了session::write_cas方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_write_order_execution
/*
* Multiple writes with same key must be processed in the same order as
* they were initiated by client.
*
* Following test checks this mechanics by calling write_cas() with data containing
* counter that is incremented after every write_cas() and checking that previosly stored
* counter is one unit less than current counter. Also this test writes multiple different
* keys (with repetitions) in different order, thereby modelling real workload case.
*/
static void test_write_order_execution(session &sess)
{
const int num_write_repetitions = 5;
const int num_different_keys = 10;
std::vector<std::pair<key, int>> keys;
for (int i = 0; i < num_different_keys; ++i) {
key id(std::to_string(static_cast<unsigned long long>(i)));
for (int j = 0; j < num_write_repetitions; ++j) {
keys.push_back(std::make_pair(id, i));
}
}
std::unique_ptr<async_write_result[]> results(new async_write_result[keys.size()]);
dnet_id old_csum;
const int num_iterations = 30;
for (int i = 0; i < num_iterations; ++i) {
// every key is associated with counter, which is initialized by zero
std::vector<int> write_counter(num_different_keys, 0);
std::random_shuffle(keys.begin(), keys.end());
for (size_t j = 0; j < keys.size(); ++j) {
// increment counter associated with key identified by key_id
const int key_id = keys[j].second;
const int new_value = write_counter[key_id]++;
if (new_value > 0) {
const int prev_value = new_value - 1;
memset(&old_csum, 0, sizeof(old_csum));
sess.transform(std::to_string(static_cast<unsigned long long>(prev_value)), old_csum);
results[j] = std::move(sess.write_cas(keys[j].first, std::to_string(static_cast<unsigned long long>(new_value)), old_csum, 0));
} else {
// first write
results[j] = std::move(sess.write_data(keys[j].first, std::to_string(static_cast<unsigned long long>(new_value)), 0));
}
}
for (size_t j = 0; j < keys.size(); ++j) {
results[j].wait();
const int err = results[j].error().code();
BOOST_REQUIRE_MESSAGE(err == 0,
"write_cas() failed (err=" + std::to_string(static_cast<unsigned long long>(err)) + "): "
"multiple consecutive writes are executed out-of-order "
"or overlapped. Oplock mechanism of backend's request queue is broken.");
}
}
}