Skip to content
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

client: remove dsn::apps::mutate in client.h #177

Merged
merged 7 commits into from
Sep 11, 2018

Conversation

vagetablechicken
Copy link
Contributor

No description provided.

std::vector<::dsn::apps::mutate> _mu_list;
std::vector<std::pair<int, int>> _ttl_list;
std::vector<mutate> mu_list;
std::vector<std::pair<int, int>> ttl_list;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释key和value都是什么意义

int current_time = ::pegasus::utils::epoch_now();
mutations = _mu_list;
for (auto &pair : _ttl_list) {
int current_time = time(nullptr) - epoch_begin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里还是用::pegasus::utils::epoch_now()吧,不要在include里面定义epoch_begin,避免暴露实现。
mutation的set/del/get_mutations实现体都比较大,可以在client_lib中增加一个cpp文件,把实现放在cpp中间中,这样也能避免client.h引用peagsus_utils头文件。

@@ -0,0 +1,68 @@
#include <pegasus/client.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright?

mutations[pair.first].set_expire_ts_seconds = pair.second + current_time;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

结尾缺少换行

for (int i = 0; i < mutate_list.size(); ++i) {
auto &mu = mutate_list[i];
req.mutate_list[i].operation = (dsn::apps::mutate_operation::type)mu.operation;
req.mutate_list[i].sort_key.assign(mu.sort_key.c_str(), 0, mu.sort_key.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有问题:mutate_list是个局部变量,将其assign给blob时,数据是浅拷贝。在这个异步函数结束的时候,mutate_list被释放,req里面的blob就有可能是野指针。建议这里使用blob::create_from_bytes函数,既避免重复的数据拷贝,又避免野指针。譬如:

req.mutate_list[i].sort_key = blob::create_from_bytes(std::move(mu.sort_key));
req.mutate_list[i].value = blob::create_from_bytes(std::move(mu.value));

mutate_operation operation;
std::string sort_key;
std::string value;
int set_expire_ts_seconds;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加注释: 0 means no ttl

std::string sort_key;
std::string value;
int set_expire_ts_seconds;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加默认构造函数

{
mutate mu;
mu.operation = mutate::mutate_operation::MO_DELETE;
mu.sort_key = sort_key;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mu.sort_key = std::move(sort_key);

{
mutate mu;
mu.operation = mutate::mutate_operation::MO_DELETE;
mu.sort_key = std::move(sort_key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不能用std::move()吧

@qinzuoyan qinzuoyan merged commit 92c1f57 into apache:master Sep 11, 2018
@neverchanje neverchanje added the component/api pegasus client interfaces label Sep 13, 2018
vagetablechicken pushed a commit to vagetablechicken/pegasus that referenced this pull request Sep 28, 2018
*  client: remove dsn::apps::mutate in client.h (apache#177)

* server: incr support reset ttl (apache#178)

* update rdsn (apache#179)

* scripts: build without building rdsn tests (apache#182)

* submodule: use new random APIs of rdsn (apache#183)
neverchanje pushed a commit to neverchanje/pegasus that referenced this pull request Jul 13, 2019


Former-commit-id: 9be860eb902656bce116db8e2d3128aefd56b7fa [formerly 92c1f57]
Former-commit-id: 6a9bb9b3656f89d887d0ef1c285f2168fe39d1c9
cauchy1988 added a commit to cauchy1988/incubator-pegasus that referenced this pull request May 7, 2022
acelyc111 pushed a commit that referenced this pull request Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/api pegasus client interfaces
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants