org.apache.hadoop.hbase.client.Durability Java Examples

The following examples show how to use org.apache.hadoop.hbase.client.Durability. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HBaseBolt.java    From storm-hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple tuple) {
    byte[] rowKey = this.mapper.rowKey(tuple);
    ColumnList cols = this.mapper.columns(tuple);
    List<Mutation> mutations = hBaseClient.constructMutationReq(rowKey, cols, writeToWAL? Durability.SYNC_WAL : Durability.SKIP_WAL);

    try {
        this.hBaseClient.batchMutate(mutations);
    } catch(Exception e){
        LOG.warn("Failing tuple. Error writing rowKey " + rowKey, e);
        this.collector.fail(tuple);
        return;
    }

    this.collector.ack(tuple);
}
 
Example #2
Source File: HBaseClient.java    From metron with Apache License 2.0 6 votes vote down vote up
/**
 * Add a Mutation such as a Put or Increment to the batch.  The Mutation is only queued for
 * later execution.
 *
 * @param rowKey     The row key of the Mutation.
 * @param cols       The columns affected by the Mutation.
 * @param durability The durability of the mutation.
 */
public void addMutation(byte[] rowKey, ColumnList cols, Durability durability) {

  if (cols.hasColumns()) {
    Put put = createPut(rowKey, cols, durability);
    mutations.add(put);
  }

  if (cols.hasCounters()) {
    Increment inc = createIncrement(rowKey, cols, durability);
    mutations.add(inc);
  }

  if (mutations.isEmpty()) {
    mutations.add(new Put(rowKey));
  }
}
 
Example #3
Source File: HBaseTestingUtility.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a pre-split table for load testing. If the table already exists,
 * logs a warning and continues.
 * @return the number of regions the table was split into
 */
public static int createPreSplitLoadTestTable(Configuration conf,
    TableName tableName, byte[][] columnFamilies, Algorithm compression,
    DataBlockEncoding dataBlockEncoding, int numRegionsPerServer, int regionReplication,
    Durability durability)
        throws IOException {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  tableDescriptor.setDurability(durability);
  tableDescriptor.setRegionReplication(regionReplication);
  ColumnFamilyDescriptor[] hcds = new ColumnFamilyDescriptor[columnFamilies.length];
  for (int i = 0; i < columnFamilies.length; i++) {
    ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(columnFamilies[i]);
    familyDescriptor.setDataBlockEncoding(dataBlockEncoding);
    familyDescriptor.setCompressionType(compression);
    hcds[i] = familyDescriptor;
  }
  return createPreSplitLoadTestTable(conf, tableDescriptor, hcds, numRegionsPerServer);
}
 
Example #4
Source File: HbaseSolrIndexCoprocesser.java    From hbase-increment-index with MIT License 6 votes vote down vote up
@Override
public void postPut(ObserverContext<RegionCoprocessorEnvironment> e, Put put, WALEdit edit, Durability durability) throws IOException {
    String rowkey = Bytes.toString(put.getRow());//得到rowkey
    SolrInputDocument doc =new SolrInputDocument();//实例化索引Doc
    doc.addField(config.getString("solr_hbase_rowkey_name"),rowkey);//添加主键
    for(String cf:config.getString("hbase_column_family").split(",")) {//遍历所有的列簇
        List<Cell> cells = put.getFamilyCellMap().get(Bytes.toBytes(cf));
        if(cells==null||cells.isEmpty()) continue; // 跳过取值为空或null的数据
        for (Cell kv : cells ) {
            String name=Bytes.toString(CellUtil.cloneQualifier(kv));//获取列名
            String value=Bytes.toString(kv.getValueArray());//获取列值 or CellUtil.cloneValue(kv)
            doc.addField(name,value);//添加到索引doc里面
        }
    }
    //发送数据到本地缓存
    SolrIndexTools.addDoc(doc);
}
 
Example #5
Source File: TestDurability.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Test when returnResults set to false in increment it should not return the result instead it
 * resturn null.
 */
@Test
public void testIncrementWithReturnResultsSetToFalse() throws Exception {
  byte[] row1 = Bytes.toBytes("row1");
  byte[] col1 = Bytes.toBytes("col1");

  // Setting up region
  WALFactory wals = new WALFactory(CONF,
      ServerName
          .valueOf("testIncrementWithReturnResultsSetToFalse", 16010, System.currentTimeMillis())
          .toString());
  HRegion region = createHRegion(wals, Durability.USE_DEFAULT);

  Increment inc1 = new Increment(row1);
  inc1.setReturnResults(false);
  inc1.addColumn(FAMILY, col1, 1);
  Result res = region.increment(inc1);
  assertTrue(res.isEmpty());
}
 
Example #6
Source File: TestHTableDescriptor.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testPb() throws DeserializationException, IOException {
  HTableDescriptor htd = new HTableDescriptor(TableName.META_TABLE_NAME);
  final int v = 123;
  htd.setMaxFileSize(v);
  htd.setDurability(Durability.ASYNC_WAL);
  htd.setReadOnly(true);
  htd.setRegionReplication(2);
  byte [] bytes = htd.toByteArray();
  HTableDescriptor deserializedHtd = HTableDescriptor.parseFrom(bytes);
  assertEquals(htd, deserializedHtd);
  assertEquals(v, deserializedHtd.getMaxFileSize());
  assertTrue(deserializedHtd.isReadOnly());
  assertEquals(Durability.ASYNC_WAL, deserializedHtd.getDurability());
  assertEquals(2, deserializedHtd.getRegionReplication());
}
 
Example #7
Source File: TestTimeRangeMapRed.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void map(ImmutableBytesWritable key, Result result,
    Context context)
throws IOException {
  List<Long> tsList = new ArrayList<>();
  for (Cell kv : result.listCells()) {
    tsList.add(kv.getTimestamp());
  }

  List<Put> puts = new ArrayList<>();
  for (Long ts : tsList) {
    Put put = new Put(key.get());
    put.setDurability(Durability.SKIP_WAL);
    put.addColumn(FAMILY_NAME, COLUMN_NAME, ts, Bytes.toBytes(true));
    puts.add(put);
  }
  table.put(puts);
}
 
Example #8
Source File: TestVisibilityLabelsReplication.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> e, Put m, WALEdit edit,
    Durability durability) throws IOException {
  byte[] attribute = m.getAttribute(NON_VISIBILITY);
  byte[] cf = null;
  List<Cell> updatedCells = new ArrayList<>();
  if (attribute != null) {
    for (List<? extends Cell> edits : m.getFamilyCellMap().values()) {
      for (Cell cell : edits) {
        KeyValue kv = KeyValueUtil.ensureKeyValue(cell);
        if (cf == null) {
          cf = CellUtil.cloneFamily(kv);
        }
        Tag tag = new ArrayBackedTag((byte) NON_VIS_TAG_TYPE, attribute);
        List<Tag> tagList = new ArrayList<>(PrivateCellUtil.getTags(cell).size() + 1);
        tagList.add(tag);
        tagList.addAll(PrivateCellUtil.getTags(cell));
        Cell newcell = PrivateCellUtil.createCell(kv, tagList);
        ((List<Cell>) updatedCells).add(newcell);
      }
    }
    m.getFamilyCellMap().remove(cf);
    // Update the family map
    m.getFamilyCellMap().put(cf, updatedCells);
  }
}
 
Example #9
Source File: TestTimeRangeMapRed.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimeRangeMapRed()
    throws IOException, InterruptedException, ClassNotFoundException {
  final TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(TABLE_NAME);
  final ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(FAMILY_NAME);
  familyDescriptor.setMaxVersions(Integer.MAX_VALUE);
  tableDescriptor.setColumnFamily(familyDescriptor);
  admin.createTable(tableDescriptor);
  List<Put> puts = new ArrayList<>();
  for (Map.Entry<Long, Boolean> entry : TIMESTAMP.entrySet()) {
    Put put = new Put(KEY);
    put.setDurability(Durability.SKIP_WAL);
    put.addColumn(FAMILY_NAME, COLUMN_NAME, entry.getKey(), Bytes.toBytes(false));
    puts.add(put);
  }
  Table table = UTIL.getConnection().getTable(tableDescriptor.getTableName());
  table.put(puts);
  runTestOnTable();
  verify(table);
  table.close();
}
 
Example #10
Source File: HBaseTestingUtility.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a pre-split table for load testing. If the table already exists,
 * logs a warning and continues.
 * @return the number of regions the table was split into
 */
public static int createPreSplitLoadTestTable(Configuration conf,
    TableName tableName, byte[] columnFamily, Algorithm compression,
    DataBlockEncoding dataBlockEncoding, int numRegionsPerServer, int regionReplication,
    Durability durability)
        throws IOException {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  tableDescriptor.setDurability(durability);
  tableDescriptor.setRegionReplication(regionReplication);
  ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(columnFamily);
  familyDescriptor.setDataBlockEncoding(dataBlockEncoding);
  familyDescriptor.setCompressionType(compression);
  return createPreSplitLoadTestTable(conf, tableDescriptor, familyDescriptor,
    numRegionsPerServer);
}
 
Example #11
Source File: HBaseTestingUtility.java    From hbase with Apache License 2.0 6 votes vote down vote up
public HRegion createLocalHRegionWithInMemoryFlags(TableName tableName, byte[] startKey,
  byte[] stopKey, boolean isReadOnly, Durability durability, WAL wal, boolean[] compactedMemStore,
  byte[]... families) throws IOException {
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  tableDescriptor.setReadOnly(isReadOnly);
  int i = 0;
  for (byte[] family : families) {
    ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor =
      new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(family);
    if (compactedMemStore != null && i < compactedMemStore.length) {
      familyDescriptor.setInMemoryCompaction(MemoryCompactionPolicy.BASIC);
    } else {
      familyDescriptor.setInMemoryCompaction(MemoryCompactionPolicy.NONE);

    }
    i++;
    // Set default to be three versions.
    familyDescriptor.setMaxVersions(Integer.MAX_VALUE);
    tableDescriptor.setColumnFamily(familyDescriptor);
  }
  tableDescriptor.setDurability(durability);
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName())
    .setStartKey(startKey).setEndKey(stopKey).build();
  return createLocalHRegion(info, tableDescriptor, wal);
}
 
Example #12
Source File: PhoenixHBaseAccessor.java    From ambari-metrics with Apache License 2.0 6 votes vote down vote up
private boolean setDurabilityForTable(String tableName, TableDescriptorBuilder tableDescriptorBuilder, TableDescriptor tableDescriptor) {
  String tableDurability = metricsConf.get("timeline.metrics." + tableName + ".durability", "");

  if (StringUtils.isEmpty(tableDurability) || tableDescriptor.getDurability().toString().equals(tableDurability)) {
    return false;
  }

  if (StringUtils.isNotEmpty(tableDurability)) {
    LOG.info("Setting WAL option " + tableDurability + " for table : " + tableName);
    boolean validDurability = true;
    if ("SKIP_WAL".equals(tableDurability)) {
      tableDescriptorBuilder.setDurability(Durability.SKIP_WAL);
    } else if ("SYNC_WAL".equals(tableDurability)) {
      tableDescriptorBuilder.setDurability(Durability.SYNC_WAL);
    } else if ("ASYNC_WAL".equals(tableDurability)) {
      tableDescriptorBuilder.setDurability(Durability.ASYNC_WAL);
    } else if ("FSYNC_WAL".equals(tableDurability)) {
      tableDescriptorBuilder.setDurability(Durability.FSYNC_WAL);
    } else {
      LOG.info("Unknown value for durability : " + tableDurability);
      validDurability = false;
    }
    return validDurability;
  }
  return false;
}
 
Example #13
Source File: TestCompaction.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test public void testInterruptingRunningCompactions() throws Exception {
  // setup a compact/split thread on a mock server
  conf.set(CompactionThroughputControllerFactory.HBASE_THROUGHPUT_CONTROLLER_KEY,
      WaitThroughPutController.class.getName());
  HRegionServer mockServer = Mockito.mock(HRegionServer.class);
  Mockito.when(mockServer.getConfiguration()).thenReturn(r.getBaseConf());
  CompactSplit thread = new CompactSplit(mockServer);

  Mockito.when(mockServer.getCompactSplitThread()).thenReturn(thread);

  // setup a region/store with some files
  HStore store = r.getStore(COLUMN_FAMILY);
  int jmax = (int) Math.ceil(15.0 / compactionThreshold);
  byte[] pad = new byte[1000]; // 1 KB chunk
  for (int i = 0; i < compactionThreshold; i++) {
    Table loader = new RegionAsTable(r);
    Put p = new Put(Bytes.add(STARTROW, Bytes.toBytes(i)));
    p.setDurability(Durability.SKIP_WAL);
    for (int j = 0; j < jmax; j++) {
      p.addColumn(COLUMN_FAMILY, Bytes.toBytes(j), pad);
    }
    HTestConst.addContent(loader, Bytes.toString(COLUMN_FAMILY));
    loader.put(p);
    r.flush(true);
  }
  HStore s = r.getStore(COLUMN_FAMILY);
  int initialFiles = s.getStorefilesCount();

  thread.requestCompaction(r, store, "test custom comapction", PRIORITY_USER,
      CompactionLifeCycleTracker.DUMMY, null);

  Thread.sleep(3000);
  thread.switchCompaction(false);
  assertEquals(initialFiles, s.getStorefilesCount());
  //don't mess up future tests
  thread.switchCompaction(true);
}
 
Example #14
Source File: TransactionAwareHTableTest.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public void preDelete(final ObserverContext<RegionCoprocessorEnvironment> c,
                      final Delete delete, final WALEdit edit,
                      final Durability durability) throws IOException {
  if (delete.getAttribute(TEST_ATTRIBUTE) == null) {
    throw new DoNotRetryIOException("Delete should preserve attributes");
  }
  if (delete.getDurability() != Durability.USE_DEFAULT) {
    throw new DoNotRetryIOException("Durability is not propagated correctly");
  }
}
 
Example #15
Source File: SimpleRegionObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void postPut(final ObserverContext<RegionCoprocessorEnvironment> c,
    final Put put, final WALEdit edit,
    final Durability durability) throws IOException {
  Map<byte[], List<Cell>> familyMap  = put.getFamilyCellMap();
  RegionCoprocessorEnvironment e = c.getEnvironment();
  assertNotNull(e);
  assertNotNull(e.getRegion());
  assertNotNull(familyMap);
  List<Cell> cells = familyMap.get(TestRegionObserverInterface.A);
  if (e.getRegion().getTableDescriptor().getTableName().equals(
      TestRegionObserverInterface.TEST_TABLE)) {
    assertNotNull(cells);
    assertNotNull(cells.get(0));
    // KeyValue v1 expectation.  Cast for now until we go all Cell all the time. TODO
    Cell cell = cells.get(0);
    assertTrue(Bytes.equals(cell.getQualifierArray(), cell.getQualifierOffset(),
      cell.getQualifierLength(), TestRegionObserverInterface.A, 0,
      TestRegionObserverInterface.A.length));
    cells = familyMap.get(TestRegionObserverInterface.B);
    assertNotNull(cells);
    assertNotNull(cells.get(0));
    // KeyValue v1 expectation.  Cast for now until we go all Cell all the time. TODO
    cell = cells.get(0);
    assertTrue(Bytes.equals(cell.getQualifierArray(), cell.getQualifierOffset(),
      cell.getQualifierLength(), TestRegionObserverInterface.B, 0,
      TestRegionObserverInterface.B.length));
    cells = familyMap.get(TestRegionObserverInterface.C);
    assertNotNull(cells);
    assertNotNull(cells.get(0));
    // KeyValue v1 expectation.  Cast for now until we go all Cell all the time. TODO
    cell = cells.get(0);
    assertTrue(Bytes.equals(cell.getQualifierArray(), cell.getQualifierOffset(),
      cell.getQualifierLength(), TestRegionObserverInterface.C, 0,
      TestRegionObserverInterface.C.length));
  }
  ctPostPut.incrementAndGet();
}
 
Example #16
Source File: TestNegativeMemStoreSizeWithSlowCoprocessor.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void postPut(final ObserverContext<RegionCoprocessorEnvironment> c, final Put put,
    final WALEdit edit, final Durability durability) throws IOException {
  HRegion region = (HRegion) c.getEnvironment().getRegion();
  super.postPut(c, put, edit, durability);

  if (Bytes.equals(put.getRow(), Bytes.toBytes("row2"))) {
    region.flush(false);
    Assert.assertTrue(region.getMemStoreDataSize() >= 0);
  }
}
 
Example #17
Source File: TestImportTSVWithTTLs.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> e, Put put, WALEdit edit,
    Durability durability) throws IOException {
  Region region = e.getEnvironment().getRegion();
  if (!region.getRegionInfo().isMetaRegion()
      && !region.getRegionInfo().getTable().isSystemTable()) {
    // The put carries the TTL attribute
    if (put.getTTL() != Long.MAX_VALUE) {
      return;
    }
    throw new IOException("Operation does not have TTL set");
  }
}
 
Example #18
Source File: TestRegionObserverStacking.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void postPut(final ObserverContext<RegionCoprocessorEnvironment> c,
    final Put put, final WALEdit edit,
    final Durability durability)
    throws IOException {
  id = System.currentTimeMillis();
  try {
    Thread.sleep(10);
  } catch (InterruptedException ex) {
  }
}
 
Example #19
Source File: ThriftUtilities.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static TAppend appendFromHBase(Append in) throws IOException {
  TAppend out = new TAppend();
  out.setRow(in.getRow());

  if (in.getDurability() != Durability.USE_DEFAULT) {
    out.setDurability(durabilityFromHBase(in.getDurability()));
  }
  for (Map.Entry<byte [], List<Cell>> entry : in.getFamilyCellMap().entrySet()) {
    byte[] family = entry.getKey();
    for (Cell cell : entry.getValue()) {
      TColumnValue columnValue = new TColumnValue();
      columnValue.setFamily(family)
          .setQualifier(CellUtil.cloneQualifier(cell))
          .setType(cell.getType().getCode())
          .setTimestamp(cell.getTimestamp())
          .setValue(CellUtil.cloneValue(cell));
      if (cell.getTagsLength() != 0) {
        columnValue.setTags(PrivateCellUtil.cloneTags(cell));
      }
      out.addToColumns(columnValue);
    }
  }
  for (Map.Entry<String, byte[]> attribute : in.getAttributesMap().entrySet()) {
    out.putToAttributes(ByteBuffer.wrap(Bytes.toBytes(attribute.getKey())),
        ByteBuffer.wrap(attribute.getValue()));
  }
  try {
    CellVisibility cellVisibility = in.getCellVisibility();
    if (cellVisibility != null) {
      TCellVisibility tCellVisibility = new TCellVisibility();
      tCellVisibility.setExpression(cellVisibility.getExpression());
      out.setCellVisibility(tCellVisibility);
    }
  } catch (DeserializationException e) {
    throw new RuntimeException(e);
  }
  out.setReturnResults(in.isReturnResults());
  return out;
}
 
Example #20
Source File: AccessController.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void prePut(final ObserverContext<RegionCoprocessorEnvironment> c,
    final Put put, final WALEdit edit, final Durability durability)
    throws IOException {
  User user = getActiveUser(c);
  checkForReservedTagPresence(user, put);

  // Require WRITE permission to the table, CF, or top visible value, if any.
  // NOTE: We don't need to check the permissions for any earlier Puts
  // because we treat the ACLs in each Put as timestamped like any other
  // HBase value. A new ACL in a new Put applies to that Put. It doesn't
  // change the ACL of any previous Put. This allows simple evolution of
  // security policy over time without requiring expensive updates.
  RegionCoprocessorEnvironment env = c.getEnvironment();
  Map<byte[],? extends Collection<Cell>> families = put.getFamilyCellMap();
  AuthResult authResult = permissionGranted(OpType.PUT,
      user, env, families, Action.WRITE);
  AccessChecker.logResult(authResult);
  if (!authResult.isAllowed()) {
    if (cellFeaturesEnabled && !compatibleEarlyTermination) {
      put.setAttribute(CHECK_COVERING_PERM, TRUE);
    } else if (authorizationEnabled) {
      throw new AccessDeniedException("Insufficient permissions " + authResult.toContextString());
    }
  }

  // Add cell ACLs from the operation to the cells themselves
  byte[] bytes = put.getAttribute(AccessControlConstants.OP_ATTRIBUTE_ACL);
  if (bytes != null) {
    if (cellFeaturesEnabled) {
      addCellPermissions(bytes, put.getFamilyCellMap());
    } else {
      throw new DoNotRetryIOException("Cell ACLs cannot be persisted");
    }
  }
}
 
Example #21
Source File: AccessController.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void postDelete(final ObserverContext<RegionCoprocessorEnvironment> c,
    final Delete delete, final WALEdit edit, final Durability durability)
    throws IOException {
  if (aclRegion) {
    updateACL(c.getEnvironment(), delete.getFamilyCellMap());
  }
}
 
Example #22
Source File: WALSplitUtil.java    From hbase with Apache License 2.0 5 votes vote down vote up
public MutationReplay(ClientProtos.MutationProto.MutationType type, Mutation mutation,
    long nonceGroup, long nonce) {
  this.type = type;
  this.mutation = mutation;
  if (this.mutation.getDurability() != Durability.SKIP_WAL) {
    // using ASYNC_WAL for relay
    this.mutation.setDurability(Durability.ASYNC_WAL);
  }
  this.nonceGroup = nonceGroup;
  this.nonce = nonce;
}
 
Example #23
Source File: MutationTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void assertDurability(Connection conn, Durability durability) throws SQLException {
    PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
    Iterator<Pair<byte[], List<Mutation>>> it = pconn.getMutationState().toMutations();
    assertTrue(it.hasNext());
    while (it.hasNext()) {
        Pair<byte[], List<Mutation>> pair = it.next();
        assertFalse(pair.getSecond().isEmpty());
        for (Mutation m : pair.getSecond()) {
            assertEquals(durability, m.getDurability());
        }
    }
}
 
Example #24
Source File: Indexer.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void doPost(WALEdit edit, Mutation m, final Durability durability) throws IOException {
  try {
    doPostWithExceptions(edit, m, durability);
    return;
  } catch (Throwable e) {
    rethrowIndexingException(e);
  }
  throw new RuntimeException(
      "Somehow didn't complete the index update, but didn't return succesfully either!");
}
 
Example #25
Source File: TestScannerRetriableFailure.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void loadTable(final Table table, int numRows) throws IOException {
  List<Put> puts = new ArrayList<>(numRows);
  for (int i = 0; i < numRows; ++i) {
    byte[] row = Bytes.toBytes(String.format("%09d", i));
    Put put = new Put(row);
    put.setDurability(Durability.SKIP_WAL);
    put.addColumn(FAMILY_NAME, null, row);
    table.put(put);
  }
}
 
Example #26
Source File: TestAtomicOperation.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
  for (int i = 0; i < numIncrements; i++) {
    try {
      Increment inc = new Increment(row);
      inc.addColumn(fam1, qual1, amount);
      inc.addColumn(fam1, qual2, amount*2);
      inc.addColumn(fam2, qual3, amount*3);
      inc.setDurability(Durability.ASYNC_WAL);
      Result result = region.increment(inc);
      if (result != null) {
        assertEquals(Bytes.toLong(result.getValue(fam1, qual1))*2,
          Bytes.toLong(result.getValue(fam1, qual2)));
        assertTrue(result.getValue(fam2, qual3) != null);
        assertEquals(Bytes.toLong(result.getValue(fam1, qual1))*3,
          Bytes.toLong(result.getValue(fam2, qual3)));
        assertEquals(Bytes.toLong(result.getValue(fam1, qual1))*2,
           Bytes.toLong(result.getValue(fam1, qual2)));
        long fam1Increment = Bytes.toLong(result.getValue(fam1, qual1))*3;
        long fam2Increment = Bytes.toLong(result.getValue(fam2, qual3));
        assertEquals("fam1=" + fam1Increment + ", fam2=" + fam2Increment,
          fam1Increment, fam2Increment);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
 
Example #27
Source File: TransactionProcessor.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public void preDelete(ObserverContext<RegionCoprocessorEnvironment> e, Delete delete, WALEdit edit,
                      Durability durability) throws IOException {
  // Translate deletes into our own delete tombstones
  // Since HBase deletes cannot be undone, we need to translate deletes into special puts, which allows
  // us to rollback the changes (by a real delete) if the transaction fails

  // Deletes that are part of a transaction rollback do not need special handling.
  // They will never be rolled back, so are performed as normal HBase deletes.
  if (isRollbackOperation(delete)) {
    return;
  }

  Transaction tx = getFromOperation(delete);
  ensureValidTxLifetime(e.getEnvironment(), delete, tx);

  // Other deletes are client-initiated and need to be translated into our own tombstones
  // TODO: this should delegate to the DeleteStrategy implementation.
  Put deleteMarkers = new Put(delete.getRow(), delete.getTimeStamp());
  for (byte[] family : delete.getFamilyCellMap().keySet()) {
    List<Cell> familyCells = delete.getFamilyCellMap().get(family);
    if (isFamilyDelete(familyCells)) {
      deleteMarkers.add(family, TxConstants.FAMILY_DELETE_QUALIFIER, familyCells.get(0).getTimestamp(),
                        HConstants.EMPTY_BYTE_ARRAY);
    } else {
      for (Cell cell : familyCells) {
        deleteMarkers.add(family, CellUtil.cloneQualifier(cell), cell.getTimestamp(),
                          HConstants.EMPTY_BYTE_ARRAY);
      }
    }
  }
  for (Map.Entry<String, byte[]> entry : delete.getAttributesMap().entrySet()) {
      deleteMarkers.setAttribute(entry.getKey(), entry.getValue());
  }
  e.getEnvironment().getRegion().put(deleteMarkers);
  // skip normal delete handling
  e.bypass();
}
 
Example #28
Source File: TestProcedurePriority.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void prePut(ObserverContext<RegionCoprocessorEnvironment> c, Put put, WALEdit edit,
    Durability durability) throws IOException {
  if (FAIL && c.getEnvironment().getRegionInfo().isMetaRegion()) {
    throw new IOException("Inject error");
  }
}
 
Example #29
Source File: SimpleRegionObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void postDelete(final ObserverContext<RegionCoprocessorEnvironment> c,
    final Delete delete, final WALEdit edit,
    final Durability durability) throws IOException {
  Map<byte[], List<Cell>> familyMap  = delete.getFamilyCellMap();
  RegionCoprocessorEnvironment e = c.getEnvironment();
  assertNotNull(e);
  assertNotNull(e.getRegion());
  assertNotNull(familyMap);
  ctBeforeDelete.set(0);
  ctPostDeleted.incrementAndGet();
}
 
Example #30
Source File: TransactionAwareHTableTest.java    From phoenix-tephra with Apache License 2.0 5 votes vote down vote up
@Override
public void prePut(final ObserverContext<RegionCoprocessorEnvironment> c,
                   final Put put, final WALEdit edit,
                   final Durability durability) throws IOException {
  if (put.getAttribute(TEST_ATTRIBUTE) == null) {
    throw new DoNotRetryIOException("Put should preserve attributes");
  }
  if (put.getDurability() != Durability.USE_DEFAULT) {
    throw new DoNotRetryIOException("Durability is not propagated correctly");
  }
}