accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject svn commit: r1382566 - /accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/test/randomwalk/sequential/BatchVerify.java
Date Sun, 09 Sep 2012 20:17:12 GMT
Author: elserj
Date: Sun Sep  9 20:17:11 2012
New Revision: 1382566

URL: http://svn.apache.org/viewvc?rev=1382566&view=rev
Log:
ACCUMULO-642 Applying patch in 1.4 branch to ensure the BatchScanner is closed.

Modified:
    accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/test/randomwalk/sequential/BatchVerify.java

Modified: accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/test/randomwalk/sequential/BatchVerify.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/test/randomwalk/sequential/BatchVerify.java?rev=1382566&r1=1382565&r2=1382566&view=diff
==============================================================================
--- accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/test/randomwalk/sequential/BatchVerify.java
(original)
+++ accumulo/branches/1.4/src/server/src/main/java/org/apache/accumulo/server/test/randomwalk/sequential/BatchVerify.java
Sun Sep  9 20:17:11 2012
@@ -52,74 +52,78 @@ public class BatchVerify extends Test {
     Connector conn = state.getConnector();
     BatchScanner scanner = conn.createBatchScanner(state.getString("seqTableName"), new Authorizations(),
2);
     
-    int count = 0;
-    List<Range> ranges = new ArrayList<Range>();
-    while (count < numVerify) {
-      int rangeStart = rand.nextInt(numWrites);
-      int rangeEnd = rangeStart + 99;
-      if (rangeEnd > (numWrites - 1)) {
-        rangeEnd = numWrites - 1;
-      }
-      count += (rangeEnd - rangeStart) + 1;
-      ranges.add(new Range(new Text(String.format("%010d", rangeStart)), new Text(String.format("%010d",
rangeEnd))));
-    }
-    
-    ranges = Range.mergeOverlapping(ranges);
-    Collections.sort(ranges);
-    
-    if (count == 0 || ranges.size() == 0)
-      return;
-    
-    log.debug(String.format("scanning %d rows in the following %d ranges:", count, ranges.size()));
-    for (Range r : ranges) {
-      log.debug(r);
-    }
-    
-    scanner.setRanges(ranges);
-    
-    List<Key> keys = new ArrayList<Key>();
-    for (Entry<Key,Value> entry : scanner) {
-      keys.add(entry.getKey());
-    }
-    
-    log.debug("scan returned " + keys.size() + " rows. now verifying...");
-    
-    Collections.sort(keys);
-    
-    Iterator<Key> iterator = keys.iterator();
-    int curKey = Integer.parseInt(iterator.next().getRow().toString());
-    boolean done = false;
-    for (Range r : ranges) {
-      int start = Integer.parseInt(r.getStartKey().getRow().toString());
-      int end = Integer.parseInt(String.copyValueOf(r.getEndKey().getRow().toString().toCharArray(),
0, 10));
-      for (int i = start; i <= end; i++) {
-        
-        if (done) {
-          log.error("missing key " + i);
-          break;
+    try {
+      int count = 0;
+      List<Range> ranges = new ArrayList<Range>();
+      while (count < numVerify) {
+        int rangeStart = rand.nextInt(numWrites);
+        int rangeEnd = rangeStart + 99;
+        if (rangeEnd > (numWrites - 1)) {
+          rangeEnd = numWrites - 1;
         }
-        
-        while (curKey < i) {
-          log.error("extra key " + curKey);
-          if (iterator.hasNext() == false) {
-            done = true;
+        count += (rangeEnd - rangeStart) + 1;
+        ranges.add(new Range(new Text(String.format("%010d", rangeStart)), new Text(String.format("%010d",
rangeEnd))));
+      }
+      
+      ranges = Range.mergeOverlapping(ranges);
+      Collections.sort(ranges);
+      
+      if (count == 0 || ranges.size() == 0)
+        return;
+      
+      log.debug(String.format("scanning %d rows in the following %d ranges:", count, ranges.size()));
+      for (Range r : ranges) {
+        log.debug(r);
+      }
+      
+      scanner.setRanges(ranges);
+      
+      List<Key> keys = new ArrayList<Key>();
+      for (Entry<Key,Value> entry : scanner) {
+        keys.add(entry.getKey());
+      }
+      
+      log.debug("scan returned " + keys.size() + " rows. now verifying...");
+      
+      Collections.sort(keys);
+      
+      Iterator<Key> iterator = keys.iterator();
+      int curKey = Integer.parseInt(iterator.next().getRow().toString());
+      boolean done = false;
+      for (Range r : ranges) {
+        int start = Integer.parseInt(r.getStartKey().getRow().toString());
+        int end = Integer.parseInt(String.copyValueOf(r.getEndKey().getRow().toString().toCharArray(),
0, 10));
+        for (int i = start; i <= end; i++) {
+          
+          if (done) {
+            log.error("missing key " + i);
             break;
           }
-          curKey = Integer.parseInt(iterator.next().getRow().toString());
-        }
-        
-        if (curKey > i) {
-          log.error("missing key " + i);
-        }
-        
-        if (iterator.hasNext()) {
-          curKey = Integer.parseInt(iterator.next().getRow().toString());
-        } else {
-          done = true;
+          
+          while (curKey < i) {
+            log.error("extra key " + curKey);
+            if (iterator.hasNext() == false) {
+              done = true;
+              break;
+            }
+            curKey = Integer.parseInt(iterator.next().getRow().toString());
+          }
+          
+          if (curKey > i) {
+            log.error("missing key " + i);
+          }
+          
+          if (iterator.hasNext()) {
+            curKey = Integer.parseInt(iterator.next().getRow().toString());
+          } else {
+            done = true;
+          }
         }
       }
+      
+      log.debug("verify is now complete");
+    } finally {
+      scanner.close();
     }
-    
-    log.debug("verify is now complete");
   }
 }



Mime
View raw message