|
8 | 8 | package org.elasticsearch.common.lucene.store;
|
9 | 9 |
|
10 | 10 | import org.apache.lucene.store.IndexInput;
|
| 11 | +import org.apache.lucene.store.RandomAccessInput; |
11 | 12 | import org.elasticsearch.action.ActionListener;
|
12 | 13 | import org.elasticsearch.action.support.PlainActionFuture;
|
13 | 14 | import org.elasticsearch.common.settings.Settings;
|
@@ -73,16 +74,32 @@ protected byte[] randomReadAndSlice(IndexInput indexInput, int length) throws IO
|
73 | 74 | switch (readStrategy) {
|
74 | 75 | case 0, 1, 2, 3:
|
75 | 76 | if (length - readPos >= Long.BYTES && readStrategy <= 0) {
|
76 |
| - ByteBuffer.wrap(output, readPos, Long.BYTES).order(ByteOrder.LITTLE_ENDIAN).putLong(indexInput.readLong()); |
| 77 | + long read = indexInput.readLong(); |
| 78 | + ByteBuffer.wrap(output, readPos, Long.BYTES).order(ByteOrder.LITTLE_ENDIAN).putLong(read); |
77 | 79 | readPos += Long.BYTES;
|
| 80 | + if (indexInput instanceof RandomAccessInput randomAccessInput) { |
| 81 | + assertEquals(read, randomAccessInput.readLong(indexInput.getFilePointer() - Long.BYTES)); |
| 82 | + } |
78 | 83 | } else if (length - readPos >= Integer.BYTES && readStrategy <= 1) {
|
79 |
| - ByteBuffer.wrap(output, readPos, Integer.BYTES).order(ByteOrder.LITTLE_ENDIAN).putInt(indexInput.readInt()); |
| 84 | + int read = indexInput.readInt(); |
| 85 | + ByteBuffer.wrap(output, readPos, Integer.BYTES).order(ByteOrder.LITTLE_ENDIAN).putInt(read); |
80 | 86 | readPos += Integer.BYTES;
|
| 87 | + if (indexInput instanceof RandomAccessInput randomAccessInput) { |
| 88 | + assertEquals(read, randomAccessInput.readInt(indexInput.getFilePointer() - Integer.BYTES)); |
| 89 | + } |
81 | 90 | } else if (length - readPos >= Short.BYTES && readStrategy <= 2) {
|
82 |
| - ByteBuffer.wrap(output, readPos, Short.BYTES).order(ByteOrder.LITTLE_ENDIAN).putShort(indexInput.readShort()); |
| 91 | + short read = indexInput.readShort(); |
| 92 | + ByteBuffer.wrap(output, readPos, Short.BYTES).order(ByteOrder.LITTLE_ENDIAN).putShort(read); |
83 | 93 | readPos += Short.BYTES;
|
| 94 | + if (indexInput instanceof RandomAccessInput randomAccessInput) { |
| 95 | + assertEquals(read, randomAccessInput.readShort(indexInput.getFilePointer() - Short.BYTES)); |
| 96 | + } |
84 | 97 | } else {
|
85 |
| - output[readPos++] = indexInput.readByte(); |
| 98 | + byte read = indexInput.readByte(); |
| 99 | + output[readPos++] = read; |
| 100 | + if (indexInput instanceof RandomAccessInput randomAccessInput) { |
| 101 | + assertEquals(read, randomAccessInput.readByte(indexInput.getFilePointer() - 1)); |
| 102 | + } |
86 | 103 | }
|
87 | 104 | break;
|
88 | 105 | case 4:
|
|
0 commit comments