hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject git commit: HBASE-12096 In ZKSplitLog Coordination and AggregateImplementation replace enhaced for statements with basic for statement to avoid unnecessary object allocation
Date Tue, 30 Sep 2014 15:11:18 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 2ce0884ac -> f719b57f7


HBASE-12096 In ZKSplitLog Coordination and AggregateImplementation replace enhaced for statements
with basic for statement to avoid unnecessary object allocation


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

Branch: refs/heads/branch-1
Commit: f719b57f7668a436ffe3df826cb2187df248e552
Parents: 2ce0884
Author: stack <stack@apache.org>
Authored: Tue Sep 30 08:10:42 2014 -0700
Committer: stack <stack@apache.org>
Committed: Tue Sep 30 08:11:10 2014 -0700

----------------------------------------------------------------------
 .../ZKSplitLogManagerCoordination.java          | 40 +++++++++++++-------
 .../ZkSplitLogWorkerCoordination.java           |  7 ++--
 .../coprocessor/AggregateImplementation.java    | 29 ++++++++------
 3 files changed, 49 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/f719b57f/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZKSplitLogManagerCoordination.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZKSplitLogManagerCoordination.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZKSplitLogManagerCoordination.java
index 9876187..07986f2 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZKSplitLogManagerCoordination.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZKSplitLogManagerCoordination.java
@@ -152,8 +152,9 @@ public class ZKSplitLogManagerCoordination extends ZooKeeperListener implements
     try {
       List<String> tasks = ZKUtil.listChildrenNoWatch(watcher, watcher.splitLogZNode);
       if (tasks != null) {
-        for (String t : tasks) {
-          if (!ZKSplitLog.isRescanNode(watcher, t)) {
+        int listSize = tasks.size();
+        for (int i = 0; i < listSize; i++) {
+          if (!ZKSplitLog.isRescanNode(watcher, tasks.get(i))) {
             count++;
           }
         }
@@ -302,8 +303,9 @@ public class ZKSplitLogManagerCoordination extends ZooKeeperListener implements
     try {
       List<String> tasks = ZKUtil.listChildrenNoWatch(watcher, watcher.splitLogZNode);
       if (tasks != null) {
-        for (String t : tasks) {
-          if (!ZKSplitLog.isRescanNode(watcher, t)) {
+        int listSize = tasks.size();
+        for (int i = 0; i < listSize; i++) {
+          if (!ZKSplitLog.isRescanNode(watcher, tasks.get(i))) {
             count++;
           }
         }
@@ -319,7 +321,9 @@ public class ZKSplitLogManagerCoordination extends ZooKeeperListener implements
         // remove recovering regions which doesn't have any RS associated with it
         List<String> regions = ZKUtil.listChildrenNoWatch(watcher, watcher.recoveringRegionsZNode);
         if (regions != null) {
-          for (String region : regions) {
+          int listSize = regions.size();
+          for (int i = 0; i < listSize; i++) {
+            String region = regions.get(i);
             if (isMetaRecovery != null) {
               if ((isMetaRecovery && !region.equalsIgnoreCase(metaEncodeRegionName))
                   || (!isMetaRecovery && region.equalsIgnoreCase(metaEncodeRegionName)))
{
@@ -337,7 +341,9 @@ public class ZKSplitLogManagerCoordination extends ZooKeeperListener implements
             if (recoveredServerNameSet.containsAll(failedServers)) {
               ZKUtil.deleteNodeRecursively(watcher, nodePath);
             } else {
-              for (String failedServer : failedServers) {
+              listSize = failedServers.size();
+              for (int j = 0; j < listSize; j++) {
+                String failedServer = failedServers.get(j);
                 if (recoveredServerNameSet.contains(failedServer)) {
                   String tmpPath = ZKUtil.joinZNode(nodePath, failedServer);
                   ZKUtil.deleteNode(watcher, tmpPath);
@@ -576,7 +582,9 @@ public class ZKSplitLogManagerCoordination extends ZooKeeperListener implements
       return;
     }
     int rescan_nodes = 0;
-    for (String path : orphans) {
+    int listSize = orphans.size();
+    for (int i = 0; i < listSize; i++) {
+      String path = orphans.get(i);
       String nodepath = ZKUtil.joinZNode(watcher.splitLogZNode, path);
       if (ZKSplitLog.isRescanNode(watcher, nodepath)) {
         rescan_nodes++;
@@ -682,7 +690,9 @@ public class ZKSplitLogManagerCoordination extends ZooKeeperListener implements
     try {
       List<String> tasks = ZKUtil.listChildrenNoWatch(watcher, watcher.splitLogZNode);
       if (tasks != null) {
-        for (String t : tasks) {
+        int listSize = tasks.size();
+        for (int i = 0; i < listSize; i++) {
+          String t = tasks.get(i);
           byte[] data;
           try {
             data = ZKUtil.getData(this.watcher, ZKUtil.joinZNode(watcher.splitLogZNode, t));
@@ -714,16 +724,18 @@ public class ZKSplitLogManagerCoordination extends ZooKeeperListener
implements
       // remove recovering regions which doesn't have any RS associated with it
       List<String> regions = ZKUtil.listChildrenNoWatch(watcher, watcher.recoveringRegionsZNode);
       if (regions != null) {
-        for (String region : regions) {
-          String nodePath = ZKUtil.joinZNode(watcher.recoveringRegionsZNode, region);
+        int listSize = regions.size();
+        for (int i = 0; i < listSize; i++) {
+          String nodePath = ZKUtil.joinZNode(watcher.recoveringRegionsZNode, regions.get(i));
           List<String> regionFailedServers = ZKUtil.listChildrenNoWatch(watcher, nodePath);
           if (regionFailedServers == null || regionFailedServers.isEmpty()) {
             ZKUtil.deleteNode(watcher, nodePath);
             continue;
           }
           boolean needMoreRecovery = false;
-          for (String tmpFailedServer : regionFailedServers) {
-            if (knownFailedServers.contains(tmpFailedServer)) {
+          listSize = regionFailedServers.size();
+          for (i = 0; i < listSize; i++) {
+            if (knownFailedServers.contains(regionFailedServers.get(i))) {
               needMoreRecovery = true;
               break;
             }
@@ -787,7 +799,9 @@ public class ZKSplitLogManagerCoordination extends ZooKeeperListener implements
           hasSplitLogTask = true;
           if (isForInitialization) {
             // during initialization, try to get recovery mode from splitlogtask
-            for (String task : tasks) {
+            int listSize = tasks.size();
+            for (int i = 0; i < listSize; i++) {
+              String task = tasks.get(i);
               try {
                 byte[] data =
                     ZKUtil.getData(this.watcher, ZKUtil.joinZNode(watcher.splitLogZNode,
task));

http://git-wip-us.apache.org/repos/asf/hbase/blob/f719b57f/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZkSplitLogWorkerCoordination.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZkSplitLogWorkerCoordination.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZkSplitLogWorkerCoordination.java
index 0404f04..2945565 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZkSplitLogWorkerCoordination.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coordination/ZkSplitLogWorkerCoordination.java
@@ -450,9 +450,10 @@ public class ZkSplitLogWorkerCoordination extends ZooKeeperListener implements
               // Make a local copy to prevent ConcurrentModificationException when other
threads
               // modify recoveringRegions
               List<String> tmpCopy = new ArrayList<String>(recoveringRegions.keySet());
-              for (String region : tmpCopy) {
-                String nodePath =
-                    ZKUtil.joinZNode(watcher.recoveringRegionsZNode, region);
+              int listSize = tmpCopy.size();
+              for (int i = 0; i < listSize; i++) {
+                String region = tmpCopy.get(i);
+                String nodePath = ZKUtil.joinZNode(watcher.recoveringRegionsZNode, region);
                 try {
                   if (ZKUtil.checkExists(watcher, nodePath) == -1) {
                     HRegion r = recoveringRegions.remove(region);

http://git-wip-us.apache.org/repos/asf/hbase/blob/f719b57f/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/AggregateImplementation.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/AggregateImplementation.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/AggregateImplementation.java
index edaca1c..1db5671 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/AggregateImplementation.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/AggregateImplementation.java
@@ -92,8 +92,9 @@ extends AggregateService implements CoprocessorService, Coprocessor {
       boolean hasMoreRows = false;
       do {
         hasMoreRows = scanner.next(results);
-        for (Cell kv : results) {
-          temp = ci.getValue(colFamily, qualifier, kv);
+        int listSize = results.size();
+        for (int i = 0; i < listSize; i++) {
+          temp = ci.getValue(colFamily, qualifier, results.get(i));
           max = (max == null || (temp != null && ci.compare(temp, max) > 0)) ?
temp : max;
         }
         results.clear();
@@ -145,8 +146,9 @@ extends AggregateService implements CoprocessorService, Coprocessor {
       boolean hasMoreRows = false;
       do {
         hasMoreRows = scanner.next(results);
-        for (Cell kv : results) {
-          temp = ci.getValue(colFamily, qualifier, kv);
+        int listSize = results.size();
+        for (int i = 0; i < listSize; i++) {
+          temp = ci.getValue(colFamily, qualifier, results.get(i));
           min = (min == null || (temp != null && ci.compare(temp, min) < 0)) ?
temp : min;
         }
         results.clear();
@@ -198,8 +200,9 @@ extends AggregateService implements CoprocessorService, Coprocessor {
       boolean hasMoreRows = false;
       do {
         hasMoreRows = scanner.next(results);
-        for (Cell kv : results) {
-          temp = ci.getValue(colFamily, qualifier, kv);
+        int listSize = results.size();
+        for (int i = 0; i < listSize; i++) {
+          temp = ci.getValue(colFamily, qualifier, results.get(i));
           if (temp != null)
             sumVal = ci.add(sumVal, ci.castToReturnType(temp));
         }
@@ -310,9 +313,10 @@ extends AggregateService implements CoprocessorService, Coprocessor {
       do {
         results.clear();
         hasMoreRows = scanner.next(results);
-        for (Cell kv : results) {
+        int listSize = results.size();
+        for (int i = 0; i < listSize; i++) {
           sumVal = ci.add(sumVal, ci.castToReturnType(ci.getValue(colFamily,
-              qualifier, kv)));
+              qualifier, results.get(i))));
         }
         rowCountVal++;
       } while (hasMoreRows);
@@ -370,9 +374,10 @@ extends AggregateService implements CoprocessorService, Coprocessor {
       do {
         tempVal = null;
         hasMoreRows = scanner.next(results);
-        for (Cell kv : results) {
+        int listSize = results.size();
+        for (int i = 0; i < listSize; i++) {
           tempVal = ci.add(tempVal, ci.castToReturnType(ci.getValue(colFamily,
-              qualifier, kv)));
+              qualifier, results.get(i))));
         }
         results.clear();
         sumVal = ci.add(sumVal, tempVal);
@@ -436,7 +441,9 @@ extends AggregateService implements CoprocessorService, Coprocessor {
         tempVal = null;
         tempWeight = null;
         hasMoreRows = scanner.next(results);
-        for (Cell kv : results) {
+        int listSize = results.size();
+        for (int i = 0; i < listSize; i++) {
+          Cell kv = results.get(i);
           tempVal = ci.add(tempVal, ci.castToReturnType(ci.getValue(colFamily,
               valQualifier, kv)));
           if (weightQualifier != null) {


Mime
View raw message