Package org.apache.accumulo.core.iterators

Examples of org.apache.accumulo.core.iterators.ScanCache


   
    SortedMapIterator smi = new SortedMapIterator(m);
   
    KeyExtent extent = new KeyExtent(new Text("tablename"), null, null);
   
    ScanCache sc = new ScanCache(10000000, extent);
   
    // test correctness of the scan cache
   
    for (int i = 1; i <= 100000; i++) {
      sc.setAuthorityIterator(smi);
      int startRow = Math.abs(r.nextInt() % 2000000);
      boolean skipStartRow = false;// r.nextBoolean();
      if (i % 7 == 0) {
        Text row = new Text(String.format("row_%06d", startRow + 1));
        Key k = new Key(row, columnf, columnq, security, System.currentTimeMillis());
        final byte[] valBytes = ("added value " + k.toString()).getBytes();
        final Value dibw = new Value(valBytes);
        m.put(k, dibw);
        sc.invalidate(k);
        System.out.println("Added row " + k + ", " + dibw);
      }
      if (skipStartRow) {
        System.out.println("Scanning after " + startRow);
      } else {
        System.out.println("Scanning from " + startRow);
      }
      Key startKey = new Key(new Text(String.format("row_%06d", startRow)), columnf, columnq, Long.MAX_VALUE);
      sc.seek(new Range(startKey, null), LocalityGroupUtil.EMPTY_CF_SET, false);
      for (int j = 0; j < 20000; j++) {
        // scan through the cache
        if (!sc.hasTop()) {
          System.out.println("end of cache reached with key=" + startKey + " and j=" + j);
          break;
        }
        if (j == 0)
          System.out.println("first key: " + sc.getTopKey() + "  value: " + sc.getTopValue());
        try {
          sc.next();
        } catch (IOException e) {
          throw e;
        }
      }
      if (sc.hasTop()) {
        System.out.println("last key: " + sc.getTopKey() + "  value: " + sc.getTopValue());
      }
      sc.finishScan();
    }
   
    System.out.println("now scanning from the beginning of the table");
    Text firstRow = new Text("");// new Text(String.format("row_%06d", 0));
    Key firstKey = new Key(firstRow, columnf, columnq, Long.MAX_VALUE);
    // test scanning from the beginning of the table
    System.out.println("smi has " + m.size() + " entries");
    for (int i = 0; i < 1000; i++) {
      System.out.println("Scan " + (i + 1));
      sc.setAuthorityIterator(smi);
      sc.seek(new Range(firstKey, null), LocalityGroupUtil.EMPTY_CF_SET, false);
      Key lastKey = null;
      for (int j = 0; j < (i + 1) * 1000 && j < 100000; j++) {
        if (!sc.hasTop()) {
          System.out.println("finished at row " + j);
          break;
        }
        if (j == 0) {
          System.out.println("first key: " + sc.getTopKey());
        }
        lastKey = sc.getTopKey();
        try {
          sc.next();
        } catch (IOException e) {
          e.printStackTrace();
          break;
        }
      }
      System.out.println("last key: " + lastKey);
      sc.finishScan();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.iterators.ScanCache

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.