-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c-deps: fix an infinite loop in MVCCScan
MVCCScan would previously loop forever if asked to scan more than 2GB of data. The root problem was in the calculation of the next buffer size to use in `chunkedBuffer::put` which was not accounting for an `int` being a signed 32-bit value. Changed the logic in `chunkedBuffer::put` to use a maximum buffer size of 128 MB to avoid hitting this problem and avoid wasting excessive space wasteage if only a tiny bit of additional space is needed. Fixes #32896 Release note (bug fix): Fix an infinite loop in a low-level scanning routine that could be hit in unusual circumstances.
- Loading branch information
1 parent
67e4d98
commit 153fcf3
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2018 The Cockroach Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
// implied. See the License for the specific language governing | ||
// permissions and limitations under the License. | ||
|
||
#include <gtest/gtest.h> | ||
#include "chunked_buffer.h" | ||
|
||
// Verify we can a chunked buffer can hold more than 2GB of data when | ||
// writing in pieces that are smaller than the maximum chunk size (128 | ||
// MB). See #32896. | ||
TEST(ChunkedBuffer, PutSmall) { | ||
const std::string data(1 << 20, '.'); // 1 MB | ||
const int64_t total = 3LL << 30; // 3 GB | ||
cockroach::chunkedBuffer buf; | ||
for (int64_t sum = 0; sum < total; sum += data.size()) { | ||
buf.Put(data, data); | ||
} | ||
} | ||
|
||
// Verify we can a chunked buffer can hold more than 2GB of data when | ||
// writing in pieces that are larger than the maximum chunk size (128 | ||
// MB). See #32896. | ||
TEST(ChunkedBuffer, PutLarge) { | ||
const std::string data(256 << 20, '.'); // 256 MB | ||
const int64_t total = 3LL << 30; // 3 GB | ||
cockroach::chunkedBuffer buf; | ||
for (int64_t sum = 0; sum < total; sum += data.size()) { | ||
buf.Put(data, data); | ||
} | ||
} |