accumulo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From keith-turner <...@git.apache.org>
Subject [GitHub] accumulo pull request #140: ACCUMULO-4419: Change how compression delegation...
Date Tue, 30 Aug 2016 21:47:59 GMT
Github user keith-turner commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/140#discussion_r76885971
  
    --- 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 --
    
    I was trying to figure out how the following situation will work out by following the
code.  But I got lost and decided to just ask.
    
     1. Thread 1 gets decompressor D1 from compression factory F1
     1. Thread 2 sets the compression factory to F2
     1. Thread returns its decompressor D1. Does it go to F1 or F2?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message