Github user phrocker commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/140#discussion_r77162956
  
    --- Diff: 
core/src/main/java/org/apache/accumulo/core/file/rfile/bcfile/Compression.java 
---
    @@ -497,69 +513,66 @@ public CompressionCodec load(Entry<Algorithm,Integer> 
key) {
         public abstract boolean isSupported();
     
         public Compressor getCompressor() throws IOException {
    -      CompressionCodec codec = getCodec();
    -      if (codec != null) {
    -        Compressor compressor = CodecPool.getCompressor(codec);
    -        if (compressor != null) {
    -          if (compressor.finished()) {
    -            // Somebody returns the compressor to CodecPool but is still 
using
    -            // it.
    -            LOG.warn("Compressor obtained from CodecPool already 
finished()");
    -          } else {
    -            LOG.debug("Got a compressor: " + compressor.hashCode());
    -          }
    -          /**
    -           * Following statement is necessary to get around bugs in 0.18 
where a compressor is referenced after returned back to the codec pool.
    -           */
    -          compressor.reset();
    -        }
    -        return compressor;
    -      }
    -      return null;
    +      return compressorFactory.getCompressor(this);
         }
     
         public void returnCompressor(Compressor compressor) {
    -      if (compressor != null) {
    -        LOG.debug("Return a compressor: " + compressor.hashCode());
    -        CodecPool.returnCompressor(compressor);
    -      }
    +      compressorFactory.releaseCompressor(this, compressor);
         }
     
         public Decompressor getDecompressor() throws IOException {
    -      CompressionCodec codec = getCodec();
    -      if (codec != null) {
    -        Decompressor decompressor = CodecPool.getDecompressor(codec);
    -        if (decompressor != null) {
    -          if (decompressor.finished()) {
    -            // Somebody returns the decompressor to CodecPool but is still 
using
    -            // it.
    -            LOG.warn("Decompressor obtained from CodecPool already 
finished()");
    -          } else {
    -            LOG.debug("Got a decompressor: " + decompressor.hashCode());
    -          }
    -          /**
    -           * Following statement is necessary to get around bugs in 0.18 
where a decompressor is referenced after returned back to the codec pool.
    -           */
    -          decompressor.reset();
    -        }
    -        return decompressor;
    -      }
    -
    -      return null;
    +      return compressorFactory.getDecompressor(this);
         }
     
         public void returnDecompressor(Decompressor decompressor) {
    -      if (decompressor != null) {
    -        LOG.debug("Returned a decompressor: " + decompressor.hashCode());
    -        CodecPool.returnDecompressor(decompressor);
    -      }
    +      compressorFactory.releaseDecompressor(this, decompressor);
         }
     
         public String getName() {
           return compressName;
         }
       }
     
    +  /**
    +   * Default implementation will create new compressors.
    +   */
    +  private static CompressorFactory compressorFactory = new 
CompressorFactory(null);
    +
    +  /**
    +   * Allow the compressor factory to be set within this Instance.
    +   *
    +   * @param compFactory
    +   *          incoming compressor factory to be used by all Algorithms
    +   */
    +  public static synchronized void setCompressionFactory(final 
CompressorFactory compFactory) {
    +    Preconditions.checkNotNull(compFactory, "Compressor Factory cannot be 
null");
    +    if (null != compressorFactory) {
    +      compressorFactory.close();
    +    }
    +
    +    compressorFactory = compFactory;
    --- End diff --
    
    Implementations close compressors if they don't own it. I realize the 
fragility in making sure the release call closes the compressor/decompressor. 
The alternative I imagined would return a status from release that shows us 
whether or not the object was released. in that case Compression would call end 
manually if the factory does not. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to