Package org.apache.hadoop.hbase.io

Examples of org.apache.hadoop.hbase.io.BatchUpdate


    if (!isOnline()) {
      // Its a noop
      return;
    }
    if (!info.isMetaRegion()) {
      BatchUpdate batch = new BatchUpdate(info.getRegionName());
      batch.setTimestamp(timestamp);
      batch.put(column, Bytes.toBytes(text));
      try {
        this.metaTable.commit(batch);
      } catch (IOException ioe) {
        LOG.warn("Unable to '" + text + "'", ioe);
      }
View Full Code Here


  /** For HBASE-694 */
  public void testGetClosestRowBefore2() throws IOException{

    HRegion region = null;
    BatchUpdate batchUpdate = null;
   
    try {
      HTableDescriptor htd = createTableDescriptor(getName());
      region = createNewHRegion(htd, null, null);
    
      // set up some test data
      String t10 = "010";
      String t20 = "020";
      String t30 = "030";
      String t40 = "040";
     
      batchUpdate = new BatchUpdate(t10);
      batchUpdate.put(COLUMNS[0], "t10 bytes".getBytes());
      region.batchUpdate(batchUpdate, null);
     
      batchUpdate = new BatchUpdate(t30);
      batchUpdate.put(COLUMNS[0], "t30 bytes".getBytes());
      region.batchUpdate(batchUpdate, null);
     
      batchUpdate = new BatchUpdate(t40);
      batchUpdate.put(COLUMNS[0], "t40 bytes".getBytes());
      region.batchUpdate(batchUpdate, null);

      // try finding "035"
      String t35 = "035";
      Map<byte [], Cell> results =
        region.getClosestRowBefore(Bytes.toBytes(t35), COLUMNS[0]);
      assertEquals(new String(results.get(COLUMNS[0]).getValue()), "t30 bytes");

      region.flushcache();

      // try finding "035"
      results = region.getClosestRowBefore(Bytes.toBytes(t35), COLUMNS[0]);
      assertEquals(new String(results.get(COLUMNS[0]).getValue()), "t30 bytes");

      batchUpdate = new BatchUpdate(t20);
      batchUpdate.put(COLUMNS[0], "t20 bytes".getBytes());
      region.batchUpdate(batchUpdate, null);
     
      // try finding "035"
      results = region.getClosestRowBefore(Bytes.toBytes(t35), COLUMNS[0]);
      assertEquals(new String(results.get(COLUMNS[0]).getValue()), "t30 bytes");
View Full Code Here

      region = createNewHRegion(htd, null, null);
      region_incommon = new HRegionIncommon(region);
     
      // write a row with a bunch of columns
      byte [] row = Bytes.toBytes("some_row");
      BatchUpdate bu = new BatchUpdate(row);
      bu.put(COLUMNS[0], "column 0".getBytes());
      bu.put(COLUMNS[1], "column 1".getBytes());
      bu.put(COLUMNS[2], "column 2".getBytes());
      region.batchUpdate(bu, null);
     
      assertSpecifiedColumns(region, row);
      // try it again with a cache flush to involve the store, not just the
      // memcache.
View Full Code Here

 
 
  public void testGetFullMultiMapfile() throws IOException {
    HRegion region = null;
    HRegionIncommon region_incommon = null;
    BatchUpdate batchUpdate = null;
    Map<byte [], Cell> results = null;
   
    try {
      HTableDescriptor htd = createTableDescriptor(getName());
      region = createNewHRegion(htd, null, null);
      region_incommon = new HRegionIncommon(region);
          
      //
      // Test ordering issue
      //
      byte [] row = Bytes.toBytes("row1");
    
      // write some data
      batchUpdate = new BatchUpdate(row);
      batchUpdate.put(COLUMNS[0], "olderValue".getBytes());
      region.batchUpdate(batchUpdate, null);

      // flush
      region.flushcache();
     
      // assert that getFull gives us the older value
      results = region.getFull(row, (Set<byte []>)null, LATEST_TIMESTAMP, 1, null);
      assertEquals("olderValue", new String(results.get(COLUMNS[0]).getValue()));
     
      // write a new value for the cell
      batchUpdate = new BatchUpdate(row);
      batchUpdate.put(COLUMNS[0], "newerValue".getBytes());
      region.batchUpdate(batchUpdate, null);
     
      // flush
      region.flushcache();
     
      // assert that getFull gives us the later value
      results = region.getFull(row, (Set<byte []>)null, LATEST_TIMESTAMP, 1, null);
      assertEquals("newerValue", new String(results.get(COLUMNS[0]).getValue()));
    
      //
      // Test the delete masking issue
      //
      byte [] row2 = Bytes.toBytes("row2");
      byte [] cell1 = Bytes.toBytes(Bytes.toString(COLUMNS[0]) + "a");
      byte [] cell2 = Bytes.toBytes(Bytes.toString(COLUMNS[0]) + "b");
      byte [] cell3 = Bytes.toBytes(Bytes.toString(COLUMNS[0]) + "c");
     
      // write some data at two columns
      batchUpdate = new BatchUpdate(row2);
      batchUpdate.put(cell1, "column0 value".getBytes());
      batchUpdate.put(cell2, "column1 value".getBytes());
      region.batchUpdate(batchUpdate, null);
     
      // flush
      region.flushcache();
     
      // assert i get both columns
      results = region.getFull(row2, (Set<byte []>)null, LATEST_TIMESTAMP, 1, null);
      assertEquals("Should have two columns in the results map", 2, results.size());
      assertEquals("column0 value", new String(results.get(cell1).getValue()));
      assertEquals("column1 value", new String(results.get(cell2).getValue()));
     
      // write a delete for the first column
      batchUpdate = new BatchUpdate(row2);
      batchUpdate.delete(cell1);
      batchUpdate.put(cell2, "column1 new value".getBytes());     
      region.batchUpdate(batchUpdate, null);
           
      // flush
      region.flushcache();
     
      // assert i get the second column only
      results = region.getFull(row2, (Set<byte []>)null, LATEST_TIMESTAMP, 1, null);
      assertEquals("Should have one column in the results map", 1, results.size());
      assertNull("column0 value", results.get(cell1));
      assertEquals("column1 new value", new String(results.get(cell2).getValue()));
     
      //
      // Include a delete and value from the memcache in the mix
      //
      batchUpdate = new BatchUpdate(row2);
      batchUpdate.delete(cell2);     
      batchUpdate.put(cell3, "column2 value!".getBytes());
      region.batchUpdate(batchUpdate, null);
     
      // assert i get the third column only
      results = region.getFull(row2, (Set<byte []>)null, LATEST_TIMESTAMP, 1, null);
      assertEquals("Should have one column in the results map", 1, results.size());
View Full Code Here

      r = createNewHRegion(REGION_INFO.getTableDesc(), null, null);
      region = new HRegionIncommon(r);
     
      // Write information to the meta table

      BatchUpdate batchUpdate = new BatchUpdate(ROW_KEY, System.currentTimeMillis());

      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      DataOutputStream s = new DataOutputStream(byteStream);
      HRegionInfo.ROOT_REGIONINFO.write(s);
      batchUpdate.put(HConstants.COL_REGIONINFO, byteStream.toByteArray());
      region.commit(batchUpdate);

      // What we just committed is in the memcache. Verify that we can get
      // it back both with scanning and get
     
      scan(false, null);
      getRegionInfo();
     
      // Close and re-open
     
      r.close();
      r = openClosedRegion(r);
      region = new HRegionIncommon(r);

      // Verify we can get the data back now that it is on disk.
     
      scan(false, null);
      getRegionInfo();
     
      // Store some new information
      HServerAddress address = new HServerAddress("foo.bar.com:1234");

      batchUpdate = new BatchUpdate(ROW_KEY, System.currentTimeMillis());

      batchUpdate.put(HConstants.COL_SERVER,  Bytes.toBytes(address.toString()));

      batchUpdate.put(HConstants.COL_STARTCODE, Bytes.toBytes(START_CODE));

      region.commit(batchUpdate);
     
      // Validate that we can still get the HRegionInfo, even though it is in
      // an older row on disk and there is a newer row in the memcache
     
      scan(true, address.toString());
      getRegionInfo();
     
      // flush cache

      region.flushcache();

      // Validate again
     
      scan(true, address.toString());
      getRegionInfo();

      // Close and reopen
     
      r.close();
      r = openClosedRegion(r);
      region = new HRegionIncommon(r);

      // Validate again
     
      scan(true, address.toString());
      getRegionInfo();

      // Now update the information again

      address = new HServerAddress("bar.foo.com:4321");
     
      batchUpdate = new BatchUpdate(ROW_KEY, System.currentTimeMillis());

      batchUpdate.put(HConstants.COL_SERVER,
        Bytes.toBytes(address.toString()));

      region.commit(batchUpdate);
     
      // Validate again
View Full Code Here

      splitThread.start();
      HRegionServer server = cluster.getRegionThreads().get(0).getRegionServer();
      long id = server.addScanner(s);
      for(int i = 0; i < 6; i++) {
        try {
          BatchUpdate update =
            new BatchUpdate(region.getRegionInfo().getStartKey());
          update.put(COLFAMILY_NAME3, Bytes.toBytes("val"));
          region.batchUpdate(update);
          Thread.sleep(1000);
        }
        catch (InterruptedException e) {
          fail("Unexpected exception " + e);
View Full Code Here

    this.table = new HTable(conf, TABLE_NAME);
  }

  /** @throws Exception */
  public void testGetRowMultipleVersions() throws Exception {
    BatchUpdate b = new BatchUpdate(ROW, TIMESTAMP);
    b.put(COLUMN, Bytes.toBytes(VALUE1));
    this.table.commit(b);
    // Shut down and restart the HBase cluster
    this.cluster.shutdown();
    LOG.debug("HBase cluster shut down -- restarting");
    this.hBaseClusterSetup();
    // Make a new connection
    this.table = new HTable(conf, TABLE_NAME);
    // Overwrite previous value
    b = new BatchUpdate(ROW, TIMESTAMP);
    b.put(COLUMN, Bytes.toBytes(VALUE2));
    this.table.commit(b);
    // Now verify that getRow(row, column, latest) works
    RowResult r = table.getRow(ROW);
    assertNotNull(r);
    assertTrue(r.size() != 0);
View Full Code Here

      throw new ServletException(e);
    } catch (org.xml.sax.SAXException e){
      throw new ServletException(e);
    }

    BatchUpdate batchUpdate;
   
    try{
      // start an update
      batchUpdate = timestamp == null ?
        new BatchUpdate(row) : new BatchUpdate(row, Long.parseLong(timestamp));

      // set the columns from the xml
      NodeList columns = doc.getElementsByTagName("column");

      for(int i = 0; i < columns.getLength(); i++){
        // get the current column element we're working on
        Element column = (Element)columns.item(i);

        // extract the name and value children
        Node name_node = column.getElementsByTagName("name").item(0);
        String name = name_node.getFirstChild().getNodeValue();

        Node value_node = column.getElementsByTagName("value").item(0);

        byte[] value = new byte[0];
       
        // for some reason there's no value here. probably indicates that
        // the consumer passed a null as the cell value.
        if(value_node.getFirstChild() != null &&
          value_node.getFirstChild().getNodeValue() != null){
          // decode the base64'd value
          value = org.apache.hadoop.hbase.util.Base64.decode(
            value_node.getFirstChild().getNodeValue());
        }

        // put the value
        batchUpdate.put(name, value);
      }

      // commit the update
      table.commit(batchUpdate);
     
View Full Code Here

  Cell[] localGet(final byte[] row, final byte[] column, final long timestamp) {
    ArrayList<Cell> results = new ArrayList<Cell>();

    // Go in reverse order to put newest updates first in list
    for (int i = writeSet.size() - 1; i >= 0; i--) {
      BatchUpdate b = writeSet.get(i);

      if (!Bytes.equals(row, b.getRow())) {
        continue;
      }
      if (b.getTimestamp() > timestamp) {
        continue;
      }
      for (BatchOperation op : b) {
        if (!op.isPut() || !Bytes.equals(column, op.getColumn())) {
          continue;
        }
        results.add(new Cell(op.getValue(), b.getTimestamp()));
      }
    }
    return results.size() == 0 ? null : results
        .toArray(new Cell[results.size()]);
  }
View Full Code Here

    oldRegionInfo.setOffline(true);
    oldRegionInfo.setSplit(true);
    // Inform the HRegionServer that the parent HRegion is no-longer online.
    this.server.removeFromOnlineRegions(oldRegionInfo);
   
    BatchUpdate update = new BatchUpdate(oldRegionInfo.getRegionName());
    update.put(COL_REGIONINFO, Writables.getBytes(oldRegionInfo));
    update.put(COL_SPLITA, Writables.getBytes(newRegions[0].getRegionInfo()));
    update.put(COL_SPLITB, Writables.getBytes(newRegions[1].getRegionInfo()));
    t.commit(update);
   
    // Add new regions to META
    for (int i = 0; i < newRegions.length; i++) {
      update = new BatchUpdate(newRegions[i].getRegionName());
      update.put(COL_REGIONINFO, Writables.getBytes(
        newRegions[i].getRegionInfo()));
      t.commit(update);
    }
       
    // Now tell the master about the new regions
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.io.BatchUpdate

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.