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

curvefs/client: fix read invalid issues of memcache #2865

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions curvefs/src/client/kvclient/memcache_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ class MemCachedClient : public KVClient {
auto res = memcached_set(tcli, key.c_str(), key.length(), value,
value_len, 0, 0);
if (MEMCACHED_SUCCESS == res) {
VLOG(9) << "Set key = " << key << " OK";
VLOG(9) << "Set key: " << key << ", OK";
curve::client::CollectMetrics(&metric_->set, value_len,
butil::cpuwide_time_us() - start);
return true;
}
*errorlog = ResError(res);
memcached_free(tcli);
tcli = nullptr;
LOG(ERROR) << "Set key = " << key << " error = " << *errorlog;
LOG(ERROR) << "Set key: " << key << ", error: " << *errorlog;
metric_->set.eps.count << 1;
return false;
}
Expand All @@ -154,9 +154,17 @@ class MemCachedClient : public KVClient {
if (retCode != nullptr) {
(*retCode) = ue;
}
if (MEMCACHED_SUCCESS == ue && res != nullptr && value &&
value_length >= length) {
VLOG(9) << "Get key = " << key << " OK";

// Sometimes the s3 object size is not known,
// so the default is to download the object in the block size.
if (value_length < length) {
LOG_EVERY_N(WARNING, 100)
<< "Get key: " << key << ", value_length: " << value_length
<< ", length: " << length;
}

if (MEMCACHED_SUCCESS == ue && res != nullptr && value) {
VLOG(9) << "Get key: " << key << ", OK";
memcpy(value, res + offset, length);
free(res);
curve::client::CollectMetrics(&metric_->get, value_length,
Expand All @@ -166,9 +174,9 @@ class MemCachedClient : public KVClient {

*errorlog = ResError(ue);
if (ue != MEMCACHED_NOTFOUND) {
LOG(ERROR) << "Get key = " << key << " error = " << *errorlog
<< ", get_value_len = " << value_length
<< ", expect_value_len = " << length;
LOG(ERROR) << "Get key: " << key << ", error: " << *errorlog
<< ", get_value_len: " << value_length
<< ", expect_value_len: " << length;
free(res);
memcached_free(tcli);
tcli = nullptr;
Expand All @@ -194,7 +202,7 @@ class MemCachedClient : public KVClient {
if (MEMCACHED_SUCCESS == res) {
return true;
}
LOG(ERROR) << "client add " << hostname << " " << port << " error";
LOG(ERROR) << "client add: " << hostname << ", " << port << ", error";
return false;
}

Expand Down