From c3743be05c7e00765e3e4da55a07195c5da29b2c Mon Sep 17 00:00:00 2001 From: BELUGA BEHR Date: Thu, 7 Dec 2017 22:35:13 +0800 Subject: [PATCH] HBASE-19448 Replace StringBuffer with StringBuilder for hbase-server Signed-off-by: Chia-Ping Tsai --- .../hadoop/hbase/favored/FavoredNodeAssignmentHelper.java | 2 +- .../org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java | 2 +- .../java/org/apache/hadoop/hbase/ipc/RpcServerFactory.java | 2 +- .../apache/hadoop/hbase/regionserver/AbstractMemStore.java | 2 +- .../org/apache/hadoop/hbase/regionserver/CompactSplit.java | 2 +- .../java/org/apache/hadoop/hbase/regionserver/HRegion.java | 4 ++-- .../org/apache/hadoop/hbase/regionserver/HRegionServer.java | 2 +- .../replication/regionserver/ReplicationSourceManager.java | 2 +- .../hbase/master/TestMasterOperationsForRegionReplicas.java | 2 +- .../test/java/org/apache/hadoop/hbase/mob/MobTestUtil.java | 2 +- .../apache/hadoop/hbase/regionserver/TestDefaultMemStore.java | 4 ++-- .../apache/hadoop/hbase/security/access/SecureTestUtil.java | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java index f0afad92597..baad21b9e35 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/favored/FavoredNodeAssignmentHelper.java @@ -621,7 +621,7 @@ public class FavoredNodeAssignmentHelper { } public static String getFavoredNodesAsString(List nodes) { - StringBuffer strBuf = new StringBuffer(); + StringBuilder strBuf = new StringBuilder(); int i = 0; for (ServerName node : nodes) { strBuf.append(node.getHostAndPort()); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java index d03f57ab7a7..ac842f650b7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/bucket/BucketCache.java @@ -755,7 +755,7 @@ public class BucketCache implements BlockCache, HeapSize { freeInProgress = true; long bytesToFreeWithoutExtra = 0; // Calculate free byte for each bucketSizeinfo - StringBuffer msgBuffer = LOG.isDebugEnabled()? new StringBuffer(): null; + StringBuilder msgBuffer = LOG.isDebugEnabled()? new StringBuilder(): null; BucketAllocator.IndexStatistics[] stats = bucketAllocator.getIndexStatistics(); long[] bytesToFreeForBucket = new long[stats.length]; for (int i = 0; i < stats.length; i++) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerFactory.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerFactory.java index 649f1f19a36..67ad666846a 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerFactory.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerFactory.java @@ -49,7 +49,7 @@ public class RpcServerFactory { RpcScheduler scheduler) throws IOException { String rpcServerClass = conf.get(CUSTOM_RPC_SERVER_IMPL_CONF_KEY, NettyRpcServer.class.getName()); - StringBuffer servicesList = new StringBuffer(); + StringBuilder servicesList = new StringBuilder(); for (BlockingServiceAndInterface s: services) { ServiceDescriptor sd = s.getBlockingService().getDescriptorForType(); if (sd == null) continue; // Can be null for certain tests like TestTokenAuthentication diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java index ee480be1e2a..4614935cfc5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/AbstractMemStore.java @@ -176,7 +176,7 @@ public abstract class AbstractMemStore implements MemStore { @Override public String toString() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); int i = 1; try { for (Segment segment : getSegments()) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplit.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplit.java index 0749f8567e1..a8459da3953 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplit.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplit.java @@ -166,7 +166,7 @@ public class CompactSplit implements CompactionRequester, PropagatingConfigurati } public String dumpQueue() { - StringBuffer queueLists = new StringBuffer(); + StringBuilder queueLists = new StringBuilder(); queueLists.append("Compaction/Split Queue dump:\n"); queueLists.append(" LargeCompation Queue:\n"); BlockingQueue lq = longCompactions.getQueue(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 1b7416669e4..131fff58804 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -2266,7 +2266,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi /** * Should the memstore be flushed now */ - boolean shouldFlush(final StringBuffer whyFlush) { + boolean shouldFlush(final StringBuilder whyFlush) { whyFlush.setLength(0); // This is a rough measure. if (this.maxFlushedSeqId > 0 @@ -8299,7 +8299,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi //// method for debugging tests void throwException(String title, String regionName) { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); buf.append(title + ", "); buf.append(getRegionInfo().toString()); buf.append(getRegionInfo().isMetaRegion() ? " meta region " : " "); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 192c2e9ec53..cb0632d7657 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -1753,7 +1753,7 @@ public class HRegionServer extends HasThread implements @Override protected void chore() { - final StringBuffer whyFlush = new StringBuffer(); + final StringBuilder whyFlush = new StringBuilder(); for (HRegion r : this.server.onlineRegions.values()) { if (r == null) continue; if (r.shouldFlush(whyFlush)) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java index 3aa3843a238..c518ece18fb 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java @@ -835,7 +835,7 @@ public class ReplicationSourceManager implements ReplicationListener { * Get a string representation of all the sources' metrics */ public String getStats() { - StringBuffer stats = new StringBuffer(); + StringBuilder stats = new StringBuilder(); for (ReplicationSourceInterface source : sources) { stats.append("Normal source for cluster " + source.getPeerId() + ": "); stats.append(source.getStats() + "\n"); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java index 89f782402e8..c4e9a0a7c87 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestMasterOperationsForRegionReplicas.java @@ -287,7 +287,7 @@ public class TestMasterOperationsForRegionReplicas { } private String printRegions(List regions) { - StringBuffer strBuf = new StringBuffer(); + StringBuilder strBuf = new StringBuilder(); for (RegionInfo r : regions) { strBuf.append(" ____ " + r.toString()); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/MobTestUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/MobTestUtil.java index 3ecc57875be..76cb6645966 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/MobTestUtil.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/mob/MobTestUtil.java @@ -40,7 +40,7 @@ public class MobTestUtil { protected static String generateRandomString(int demoLength) { String base = "abcdefghijklmnopqrstuvwxyz"; Random random = new Random(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); for (int i = 0; i < demoLength; i++) { int number = random.nextInt(base.length()); sb.append(base.charAt(number)); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java index 6451d422e1f..0a0bf5d720d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestDefaultMemStore.java @@ -928,7 +928,7 @@ public class TestDefaultMemStore { p.add(KeyValueTestUtil.create("r", cf, "q", 100, "v")); region.put(p); edge.setCurrentTimeMillis(1234 + 100); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); assertTrue(!region.shouldFlush(sb)); edge.setCurrentTimeMillis(1234 + 10000); assertTrue(region.shouldFlush(sb) == expected); @@ -966,7 +966,7 @@ public class TestDefaultMemStore { wFactory.getWAL(hri.getEncodedNameAsBytes(), hri.getTable().getNamespace())); addRegionToMETA(meta, r); edge.setCurrentTimeMillis(1234 + 100); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); assertTrue(meta.shouldFlush(sb) == false); edge.setCurrentTimeMillis(edge.currentTime() + HRegion.SYSTEM_CACHE_FLUSH_INTERVAL + 1); assertTrue(meta.shouldFlush(sb) == true); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/SecureTestUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/SecureTestUtil.java index a43c792f5be..e477026bf30 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/SecureTestUtil.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/SecureTestUtil.java @@ -85,7 +85,7 @@ public class SecureTestUtil { // the superuser list or security won't function properly. We expect the // HBase service account(s) to have superuser privilege. String currentUser = User.getCurrent().getName(); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); sb.append("admin,"); sb.append(currentUser); // Assumes we won't ever have a minicluster with more than 5 slaves