Skip to content

Commit

Permalink
[#25436] DocDB: Fix GcMemory result
Browse files Browse the repository at this point in the history
Summary:
MemTracker::GcMemory tries to release memory, then returns true if we still cannot consume requested amount of bytes.
There is a bug in logic, that return `false` if we already released enough memory.
It could lead to situation when RPC call or response will be rejected due to lack of memory, while actually we could handle it.

Fixed to returning `true` in this case.
Jira: DB-14673

Test Plan: ./yb_build.sh -n 200 --cxx-test redisserver_redisserver-test --gtest_filter TestRedisService.HugeCommandInline

Reviewers: timur

Reviewed By: timur

Subscribers: ybase

Tags: #jenkins-ready

Differential Revision: https://phorge.dev.yugabyte.com/D40911
  • Loading branch information
spolitov committed Dec 26, 2024
1 parent 3af60d8 commit f14450e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/yb/docdb/redis_operation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1448,8 +1448,9 @@ Status RedisReadOperation::ExecuteHGetAllLikeCommands(ValueEntryType value_type,

RETURN_NOT_OK(GetRedisSubDocument(iterator_.get(), data, /* projection */ nullptr,
SeekFwdSuffices::kFalse));
if (return_array_response)
if (return_array_response) {
response_.set_allocated_array_response(new RedisArrayPB());
}

if (!doc_found) {
response_.set_code(RedisResponsePB::OK);
Expand Down
12 changes: 5 additions & 7 deletions src/yb/util/mem_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -518,12 +518,10 @@ bool MemTracker::TryConsume(int64_t bytes, MemTracker** blocking_mem_tracker) {
if (!TryIncrementBy(bytes, tracker->limit_, &tracker->consumption_, tracker->metrics_)) {
// One of the trackers failed, attempt to GC memory or expand our limit. If that
// succeeds, TryUpdate() again. Bail if either fails.
if (!tracker->GcMemory(tracker->limit_ - bytes) ||
tracker->ExpandLimit(bytes)) {
if (!TryIncrementBy(bytes, tracker->limit_, &tracker->consumption_, tracker->metrics_)) {
break;
}
} else {
if (tracker->GcMemory(tracker->limit_ - bytes)) {
break;
}
if (!TryIncrementBy(bytes, tracker->limit_, &tracker->consumption_, tracker->metrics_)) {
break;
}
}
Expand Down Expand Up @@ -728,7 +726,7 @@ bool MemTracker::GcMemory(int64_t max_consumption) {
if (did_gc) {
current_consumption = GetUpdatedConsumption();
if (current_consumption <= max_consumption) {
return true;
return false;
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/yb/util/mem_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,6 @@ class MemTracker : public std::enable_shared_from_this<MemTracker> {
// Increases consumption of this tracker and its ancestors by 'bytes'.
void Consume(int64_t bytes);

// Try to expand the limit (by asking the resource broker for more memory) by at least
// 'bytes'. Returns false if not possible, true if the request succeeded. May allocate
// more memory than was requested.
// TODO: always returns false for now, not yet implemented.
bool ExpandLimit(int64_t /* unused: bytes */) { return false; }

// Increases consumption of this tracker and its ancestors by 'bytes' only if
// they can all consume 'bytes'. If this brings any of them over, none of them
// are updated.
Expand Down

0 comments on commit f14450e

Please sign in to comment.