Merge branch '1.6' into 1.7

Conflicts:
        core/src/main/java/org/apache/accumulo/core/iterators/Combiner.java


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/f50db38f
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/f50db38f
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/f50db38f

Branch: refs/heads/1.7
Commit: f50db38f7ad71cb22480c457b7c42ab233c41b21
Parents: 38f36e2 7a1d6d9
Author: Keith Turner <ktur...@apache.org>
Authored: Fri Oct 2 11:46:54 2015 -0400
Committer: Keith Turner <ktur...@apache.org>
Committed: Fri Oct 2 11:46:54 2015 -0400

----------------------------------------------------------------------
 .../accumulo/core/iterators/Combiner.java       |  97 ++++++++++-
 .../core/iterators/CombinerTestUtil.java        |  23 +++
 .../iterators/user/BigDecimalCombinerTest.java  |   6 +-
 .../core/iterators/user/CombinerTest.java       | 170 ++++++++++++++++---
 4 files changed, 272 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/f50db38f/core/src/main/java/org/apache/accumulo/core/iterators/Combiner.java
----------------------------------------------------------------------
diff --cc core/src/main/java/org/apache/accumulo/core/iterators/Combiner.java
index 1c2d8b5,091803b..b3cd93b
--- a/core/src/main/java/org/apache/accumulo/core/iterators/Combiner.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/Combiner.java
@@@ -31,10 -34,15 +34,16 @@@ import org.apache.accumulo.core.data.Ke
  import org.apache.accumulo.core.data.PartialKey;
  import org.apache.accumulo.core.data.Range;
  import org.apache.accumulo.core.data.Value;
+ import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
  import org.apache.accumulo.core.iterators.conf.ColumnSet;
  import org.apache.hadoop.io.Text;
 -import org.apache.log4j.Logger;
++import org.slf4j.Logger;
++import org.slf4j.LoggerFactory;
  
+ import com.google.common.annotations.VisibleForTesting;
  import com.google.common.base.Splitter;
+ import com.google.common.cache.Cache;
+ import com.google.common.cache.CacheBuilder;
  import com.google.common.collect.Lists;
  
  /**
@@@ -49,12 -59,21 +60,23 @@@
   * This reduce method will be passed the most recent Key and an iterator over 
the Values for all non-deleted versions of that Key. A combiner will not combine
   * keys that differ by more than the timestamp.
   *
+  * <p>
   * This class and its implementations do not automatically filter out 
unwanted columns from those being combined, thus it is generally recommended to 
use a
   * {@link Combiner} implementation with the {@link 
ScannerBase#fetchColumnFamily(Text)} or {@link ScannerBase#fetchColumn(Text, 
Text)} methods.
+  *
+  * <p>
+  * WARNING : Using deletes with Combiners may not work as intended. See 
{@link #setReduceOnFullCompactionOnly(IteratorSetting, boolean)}
   */
  public abstract class Combiner extends WrappingIterator implements 
OptionDescriber {
 -  static final Logger sawDeleteLog = 
Logger.getLogger(Combiner.class.getName()+".SawDelete");
++
++  static final Logger sawDeleteLog = 
LoggerFactory.getLogger(Combiner.class.getName() + ".SawDelete");
++
    protected static final String COLUMNS_OPTION = "columns";
    protected static final String ALL_OPTION = "all";
+   protected static final String REDUCE_ON_FULL_COMPACTION_ONLY_OPTION = 
"reduceOnFullCompactionOnly";
+ 
+   private boolean isMajorCompaction;
+   private boolean reduceOnFullCompactionOnly;
  
    /**
     * A Java Iterator that iterates over the Values for a given Key from a 
source SortedKeyValueIterator.
@@@ -147,6 -166,27 +169,28 @@@
  
    private Key workKey = new Key();
  
+   @VisibleForTesting
+   static final Cache<String,Boolean> loggedMsgCache = 
CacheBuilder.newBuilder().expireAfterWrite(1, 
TimeUnit.HOURS).maximumSize(10000).build();
+ 
+   private void sawDelete() {
+     if (isMajorCompaction && !reduceOnFullCompactionOnly) {
+       try {
+         loggedMsgCache.get(this.getClass().getName(), new Callable<Boolean>() 
{
+           @Override
+           public Boolean call() throws Exception {
 -            sawDeleteLog.error("Combiner of type " + 
Combiner.this.getClass().getSimpleName()
 -                + " saw a delete during a partial compaction.  This could 
cause undesired results.  See ACCUMULO-2232.  Will not log subsequent 
occurences for at least 1 hour.");
++            sawDeleteLog.error(
++                "Combiner of type {} saw a delete during a partial 
compaction.  This could cause undesired results.  See ACCUMULO-2232.  Will not 
log subsequent "
++                    + "occurences for at least 1 hour.", 
Combiner.this.getClass().getSimpleName());
+             // the value is not used and does not matter
+             return Boolean.TRUE;
+           }
+         });
+       } catch (ExecutionException e) {
+         throw new RuntimeException(e);
+       }
+     }
+   }
+ 
    /**
     * Sets the topKey and topValue based on the top key of the source. If the 
column of the source top key is in the set of combiners, topKey will be the top 
key
     * of the source and topValue will be the result of the reduce method. 
Otherwise, topKey and topValue will be unchanged. (They are always set to null 
before
@@@ -311,4 -373,31 +377,31 @@@
    public static void setCombineAllColumns(IteratorSetting is, boolean 
combineAllColumns) {
      is.addOption(ALL_OPTION, Boolean.toString(combineAllColumns));
    }
+ 
+   /**
+    * Combiners may not work correctly with deletes. Sometimes when Accumulo 
compacts the files in a tablet, it only compacts a subset of the files. If a 
delete
 -   * marker exists in one of the files that is not being compacted, then data 
that should be deleted may be combined. See
 -   * <a 
href="https://issues.apache.org/jira/browse/ACCUMULO-2232";>ACCUMULO-2232</a> 
for more information. For correctness deletes should not be used with
 -   * columns that are combined OR this option should be set to true.
++   * marker exists in one of the files that is not being compacted, then data 
that should be deleted may be combined. See <a
++   * 
href="https://issues.apache.org/jira/browse/ACCUMULO-2232";>ACCUMULO-2232</a> 
for more information. For correctness deletes should not be used with columns
++   * that are combined OR this option should be set to true.
+    *
+    * <p>
+    * When this method is set to true all data is passed through during 
partial major compactions and no reducing is done. Reducing is only done during 
scan and
+    * full major compactions, when deletes can be correctly handled. Only 
reducing on full major compactions may have negative performance implications, 
leaving
+    * lots of work to be done at scan time.
+    *
+    * <p>
+    * When this method is set to false, combiners will log an error if a 
delete is seen during any compaction. This can be suppressed by adjusting 
logging
+    * configuration. Errors will not be logged more than once an hour per 
Combiner, regardless of how many deletes are seen.
+    *
+    * <p>
+    * This method was added in 1.6.4 and 1.7.1. If you want your code to work 
in earlier versions of 1.6 and 1.7 then do not call this method. If not set this
+    * property defaults to false in order to maintain compatibility.
+    *
+    * @since 1.6.4 1.7.1 1.8.0
+    */
+ 
+   public static void setReduceOnFullCompactionOnly(IteratorSetting is, 
boolean reduceOnFullCompactionOnly) {
+     is.addOption(REDUCE_ON_FULL_COMPACTION_ONLY_OPTION, 
Boolean.toString(reduceOnFullCompactionOnly));
+   }
+ 
  }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f50db38f/core/src/test/java/org/apache/accumulo/core/iterators/CombinerTestUtil.java
----------------------------------------------------------------------
diff --cc 
core/src/test/java/org/apache/accumulo/core/iterators/CombinerTestUtil.java
index 0000000,f874173..f9ef933
mode 000000,100644..100644
--- 
a/core/src/test/java/org/apache/accumulo/core/iterators/CombinerTestUtil.java
+++ 
b/core/src/test/java/org/apache/accumulo/core/iterators/CombinerTestUtil.java
@@@ -1,0 -1,23 +1,23 @@@
+ /*
+  * 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.iterators;
+ 
+ public class CombinerTestUtil {
 -  public static void clearLogCache(){
++  public static void clearLogCache() {
+     Combiner.loggedMsgCache.invalidateAll();
+   }
+ }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/f50db38f/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
----------------------------------------------------------------------
diff --cc 
core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
index 26326a5,152e12f..a442534
--- 
a/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
+++ 
b/core/src/test/java/org/apache/accumulo/core/iterators/user/CombinerTest.java
@@@ -790,4 -816,107 +820,106 @@@ public class CombinerTest 
      assertEquals(LongCombiner.safeAdd(Long.MAX_VALUE - 5, 5), Long.MAX_VALUE);
    }
  
+   private TreeMap<Key,Value> readAll(SortedKeyValueIterator<Key,Value> 
combiner) throws Exception {
+     TreeMap<Key,Value> ret = new TreeMap<Key,Value>();
+ 
+     combiner.seek(new Range(), EMPTY_COL_FAMS, false);
+ 
+     while (combiner.hasTop()) {
+       ret.put(new Key(combiner.getTopKey()), new 
Value(combiner.getTopValue()));
+       combiner.next();
+     }
+ 
+     return ret;
+   }
+ 
 -  private void runDeleteHandlingTest(TreeMap<Key,Value> input, 
TreeMap<Key,Value> expected, Boolean rofco, IteratorEnvironment env)
 -      throws Exception {
++  private void runDeleteHandlingTest(TreeMap<Key,Value> input, 
TreeMap<Key,Value> expected, Boolean rofco, IteratorEnvironment env) throws 
Exception {
+     runDeleteHandlingTest(input, expected, rofco, env, null, true);
+   }
+ 
 -  private void runDeleteHandlingTest(TreeMap<Key,Value> input, 
TreeMap<Key,Value> expected, Boolean rofco, IteratorEnvironment env,
 -      String expectedLog) throws Exception {
++  private void runDeleteHandlingTest(TreeMap<Key,Value> input, 
TreeMap<Key,Value> expected, Boolean rofco, IteratorEnvironment env, String 
expectedLog)
++      throws Exception {
+     runDeleteHandlingTest(input, expected, rofco, env, expectedLog, true);
+     if (expectedLog != null) {
+       // run test again... should not see log message again because cache is 
not cleared
+       runDeleteHandlingTest(input, expected, rofco, env, null, false);
+     }
+   }
+ 
 -  private void runDeleteHandlingTest(TreeMap<Key,Value> input, 
TreeMap<Key,Value> expected, Boolean rofco, IteratorEnvironment env,
 -      String expectedLog, boolean clearLogMsgCache) throws Exception {
++  private void runDeleteHandlingTest(TreeMap<Key,Value> input, 
TreeMap<Key,Value> expected, Boolean rofco, IteratorEnvironment env, String 
expectedLog,
++      boolean clearLogMsgCache) throws Exception {
+     boolean deepCopy = expected == null;
+ 
+     if (clearLogMsgCache) {
+       CombinerTestUtil.clearLogCache();
+     }
+ 
+     StringWriter writer = new StringWriter();
+     WriterAppender appender = new WriterAppender(new PatternLayout("%p, 
%m%n"), writer);
+     Logger logger = Logger.getLogger(Combiner.class);
+     boolean additivity = logger.getAdditivity();
+     try {
+       logger.addAppender(appender);
+       logger.setAdditivity(false);
+ 
+       Combiner ai = new SummingCombiner();
+ 
+       IteratorSetting is = new IteratorSetting(1, SummingCombiner.class);
+       SummingCombiner.setEncodingType(is, LongCombiner.StringEncoder.class);
+       Combiner.setColumns(is, Collections.singletonList(new 
IteratorSetting.Column("cf001")));
+       if (rofco != null) {
+         Combiner.setReduceOnFullCompactionOnly(is, rofco);
+       }
+ 
+       ai.init(new SortedMapIterator(input), is.getOptions(), env);
+ 
+       if (deepCopy)
+         assertEquals(expected, readAll(ai.deepCopy(env)));
+       assertEquals(expected, readAll(ai));
+ 
+     } finally {
+       logger.removeAppender(appender);
+       logger.setAdditivity(additivity);
+     }
+ 
+     String logMsgs = writer.toString();
+     if (expectedLog == null) {
+       Assert.assertTrue("Expected 0 length log message, but got : " + 
logMsgs, logMsgs.length() == 0);
+     } else {
+       logMsgs = logMsgs.replace('\n', ' ');
+       Assert.assertTrue("Did not match pattern [" + expectedLog + "] in [" + 
logMsgs + "]", logMsgs.matches(expectedLog));
+     }
+   }
+ 
+   @Test
+   public void testDeleteHandling() throws Exception {
+     Encoder<Long> encoder = LongCombiner.STRING_ENCODER;
+ 
+     TreeMap<Key,Value> input = new TreeMap<Key,Value>();
+ 
+     IteratorEnvironment paritalMajcIe = new 
CombinerIteratorEnvironment(IteratorScope.majc, false);
+     IteratorEnvironment fullMajcIe = new 
CombinerIteratorEnvironment(IteratorScope.majc, true);
+ 
+     // keys that aggregate
+     nkv(input, 1, 1, 1, 1, false, 4l, encoder);
+     nkv(input, 1, 1, 1, 2, true, 0l, encoder);
+     nkv(input, 1, 1, 1, 3, false, 2l, encoder);
+     nkv(input, 1, 1, 1, 4, false, 9l, encoder);
+ 
+     TreeMap<Key,Value> expected = new TreeMap<Key,Value>();
+     nkv(expected, 1, 1, 1, 1, false, 4l, encoder);
+     nkv(expected, 1, 1, 1, 2, true, 0l, encoder);
+     nkv(expected, 1, 1, 1, 4, false, 11l, encoder);
+ 
+     runDeleteHandlingTest(input, input, true, paritalMajcIe);
+     runDeleteHandlingTest(input, expected, true, fullMajcIe);
+     runDeleteHandlingTest(input, expected, true, SCAN_IE);
+ 
+     runDeleteHandlingTest(input, expected, false, fullMajcIe, 
".*ERROR.*ACCUMULO-2232.*");
+     runDeleteHandlingTest(input, expected, false, SCAN_IE);
+ 
+     runDeleteHandlingTest(input, expected, false, paritalMajcIe, 
".*ERROR.*SummingCombiner.*ACCUMULO-2232.*");
+     runDeleteHandlingTest(input, expected, null, paritalMajcIe, 
".*ERROR.*SummingCombiner.*ACCUMULO-2232.*");
+     runDeleteHandlingTest(input, expected, null, fullMajcIe, 
".*ERROR.*SummingCombiner.*ACCUMULO-2232.*");
+   }
  }

Reply via email to