accumulo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From keith-turner <...@git.apache.org>
Subject [GitHub] accumulo pull request #168: ACCUMULO-4501 (work in progress) Very simple imp...
Date Mon, 17 Oct 2016 12:45:49 GMT
Github user keith-turner commented on a diff in the pull request:

    https://github.com/apache/accumulo/pull/168#discussion_r83632592
  
    --- Diff: core/src/main/java/org/apache/accumulo/core/file/rfile/histogram/HashMapVisibilityHistogram.java
---
    @@ -0,0 +1,141 @@
    +/*
    + * 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.histogram;
    +
    +import java.io.DataInput;
    +import java.io.DataOutput;
    +import java.io.IOException;
    +import java.util.AbstractMap;
    +import java.util.HashMap;
    +import java.util.Iterator;
    +import java.util.Map.Entry;
    +import java.util.Objects;
    +import java.util.concurrent.atomic.AtomicLong;
    +
    +import org.apache.accumulo.core.data.Key;
    +import org.apache.hadoop.io.Text;
    +
    +import com.google.common.base.Function;
    +import com.google.common.collect.Iterators;
    +
    +/**
    + * A basic unbounded hash map implementation.
    + */
    +public class HashMapVisibilityHistogram implements VisibilityHistogram {
    +
    +  private HashMap<Text,AtomicLong> histogram;
    +  private ThreadLocal<Text> buffer = new ThreadLocal<Text>() {
    +    @Override public Text initialValue() {
    +      return new Text();
    +    }
    +  };
    +
    +  public HashMapVisibilityHistogram() {
    +    this.histogram = new HashMap<>();
    +  }
    +
    +  @Override
    +  public long increment(Key k) {
    +    final Text t = buffer.get();
    +    Objects.requireNonNull(k.getColumnVisibility(t));
    +    AtomicLong count = histogram.get(t);
    --- End diff --
    
    Is an AtomicLong needed for concurrency reasons?  If not, then could create a simple class
like MutableLong in [MapCounter][1] to avoid volatile.
    
    [1]: https://github.com/apache/accumulo/blob/e900e67425d950bd4c0c5288a6270d7b362ac458/core/src/main/java/org/apache/accumulo/core/util/MapCounter.java


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