accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [accumulo] branch master updated: Add missing LRUMap generic parameters (#1156)
Date Thu, 09 May 2019 21:24:35 GMT
This is an automated email from the ASF dual-hosted git repository.

ctubbsii pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git


The following commit(s) were added to refs/heads/master by this push:
     new 5e072bb  Add missing LRUMap generic parameters (#1156)
5e072bb is described below

commit 5e072bb2a1820eaddfd1da860c6feb32ac8f1726
Author: Christopher Tubbs <ctubbsii@apache.org>
AuthorDate: Thu May 9 17:24:30 2019 -0400

    Add missing LRUMap generic parameters (#1156)
    
    Since the update to commons-collections 4.3 in #1110, the LRUMap now
    accepts generic parameter types. This change adds those that were
    missing, which gives us better type safety when using these maps.
---
 .../apache/accumulo/core/client/rfile/RFileWriter.java   |  6 +++---
 .../accumulo/core/clientImpl/ConditionalWriterImpl.java  |  3 +--
 .../accumulo/core/iterators/system/VisibilityFilter.java |  6 +++---
 .../core/iterators/user/TransformingIterator.java        | 16 ++++++++--------
 .../accumulo/core/iterators/user/VisibilityFilter.java   |  8 ++++----
 .../apache/accumulo/server/problems/ProblemReports.java  |  2 +-
 .../java/org/apache/accumulo/tserver/TabletServer.java   |  3 +--
 .../apache/accumulo/tserver/log/RecoveryLogReader.java   | 12 +++++-------
 .../apache/accumulo/shell/commands/TablesCommand.java    |  3 +--
 9 files changed, 27 insertions(+), 32 deletions(-)

diff --git a/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileWriter.java b/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileWriter.java
index e531722..1b9d8ab 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileWriter.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/rfile/RFileWriter.java
@@ -89,13 +89,13 @@ import com.google.common.base.Preconditions;
 public class RFileWriter implements AutoCloseable {
 
   private FileSKVWriter writer;
-  private final LRUMap validVisibilities;
+  private final LRUMap<ByteSequence,Boolean> validVisibilities;
   private boolean startedLG;
   private boolean startedDefaultLG;
 
   RFileWriter(FileSKVWriter fileSKVWriter, int visCacheSize) {
     this.writer = fileSKVWriter;
-    this.validVisibilities = new LRUMap(visCacheSize);
+    this.validVisibilities = new LRUMap<>(visCacheSize);
   }
 
   private void _startNewLocalityGroup(String name, Set<ByteSequence> columnFamilies)
@@ -206,7 +206,7 @@ public class RFileWriter implements AutoCloseable {
     if (!startedLG) {
       startDefaultLocalityGroup();
     }
-    Boolean wasChecked = (Boolean) validVisibilities.get(key.getColumnVisibilityData());
+    Boolean wasChecked = validVisibilities.get(key.getColumnVisibilityData());
     if (wasChecked == null) {
       byte[] cv = key.getColumnVisibilityData().toArray();
       new ColumnVisibility(cv);
diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/ConditionalWriterImpl.java
b/core/src/main/java/org/apache/accumulo/core/clientImpl/ConditionalWriterImpl.java
index 80df6cf..8439c1c 100644
--- a/core/src/main/java/org/apache/accumulo/core/clientImpl/ConditionalWriterImpl.java
+++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ConditionalWriterImpl.java
@@ -110,8 +110,7 @@ class ConditionalWriterImpl implements ConditionalWriter {
 
   private Authorizations auths;
   private VisibilityEvaluator ve;
-  @SuppressWarnings("unchecked")
-  private Map<Text,Boolean> cache = Collections.synchronizedMap(new LRUMap(1000));
+  private Map<Text,Boolean> cache = Collections.synchronizedMap(new LRUMap<>(1000));
   private final ClientContext context;
   private TabletLocator locator;
   private final TableId tableId;
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/system/VisibilityFilter.java
b/core/src/main/java/org/apache/accumulo/core/iterators/system/VisibilityFilter.java
index 463add0..2d05ead 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/system/VisibilityFilter.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/system/VisibilityFilter.java
@@ -43,7 +43,7 @@ import org.slf4j.LoggerFactory;
 public class VisibilityFilter extends SynchronizedServerFilter {
   protected VisibilityEvaluator ve;
   protected ByteSequence defaultVisibility;
-  protected LRUMap cache;
+  protected LRUMap<ByteSequence,Boolean> cache;
   protected Authorizations authorizations;
 
   private static final Logger log = LoggerFactory.getLogger(VisibilityFilter.class);
@@ -54,7 +54,7 @@ public class VisibilityFilter extends SynchronizedServerFilter {
     this.ve = new VisibilityEvaluator(authorizations);
     this.authorizations = authorizations;
     this.defaultVisibility = new ArrayByteSequence(defaultVisibility);
-    this.cache = new LRUMap(1000);
+    this.cache = new LRUMap<>(1000);
   }
 
   @Override
@@ -71,7 +71,7 @@ public class VisibilityFilter extends SynchronizedServerFilter {
     else if (testVis.length() == 0)
       testVis = defaultVisibility;
 
-    Boolean b = (Boolean) cache.get(testVis);
+    Boolean b = cache.get(testVis);
     if (b != null)
       return b;
 
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/user/TransformingIterator.java
b/core/src/main/java/org/apache/accumulo/core/iterators/user/TransformingIterator.java
index 7d2f542..bc5ef88 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/user/TransformingIterator.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/user/TransformingIterator.java
@@ -104,8 +104,8 @@ public abstract class TransformingIterator extends WrappingIterator implements
O
   protected boolean seekColumnFamiliesInclusive;
 
   private VisibilityEvaluator ve = null;
-  private LRUMap visibleCache = null;
-  private LRUMap parsedVisibilitiesCache = null;
+  private LRUMap<ByteSequence,Boolean> visibleCache = null;
+  private LRUMap<ByteSequence,Boolean> parsedVisibilitiesCache = null;
   private long maxBufferSize;
 
   private static Comparator<Pair<Key,Value>> keyComparator = Comparator.comparing(Pair::getFirst);
@@ -119,7 +119,7 @@ public abstract class TransformingIterator extends WrappingIterator implements
O
       String auths = options.get(AUTH_OPT);
       if (auths != null && !auths.isEmpty()) {
         ve = new VisibilityEvaluator(new Authorizations(auths.getBytes(UTF_8)));
-        visibleCache = new LRUMap(100);
+        visibleCache = new LRUMap<>(100);
       }
     }
 
@@ -130,7 +130,7 @@ public abstract class TransformingIterator extends WrappingIterator implements
O
       maxBufferSize = DEFAULT_MAX_BUFFER_SIZE;
     }
 
-    parsedVisibilitiesCache = new LRUMap(100);
+    parsedVisibilitiesCache = new LRUMap<>(100);
   }
 
   @Override
@@ -192,12 +192,12 @@ public abstract class TransformingIterator extends WrappingIterator
implements O
 
     copy.ve = ve;
     if (visibleCache != null) {
-      copy.visibleCache = new LRUMap(visibleCache.maxSize());
+      copy.visibleCache = new LRUMap<>(visibleCache.maxSize());
       copy.visibleCache.putAll(visibleCache);
     }
 
     if (parsedVisibilitiesCache != null) {
-      copy.parsedVisibilitiesCache = new LRUMap(parsedVisibilitiesCache.maxSize());
+      copy.parsedVisibilitiesCache = new LRUMap<>(parsedVisibilitiesCache.maxSize());
       copy.parsedVisibilitiesCache.putAll(parsedVisibilitiesCache);
     }
 
@@ -406,7 +406,7 @@ public abstract class TransformingIterator extends WrappingIterator implements
O
     // check, even if visibility is not evaluated.
     ByteSequence visibility = key.getColumnVisibilityData();
     ColumnVisibility colVis = null;
-    Boolean parsed = (Boolean) parsedVisibilitiesCache.get(visibility);
+    Boolean parsed = parsedVisibilitiesCache.get(visibility);
     if (parsed == null) {
       try {
         colVis = new ColumnVisibility(visibility.toArray());
@@ -432,7 +432,7 @@ public abstract class TransformingIterator extends WrappingIterator implements
O
     if (!scanning || !visible || ve == null || visibleCache == null || visibility.length()
== 0)
       return visible;
 
-    visible = (Boolean) visibleCache.get(visibility);
+    visible = visibleCache.get(visibility);
     if (visible == null) {
       try {
         if (colVis == null)
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/user/VisibilityFilter.java
b/core/src/main/java/org/apache/accumulo/core/iterators/user/VisibilityFilter.java
index 08dab37..d86237d 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/user/VisibilityFilter.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/user/VisibilityFilter.java
@@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory;
 public class VisibilityFilter extends Filter implements OptionDescriber {
 
   protected VisibilityEvaluator ve;
-  protected LRUMap cache;
+  protected LRUMap<ByteSequence,Boolean> cache;
 
   private static final Logger log = LoggerFactory.getLogger(VisibilityFilter.class);
 
@@ -66,14 +66,14 @@ public class VisibilityFilter extends Filter implements OptionDescriber
{
           : new Authorizations(auths.getBytes(UTF_8));
       this.ve = new VisibilityEvaluator(authObj);
     }
-    this.cache = new LRUMap(1000);
+    this.cache = new LRUMap<>(1000);
   }
 
   @Override
   public boolean accept(Key k, Value v) {
     ByteSequence testVis = k.getColumnVisibilityData();
     if (filterInvalid) {
-      Boolean b = (Boolean) cache.get(testVis);
+      Boolean b = cache.get(testVis);
       if (b != null)
         return b;
       try {
@@ -89,7 +89,7 @@ public class VisibilityFilter extends Filter implements OptionDescriber
{
         return true;
       }
 
-      Boolean b = (Boolean) cache.get(testVis);
+      Boolean b = cache.get(testVis);
       if (b != null)
         return b;
 
diff --git a/server/base/src/main/java/org/apache/accumulo/server/problems/ProblemReports.java
b/server/base/src/main/java/org/apache/accumulo/server/problems/ProblemReports.java
index b39939a..b903cf2 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/problems/ProblemReports.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/problems/ProblemReports.java
@@ -57,7 +57,7 @@ public class ProblemReports implements Iterable<ProblemReport> {
 
   private static final Logger log = LoggerFactory.getLogger(ProblemReports.class);
 
-  private final LRUMap problemReports = new LRUMap(1000);
+  private final LRUMap<ProblemReport,Long> problemReports = new LRUMap<>(1000);
 
   /**
    * use a thread pool so that reporting a problem never blocks
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java
index d238804..abf2a80 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java
@@ -316,9 +316,8 @@ public class TabletServer extends AbstractServer {
       Collections.synchronizedSortedSet(new TreeSet<KeyExtent>());
   private final SortedSet<KeyExtent> openingTablets =
       Collections.synchronizedSortedSet(new TreeSet<KeyExtent>());
-  @SuppressWarnings("unchecked")
   private final Map<KeyExtent,Long> recentlyUnloadedCache =
-      Collections.synchronizedMap(new LRUMap(1000));
+      Collections.synchronizedMap(new LRUMap<>(1000));
 
   private final TabletServerResourceManager resourceManager;
   private final SecurityOperation security;
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/log/RecoveryLogReader.java
b/server/tserver/src/main/java/org/apache/accumulo/tserver/log/RecoveryLogReader.java
index 2fe9d47..95611d9 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/log/RecoveryLogReader.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/log/RecoveryLogReader.java
@@ -111,7 +111,7 @@ public class RecoveryLogReader implements CloseableIterator<Entry<LogFileKey,Log
     }
   }
 
-  private PriorityQueue heap = new PriorityQueue<>();
+  private PriorityQueue<Index> heap = new PriorityQueue<>();
   private Iterator<Entry<LogFileKey,LogFileValue>> iter;
 
   public RecoveryLogReader(VolumeManager fs, Path directory) throws IOException {
@@ -152,7 +152,7 @@ public class RecoveryLogReader implements CloseableIterator<Entry<LogFileKey,Log
 
   @VisibleForTesting
   synchronized boolean next(WritableComparable<?> key, Writable val) throws IOException
{
-    Index elt = (Index) heap.remove();
+    Index elt = heap.remove();
     try {
       elt.cache();
       if (elt.cached) {
@@ -170,10 +170,9 @@ public class RecoveryLogReader implements CloseableIterator<Entry<LogFileKey,Log
 
   @VisibleForTesting
   synchronized boolean seek(WritableComparable<?> key) throws IOException {
-    PriorityQueue reheap = new PriorityQueue(heap.size());
+    PriorityQueue<Index> reheap = new PriorityQueue<>(heap.size());
     boolean result = false;
-    for (Object obj : heap) {
-      Index index = (Index) obj;
+    for (Index index : heap) {
       try {
         WritableComparable<?> found = index.reader.getClosest(key, index.value, true);
         if (found != null && found.equals(key)) {
@@ -192,8 +191,7 @@ public class RecoveryLogReader implements CloseableIterator<Entry<LogFileKey,Log
   @Override
   public void close() throws IOException {
     IOException problem = null;
-    for (Object obj : heap) {
-      Index index = (Index) obj;
+    for (Index index : heap) {
       try {
         index.reader.close();
       } catch (IOException ex) {
diff --git a/shell/src/main/java/org/apache/accumulo/shell/commands/TablesCommand.java b/shell/src/main/java/org/apache/accumulo/shell/commands/TablesCommand.java
index 08154ce..f13b0d0 100644
--- a/shell/src/main/java/org/apache/accumulo/shell/commands/TablesCommand.java
+++ b/shell/src/main/java/org/apache/accumulo/shell/commands/TablesCommand.java
@@ -42,7 +42,6 @@ public class TablesCommand extends Command {
   private Option sortByTableIdOption;
   private Option disablePaginationOpt;
 
-  @SuppressWarnings("unchecked")
   @Override
   public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
       throws AccumuloException, AccumuloSecurityException, IOException, NamespaceNotFoundException
{
@@ -56,7 +55,7 @@ public class TablesCommand extends Command {
         tableName -> namespace == null || Tables.qualify(tableName).getFirst().equals(namespace));
 
     final boolean sortByTableId = cl.hasOption(sortByTableIdOption.getOpt());
-    tables = new TreeMap<String,String>((sortByTableId ? MapUtils.invertMap(tables)
: tables));
+    tables = new TreeMap<>((sortByTableId ? MapUtils.invertMap(tables) : tables));
 
     Iterator<String> it = Iterators.transform(tables.entrySet().iterator(), entry ->
{
       String tableName = String.valueOf(sortByTableId ? entry.getValue() : entry.getKey());


Mime
View raw message