sodonnel commented on pull request #3168:
URL: https://github.com/apache/ozone/pull/3168#issuecomment-1060562449


   The problem with the current code goes beyond just the threads.
   
   In `KeyInputStream.initialize()` it takes the list of blocks for the key, 
and pre-creates all the stream. There is a comment in the code:
   
   ```
     /**
      * Append another BlockInputStream to the end of the list. Note that the
      * BlockInputStream is only created here and not initialized. The
      * BlockInputStream is initialized when a read operation is performed on
      * the block for the first time.
      */
   ```
   But I don't think that is good - it forces the constructor on the downstream 
objects to know that the constructor should not do anything expensive. In the 
case of the ECReconstructionReader, it allocates the buffers it needs in the 
constructor:
   
   ```
     public ECBlockReconstructedInputStream(ECReplicationConfig repConfig,
         ByteBufferPool byteBufferPool,
         ECBlockReconstructedStripeInputStream stripeReader) {
       this.repConfig = repConfig;
       this.byteBufferPool = byteBufferPool;
       this.stripeReader = stripeReader;
   
       allocateBuffers();
     }
   ```
   
   And the StripeReader allocates the decoder and the thread pool:
   
   ```
     public ECBlockReconstructedStripeInputStream(ECReplicationConfig repConfig,
         OmKeyLocationInfo blockInfo, boolean verifyChecksum,
          XceiverClientFactory xceiverClientFactory, Function<BlockID,
         Pipeline> refreshFunction, BlockInputStreamFactory streamFactory,
         ByteBufferPool byteBufferPool) {
       super(repConfig, blockInfo, verifyChecksum, xceiverClientFactory,
           refreshFunction, streamFactory);
       this.byteBufferPool = byteBufferPool;
       decoder = CodecUtil.createRawDecoderWithFallback(repConfig);
   
       // The EC decoder needs an array data+parity long, with missing or not
       // needed indexes set to null.
       decoderInputBuffers = new ByteBuffer[getRepConfig().getRequiredNodes()];
   
       ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(
           "ec-reader-for-" + blockInfo.getBlockID() + "-TID-%d").build();
       executor = Executors.newFixedThreadPool(repConfig.getData(), 
threadFactory);
     }
   ```
   
   So this means we will have a buffer of EC stripe size allocated for every 
block in the file, and the current threadpool allocated too. Then there is the 
additional problem that KeyInputStream does not close the block it has 
completed reading, but instead keeps it open.
   
   It would be easy to move the expensive parts of creating the EC Streams out 
of the constructor and create them when the first read comes on, but I feel it 
should not have to. We should probably make KeyInputStream create the 
underlying block stream on demand instead, and importantly close it when it is 
done.
   
   For a very large file, even without EC - there is no real point in 
pre-creating all the BlockInputStreams - we may never even read all of the 
keys, so its a waste of resources to create them all just incase.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to