From 16589af63455f8c251a501acc629eafeecc4fa42 Mon Sep 17 00:00:00 2001 From: mbertozzi Date: Fri, 15 Mar 2013 20:04:08 +0000 Subject: [PATCH] HBASE-8123 Replace HashMap/HashSet with TreeMap/TreeSet where byte[] is used as key git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1457089 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/client/HTableMultiplexer.java | 4 +++- .../hadoop/hbase/mapreduce/IndexBuilder.java | 6 +++--- .../hadoop/hbase/mapreduce/PutCombiner.java | 5 +++-- .../hadoop/hbase/regionserver/wal/FSHLog.java | 5 +++-- .../hbase/security/access/AccessController.java | 16 ++++++++-------- .../hadoop/hbase/regionserver/wal/TestHLog.java | 4 ++-- 6 files changed, 22 insertions(+), 18 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTableMultiplexer.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTableMultiplexer.java index 2fffd6c83a6..70b44156989 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTableMultiplexer.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HTableMultiplexer.java @@ -27,6 +27,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.exceptions.ZooKeeperConnectionException; +import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import java.io.IOException; @@ -38,6 +39,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -89,7 +91,7 @@ public class HTableMultiplexer { this.serverToBufferQueueMap = new ConcurrentHashMap>(); this.serverToFlushWorkerMap = new ConcurrentHashMap(); - this.tableNameToHTableMap = new ConcurrentHashMap(); + this.tableNameToHTableMap = new ConcurrentSkipListMap(Bytes.BYTES_COMPARATOR); this.retryNum = conf.getInt("hbase.client.retries.number", 10); this.perRegionServerBufferQueueSize = perRegionServerBufferQueueSize; } diff --git a/hbase-examples/src/main/java/org/apache/hadoop/hbase/mapreduce/IndexBuilder.java b/hbase-examples/src/main/java/org/apache/hadoop/hbase/mapreduce/IndexBuilder.java index c1acd2d5bfd..deead646f1e 100644 --- a/hbase-examples/src/main/java/org/apache/hadoop/hbase/mapreduce/IndexBuilder.java +++ b/hbase-examples/src/main/java/org/apache/hadoop/hbase/mapreduce/IndexBuilder.java @@ -19,7 +19,7 @@ package org.apache.hadoop.hbase.mapreduce; import java.io.IOException; -import java.util.HashMap; +import java.util.TreeMap; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; @@ -74,7 +74,7 @@ public class IndexBuilder { public static class Map extends Mapper { private byte[] family; - private HashMap indexes; + private TreeMap indexes; @Override protected void map(ImmutableBytesWritable rowKey, Result result, Context context) @@ -101,7 +101,7 @@ public class IndexBuilder { String[] fields = configuration.getStrings("index.fields"); String familyName = configuration.get("index.familyname"); family = Bytes.toBytes(familyName); - indexes = new HashMap(); + indexes = new TreeMap(Bytes.BYTES_COMPARATOR); for(String field : fields) { // if the table is "people" and the field to index is "email", then the // index table will be called "people-email" diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/PutCombiner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/PutCombiner.java index 3dd8696dbc7..ee8290e52e1 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/PutCombiner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mapreduce/PutCombiner.java @@ -19,7 +19,7 @@ package org.apache.hadoop.hbase.mapreduce; import java.io.IOException; -import java.util.HashMap; +import java.util.TreeMap; import java.util.Map; import org.apache.commons.logging.Log; @@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.mapreduce.Reducer; /** @@ -54,7 +55,7 @@ public class PutCombiner extends Reducer { // flush could result in multiple Puts for a single rowkey. That is // acceptable because Combiner is run as an optimization and it's not // critical that all Puts are grouped perfectly. - Map puts = new HashMap(); + Map puts = new TreeMap(Bytes.BYTES_COMPARATOR); for (Put p : vals) { cnt++; if (!puts.containsKey(p.getRow())) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java index f4324ebdd47..dd7d37dcba7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSHLog.java @@ -27,7 +27,7 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; +import java.util.TreeMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -172,7 +172,8 @@ class FSHLog implements HLog, Syncable { * contains the regions that are currently flushing. That way we can store two numbers for * flushing and non-flushing (oldestUnflushedSeqNums) memstore for the same region. */ - private final Map oldestFlushingSeqNums = new HashMap(); + private final Map oldestFlushingSeqNums = + new TreeMap(Bytes.BYTES_COMPARATOR); private volatile boolean closed = false; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java index 6d06573eb4d..0aac1a2a545 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java @@ -19,8 +19,6 @@ import java.net.InetAddress; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -485,7 +483,7 @@ public class AccessController extends BaseRegionObserver public void preCreateTable(ObserverContext c, HTableDescriptor desc, HRegionInfo[] regions) throws IOException { Set families = desc.getFamiliesKeys(); - HashMap> familyMap = Maps.newHashMapWithExpectedSize(families.size()); + Map> familyMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); for (byte[] family: families) { familyMap.put(family, null); } @@ -969,9 +967,9 @@ public class AccessController extends BaseRegionObserver final Increment increment) throws IOException { // Create a map of family to qualifiers. - Map> familyMap = Maps.newHashMap(); + Map> familyMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); for (Map.Entry> entry: increment.getFamilyMap().entrySet()) { - Set qualifiers = new HashSet(entry.getValue().size()); + Set qualifiers = Sets.newTreeSet(Bytes.BYTES_COMPARATOR); for (Cell cell: entry.getValue()) { KeyValue kv = KeyValueUtil.ensureKeyValue(cell); qualifiers.add(kv.getQualifier()); @@ -1257,10 +1255,12 @@ public class AccessController extends BaseRegionObserver Bytes.toString(tperm.getTable()))); } - HashMap> familyMap = Maps.newHashMapWithExpectedSize(1); + Map> familyMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); if (tperm.getFamily() != null) { if (tperm.getQualifier() != null) { - familyMap.put(tperm.getFamily(), Sets.newHashSet(tperm.getQualifier())); + Set qualifiers = Sets.newTreeSet(Bytes.BYTES_COMPARATOR); + qualifiers.add(tperm.getQualifier()); + familyMap.put(tperm.getFamily(), qualifiers); } else { familyMap.put(tperm.getFamily(), null); } @@ -1345,7 +1345,7 @@ public class AccessController extends BaseRegionObserver return null; } - Map> familyMap = Maps.newHashMapWithExpectedSize(1); + Map> familyMap = Maps.newTreeMap(Bytes.BYTES_COMPARATOR); familyMap.put(family, qualifier != null ? ImmutableSet.of(qualifier) : null); return familyMap; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java index ae0adf75d3b..879649bfa10 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestHLog.java @@ -22,7 +22,7 @@ import static org.junit.Assert.*; import java.io.IOException; import java.lang.reflect.Method; -import java.util.HashMap; +import java.util.TreeMap; import java.util.List; import java.util.Map; @@ -317,7 +317,7 @@ public class TestHLog { */ @Test public void testFindMemstoresWithEditsEqualOrOlderThan() throws IOException { - Map regionsToSeqids = new HashMap(); + Map regionsToSeqids = new TreeMap(Bytes.BYTES_COMPARATOR); for (int i = 0; i < 10; i++) { Long l = Long.valueOf(i); regionsToSeqids.put(l.toString().getBytes(), l);