Skip to content

Commit

Permalink
curvefs/client: fix read invalid issues of memcache
Browse files Browse the repository at this point in the history
  • Loading branch information
wuhongsong committed Nov 6, 2023
1 parent 1867323 commit 6b6f29c
Showing 1 changed file with 17 additions and 9 deletions.
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 available,
// 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;
memcached_free(tcli);
tcli = nullptr;
}
Expand All @@ -193,7 +201,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

0 comments on commit 6b6f29c

Please sign in to comment.