You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2019/07/15 22:07:52 UTC

[GitHub] [accumulo] keith-turner commented on a change in pull request #1271: Fix #483

keith-turner commented on a change in pull request #1271: Fix #483
URL: https://github.com/apache/accumulo/pull/1271#discussion_r303646522
 
 

 ##########
 File path: core/src/main/java/org/apache/accumulo/core/file/rfile/bcfile/Compression.java
 ##########
 @@ -677,57 +569,204 @@ public Decompressor getDecompressor() {
         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()");
+            // 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());
+            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.
-           */
+          // The following statement is necessary to get around bugs in 0.18 where a decompressor is
+          // referenced after
+          // it's returned back to the codec pool.
           decompressor.reset();
         }
         return decompressor;
       }
-
       return null;
     }
 
-    public void returnDecompressor(Decompressor decompressor) {
+    /**
+     * Returns the given {@link Decompressor} to the codec cache if it is not null.
+     *
+     * @param decompressor
+     *          the decompressor to return
+     */
+    public void returnDecompressor(final Decompressor decompressor) {
       if (decompressor != null) {
-        log.debug("Returned a decompressor: {}", decompressor.hashCode());
+        LOG.debug("Returned a decompressor: {}", decompressor.hashCode());
         CodecPool.returnDecompressor(decompressor);
       }
     }
 
+    /**
+     * Returns the name of the compression algorithm.
+     *
+     * @return the name
+     */
     public String getName() {
-      return compressName;
+      return name;
     }
-  }
 
-  static Algorithm getCompressionAlgorithmByName(String compressName) {
-    Algorithm[] algos = Algorithm.class.getEnumConstants();
+    /**
+     * Initializes and returns a new codec with the specified buffer size if and only if the
+     * specified {@link AtomicBoolean} has a value of false, or returns the specified original coded
+     * otherwise.
+     *
+     * @param checked
+     *          whether or not the codec has already been checked
+     * @param bufferSize
+     *          the default buffer size for the new coded
+     * @param originalCodec
+     *          the original codec
+     * @return a codec
+     */
+    CompressionCodec initCodec(final AtomicBoolean checked, final int bufferSize,
+        final CompressionCodec originalCodec) {
+      if (!checked.get()) {
+        checked.set(true);
+        return createNewCodec(bufferSize);
+      }
+      return originalCodec;
+    }
 
-    for (Algorithm a : algos) {
-      if (a.getName().equals(compressName)) {
-        return a;
+    /**
+     * Returns a new {@link CompressionCodec} of the specified type, or the default type if no
+     * primary type is specified. If the specified buffer size is greater than 0, the specified
+     * buffer size configuration option will be updated in the codec's configuration with the buffer
+     * size.
+     *
+     * @param codecClazz
+     *          the codec type to initialize and return
+     * @param defaultClazz
+     *          the default codec type to return if codecClazz is null
+     * @param bufferSize
+     *          the buffer size to use (if greater than 0)
+     * @param bufferSizeConfigOpt
+     *          the configuration opt for the buffer size
+     * @return the initialized {@link CompressionCodec}, or null if the codec type was not found
+     */
+    CompressionCodec createNewCodec(final String codecClazz, final String defaultClazz,
+        final int bufferSize, final String bufferSizeConfigOpt) {
+      String extClazz = (conf.get(codecClazz) == null ? System.getProperty(codecClazz) : null);
+      String clazz = (extClazz != null) ? extClazz : defaultClazz;
+      try {
+        LOG.info("Trying to load codec class: {}", clazz);
 
 Review comment:
   Some of the log messages used to mention that it was loading for snappy or gz.  Could possibly include the prop name in the log message as a way to preserve this information.
   
   ```java
   LOG.info("Trying to load codec class {} for {}", clazz, codecClazz);
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services