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: Remove unnecessary code blocks (#968)
Date Tue, 19 Feb 2019 18:10:12 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 70541a3  Remove unnecessary code blocks (#968)
70541a3 is described below

commit 70541a34c66fcccd8219f6fdeb4f8019d31e46e9
Author: Mike Walch <mwalch@apache.org>
AuthorDate: Tue Feb 19 13:10:07 2019 -0500

    Remove unnecessary code blocks (#968)
---
 .../file/blockfile/cache/lru/LruBlockCache.java    |  9 +++----
 .../cache/lru/SynchronousLoadingBlockCache.java    |  3 +--
 .../iterators/user/WholeColumnFamilyIterator.java  | 21 +++++++---------
 .../core/iterators/user/WholeRowIterator.java      | 28 +++++++---------------
 .../accumulo/core/security/ColumnVisibility.java   | 18 +++++---------
 .../server/replication/proto/Replication.java      | 18 +++++---------
 .../apache/accumulo/master/FateServiceHandler.java |  3 +--
 .../java/org/apache/accumulo/master/Master.java    |  3 +--
 .../accumulo/test/BatchWriterInTabletServerIT.java |  8 +++----
 9 files changed, 38 insertions(+), 73 deletions(-)

diff --git a/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/LruBlockCache.java
b/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/LruBlockCache.java
index cd2ffac..127db09 100644
--- a/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/LruBlockCache.java
+++ b/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/LruBlockCache.java
@@ -334,18 +334,15 @@ public class LruBlockCache extends SynchronousLoadingBlockCache implements
Block
       // Scan entire map putting into appropriate buckets
       for (CachedBlock cachedBlock : map.values()) {
         switch (cachedBlock.getPriority()) {
-          case SINGLE: {
+          case SINGLE:
             bucketSingle.add(cachedBlock);
             break;
-          }
-          case MULTI: {
+          case MULTI:
             bucketMulti.add(cachedBlock);
             break;
-          }
-          case MEMORY: {
+          case MEMORY:
             bucketMemory.add(cachedBlock);
             break;
-          }
         }
       }
 
diff --git a/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/SynchronousLoadingBlockCache.java
b/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/SynchronousLoadingBlockCache.java
index 716e274..64d196b 100644
--- a/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/SynchronousLoadingBlockCache.java
+++ b/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/SynchronousLoadingBlockCache.java
@@ -69,7 +69,7 @@ public abstract class SynchronousLoadingBlockCache implements BlockCache
{
         }
         break;
       }
-      default: {
+      default:
         depData = new HashMap<>();
         Set<Entry<String,Loader>> es = loaderDeps.entrySet();
         for (Entry<String,Loader> entry : es) {
@@ -82,7 +82,6 @@ public abstract class SynchronousLoadingBlockCache implements BlockCache
{
           depData.put(entry.getKey(), dce.getBuffer());
         }
         break;
-      }
     }
 
     return depData;
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/user/WholeColumnFamilyIterator.java
b/core/src/main/java/org/apache/accumulo/core/iterators/user/WholeColumnFamilyIterator.java
index cdc6f09..e49f05e 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/user/WholeColumnFamilyIterator.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/user/WholeColumnFamilyIterator.java
@@ -111,6 +111,11 @@ public class WholeColumnFamilyIterator
     return map;
   }
 
+  private static void encode(DataOutputStream dout, ByteSequence bs) throws IOException {
+    dout.writeInt(bs.length());
+    dout.write(bs.getBackingArray(), bs.offset(), bs.length());
+  }
+
   /**
    * Encode row/cf. Take a stream of keys and values and output a value that encodes everything
but
    * their row and column families keys and values must be paired one for one
@@ -131,18 +136,9 @@ public class WholeColumnFamilyIterator
     for (int i = 0; i < keys.size(); i++) {
       Key k = keys.get(i);
       Value v = values.get(i);
-      // write the colqual
-      {
-        ByteSequence bs = k.getColumnQualifierData();
-        dout.writeInt(bs.length());
-        dout.write(bs.getBackingArray(), bs.offset(), bs.length());
-      }
-      // write the column visibility
-      {
-        ByteSequence bs = k.getColumnVisibilityData();
-        dout.writeInt(bs.length());
-        dout.write(bs.getBackingArray(), bs.offset(), bs.length());
-      }
+      // write column qualifier & visibility
+      encode(dout, k.getColumnQualifierData());
+      encode(dout, k.getColumnVisibilityData());
       // write the timestamp
       dout.writeLong(k.getTimestamp());
       // write the value
@@ -150,7 +146,6 @@ public class WholeColumnFamilyIterator
       dout.writeInt(valBytes.length);
       dout.write(valBytes);
     }
-
     return new Value(out.toByteArray());
   }
 
diff --git a/core/src/main/java/org/apache/accumulo/core/iterators/user/WholeRowIterator.java
b/core/src/main/java/org/apache/accumulo/core/iterators/user/WholeRowIterator.java
index 5680d34..ae456a9 100644
--- a/core/src/main/java/org/apache/accumulo/core/iterators/user/WholeRowIterator.java
+++ b/core/src/main/java/org/apache/accumulo/core/iterators/user/WholeRowIterator.java
@@ -103,6 +103,11 @@ public class WholeRowIterator extends RowEncodingIterator {
     return map;
   }
 
+  private static void encode(DataOutputStream dout, ByteSequence bs) throws IOException {
+    dout.writeInt(bs.length());
+    dout.write(bs.getBackingArray(), bs.offset(), bs.length());
+  }
+
   // take a stream of keys and values and output a value that encodes everything but their
row
   // keys and values must be paired one for one
   public static final Value encodeRow(List<Key> keys, List<Value> values) throws
IOException {
@@ -112,24 +117,10 @@ public class WholeRowIterator extends RowEncodingIterator {
     for (int i = 0; i < keys.size(); i++) {
       Key k = keys.get(i);
       Value v = values.get(i);
-      // write the colfam
-      {
-        ByteSequence bs = k.getColumnFamilyData();
-        dout.writeInt(bs.length());
-        dout.write(bs.getBackingArray(), bs.offset(), bs.length());
-      }
-      // write the colqual
-      {
-        ByteSequence bs = k.getColumnQualifierData();
-        dout.writeInt(bs.length());
-        dout.write(bs.getBackingArray(), bs.offset(), bs.length());
-      }
-      // write the column visibility
-      {
-        ByteSequence bs = k.getColumnVisibilityData();
-        dout.writeInt(bs.length());
-        dout.write(bs.getBackingArray(), bs.offset(), bs.length());
-      }
+      // write the column family, qualifier & visibility
+      encode(dout, k.getColumnFamilyData());
+      encode(dout, k.getColumnQualifierData());
+      encode(dout, k.getColumnVisibilityData());
       // write the timestamp
       dout.writeLong(k.getTimestamp());
       // write the value
@@ -137,7 +128,6 @@ public class WholeRowIterator extends RowEncodingIterator {
       dout.writeInt(valBytes.length);
       dout.write(valBytes);
     }
-
     return new Value(out.toByteArray());
   }
 }
diff --git a/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java b/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
index 82f4a9a..6389389 100644
--- a/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
+++ b/core/src/main/java/org/apache/accumulo/core/security/ColumnVisibility.java
@@ -324,7 +324,7 @@ public class ColumnVisibility {
 
       while (index < expression.length) {
         switch (expression[index++]) {
-          case '&': {
+          case '&':
             expr = processTerm(subtermStart, index - 1, expr, expression);
             if (result != null) {
               if (!result.type.equals(NodeType.AND))
@@ -338,8 +338,7 @@ public class ColumnVisibility {
             subtermStart = index;
             subtermComplete = false;
             break;
-          }
-          case '|': {
+          case '|':
             expr = processTerm(subtermStart, index - 1, expr, expression);
             if (result != null) {
               if (!result.type.equals(NodeType.OR))
@@ -353,8 +352,7 @@ public class ColumnVisibility {
             subtermStart = index;
             subtermComplete = false;
             break;
-          }
-          case '(': {
+          case '(':
             parens++;
             if (subtermStart != index - 1 || expr != null)
               throw new BadArgumentException("expression needs & or |",
@@ -363,8 +361,7 @@ public class ColumnVisibility {
             subtermStart = index;
             subtermComplete = false;
             break;
-          }
-          case ')': {
+          case ')':
             parens--;
             Node child = processTerm(subtermStart, index - 1, expr, expression);
             if (child == null && result == null)
@@ -379,8 +376,7 @@ public class ColumnVisibility {
               result.add(child);
             result.end = index - 1;
             return result;
-          }
-          case '"': {
+          case '"':
             if (subtermStart != index - 1)
               throw new BadArgumentException("expression needs & or |",
                   new String(expression, UTF_8), index - 1);
@@ -408,8 +404,7 @@ public class ColumnVisibility {
             subtermComplete = true;
 
             break;
-          }
-          default: {
+          default:
             if (subtermComplete)
               throw new BadArgumentException("expression needs & or |",
                   new String(expression, UTF_8), index - 1);
@@ -418,7 +413,6 @@ public class ColumnVisibility {
             if (!Authorizations.isValidAuthChar(c))
               throw new BadArgumentException("bad character (" + c + ")",
                   new String(expression, UTF_8), index - 1);
-          }
         }
       }
       Node child = processTerm(subtermStart, index, expr, expression);
diff --git a/server/base/src/main/java/org/apache/accumulo/server/replication/proto/Replication.java
b/server/base/src/main/java/org/apache/accumulo/server/replication/proto/Replication.java
index 6a87080..43fa3d0 100644
--- a/server/base/src/main/java/org/apache/accumulo/server/replication/proto/Replication.java
+++ b/server/base/src/main/java/org/apache/accumulo/server/replication/proto/Replication.java
@@ -161,38 +161,32 @@ package org.apache.accumulo.server.replication.proto;
             case 0:
               done = true;
               break;
-            default: {
+            default:
               if (!parseUnknownField(input, unknownFields,
                                      extensionRegistry, tag)) {
                 done = true;
               }
               break;
-            }
-            case 8: {
+            case 8:
               bitField0_ |= 0x00000001;
               begin_ = input.readInt64();
               break;
-            }
-            case 16: {
+            case 16:
               bitField0_ |= 0x00000002;
               end_ = input.readInt64();
               break;
-            }
-            case 24: {
+            case 24:
               bitField0_ |= 0x00000004;
               infiniteEnd_ = input.readBool();
               break;
-            }
-            case 32: {
+            case 32:
               bitField0_ |= 0x00000008;
               closed_ = input.readBool();
               break;
-            }
-            case 40: {
+            case 40:
               bitField0_ |= 0x00000010;
               createdTime_ = input.readInt64();
               break;
-            }
           }
         }
       } catch (com.google.protobuf.InvalidProtocolBufferException e) {
diff --git a/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java
b/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java
index b535b5b..1f794bf 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/FateServiceHandler.java
@@ -536,7 +536,7 @@ class FateServiceHandler implements FateService.Iface {
             autoCleanup);
         break;
       }
-      case TABLE_BULK_IMPORT2: {
+      case TABLE_BULK_IMPORT2:
         TableOperation tableOp = TableOperation.BULK_IMPORT;
         TableId tableId = validateTableIdArgument(arguments.get(0), tableOp, NOT_ROOT_ID);
         String dir = ByteBufferUtil.toString(arguments.get(1));
@@ -565,7 +565,6 @@ class FateServiceHandler implements FateService.Iface {
         master.fate.seedTransaction(opid,
             new TraceRepo<>(new PrepBulkImport(tableId, dir, setTime)), autoCleanup);
         break;
-      }
       default:
         throw new UnsupportedOperationException();
     }
diff --git a/server/master/src/main/java/org/apache/accumulo/master/Master.java b/server/master/src/main/java/org/apache/accumulo/master/Master.java
index 2c5bc57..e366c04 100644
--- a/server/master/src/main/java/org/apache/accumulo/master/Master.java
+++ b/server/master/src/main/java/org/apache/accumulo/master/Master.java
@@ -1053,7 +1053,7 @@ public class Master
                     setMasterState(MasterState.UNLOAD_ROOT_TABLET);
                 }
                   break;
-                case UNLOAD_ROOT_TABLET: {
+                case UNLOAD_ROOT_TABLET:
                   int count = assignedOrHosted(MetadataTable.ID);
                   if (count > 0 && goodStats()) {
                     log.debug(String.format("%d metadata tablets online", count));
@@ -1078,7 +1078,6 @@ public class Master
                     if (currentServers.size() == 0)
                       setMasterState(MasterState.STOP);
                   }
-                }
                   break;
                 default:
                   break;
diff --git a/test/src/main/java/org/apache/accumulo/test/BatchWriterInTabletServerIT.java
b/test/src/main/java/org/apache/accumulo/test/BatchWriterInTabletServerIT.java
index 8d85f0b..1a21680 100644
--- a/test/src/main/java/org/apache/accumulo/test/BatchWriterInTabletServerIT.java
+++ b/test/src/main/java/org/apache/accumulo/test/BatchWriterInTabletServerIT.java
@@ -94,14 +94,12 @@ public class BatchWriterInTabletServerIT extends AccumuloClusterHarness
{
     c.tableOperations().create(t1);
     Key k = new Key(new Text("row"), new Text("cf"), new Text("cq"));
     Value v = new Value("1".getBytes());
-    {
-      BatchWriterConfig config = new BatchWriterConfig();
-      config.setMaxMemory(0);
-      BatchWriter writer = c.createBatchWriter(t1, config);
+    BatchWriterConfig config = new BatchWriterConfig();
+    config.setMaxMemory(0);
+    try (BatchWriter writer = c.createBatchWriter(t1, config)) {
       Mutation m = new Mutation(k.getRow());
       m.put(k.getColumnFamily(), k.getColumnQualifier(), v);
       writer.addMutation(m);
-      writer.close();
     }
 
     // Create t2 with a combiner to count entries written to it


Mime
View raw message