Skip to content

Commit 3510a93

Browse files
committed
[common] Boundary case of Write buffer that throw IndexOutOfBoundsException
1 parent 04291ff commit 3510a93

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

fluss-common/src/main/java/com/alibaba/fluss/record/ChangeTypeVectorWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public ChangeTypeVectorWriter(MemorySegment segment, int startPosition) {
3636
}
3737

3838
public void writeChangeType(ChangeType changeType) {
39-
if (recordsCount > capacity) {
39+
if (recordsCount >= capacity) {
4040
// TODO: support AbstractPagedOutputView to have extendable capacity
4141
throw new IllegalStateException("The change type vector is full.");
4242
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2025 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.alibaba.fluss.record;
18+
19+
import com.alibaba.fluss.memory.MemorySegment;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
24+
25+
/** Tests for {@link ChangeTypeVectorWriter}. */
26+
public class ChangeTypeVectorWriterTest {
27+
28+
@Test
29+
public void testReproduceOriginalIndexOutOfBoundsExceptionScenario() {
30+
int segmentSize = 131072; // 128KB
31+
MemorySegment segment = MemorySegment.allocateHeapMemory(segmentSize);
32+
33+
// Create a ChangeTypeVectorWriter that uses the entire segment
34+
ChangeTypeVectorWriter writer = new ChangeTypeVectorWriter(segment, 0);
35+
36+
// Write records up to capacity
37+
for (int i = 0; i < segmentSize; i++) {
38+
writer.writeChangeType(ChangeType.INSERT);
39+
}
40+
41+
// This should now throw IllegalStateException instead of IndexOutOfBoundsException
42+
assertThatThrownBy(() -> writer.writeChangeType(ChangeType.INSERT))
43+
.isInstanceOf(IllegalStateException.class)
44+
.hasMessage("The change type vector is full.");
45+
}
46+
}

0 commit comments

Comments
 (0)