Exemplo n.º 1
0
 private void doPuts(HRegion region) throws IOException {
   LoadTestKVGenerator dataGenerator = new LoadTestKVGenerator(MIN_VALUE_SIZE, MAX_VALUE_SIZE);
   for (int i = 0; i < NUM_ROWS; ++i) {
     byte[] key = LoadTestKVGenerator.md5PrefixedKey(i).getBytes();
     for (int j = 0; j < NUM_COLS_PER_ROW; ++j) {
       Put put = new Put(key);
       byte[] col = Bytes.toBytes(String.valueOf(j));
       byte[] value = dataGenerator.generateRandomSizeValue(key, col);
       if (includeTags) {
         Tag[] tag = new Tag[1];
         tag[0] = new Tag((byte) 1, "Visibility");
         KeyValue kv = new KeyValue(key, CF_BYTES, col, HConstants.LATEST_TIMESTAMP, value, tag);
         put.add(kv);
       } else {
         put.add(CF_BYTES, col, value);
       }
       if (VERBOSE) {
         KeyValue kvPut = new KeyValue(key, CF_BYTES, col, value);
         System.err.println(Strings.padFront(i + "", ' ', 4) + " " + kvPut);
       }
       region.put(put);
     }
     if (i % NUM_ROWS_PER_FLUSH == 0) {
       region.flushcache();
     }
   }
 }
  @Test
  public void testRegionObserverFlushTimeStacking() throws Exception {
    byte[] ROW = Bytes.toBytes("testRow");
    byte[] TABLE = Bytes.toBytes(getClass().getName());
    byte[] A = Bytes.toBytes("A");
    byte[][] FAMILIES = new byte[][] {A};

    Configuration conf = HBaseConfiguration.create();
    HRegion region = initHRegion(TABLE, getClass().getName(), conf, FAMILIES);
    RegionCoprocessorHost h = region.getCoprocessorHost();
    h.load(NoDataFromFlush.class, Coprocessor.PRIORITY_HIGHEST, conf);
    h.load(EmptyRegionObsever.class, Coprocessor.PRIORITY_USER, conf);

    // put a row and flush it to disk
    Put put = new Put(ROW);
    put.add(A, A, A);
    region.put(put);
    region.flushcache();
    Get get = new Get(ROW);
    Result r = region.get(get);
    assertNull(
        "Got an unexpected number of rows - no data should be returned with the NoDataFromScan coprocessor. Found: "
            + r,
        r.listCells());
  }
 private void doPuts(HRegion region) throws IOException {
   LoadTestKVGenerator dataGenerator = new LoadTestKVGenerator(MIN_VALUE_SIZE, MAX_VALUE_SIZE);
   for (int i = 0; i < NUM_ROWS; ++i) {
     byte[] key = MultiThreadedWriter.longToByteArrayKey(i);
     for (int j = 0; j < NUM_COLS_PER_ROW; ++j) {
       Put put = new Put(key);
       String colAsStr = String.valueOf(j);
       byte[] col = Bytes.toBytes(colAsStr);
       byte[] value = dataGenerator.generateRandomSizeValue(i, colAsStr);
       put.add(CF_BYTES, Bytes.toBytes(colAsStr), value);
       if (VERBOSE) {
         KeyValue kvPut = new KeyValue(key, CF_BYTES, col, value);
         System.err.println(Strings.padFront(i + "", ' ', 4) + " " + kvPut);
       }
       region.put(put);
     }
     if (i % NUM_ROWS_PER_FLUSH == 0) {
       region.flushcache();
     }
   }
 }