accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From md...@apache.org
Subject git commit: ACCUMULO-2477 Replace our implemenations of Entry
Date Tue, 18 Mar 2014 03:09:26 GMT
Repository: accumulo
Updated Branches:
  refs/heads/master c121ae2d2 -> b7fe94c02


ACCUMULO-2477 Replace our implemenations of Entry

Our uses of Map.Entry can defer to SimpleImmutableEntry. We should use
that instead of maintaining our own version.


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

Branch: refs/heads/master
Commit: b7fe94c02e74f640fe1ba8b5e71439a189636b42
Parents: c121ae2
Author: Mike Drob <mdrob@cloudera.com>
Authored: Mon Mar 17 12:21:09 2014 -0400
Committer: Mike Drob <mdrob@cloudera.com>
Committed: Mon Mar 17 12:21:09 2014 -0400

----------------------------------------------------------------------
 .../impl/TabletServerBatchReaderIterator.java   | 32 ++------------
 .../java/org/apache/accumulo/core/data/Key.java |  8 ++--
 .../org/apache/accumulo/core/data/KeyValue.java | 45 ++++++--------------
 .../org/apache/accumulo/core/util/Pair.java     | 20 +--------
 .../examples/simple/mapreduce/TableToFile.java  | 20 +--------
 .../org/apache/accumulo/tserver/NativeMap.java  | 34 +--------------
 .../org/apache/accumulo/tserver/Tablet.java     | 11 ++---
 .../apache/accumulo/tserver/TabletServer.java   |  4 +-
 8 files changed, 32 insertions(+), 142 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/b7fe94c0/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java
b/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java
index 30e12c1..d2ca60e 100644
--- a/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java
+++ b/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java
@@ -17,6 +17,7 @@
 package org.apache.accumulo.core.client.impl;
 
 import java.io.IOException;
+import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -104,33 +105,6 @@ public class TabletServerBatchReaderIterator implements Iterator<Entry<Key,Value
     void receive(List<Entry<Key,Value>> entries);
   }
   
-  private static class MyEntry implements Entry<Key,Value> {
-    
-    private Key key;
-    private Value value;
-    
-    MyEntry(Key key, Value value) {
-      this.key = key;
-      this.value = value;
-    }
-    
-    @Override
-    public Key getKey() {
-      return key;
-    }
-    
-    @Override
-    public Value getValue() {
-      return value;
-    }
-    
-    @Override
-    public Value setValue(Value value) {
-      throw new UnsupportedOperationException();
-    }
-    
-  }
-  
   public TabletServerBatchReaderIterator(Instance instance, Credentials credentials, String
table, Authorizations authorizations, ArrayList<Range> ranges,
       int numThreads, ExecutorService queryThreadPool, ScannerOptions scannerOptions, long
timeout) {
     
@@ -668,7 +642,7 @@ public class TabletServerBatchReaderIterator implements Iterator<Entry<Key,Value
         
         ArrayList<Entry<Key,Value>> entries = new ArrayList<Map.Entry<Key,Value>>(scanResult.results.size());
         for (TKeyValue kv : scanResult.results) {
-          entries.add(new MyEntry(new Key(kv.key), new Value(kv.value)));
+          entries.add(new SimpleImmutableEntry<Key,Value>(new Key(kv.key), new Value(kv.value)));
         }
         
         if (entries.size() > 0)
@@ -690,7 +664,7 @@ public class TabletServerBatchReaderIterator implements Iterator<Entry<Key,Value
           
           entries = new ArrayList<Map.Entry<Key,Value>>(scanResult.results.size());
           for (TKeyValue kv : scanResult.results) {
-            entries.add(new MyEntry(new Key(kv.key), new Value(kv.value)));
+            entries.add(new SimpleImmutableEntry<Key,Value>(new Key(kv.key), new Value(kv.value)));
           }
           
           if (entries.size() > 0)

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b7fe94c0/core/src/main/java/org/apache/accumulo/core/data/Key.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/data/Key.java b/core/src/main/java/org/apache/accumulo/core/data/Key.java
index 74975ae..41754b5 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/Key.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/Key.java
@@ -877,12 +877,12 @@ public class Key implements WritableComparable<Key>, Cloneable
{
     List<TKeyValue> tkvl = Arrays.asList(new TKeyValue[param.size()]);
     
     if (param.size() > 0)
-      tkvl.set(0, new TKeyValue(param.get(0).key.toThrift(), ByteBuffer.wrap(param.get(0).value)));
+      tkvl.set(0, new TKeyValue(param.get(0).getKey().toThrift(), ByteBuffer.wrap(param.get(0).getValue().get())));
     
     for (int i = param.size() - 1; i > 0; i--) {
-      Key prevKey = param.get(i - 1).key;
+      Key prevKey = param.get(i - 1).getKey();
       KeyValue kv = param.get(i);
-      Key key = kv.key;
+      Key key = kv.getKey();
       
       TKey newKey = null;
       
@@ -912,7 +912,7 @@ public class Key implements WritableComparable<Key>, Cloneable {
       if (newKey == null)
         newKey = key.toThrift();
       
-      tkvl.set(i, new TKeyValue(newKey, ByteBuffer.wrap(kv.value)));
+      tkvl.set(i, new TKeyValue(newKey, ByteBuffer.wrap(kv.getValue().get())));
     }
     
     return tkvl;

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b7fe94c0/core/src/main/java/org/apache/accumulo/core/data/KeyValue.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/data/KeyValue.java b/core/src/main/java/org/apache/accumulo/core/data/KeyValue.java
index 83996f8..9a0bdbd 100644
--- a/core/src/main/java/org/apache/accumulo/core/data/KeyValue.java
+++ b/core/src/main/java/org/apache/accumulo/core/data/KeyValue.java
@@ -16,20 +16,13 @@
  */
 package org.apache.accumulo.core.data;
 
-import static org.apache.accumulo.core.util.ByteBufferUtil.toBytes;
-
 import java.nio.ByteBuffer;
-import java.util.Map;
-
-import org.apache.accumulo.core.Constants;
+import java.util.AbstractMap.SimpleImmutableEntry;
 
 /**
  * A key/value pair. The key and value may not be set after construction.
  */
-public class KeyValue implements Map.Entry<Key,Value> {
-  
-  public Key key;
-  public byte[] value;
+public class KeyValue extends SimpleImmutableEntry<Key,Value> {
   
   /**
    * Creates a new key/value pair.
@@ -38,8 +31,7 @@ public class KeyValue implements Map.Entry<Key,Value> {
    * @param value bytes of value
    */
   public KeyValue(Key key, byte[] value) {
-    this.key = key;
-    this.value = value;
+    super(key, new Value(value, false));
   }
   
   /**
@@ -49,27 +41,18 @@ public class KeyValue implements Map.Entry<Key,Value> {
    * @param value buffer containing bytes of value
    */
   public KeyValue(Key key, ByteBuffer value) {
-    this.key = key;
-    this.value = toBytes(value);
-  }
-  
-  @Override
-  public Key getKey() {
-    return key;
-  }
-  
-  @Override
-  public Value getValue() {
-    return new Value(value);
+    super(key, new Value(value));
   }
   
-  @Override
-  public Value setValue(Value value) {
-    throw new UnsupportedOperationException();
-  }
-  
-  public String toString() {
-    return key + " " + new String(value, Constants.UTF8);
+  /**
+   * Creates a new key/value pair.
+   * 
+   * @param key
+   *          key
+   * @param value
+   *          buffer containing bytes of value
+   */
+  public KeyValue(Key key, Value value) {
+    super(key, value);
   }
-  
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b7fe94c0/core/src/main/java/org/apache/accumulo/core/util/Pair.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/Pair.java b/core/src/main/java/org/apache/accumulo/core/util/Pair.java
index fb4ad80..00eab0e 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/Pair.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/Pair.java
@@ -16,7 +16,7 @@
  */
 package org.apache.accumulo.core.util;
 
-import java.util.Map;
+import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.Map.Entry;
 
 public class Pair<A,B> {
@@ -73,23 +73,7 @@ public class Pair<A,B> {
   }
 
   public Entry<A,B> toMapEntry() {
-    return new Map.Entry<A,B>() {
-
-      @Override
-      public A getKey() {
-        return getFirst();
-      }
-
-      @Override
-      public B getValue() {
-        return getSecond();
-      }
-
-      @Override
-      public B setValue(B value) {
-        throw new UnsupportedOperationException();
-      }
-    };
+    return new SimpleImmutableEntry<A,B>(getFirst(), getSecond());
   }
 
   public Pair<B,A> swap() {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b7fe94c0/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/TableToFile.java
----------------------------------------------------------------------
diff --git a/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/TableToFile.java
b/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/TableToFile.java
index 3a211e2..48e3d5e 100644
--- a/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/TableToFile.java
+++ b/examples/simple/src/main/java/org/apache/accumulo/examples/simple/mapreduce/TableToFile.java
@@ -17,6 +17,7 @@
 package org.apache.accumulo.examples.simple.mapreduce;
 
 import java.io.IOException;
+import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.HashSet;
 import java.util.Map;
 
@@ -59,24 +60,7 @@ public class TableToFile extends Configured implements Tool {
   public static class TTFMapper extends Mapper<Key,Value,NullWritable,Text> {
     @Override
     public void map(Key row, Value data, Context context) throws IOException, InterruptedException
{
-      final Key r = row;
-      final Value v = data;
-      Map.Entry<Key,Value> entry = new Map.Entry<Key,Value>() {
-        @Override
-        public Key getKey() {
-          return r;
-        }
-
-        @Override
-        public Value getValue() {
-          return v;
-        }
-
-        @Override
-        public Value setValue(Value value) {
-          return null;
-        }
-      };
+      Map.Entry<Key,Value> entry = new SimpleImmutableEntry<Key,Value>(row, data);
       context.write(NullWritable.get(), new Text(DefaultFormatter.formatEntry(entry, false)));
       context.setStatus("Outputed Value");
     }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b7fe94c0/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java
index a454d6c..e22a54f 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/NativeMap.java
@@ -18,6 +18,7 @@ package org.apache.accumulo.tserver;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.AbstractMap.SimpleImmutableEntry;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -451,7 +452,7 @@ public class NativeMap implements Iterable<Map.Entry<Key,Value>>
{
 
       hasNext = nmiNext(nmiPointer, fieldsLens);
 
-      return new NMEntry(k, v);
+      return new SimpleImmutableEntry<Key,Value>(k, v);
     }
 
     @Override
@@ -470,37 +471,6 @@ public class NativeMap implements Iterable<Map.Entry<Key,Value>>
{
 
   }
 
-  private static class NMEntry implements Map.Entry<Key,Value> {
-
-    private Key key;
-    private Value val;
-
-    NMEntry(Key k, Value v) {
-      this.key = k;
-      this.val = v;
-    }
-
-    @Override
-    public Key getKey() {
-      return key;
-    }
-
-    @Override
-    public Value getValue() {
-      return val;
-    }
-
-    @Override
-    public Value setValue(Value value) {
-      throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public String toString() {
-      return key + "=" + val;
-    }
-  }
-
   public NativeMap() {
     nmPointer = createNativeMap();
     rwLock = new ReentrantReadWriteLock();

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b7fe94c0/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
----------------------------------------------------------------------
diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
index dd20fd9..9ce24be 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java
@@ -1455,17 +1455,12 @@ public class Tablet {
       super(new Key(k), Arrays.copyOf(v.get(), v.get().length));
     }
 
-    @Override
-    public String toString() {
-      return key.toString() + "=" + getValue();
-    }
-
     int numBytes() {
-      return key.getSize() + getValue().get().length;
+      return getKey().getSize() + getValue().get().length;
     }
 
     int estimateMemoryUsed() {
-      return key.getSize() + getValue().get().length + (9 * 32); // overhead is 32 per object
+      return getKey().getSize() + getValue().get().length + (9 * 32); // overhead is 32 per
object
     }
   }
 
@@ -1551,7 +1546,7 @@ public class Tablet {
       throw new IllegalStateException("tablet should not exceed memory usage or close, not
both");
 
     if (entriesAdded > 0)
-      addUnfinishedRange(lookupResult, range, results.get(results.size() - 1).key, false);
+      addUnfinishedRange(lookupResult, range, results.get(results.size() - 1).getKey(), false);
     else
       lookupResult.unfinishedRanges.add(range);
 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/b7fe94c0/server/tserver/src/main/java/org/apache/accumulo/tserver/TabletServer.java
----------------------------------------------------------------------
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 cdb9dbf..3d58a99 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
@@ -72,9 +72,9 @@ import org.apache.accumulo.core.client.impl.TabletType;
 import org.apache.accumulo.core.client.impl.Translator;
 import org.apache.accumulo.core.client.impl.Translator.TKeyExtentTranslator;
 import org.apache.accumulo.core.client.impl.Translator.TRangeTranslator;
+import org.apache.accumulo.core.client.impl.Translators;
 import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
 import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
-import org.apache.accumulo.core.client.impl.Translators;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.constraints.Constraint.Environment;
@@ -1153,7 +1153,7 @@ public class TabletServer extends AbstractMetricsImpl implements org.apache.accu
           // convert everything to thrift before adding result
           List<TKeyValue> retResults = new ArrayList<TKeyValue>();
           for (KVEntry entry : results)
-            retResults.add(new TKeyValue(entry.key.toThrift(), ByteBuffer.wrap(entry.value)));
+            retResults.add(new TKeyValue(entry.getKey().toThrift(), ByteBuffer.wrap(entry.getValue().get())));
           Map<TKeyExtent,List<TRange>> retFailures = Translator.translate(failures,
Translators.KET, new Translator.ListTranslator<Range,TRange>(Translators.RT));
           List<TKeyExtent> retFullScans = Translator.translate(fullScans, Translators.KET);
           TKeyExtent retPartScan = null;


Mime
View raw message