accumulo-dev mailing list archives

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

    https://github.com/apache/accumulo/pull/140#discussion_r75886697
  
    --- 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)
{
    --- End diff --
    
    With the `AtomicReference`, we could remove the synchronization and just close the previous
value we get from the `getAndSet(V)` method.


---
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