File tree 3 files changed +25
-11
lines changed
main/java/org/elasticsearch/common/io/stream
test/java/org/elasticsearch/common/io/stream
3 files changed +25
-11
lines changed Original file line number Diff line number Diff line change
1
+ pr : 95114
2
+ summary : Fix `RecyclerBytesStreamOutput` corrupting when ending write on page boundary
3
+ area : Network
4
+ type : bug
5
+ issues : []
Original file line number Diff line number Diff line change @@ -144,13 +144,6 @@ public void writeWithSizePrefix(Writeable writeable) throws IOException {
144
144
}
145
145
}
146
146
147
- public void reset () {
148
- Releasables .close (pages );
149
- pages .clear ();
150
- pageIndex = -1 ;
151
- currentPageOffset = pageSize ;
152
- }
153
-
154
147
@ Override
155
148
public void flush () {
156
149
// nothing to do
@@ -235,11 +228,11 @@ private void ensureCapacityFromPosition(long newPosition) {
235
228
assert pageSize == newPage .v ().length ;
236
229
pages .add (newPage );
237
230
// We are at the end of the current page, increment page index
238
- if (currentPageOffset == pageSize ) {
239
- pageIndex ++;
240
- currentPageOffset = 0 ;
241
- }
242
231
currentCapacity += pageSize ;
243
232
}
233
+ if (currentPageOffset == pageSize ) {
234
+ pageIndex ++;
235
+ currentPageOffset = 0 ;
236
+ }
244
237
}
245
238
}
Original file line number Diff line number Diff line change @@ -712,6 +712,22 @@ public void testReadWriteGeoPoint() throws IOException {
712
712
}
713
713
}
714
714
715
+ public void testWriteLongToCompletePage () throws IOException {
716
+ try (RecyclerBytesStreamOutput out = new RecyclerBytesStreamOutput (recycler )) {
717
+ out .seek (PageCacheRecycler .BYTE_PAGE_SIZE + 1 );
718
+ int longPos = PageCacheRecycler .BYTE_PAGE_SIZE - Long .BYTES ;
719
+ out .seek (longPos );
720
+ long longValue = randomLong ();
721
+ out .writeLong (longValue );
722
+ byte byteValue = randomByte ();
723
+ out .writeByte (byteValue );
724
+ var input = out .bytes ().streamInput ();
725
+ assertEquals (longPos , input .skip (longPos ));
726
+ assertEquals (longValue , input .readLong ());
727
+ assertEquals (byteValue , input .readByte ());
728
+ }
729
+ }
730
+
715
731
private static class TestWriteable implements Writeable {
716
732
717
733
private boolean value ;
You can’t perform that action at this time.
0 commit comments