1919package org .apache .hadoop .hdds .scm .storage ;
2020
2121import com .google .common .annotations .VisibleForTesting ;
22- <<<<<<< HEAD
23- import com .google .common .base .Preconditions ;
24- import org .apache .hadoop .hdds .protocol .DatanodeDetails ;
25- import org .apache .hadoop .hdds .scm .container .common .helpers
26- .StorageContainerException ;
27- import org .apache .hadoop .ozone .common .Checksum ;
28- import org .apache .hadoop .ozone .common .ChecksumData ;
29- import org .apache .hadoop .ozone .common .OzoneChecksumException ;
30- import org .apache .ratis .thirdparty .com .google .protobuf .ByteString ;
31- =======
22+
3223import org .apache .hadoop .hdds .protocol .proto .HddsProtos ;
3324import org .apache .hadoop .hdds .scm .pipeline .Pipeline ;
3425import org .apache .hadoop .hdds .security .token .OzoneBlockTokenIdentifier ;
3526import org .apache .hadoop .security .UserGroupInformation ;
3627import org .apache .hadoop .security .token .Token ;
37- >>>>>>> Partial Chunk reads
3828import org .apache .hadoop .fs .Seekable ;
3929import org .apache .hadoop .hdds .scm .XceiverClientManager ;
4030import org .apache .hadoop .hdds .scm .XceiverClientSpi ;
4131import org .apache .hadoop .hdds .protocol .datanode .proto .ContainerProtos .ChunkInfo ;
42- <<<<<<< HEAD
43- import org .apache .hadoop .hdds .protocol .datanode .proto .ContainerProtos
44- .ReadChunkResponseProto ;
45- import org .apache .hadoop .hdds .protocol .datanode .proto .ContainerProtos .
46- ContainerCommandResponseProto ;
47- import org .apache .hadoop .hdds .protocol .datanode .proto .ContainerProtos .
48- ContainerCommandRequestProto ;
4932import org .apache .hadoop .hdds .client .BlockID ;
50- =======
5133import org .apache .hadoop .hdds .protocol .datanode .proto .ContainerProtos .DatanodeBlockID ;
5234import org .apache .hadoop .hdds .protocol .datanode .proto .ContainerProtos .GetBlockResponseProto ;
53- import org .apache .hadoop .hdds .client .BlockID ;
54- import org .apache .ratis .util .Preconditions ;
5535import org .slf4j .Logger ;
5636import org .slf4j .LoggerFactory ;
5737
58- >>>>>>> Partial Chunk reads
5938import java .io .EOFException ;
6039import java .io .IOException ;
6140import java .io .InputStream ;
6241import java .nio .ByteBuffer ;
42+ import java .util .ArrayList ;
6343import java .util .Arrays ;
6444import java .util .List ;
6545
@@ -103,18 +83,6 @@ public class BlockInputStream extends InputStream implements Seekable {
10383 // Index of the chunkStream corresponding to the current position of the
10484 // BlockInputStream i.e offset of the data to be read next from this block
10585 private int chunkIndex ;
106- <<<<<<< HEAD
107- // ChunkIndexOfCurrentBuffer points to the index of chunk read into the
108- // buffers or index of the last chunk in the buffers. It is updated only
109- // when a new chunk is read from container into the buffers.
110- private int chunkIndexOfCurrentBuffer ;
111- private long [] chunkOffset ;
112- private List <ByteBuffer > buffers ;
113- private int bufferIndex ;
114- private long bufferPosition ;
115- private boolean verifyChecksum ;
116- =======
117- >>>>>>> Partial Chunk reads
11886
11987 // Position of the BlockInputStream is maintainted by this variable till
12088 // the stream is initialized. This position is w.r.t to the block only and
@@ -241,37 +209,13 @@ public synchronized int read(byte[] b, int off, int len) throws IOException {
241209 if (off < 0 || len < 0 || len > b .length - off ) {
242210 throw new IndexOutOfBoundsException ();
243211 }
244- <<<<<<< HEAD
245- // ChunkIndex is the last chunk in the stream. Check if this chunk has
246- // been read from container or not. Return true if chunkIndex has not
247- // been read yet and false otherwise.
248- return chunkIndexOfCurrentBuffer != chunkIndex ;
249- }
250-
251- /**
252- * Attempts to read the chunk at the specified offset in the chunk list. If
253- * successful, then the data of the read chunk is saved so that its bytes can
254- * be returned from subsequent read calls.
255- *
256- * @throws IOException if there is an I/O error while performing the call
257- */
258- private synchronized void readChunkFromContainer () throws IOException {
259- // Read the chunk at chunkIndex
260- final ChunkInfo chunkInfo = chunks .get (chunkIndex );
261- ByteString byteString ;
262- byteString = readChunk (chunkInfo );
263- buffers = byteString .asReadOnlyByteBufferList ();
264- bufferIndex = 0 ;
265- chunkIndexOfCurrentBuffer = chunkIndex ;
266- =======
267212 if (len == 0 ) {
268213 return 0 ;
269214 }
270215
271216 if (!initialized ) {
272217 initialize ();
273218 }
274- >>>>>>> Partial Chunk reads
275219
276220 checkOpen ();
277221 int totalReadLen = 0 ;
@@ -284,26 +228,6 @@ private synchronized void readChunkFromContainer() throws IOException {
284228 return totalReadLen == 0 ? EOF : totalReadLen ;
285229 }
286230
287- <<<<<<< HEAD
288- /**
289- * Send RPC call to get the chunk from the container.
290- */
291- @ VisibleForTesting
292- protected ByteString readChunk (final ChunkInfo chunkInfo )
293- throws IOException {
294- ReadChunkResponseProto readChunkResponse ;
295- try {
296- List <CheckedBiFunction > validators =
297- ContainerProtocolCalls .getValidatorList ();
298- validators .add (validator );
299- readChunkResponse = ContainerProtocolCalls
300- .readChunk (xceiverClient , chunkInfo , blockID , traceID , validators );
301- } catch (IOException e ) {
302- if (e instanceof StorageContainerException ) {
303- throw e ;
304- }
305- throw new IOException ("Unexpected OzoneException: " + e .toString (), e );
306- =======
307231 // Get the current chunkStream and read data from it
308232 ChunkInputStream current = chunkStreams .get (chunkIndex );
309233 int numBytesToRead = Math .min (len , (int )current .getRemaining ());
@@ -323,33 +247,10 @@ protected ByteString readChunk(final ChunkInfo chunkInfo)
323247 ((chunkIndex + 1 ) < chunkStreams .size ())) {
324248 chunkIndex += 1 ;
325249 }
326- >>>>>>> Partial Chunk reads
327250 }
328251 return totalReadLen ;
329252 }
330253
331- <<<<<<< HEAD
332- private CheckedBiFunction <ContainerCommandRequestProto ,
333- ContainerCommandResponseProto , IOException > validator =
334- (request , response ) -> {
335- ReadChunkResponseProto readChunkResponse = response .getReadChunk ();
336- final ChunkInfo chunkInfo = readChunkResponse .getChunkData ();
337- ByteString byteString = readChunkResponse .getData ();
338- if (byteString .size () != chunkInfo .getLen ()) {
339- // Bytes read from chunk should be equal to chunk size.
340- throw new OzoneChecksumException (String
341- .format ("Inconsistent read for chunk=%s len=%d bytesRead=%d" ,
342- chunkInfo .getChunkName (), chunkInfo .getLen (),
343- byteString .size ()));
344- }
345- ChecksumData checksumData =
346- ChecksumData .getFromProtoBuf (chunkInfo .getChecksumData ());
347- if (verifyChecksum ) {
348- Checksum .verifyChecksum (byteString , checksumData );
349- }
350- };
351-
352- =======
353254 /**
354255 * Seeks the BlockInputStream to the specified position. If the stream is
355256 * not initialized, save the seeked position via blockPosition. Otherwise,
@@ -366,7 +267,6 @@ protected ByteString readChunk(final ChunkInfo chunkInfo)
366267 * 2. chunkStream[2] will be seeked to position 10
367268 * (= 90 - chunkOffset[2] (= 80)).
368269 */
369- >>>>>>> Partial Chunk reads
370270 @ Override
371271 public synchronized void seek (long pos ) throws IOException {
372272 if (!initialized ) {
@@ -386,7 +286,7 @@ public synchronized void seek(long pos) throws IOException {
386286 throw new EOFException (
387287 "EOF encountered at pos: " + pos + " for block: " + blockID );
388288 }
389- Preconditions . assertTrue ( chunkIndex >= 0 );
289+
390290 if (chunkIndex >= chunkStreams .size ()) {
391291 chunkIndex = Arrays .binarySearch (chunkOffsets , pos );
392292 } else if (pos < chunkOffsets [chunkIndex ]) {
0 commit comments