hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r945418 - in /hadoop/hbase/trunk: ./ core/src/main/java/org/apache/hadoop/hbase/regionserver/ core/src/test/java/org/apache/hadoop/hbase/regionserver/
Date Mon, 17 May 2010 23:11:14 GMT
Author: stack
Date: Mon May 17 23:11:13 2010
New Revision: 945418

URL: http://svn.apache.org/viewvc?rev=945418&view=rev
Log:
HBASE-2520 Cleanup arrays vs Lists of scanners

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
    hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/KeyValueHeap.java
    hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java
    hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/MinorCompactingStoreScanner.java
    hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java
    hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java
    hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
    hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/KeyValueScanFixture.java
    hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeyValueHeap.java
    hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStore.java
    hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestMinorCompactingStoreScanner.java
    hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Mon May 17 23:11:13 2010
@@ -595,6 +595,7 @@ Release 0.21.0 - Unreleased
                (Nicolas Spiegelberg via Stack)
    HBASE-2340  Add end-to-end test of sync/flush (Forward-port from branch)
    HBASE-2555  Get rid of HColumnDescriptor.MAPFILE_INDEX_INTERVAL
+   HBASE-2520  Cleanup arrays vs Lists of scanners (Todd Lipcon via Stack)
 
 
   NEW FEATURES

Modified: hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
(original)
+++ hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
Mon May 17 23:11:13 2010
@@ -1962,8 +1962,7 @@ public class HRegion implements HConstan
         Store store = stores.get(entry.getKey());
         scanners.add(store.getScanner(theScan, entry.getValue()));
       }
-      this.storeHeap =
-        new KeyValueHeap(scanners.toArray(new KeyValueScanner[0]), comparator);
+      this.storeHeap = new KeyValueHeap(scanners, comparator);
     }
 
     private void resetFilters() {

Modified: hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/KeyValueHeap.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/KeyValueHeap.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/KeyValueHeap.java
(original)
+++ hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/KeyValueHeap.java
Mon May 17 23:11:13 2010
@@ -51,9 +51,9 @@ public class KeyValueHeap implements Key
    * @param scanners
    * @param comparator
    */
-  public KeyValueHeap(KeyValueScanner [] scanners, KVComparator comparator) {
+  public KeyValueHeap(List<KeyValueScanner> scanners, KVComparator comparator) {
     this.comparator = new KVScannerComparator(comparator);
-    this.heap = new PriorityQueue<KeyValueScanner>(scanners.length,
+    this.heap = new PriorityQueue<KeyValueScanner>(scanners.size(),
         this.comparator);
     for (KeyValueScanner scanner : scanners) {
       if (scanner.peek() != null) {
@@ -210,4 +210,4 @@ public class KeyValueHeap implements Key
   public PriorityQueue<KeyValueScanner> getHeap() {
     return this.heap;
   }
-}
\ No newline at end of file
+}

Modified: hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java
(original)
+++ hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/MemStore.java
Mon May 17 23:11:13 2010
@@ -25,6 +25,7 @@ import java.lang.management.ManagementFa
 import java.lang.management.RuntimeMXBean;
 import java.rmi.UnexpectedException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.NavigableSet;
@@ -379,12 +380,11 @@ public class MemStore implements HeapSiz
   /**
    * @return scanner on memstore and snapshot in this order.
    */
-  KeyValueScanner [] getScanners() {
+  List<KeyValueScanner> getScanners() {
     this.lock.readLock().lock();
     try {
-      KeyValueScanner [] scanners = new KeyValueScanner[1];
-      scanners[0] = new MemStoreScanner();
-      return scanners;
+      return Collections.<KeyValueScanner>singletonList(
+          new MemStoreScanner());
     } finally {
       this.lock.readLock().unlock();
     }

Modified: hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/MinorCompactingStoreScanner.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/MinorCompactingStoreScanner.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/MinorCompactingStoreScanner.java
(original)
+++ hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/MinorCompactingStoreScanner.java
Mon May 17 23:11:13 2010
@@ -38,7 +38,7 @@ public class MinorCompactingStoreScanner
   private KeyValue.KVComparator comparator;
 
   MinorCompactingStoreScanner(Store store,
-                              KeyValueScanner [] scanners) {
+                              List<KeyValueScanner> scanners) {
     comparator = store.comparator;
     KeyValue firstKv = KeyValue.createFirstOnRow(HConstants.EMPTY_START_ROW);
     for (KeyValueScanner scanner : scanners ) {
@@ -49,7 +49,7 @@ public class MinorCompactingStoreScanner
   }
 
   MinorCompactingStoreScanner(String cfName, KeyValue.KVComparator comparator,
-                              KeyValueScanner [] scanners) {
+                              List<KeyValueScanner> scanners) {
     this.comparator = comparator;
 
     KeyValue firstKv = KeyValue.createFirstOnRow(HConstants.EMPTY_START_ROW);

Modified: hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java
(original)
+++ hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/Store.java
Mon May 17 23:11:13 2010
@@ -880,16 +880,8 @@ public class Store implements HConstants
       final boolean majorCompaction, final long maxId)
   throws IOException {
     // For each file, obtain a scanner:
-    KeyValueScanner [] scanners = new KeyValueScanner[filesToCompact.size()];
-    for (int i = 0; i < filesToCompact.size(); ++i) {
-      Reader r = filesToCompact.get(i).getReader();
-      if (r == null) {
-        LOG.warn("StoreFile " + filesToCompact.get(i) + " has a null Reader");
-        continue;
-      }
-      // Instantiate HFile.Reader.Scanner to not cache blocks and not use pread
-      scanners[i] = new StoreFileScanner(r.getScanner(false, false));
-    }
+    List<KeyValueScanner> scanners = StoreFileScanner.getScannersForStoreFiles(
+        filesToCompact, false, false);
 
     // Make the instantiation lazy in case compaction produces no product; i.e.
     // where all source cells are expired or deleted.
@@ -904,9 +896,7 @@ public class Store implements HConstants
         // since scanner.next() can return 'false' but still be delivering data,
         // we have to use a do/while loop.
         ArrayList<KeyValue> kvs = new ArrayList<KeyValue>();
-        boolean more = true;
-        while (more) {
-          more = scanner.next(kvs);
+        while (scanner.next(kvs)) {
           // output to writer:
           for (KeyValue kv : kvs) {
             if (writer == null) {
@@ -1003,6 +993,7 @@ public class Store implements HConstants
         }
 
         // WARN ugly hack here, but necessary sadly.
+        // TODO why is this necessary? need a comment here if it's unintuitive!
         ReadWriteConsistencyControl.resetThreadReadPoint(region.getRWCC());
         
         // Tell observers that list of StoreFiles has changed.
@@ -1359,7 +1350,7 @@ public class Store implements HConstants
     return size;
   }
 
-  /*
+  /**
    * Datastructure that holds size and row to split a file around.
    * TODO: Take a KeyValue rather than row.
    */

Modified: hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java
(original)
+++ hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFileScanner.java
Mon May 17 23:11:13 2010
@@ -20,15 +20,23 @@
 
 package org.apache.hadoop.hbase.regionserver;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.io.hfile.HFileScanner;
+import org.apache.hadoop.hbase.io.hfile.HFile.Reader;
+
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 
 /**
  * A KeyValue scanner that iterates over a single HFile
  */
 class StoreFileScanner implements KeyValueScanner {
+  static final Log LOG = LogFactory.getLog(Store.class);
 
   private HFileScanner hfs;
   private KeyValue cur = null;
@@ -37,10 +45,33 @@ class StoreFileScanner implements KeyVal
    * Implements a {@link KeyValueScanner} on top of the specified {@link HFileScanner}
    * @param hfs HFile scanner
    */
-  public StoreFileScanner(HFileScanner hfs) {
+  private StoreFileScanner(HFileScanner hfs) {
     this.hfs = hfs;
   }
 
+  /**
+   * Return an array of scanners corresponding to the given
+   * set of store files.
+   */
+  public static List<KeyValueScanner> getScannersForStoreFiles(
+      Collection<StoreFile> filesToCompact,
+      boolean cacheBlocks,
+      boolean usePread) {
+    List<KeyValueScanner> scanners =
+      new ArrayList<KeyValueScanner>(filesToCompact.size());
+    for (StoreFile file : filesToCompact) {
+      Reader r = file.getReader();
+      if (r == null) {
+        // TODO why can this happen? this seems like something worth
+        // throwing an exception over!
+        LOG.error("StoreFile " + file + " has a null Reader");
+        continue;
+      }
+      scanners.add(new StoreFileScanner(r.getScanner(cacheBlocks, usePread)));
+    }
+    return scanners;
+  }
+  
   public String toString() {
     return "StoreFileScanner[" + hfs.toString() + ", cur=" + cur + "]";
   }
@@ -104,4 +135,4 @@ class StoreFileScanner implements KeyVal
     // Seeked to the exact key
     return true;
   }
-}
\ No newline at end of file
+}

Modified: hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
(original)
+++ hadoop/hbase/trunk/core/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java
Mon May 17 23:11:13 2010
@@ -24,8 +24,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.client.Scan;
-import org.apache.hadoop.hbase.io.hfile.HFile;
-import org.apache.hadoop.hbase.io.hfile.HFileScanner;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -72,8 +70,7 @@ class StoreScanner implements KeyValueSc
     }
 
     // Combine all seeked scanners with a heap
-    heap = new KeyValueHeap(
-      scanners.toArray(new KeyValueScanner[scanners.size()]), store.comparator);
+    heap = new KeyValueHeap(scanners, store.comparator);
 
     this.store.addChangedReaderObserver(this);
   }
@@ -86,7 +83,7 @@ class StoreScanner implements KeyValueSc
    * @param scan the spec
    * @param scanners ancilliary scanners
    */
-  StoreScanner(Store store, Scan scan, KeyValueScanner [] scanners) {
+  StoreScanner(Store store, Scan scan, List<KeyValueScanner> scanners) {
     this.store = store;
     this.cacheBlocks = false;
     this.isGet = false;
@@ -107,7 +104,7 @@ class StoreScanner implements KeyValueSc
   StoreScanner(final Scan scan, final byte [] colFamily, final long ttl,
       final KeyValue.KVComparator comparator,
       final NavigableSet<byte[]> columns,
-      final KeyValueScanner [] scanners) {
+      final List<KeyValueScanner> scanners) {
     this.store = null;
     this.isGet = false;
     this.cacheBlocks = scan.getCacheBlocks();
@@ -125,11 +122,13 @@ class StoreScanner implements KeyValueSc
    * @return List of scanners ordered properly.
    */
   private List<KeyValueScanner> getScanners() {
-    List<KeyValueScanner> scanners = getStoreFileScanners();
-    KeyValueScanner [] memstorescanners = this.store.memstore.getScanners();
-    for (int i = memstorescanners.length - 1; i >= 0; i--) {
-      scanners.add(memstorescanners[i]);
-    }
+    // First the store file scanners
+    Map<Long, StoreFile> map = this.store.getStorefiles().descendingMap();
+    List<KeyValueScanner> scanners =
+      StoreFileScanner.getScannersForStoreFiles(map.values(),
+      cacheBlocks, isGet);
+    // Then the memstore scanners
+    scanners.addAll(this.store.memstore.getScanners());
     return scanners;
   }
 
@@ -231,27 +230,6 @@ class StoreScanner implements KeyValueSc
     return next(outResult, -1);
   }
 
-  private List<KeyValueScanner> getStoreFileScanners() {
-    List<HFileScanner> s =
-      new ArrayList<HFileScanner>(this.store.getStorefilesCount());
-    Map<Long, StoreFile> map = this.store.getStorefiles().descendingMap();
-    for(StoreFile sf : map.values()) {
-      HFile.Reader r = sf.getReader();
-      if (r == null) {
-        LOG.warn("StoreFile " + sf + " has null Reader");
-        continue;
-      }
-      // If isGet, use pread, else false, dont use pread
-      s.add(r.getScanner(this.cacheBlocks, isGet));
-    }
-    List<KeyValueScanner> scanners =
-      new ArrayList<KeyValueScanner>(s.size()+1);
-    for(HFileScanner hfs : s) {
-      scanners.add(new StoreFileScanner(hfs));
-    }
-    return scanners;
-  }
-
   // Implementation of ChangedReadersObserver
   public synchronized void updateReaders() throws IOException {
     if (this.closing) return;
@@ -269,8 +247,7 @@ class StoreScanner implements KeyValueSc
     }
 
     // Combine all seeked scanners with a heap
-    heap = new KeyValueHeap(
-        scanners.toArray(new KeyValueScanner[scanners.size()]), store.comparator);
+    heap = new KeyValueHeap(scanners, store.comparator);
 
     // Reset the state of the Query Matcher and set to top row
     matcher.reset();

Modified: hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/KeyValueScanFixture.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/KeyValueScanFixture.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/KeyValueScanFixture.java
(original)
+++ hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/KeyValueScanFixture.java
Mon May 17 23:11:13 2010
@@ -26,6 +26,7 @@ import org.apache.hadoop.hbase.KeyValue;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Collections;
+import java.util.List;
 
 /**
  * A fixture that implements and presents a KeyValueScanner.
@@ -50,6 +51,15 @@ public class KeyValueScanFixture impleme
     Collections.sort(data, this.comparator);
   }
 
+  public static List<KeyValueScanner> scanFixture(KeyValue[] ... kvArrays) {
+    ArrayList<KeyValueScanner> scanners = new ArrayList<KeyValueScanner>();
+    for (KeyValue [] kvs : kvArrays) {
+      scanners.add(new KeyValueScanFixture(KeyValue.COMPARATOR, kvs));
+    }
+    return scanners;
+  }
+
+
   @Override
   public KeyValue peek() {
     return this.current;

Modified: hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeyValueHeap.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeyValueHeap.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeyValueHeap.java
(original)
+++ hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestKeyValueHeap.java
Mon May 17 23:11:13 2010
@@ -35,7 +35,7 @@ public class TestKeyValueHeap extends HB
 implements HConstants {
   private static final boolean PRINT = false;
 
-  List<Scanner> scanners = new ArrayList<Scanner>();
+  List<KeyValueScanner> scanners = new ArrayList<KeyValueScanner>();
 
   private byte [] row1;
   private byte [] fam1;
@@ -102,7 +102,7 @@ implements HConstants {
 
     //Creating KeyValueHeap
     KeyValueHeap kvh =
-      new KeyValueHeap(scanners.toArray(new Scanner[0]), KeyValue.COMPARATOR);
+      new KeyValueHeap(scanners, KeyValue.COMPARATOR);
 
     List<KeyValue> actual = new ArrayList<KeyValue>();
     while(kvh.peek() != null){
@@ -155,7 +155,7 @@ implements HConstants {
 
     //Creating KeyValueHeap
     KeyValueHeap kvh =
-      new KeyValueHeap(scanners.toArray(new Scanner[0]), KeyValue.COMPARATOR);
+      new KeyValueHeap(scanners, KeyValue.COMPARATOR);
 
     KeyValue seekKv = new KeyValue(row2, fam1, null, null);
     kvh.seek(seekKv);
@@ -200,13 +200,12 @@ implements HConstants {
     scanners.add(new Scanner(l4));
 
     //Creating KeyValueHeap
-    KeyValueHeap kvh =
-      new KeyValueHeap(scanners.toArray(new Scanner[0]), KeyValue.COMPARATOR);
+    KeyValueHeap kvh = new KeyValueHeap(scanners, KeyValue.COMPARATOR);
 
     while(kvh.next() != null);
 
-    for(Scanner scanner : scanners) {
-      assertTrue(scanner.isClosed());
+    for(KeyValueScanner scanner : scanners) {
+      assertTrue(((Scanner)scanner).isClosed());
     }
   }
 

Modified: hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStore.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStore.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStore.java
(original)
+++ hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStore.java
Mon May 17 23:11:13 2010
@@ -76,7 +76,7 @@ public class TestMemStore extends TestCa
    */
   public void testScanAcrossSnapshot() throws IOException {
     int rowCount = addRows(this.memstore);
-    KeyValueScanner [] memstorescanners = this.memstore.getScanners();
+    List<KeyValueScanner> memstorescanners = this.memstore.getScanners();
     Scan scan = new Scan();
     List<KeyValue> result = new ArrayList<KeyValue>();
     ReadWriteConsistencyControl.resetThreadReadPoint(rwcc);
@@ -95,8 +95,8 @@ public class TestMemStore extends TestCa
       s.close();
     }
     assertEquals(rowCount, count);
-    for (int i = 0; i < memstorescanners.length; i++) {
-      memstorescanners[0].close();
+    for (KeyValueScanner scanner : memstorescanners) {
+      scanner.close();
     }
 
     ReadWriteConsistencyControl.resetThreadReadPoint(rwcc);
@@ -123,8 +123,8 @@ public class TestMemStore extends TestCa
       s.close();
     }
     assertEquals(rowCount, count);
-    for (int i = 0; i < memstorescanners.length; i++) {
-      memstorescanners[0].close();
+    for (KeyValueScanner scanner : memstorescanners) {
+      scanner.close();
     }
     memstorescanners = this.memstore.getScanners();
     // Assert that new values are seen in kvset as we scan.
@@ -190,9 +190,9 @@ public class TestMemStore extends TestCa
 
   private void verifyScanAcrossSnapshot2(KeyValue kv1, KeyValue kv2) {
     ReadWriteConsistencyControl.resetThreadReadPoint(rwcc);
-    KeyValueScanner[] memstorescanners = this.memstore.getScanners();
-    assertEquals(1, memstorescanners.length);
-    final KeyValueScanner scanner = memstorescanners[0];
+    List<KeyValueScanner> memstorescanners = this.memstore.getScanners();
+    assertEquals(1, memstorescanners.size());
+    final KeyValueScanner scanner = memstorescanners.get(0);
     scanner.seek(KeyValue.createFirstOnRow(HConstants.EMPTY_START_ROW));
     assertEquals(kv1, scanner.next());
     assertEquals(kv2, scanner.next());
@@ -224,14 +224,14 @@ public class TestMemStore extends TestCa
     memstore.add(kv1);
 
     ReadWriteConsistencyControl.resetThreadReadPoint(rwcc);
-    KeyValueScanner[] s = this.memstore.getScanners();
-    assertScannerResults(s[0], new KeyValue[]{});
+    KeyValueScanner s = this.memstore.getScanners().get(0);
+    assertScannerResults(s, new KeyValue[]{});
 
     rwcc.completeMemstoreInsert(w);
 
     ReadWriteConsistencyControl.resetThreadReadPoint(rwcc);
-    s = this.memstore.getScanners();
-    assertScannerResults(s[0], new KeyValue[]{kv1});
+    s = this.memstore.getScanners().get(0);
+    assertScannerResults(s, new KeyValue[]{kv1});
 
     w = rwcc.beginMemstoreInsert();
     KeyValue kv2 = new KeyValue(row, f, q2, v);
@@ -239,14 +239,14 @@ public class TestMemStore extends TestCa
     memstore.add(kv2);
 
     ReadWriteConsistencyControl.resetThreadReadPoint(rwcc);
-    s = this.memstore.getScanners();
-    assertScannerResults(s[0], new KeyValue[]{kv1});
+    s = this.memstore.getScanners().get(0);
+    assertScannerResults(s, new KeyValue[]{kv1});
 
     rwcc.completeMemstoreInsert(w);
 
     ReadWriteConsistencyControl.resetThreadReadPoint(rwcc);
-    s = this.memstore.getScanners();
-    assertScannerResults(s[0], new KeyValue[]{kv1, kv2});
+    s = this.memstore.getScanners().get(0);
+    assertScannerResults(s, new KeyValue[]{kv1, kv2});
   }
 
   private static class ReadOwnWritesTester extends Thread {
@@ -300,7 +300,7 @@ public class TestMemStore extends TestCa
         // Assert that we can read back
         ReadWriteConsistencyControl.resetThreadReadPoint(rwcc);
 
-        KeyValueScanner s = this.memstore.getScanners()[0];
+        KeyValueScanner s = this.memstore.getScanners().get(0);
         s.seek(kv);
 
         KeyValue ret = s.next();
@@ -429,7 +429,7 @@ public class TestMemStore extends TestCa
       InternalScanner scanner =
           new StoreScanner(new Scan(Bytes.toBytes(startRowId)), FAMILY,
               Integer.MAX_VALUE, this.memstore.comparator, null,
-              new KeyValueScanner[]{memstore.getScanners()[0]});
+              memstore.getScanners());
       List<KeyValue> results = new ArrayList<KeyValue>();
       for (int i = 0; scanner.next(results); i++) {
         int rowId = startRowId + i;
@@ -857,8 +857,7 @@ public class TestMemStore extends TestCa
 
   static void doScan(MemStore ms, int iteration) {
     long nanos = System.nanoTime();
-    KeyValueScanner [] ss = ms.getScanners();
-    KeyValueScanner s = ss[0];
+    KeyValueScanner s = ms.getScanners().get(0);
     s.seek(KeyValue.createFirstOnRow(new byte[]{}));
 
     System.out.println(iteration + " create/seek took: " + (System.nanoTime() - nanos)/1000);

Modified: hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestMinorCompactingStoreScanner.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestMinorCompactingStoreScanner.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestMinorCompactingStoreScanner.java
(original)
+++ hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestMinorCompactingStoreScanner.java
Mon May 17 23:11:13 2010
@@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.KeyValueT
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
+import static org.apache.hadoop.hbase.regionserver.KeyValueScanFixture.scanFixture;
 
 public class TestMinorCompactingStoreScanner extends TestCase {
 
@@ -45,9 +46,8 @@ public class TestMinorCompactingStoreSca
         KeyValueTestUtil.create("R1", "cf", "i", 11, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create("R2", "cf", "a", 11, KeyValue.Type.Put, "dont-care"),
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs);
+    
     InternalScanner scan =
         new MinorCompactingStoreScanner("cf", KeyValue.COMPARATOR, scanners);
     List<KeyValue> results = new ArrayList<KeyValue>();
@@ -77,9 +77,7 @@ public class TestMinorCompactingStoreSca
         KeyValueTestUtil.create("R1", "cf", "a", 10, KeyValue.Type.Delete, "dont-care"),
         KeyValueTestUtil.create("R1", "cf", "a", 10, KeyValue.Type.Put, "dont-care")
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs);
     InternalScanner scan =
         new MinorCompactingStoreScanner("cf", KeyValue.COMPARATOR, scanners);
     List<KeyValue> results = new ArrayList<KeyValue>();

Modified: hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java?rev=945418&r1=945417&r2=945418&view=diff
==============================================================================
--- hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java
(original)
+++ hadoop/hbase/trunk/core/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreScanner.java
Mon May 17 23:11:13 2010
@@ -28,9 +28,12 @@ import org.apache.hadoop.hbase.util.Byte
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.NavigableSet;
 import java.util.TreeSet;
+import static org.apache.hadoop.hbase.regionserver.KeyValueScanFixture.scanFixture;
 
 public class TestStoreScanner extends TestCase {
   private static final String CF_STR = "cf";
@@ -60,9 +63,10 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create(r1, CF_STR, "a", 4, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create(r1, CF_STR, "a", 5, KeyValue.Type.Put, "dont-care"),
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-      new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
-    };
+    List<KeyValueScanner> scanners = Arrays.<KeyValueScanner>asList(
+        new KeyValueScanner[] {
+            new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
+    });
     Scan scanSpec = new Scan(Bytes.toBytes(r1));
     scanSpec.setTimeRange(0, 6);
     scanSpec.setMaxVersions();
@@ -110,9 +114,10 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"),
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-      new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
-    };
+    List<KeyValueScanner> scanners = Arrays.asList(
+        new KeyValueScanner[] {
+            new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
+        });
 
     Scan scanSpec = new Scan(Bytes.toBytes("R1"));
     // this only uses maxVersions (default=1) and TimeRange (default=all)
@@ -140,10 +145,7 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create("R2", "cf", "a", 1, KeyValue.Type.Put, "dont-care")
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR,
-            kvs)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs);
 
     Scan scanSpec = new Scan(Bytes.toBytes("R1"));
     // this only uses maxVersions (default=1) and TimeRange (default=all)
@@ -175,9 +177,7 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Delete, "dont-care"),
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs);
     Scan scanSpec = new Scan(Bytes.toBytes("R1"));
     StoreScanner scan =
       new StoreScanner(scanSpec, CF, Long.MAX_VALUE, KeyValue.COMPARATOR,
@@ -198,9 +198,7 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.Delete, "dont-care"),
         KeyValueTestUtil.create("R2", "cf", "a", 20, KeyValue.Type.Put, "dont-care")
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs);
     Scan scanSpec = new Scan(Bytes.toBytes("R1"));
     StoreScanner scan =
       new StoreScanner(scanSpec, CF, Long.MAX_VALUE, KeyValue.COMPARATOR,
@@ -228,10 +226,8 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R1", "cf", "a", now-100, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care")
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs1),
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs2)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs1, kvs2);
+
     StoreScanner scan =
       new StoreScanner(new Scan(Bytes.toBytes("R1")), CF, Long.MAX_VALUE, KeyValue.COMPARATOR,
           getCols("a"), scanners);
@@ -255,10 +251,8 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R1", "cf", "a", now, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create("R2", "cf", "z", now, KeyValue.Type.Put, "dont-care")
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs1),
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs2)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs1, kvs2);
+    
     Scan scanSpec = new Scan(Bytes.toBytes("R1")).setMaxVersions(2);
     StoreScanner scan =
       new StoreScanner(scanSpec, CF, Long.MAX_VALUE, KeyValue.COMPARATOR,
@@ -276,9 +270,7 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R1", "cf", "b", 1, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create("R1", "cf", "a", 1, KeyValue.Type.DeleteColumn, "dont-care"),
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs);
     StoreScanner scan =
       new StoreScanner(new Scan(Bytes.toBytes("R1")), CF, Long.MAX_VALUE, KeyValue.COMPARATOR,
           null, scanners);
@@ -307,9 +299,7 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R1", "cf", "d", 8, KeyValue.Type.Put, "dont-care"),  //
no
 
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs);
     StoreScanner scan =
       new StoreScanner(new Scan().setMaxVersions(2), CF, Long.MAX_VALUE, KeyValue.COMPARATOR,
           null, scanners);
@@ -337,9 +327,7 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R1", "cf", "i", 11, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create("R2", "cf", "a", 11, KeyValue.Type.Put, "dont-care"),
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs);
     StoreScanner scan =
       new StoreScanner(new Scan().setMaxVersions(Integer.MAX_VALUE), CF, Long.MAX_VALUE,
KeyValue.COMPARATOR,
           null, scanners);
@@ -360,9 +348,7 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R1", "cf", "a", 8, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create("R1", "cf", "b", 5, KeyValue.Type.Put, "dont-care")
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs),
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs);
     StoreScanner scan =
       new StoreScanner(new Scan(), CF, Long.MAX_VALUE, KeyValue.COMPARATOR,
           null, scanners);
@@ -385,9 +371,7 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R1", "cf", "i", 11, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create("R2", "cf", "a", 11, KeyValue.Type.Put, "dont-care"),
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs);
     StoreScanner scan =
       new StoreScanner(new Scan(), CF, Long.MAX_VALUE, KeyValue.COMPARATOR,
           getCols("a", "d"), scanners);
@@ -423,9 +407,7 @@ public class TestStoreScanner extends Te
         KeyValueTestUtil.create("R2", "cf", "c", now-200, KeyValue.Type.Put, "dont-care"),
         KeyValueTestUtil.create("R2", "cf", "c", now-1000, KeyValue.Type.Put, "dont-care")
     };
-    KeyValueScanner [] scanners = new KeyValueScanner[] {
-        new KeyValueScanFixture(KeyValue.COMPARATOR, kvs)
-    };
+    List<KeyValueScanner> scanners = scanFixture(kvs);
     Scan scan = new Scan();
     scan.setMaxVersions(1);
     StoreScanner scanner =



Mime
View raw message