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 #224: ACCUMULO-4500 ACCUMULO-96 Added summarization
Date Thu, 09 Mar 2017 19:43:24 GMT
Github user joshelser commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/224#discussion_r105244887
  
    --- Diff: test/src/main/java/org/apache/accumulo/test/functional/SummaryIT.java ---
    @@ -0,0 +1,759 @@
    +/*
    + * 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.test.functional;
    +
    +import static java.util.function.Function.identity;
    +import static java.util.stream.Collectors.counting;
    +import static java.util.stream.Collectors.groupingBy;
    +import static org.apache.accumulo.core.client.summary.CountingSummarizer.DELETES_IGNORED_STAT;
    +import static org.apache.accumulo.core.client.summary.CountingSummarizer.EMITTED_STAT;
    +import static org.apache.accumulo.core.client.summary.CountingSummarizer.SEEN_STAT;
    +import static org.apache.accumulo.core.client.summary.CountingSummarizer.TOO_LONG_STAT;
    +import static org.apache.accumulo.core.client.summary.CountingSummarizer.TOO_MANY_STAT;
    +
    +import java.io.IOException;
    +import java.util.Arrays;
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.LongSummaryStatistics;
    +import java.util.Map;
    +import java.util.Map.Entry;
    +import java.util.Set;
    +import java.util.TreeSet;
    +import java.util.regex.PatternSyntaxException;
    +import java.util.stream.Stream;
    +import java.util.stream.StreamSupport;
    +
    +import org.apache.accumulo.core.client.AccumuloException;
    +import org.apache.accumulo.core.client.AccumuloSecurityException;
    +import org.apache.accumulo.core.client.BatchWriter;
    +import org.apache.accumulo.core.client.BatchWriterConfig;
    +import org.apache.accumulo.core.client.Connector;
    +import org.apache.accumulo.core.client.IteratorSetting;
    +import org.apache.accumulo.core.client.MutationsRejectedException;
    +import org.apache.accumulo.core.client.Scanner;
    +import org.apache.accumulo.core.client.TableNotFoundException;
    +import org.apache.accumulo.core.client.TableOfflineException;
    +import org.apache.accumulo.core.client.ZooKeeperInstance;
    +import org.apache.accumulo.core.client.admin.CompactionConfig;
    +import org.apache.accumulo.core.client.admin.CompactionStrategyConfig;
    +import org.apache.accumulo.core.client.admin.NewTableConfiguration;
    +import org.apache.accumulo.core.client.impl.AccumuloServerException;
    +import org.apache.accumulo.core.client.security.SecurityErrorCode;
    +import org.apache.accumulo.core.client.security.tokens.PasswordToken;
    +import org.apache.accumulo.core.client.summary.Summarizer;
    +import org.apache.accumulo.core.client.summary.SummarizerConfiguration;
    +import org.apache.accumulo.core.client.summary.Summary;
    +import org.apache.accumulo.core.client.summary.summarizers.FamilySummarizer;
    +import org.apache.accumulo.core.client.summary.summarizers.VisibilitySummarizer;
    +import org.apache.accumulo.core.data.Key;
    +import org.apache.accumulo.core.data.Mutation;
    +import org.apache.accumulo.core.data.Range;
    +import org.apache.accumulo.core.data.Value;
    +import org.apache.accumulo.core.iterators.Filter;
    +import org.apache.accumulo.core.security.Authorizations;
    +import org.apache.accumulo.core.security.TablePermission;
    +import org.apache.accumulo.fate.util.UtilWaitThread;
    +import org.apache.accumulo.harness.AccumuloClusterHarness;
    +import org.apache.accumulo.tserver.compaction.CompactionPlan;
    +import org.apache.accumulo.tserver.compaction.CompactionStrategy;
    +import org.apache.accumulo.tserver.compaction.MajorCompactionRequest;
    +import org.apache.hadoop.io.Text;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import com.google.common.collect.ImmutableMap;
    +import com.google.common.collect.ImmutableMap.Builder;
    +import com.google.common.collect.ImmutableSet;
    +import com.google.common.collect.Iterables;
    +import com.google.common.collect.Lists;
    +
    +public class SummaryIT extends AccumuloClusterHarness {
    +
    +  private LongSummaryStatistics getTimestampStats(final String table, Connector c) throws
TableNotFoundException {
    +    try (Scanner scanner = c.createScanner(table, Authorizations.EMPTY)) {
    +      Stream<Entry<Key,Value>> stream = StreamSupport.stream(scanner.spliterator(),
false);
    +      LongSummaryStatistics stats = stream.mapToLong(e -> e.getKey().getTimestamp()).summaryStatistics();
    +      return stats;
    +    }
    +  }
    +
    +  private LongSummaryStatistics getTimestampStats(final String table, Connector c, String
startRow, String endRow) throws TableNotFoundException {
    +    try (Scanner scanner = c.createScanner(table, Authorizations.EMPTY)) {
    +      scanner.setRange(new Range(startRow, false, endRow, true));
    +      Stream<Entry<Key,Value>> stream = StreamSupport.stream(scanner.spliterator(),
false);
    +      LongSummaryStatistics stats = stream.mapToLong(e -> e.getKey().getTimestamp()).summaryStatistics();
    +      return stats;
    +    }
    +  }
    +
    +  private void checkSummaries(Collection<Summary> summaries, SummarizerConfiguration
sc, int total, int missing, int extra, Object... kvs) {
    +    Summary summary = Iterables.getOnlyElement(summaries);
    +    Assert.assertEquals("total wrong", total, summary.getFileStatistics().getTotal());
    +    Assert.assertEquals("missing wrong", missing, summary.getFileStatistics().getMissing());
    +    Assert.assertEquals("extra wrong", extra, summary.getFileStatistics().getExtra());
    +    Assert.assertEquals(sc, summary.getSummarizerConfiguration());
    +    Map<String,Long> expected = new HashMap<>();
    +    for (int i = 0; i < kvs.length; i += 2) {
    +      expected.put((String) kvs[i], (Long) kvs[i + 1]);
    +    }
    +    Assert.assertEquals(expected, summary.getStatistics());
    +  }
    +
    +  private void addSplits(final String table, Connector c, String... splits) throws TableNotFoundException,
AccumuloException, AccumuloSecurityException {
    +    c.tableOperations().addSplits(table, new TreeSet<Text>(Lists.transform(Arrays.asList(splits),
Text::new)));
    +  }
    +
    +  @Test
    +  public void basicSummaryTest() throws Exception {
    +    final String table = getUniqueNames(1)[0];
    +    Connector c = getConnector();
    +    NewTableConfiguration ntc = new NewTableConfiguration();
    +    SummarizerConfiguration sc1 = SummarizerConfiguration.builder(BasicSummarizer.class.getName()).build();
    +    ntc.enableSummarization(sc1);
    +    c.tableOperations().create(table, ntc);
    +
    +    BatchWriter bw = writeData(table, c);
    +
    +    Collection<Summary> summaries = c.tableOperations().getSummaries(table).flush(false).retrieve();
    +    Assert.assertEquals(0, summaries.size());
    +
    +    LongSummaryStatistics stats = getTimestampStats(table, c);
    +
    +    summaries = c.tableOperations().getSummaries(table).flush(true).retrieve();
    +    checkSummaries(summaries, sc1, 1, 0, 0, "total", 100_000l, "minStamp", stats.getMin(),
"maxStamp", stats.getMax(), "deletes", 0l);
    +
    +    Mutation m = new Mutation(String.format("r%09x", 999));
    +    m.put("f1", "q1", "999-0");
    +    m.putDelete("f1", "q2");
    +    bw.addMutation(m);
    +    bw.flush();
    +
    +    c.tableOperations().flush(table, null, null, true);
    +
    +    stats = getTimestampStats(table, c);
    +
    +    summaries = c.tableOperations().getSummaries(table).retrieve();
    +
    +    checkSummaries(summaries, sc1, 2, 0, 0, "total", 100_002l, "minStamp", stats.getMin(),
"maxStamp", stats.getMax(), "deletes", 1l);
    +
    +    bw.close();
    +
    +    c.tableOperations().compact(table, new CompactionConfig().setWait(true));
    +
    +    summaries = c.tableOperations().getSummaries(table).retrieve();
    +    checkSummaries(summaries, sc1, 1, 0, 0, "total", 100_000l, "minStamp", stats.getMin(),
"maxStamp", stats.getMax(), "deletes", 0l);
    +
    +    // split tablet into two
    +    String sp1 = String.format("r%09x", 50_000);
    +    addSplits(table, c, sp1);
    +
    +    summaries = c.tableOperations().getSummaries(table).retrieve();
    +
    +    checkSummaries(summaries, sc1, 1, 0, 0, "total", 100_000l, "minStamp", stats.getMin(),
"maxStamp", stats.getMax(), "deletes", 0l);
    +
    +    // compact 2nd tablet
    +    c.tableOperations().compact(table, new CompactionConfig().setStartRow(new Text(sp1)).setWait(true));
    +
    +    summaries = c.tableOperations().getSummaries(table).retrieve();
    +    checkSummaries(summaries, sc1, 2, 0, 1, "total", 113_999l, "minStamp", stats.getMin(),
"maxStamp", stats.getMax(), "deletes", 0l);
    +
    +    // get summaries for first tablet
    +    stats = getTimestampStats(table, c, sp1, null);
    +    summaries = c.tableOperations().getSummaries(table).startRow(sp1).retrieve();
    +    checkSummaries(summaries, sc1, 1, 0, 0, "total", 49_999l, "minStamp", stats.getMin(),
"maxStamp", stats.getMax(), "deletes", 0l);
    +
    +    // compact all tablets and regenerate all summaries
    +    c.tableOperations().compact(table, new CompactionConfig());
    +
    +    summaries = c.tableOperations().getSummaries(table).retrieve();
    +    stats = getTimestampStats(table, c);
    +    checkSummaries(summaries, sc1, 2, 0, 0, "total", 100_000l, "minStamp", stats.getMin(),
"maxStamp", stats.getMax(), "deletes", 0l);
    +
    +    summaries = c.tableOperations().getSummaries(table).startRow(String.format("r%09x",
75_000)).endRow(String.format("r%09x", 80_000)).retrieve();
    +    Summary summary = Iterables.getOnlyElement(summaries);
    +    Assert.assertEquals(1, summary.getFileStatistics().getTotal());
    +    Assert.assertEquals(1, summary.getFileStatistics().getExtra());
    +    long total = summary.getStatistics().get("total");
    +    Assert.assertTrue(total > 0 && total <= 10_000);
    --- End diff --
    
    Nit: list what the total was in the message argument for `assertTrue(String, boolean)`.


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