This is an automated email from the ASF dual-hosted git repository.
LuciferYang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gluten.git
The following commit(s) were added to refs/heads/main by this push:
new b1b8f8c334 [GLUTEN-13544][VL] Reset the counted string buffers when
the RSS sort shuffle writer reclaims memory (#13550)
b1b8f8c334 is described below
commit b1b8f8c334943d7914f8f11e4d21d05ed0dbc696
Author: YangJie <[email protected]>
AuthorDate: Thu Nov 26 23:48:46 2026 -0500
[GLUTEN-13544][VL] Reset the counted string buffers when the RSS sort
shuffle writer reclaims memory (#13550)
## What changes are proposed in this pull request?
`VeloxRssSortShuffleWriter::reclaimFixedSize` cleared the buffered batches
and the byte counter but not `stringBuffers_`, the set of string buffers
already counted. After a reclaim, a string buffer that was still alive, or a
new one at a reused address, was skipped as already counted, so the next
batches under-reported their size and the writer evicted later than its
threshold. Reclaim now calls `resetBatches()`, which clears all three, as the
normal eviction path does. `stop()` uses [...]
Fixes #13544.
## How was this patch tested?
Added `calculateBatchesSizeAfterReclaim` to
`VeloxRssSortShuffleWriterTest`. It writes a batch whose string buffer is
shared, reclaims, writes another batch using the same buffer, and checks the
counted bytes. Before this change the second batch was short by the buffer's
capacity.
## Was this patch authored or co-authored using generative AI tooling?
Yes. Generated-by: Claude Opus.
---
cpp/velox/shuffle/VeloxRssSortShuffleWriter.cc | 6 ++----
cpp/velox/shuffle/VeloxRssSortShuffleWriter.h | 5 ++---
cpp/velox/tests/VeloxRssSortShuffleWriterTest.cc | 15 +++++++++++++++
3 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/cpp/velox/shuffle/VeloxRssSortShuffleWriter.cc
b/cpp/velox/shuffle/VeloxRssSortShuffleWriter.cc
index 6a95ac3d23..b8b53e6397 100644
--- a/cpp/velox/shuffle/VeloxRssSortShuffleWriter.cc
+++ b/cpp/velox/shuffle/VeloxRssSortShuffleWriter.cc
@@ -199,8 +199,7 @@ arrow::Status VeloxRssSortShuffleWriter::stop() {
for (auto pid = 0; pid < numPartitions(); ++pid) {
RETURN_NOT_OK(evictRowVector(pid));
}
- batches_.clear();
- currentInputColumnBytes_ = 0;
+ resetBatches();
{
SCOPED_TIMER(cpuWallTimingList_[CpuWallTimingStop]);
setSortState(RssSortState::kSortStop);
@@ -235,9 +234,8 @@ arrow::Status
VeloxRssSortShuffleWriter::reclaimFixedSize(int64_t size, int64_t*
for (auto pid = 0; pid < numPartitions(); ++pid) {
RETURN_NOT_OK(evictRowVector(pid));
}
- batches_.clear();
*actual = currentInputColumnBytes_;
- currentInputColumnBytes_ = 0;
+ resetBatches();
}
return arrow::Status::OK();
}
diff --git a/cpp/velox/shuffle/VeloxRssSortShuffleWriter.h
b/cpp/velox/shuffle/VeloxRssSortShuffleWriter.h
index e2914f2322..bf0331000e 100644
--- a/cpp/velox/shuffle/VeloxRssSortShuffleWriter.h
+++ b/cpp/velox/shuffle/VeloxRssSortShuffleWriter.h
@@ -69,9 +69,6 @@ class VeloxRssSortShuffleWriter final : public
VeloxShuffleWriter {
// Only for test.
uint32_t getInputColumnBytes() const;
- // Public for test.
- void resetBatches();
-
private:
VeloxRssSortShuffleWriter(
uint32_t numPartitions,
@@ -99,6 +96,8 @@ class VeloxRssSortShuffleWriter final : public
VeloxShuffleWriter {
void deduplicateStrBuffer(const facebook::velox::VectorPtr& vector);
+ void resetBatches();
+
int32_t splitBufferSize_;
int64_t sortBufferMaxSize_;
facebook::velox::common::CompressionKind compressionKind_;
diff --git a/cpp/velox/tests/VeloxRssSortShuffleWriterTest.cc
b/cpp/velox/tests/VeloxRssSortShuffleWriterTest.cc
index 129097106c..14880f438b 100644
--- a/cpp/velox/tests/VeloxRssSortShuffleWriterTest.cc
+++ b/cpp/velox/tests/VeloxRssSortShuffleWriterTest.cc
@@ -98,6 +98,21 @@ TEST_F(VeloxRssSortShuffleWriterTest, calculateBatchesSize) {
EXPECT_EQ(expectedSize, shuffleWriter->getInputColumnBytes());
}
+TEST_F(VeloxRssSortShuffleWriterTest, calculateBatchesSizeAfterReclaim) {
+ auto shuffleWriter =
std::dynamic_pointer_cast<VeloxRssSortShuffleWriter>(createShuffleWriter(10));
+
+ auto rowVector1 = makeRowVector({makeSharedStringVector(),
makeSharedStringVector()});
+
ASSERT_NOT_OK(shuffleWriter->write(std::make_shared<VeloxColumnarBatch>(rowVector1),
kMemLimit));
+ int64_t reclaimed = 0;
+ ASSERT_NOT_OK(shuffleWriter->reclaimFixedSize(kMemLimit, &reclaimed));
+ EXPECT_EQ(rowVector1->retainedSize() - strBuffer_->capacity(), reclaimed);
+
+ // strBuffer_ is still alive after the reclaim, so the next batch must count
it again.
+ auto rowVector2 = makeRowVector({makeSharedStringVector(),
makeSharedStringVector()});
+
ASSERT_NOT_OK(shuffleWriter->write(std::make_shared<VeloxColumnarBatch>(rowVector2),
kMemLimit));
+ EXPECT_EQ(rowVector2->retainedSize() - strBuffer_->capacity(),
shuffleWriter->getInputColumnBytes());
+}
+
TEST_F(VeloxRssSortShuffleWriterTest, sharedStringInArray) {
auto shuffleWriter =
std::dynamic_pointer_cast<VeloxRssSortShuffleWriter>(createShuffleWriter(10));
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]