Github user joshelser commented on a diff in the pull request:
https://github.com/apache/accumulo/pull/140#discussion_r75883337
--- Diff:
core/src/main/java/org/apache/accumulo/core/file/rfile/bcfile/codec/CompressorPool.java
---
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.file.rfile.bcfile.codec;
+
+import java.io.IOException;
+
+import org.apache.accumulo.core.conf.AccumuloConfiguration;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.file.rfile.bcfile.Compression.Algorithm;
+import org.apache.commons.pool.impl.GenericKeyedObjectPool;
+import org.apache.hadoop.io.compress.Compressor;
+import org.apache.hadoop.io.compress.Decompressor;
+import org.apache.log4j.Logger;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Compressor factory extension that enables object pooling using Commons
Pool. The design will have a keyed compressor pool and decompressor pool. The
key of
+ * which will be the Algorithm itself.
+ *
+ */
+public class CompressorPool extends CompressorFactory {
+
+ private static final Logger LOG =
Logger.getLogger(CompressorObjectFactory.class);
+
+ /**
+ * Compressor pool.
+ */
+ GenericKeyedObjectPool<Algorithm,Compressor> compressorPool;
+
+ /**
+ * Decompressor pool
+ */
+ GenericKeyedObjectPool<Algorithm,Decompressor> decompressorPool;
+
+ public CompressorPool(AccumuloConfiguration acuConf) {
+
+ super(acuConf);
+
+ compressorPool = new GenericKeyedObjectPool<Algorithm,Compressor>(new
CompressorObjectFactory());
+ // ensure that the pool grows when needed
+
compressorPool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW);
+
+ decompressorPool = new
GenericKeyedObjectPool<Algorithm,Decompressor>(new DecompressorObjectFactory());
+ // ensure that the pool grows when needed.
+
decompressorPool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW);
+
+ // perform the initial update.
+ update(acuConf);
+
+ }
+
+ public void setMaxIdle(final int size) {
+ // check that we are changing the value.
+ // this will avoid synchronization within the pool
+ if (size != compressorPool.getMaxIdle())
+ compressorPool.setMaxIdle(size);
+ if (size != decompressorPool.getMaxIdle())
+ decompressorPool.setMaxIdle(size);
+ }
+
+ @Override
+ public Compressor getCompressor(Algorithm compressionAlgorithm) throws
IOException {
+ Preconditions.checkNotNull(compressionAlgorithm, "Algorithm cannot be
null");
+ try {
+ return compressorPool.borrowObject(compressionAlgorithm);
+ } catch (Exception e) {
--- End diff --
Commons-Pool doesn't give us a named exception to differentiate between the
Pool failing to construct a new instance and some pool operation failing? (your
`catch Exception` clause)
---
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.
---