File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
main/java/org/elasticsearch/index/snapshots/blobstore
test/java/org/elasticsearch/index/snapshots/blobstore Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -171,6 +171,10 @@ public void reset() throws IOException {
171171 if (markedSlice < 0 || markedSliceOffset < 0 ) {
172172 throw new IOException ("Mark has not been set" );
173173 }
174+ if (initialized && nextSlice == markedSlice + 1 && currentSliceOffset == markedSliceOffset ) {
175+ // Reset at the marked offset should return immediately without re-opening the slice
176+ return ;
177+ }
174178
175179 nextSlice = markedSlice ;
176180 initialized = true ;
Original file line number Diff line number Diff line change @@ -155,9 +155,10 @@ protected InputStream openSlice(int slice) throws IOException {
155155
156156 // Mark
157157 input .mark (randomNonNegativeInt ());
158+ int slicesOpenedAtMark = streamsOpened .size ();
158159
159160 // Read or skip up to another random point
160- final int moreBytes = randomIntBetween (0 , bytes .length - mark );
161+ int moreBytes = randomIntBetween (0 , bytes .length - mark );
161162 if (moreBytes > 0 ) {
162163 if (randomBoolean ()) {
163164 final var moreBytesRead = new byte [moreBytes ];
@@ -171,11 +172,13 @@ protected InputStream openSlice(int slice) throws IOException {
171172
172173 // Randomly read to EOF
173174 if (randomBoolean ()) {
174- input .readAllBytes ();
175+ moreBytes += input .readAllBytes (). length ;
175176 }
176177
177178 // Reset
178179 input .reset ();
180+ int slicesOpenedAfterReset = streamsOpened .size ();
181+ assert moreBytes > 0 || mark == 0 || slicesOpenedAfterReset == slicesOpenedAtMark : "Reset at mark should not re-open slices" ;
179182
180183 // Read all remaining bytes, which should be the bytes from mark up to the end
181184 final int remainingBytes = bytes .length - mark ;
You can’t perform that action at this time.
0 commit comments