-
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
client: remove dsn::apps::mutate in client.h #177
Conversation
src/include/pegasus/client.h
Outdated
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; |
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.
注释key和value都是什么意义
src/include/pegasus/client.h
Outdated
int current_time = ::pegasus::utils::epoch_now(); | ||
mutations = _mu_list; | ||
for (auto &pair : _ttl_list) { | ||
int current_time = time(nullptr) - epoch_begin; |
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.
这里还是用::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> |
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.
copyright?
mutations[pair.first].set_expire_ts_seconds = pair.second + current_time; | ||
} | ||
} | ||
} |
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.
结尾缺少换行
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()); |
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.
这里有问题: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));
src/include/pegasus/client.h
Outdated
mutate_operation operation; | ||
std::string sort_key; | ||
std::string value; | ||
int set_expire_ts_seconds; |
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.
加注释: 0 means no ttl
src/include/pegasus/client.h
Outdated
std::string sort_key; | ||
std::string value; | ||
int set_expire_ts_seconds; | ||
}; |
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.
加默认构造函数
src/client_lib/mutation.cpp
Outdated
{ | ||
mutate mu; | ||
mu.operation = mutate::mutate_operation::MO_DELETE; | ||
mu.sort_key = sort_key; |
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.
mu.sort_key = std::move(sort_key);
src/client_lib/mutation.cpp
Outdated
{ | ||
mutate mu; | ||
mu.operation = mutate::mutate_operation::MO_DELETE; | ||
mu.sort_key = std::move(sort_key); |
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.
这里不能用std::move()吧
* 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)
Former-commit-id: 9be860eb902656bce116db8e2d3128aefd56b7fa [formerly 92c1f57] Former-commit-id: 6a9bb9b3656f89d887d0ef1c285f2168fe39d1c9
No description provided.