本文整理了Java中org.apache.hadoop.hbase.client.Increment.setDurability()
方法的一些代码示例,展示了Increment.setDurability()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Increment.setDurability()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Increment
类名称:Increment
方法名:setDurability
暂无
代码示例来源:origin: apache/hbase
private Increment newIncrementWithSkipWAL() {
Increment increment = new Increment(Bytes.toBytes("row"));
increment.addColumn(CF, CQ, 1);
increment.setDurability(Durability.SKIP_WAL);
return increment;
}
代码示例来源:origin: apache/hbase
/**
* Atomically increments a column value. If the column value already exists and is not a
* big-endian long, this could throw an exception. If the column value does not yet exist it is
* initialized to <code>amount</code> and written to the specified column.
* <p>
* Setting durability to {@link Durability#SKIP_WAL} means that in a fail scenario you will lose
* any increments that have not been flushed.
* @param row The row that contains the cell to increment.
* @param family The column family of the cell to increment.
* @param qualifier The column qualifier of the cell to increment.
* @param amount The amount to increment the cell with (or decrement, if the amount is negative).
* @param durability The persistence guarantee for this increment.
* @return The new value, post increment. The return value will be wrapped by a
* {@link CompletableFuture}.
*/
default CompletableFuture<Long> incrementColumnValue(byte[] row, byte[] family, byte[] qualifier,
long amount, Durability durability) {
Preconditions.checkNotNull(row, "row is null");
Preconditions.checkNotNull(family, "family is null");
return increment(
new Increment(row).addColumn(family, qualifier, amount).setDurability(durability))
.thenApply(r -> Bytes.toLong(r.getValue(family, qualifier)));
}
代码示例来源:origin: apache/flume
((Increment) r).setDurability(enableWal ? Durability.USE_DEFAULT : Durability.SKIP_WAL);
i.setDurability(enableWal ? Durability.USE_DEFAULT : Durability.SKIP_WAL);
table.mutate(i);
代码示例来源:origin: apache/hbase
@Test
public void testIncrWithReadOnlyTable() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
this.region = initHRegion(tableName, method, CONF, true, Bytes.toBytes("somefamily"));
boolean exceptionCaught = false;
Increment inc = new Increment(Bytes.toBytes("somerow"));
inc.setDurability(Durability.SKIP_WAL);
inc.addColumn(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"), 1L);
try {
region.increment(inc);
} catch (IOException e) {
exceptionCaught = true;
}
assertTrue(exceptionCaught == true);
}
代码示例来源:origin: apache/storm
inc.setDurability(durability);
for (ColumnList.Counter cnt : cols.getCounters()) {
inc.addColumn(
代码示例来源:origin: apache/hbase
/**
* Atomically increments a column value. If the column value already exists
* and is not a big-endian long, this could throw an exception. If the column
* value does not yet exist it is initialized to <code>amount</code> and
* written to the specified column.
*
* <p>Setting durability to {@link Durability#SKIP_WAL} means that in a fail
* scenario you will lose any increments that have not been flushed.
* @param row The row that contains the cell to increment.
* @param family The column family of the cell to increment.
* @param qualifier The column qualifier of the cell to increment.
* @param amount The amount to increment the cell with (or decrement, if the
* amount is negative).
* @param durability The persistence guarantee for this increment.
* @return The new value, post increment.
* @throws IOException if a remote or network exception occurs.
*/
default long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier,
long amount, Durability durability) throws IOException {
Increment increment = new Increment(row)
.addColumn(family, qualifier, amount)
.setDurability(durability);
Cell cell = increment(increment).getColumnLatestCell(family, qualifier);
return Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
}
代码示例来源:origin: apache/hbase
@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();
}
}
}
}
代码示例来源:origin: apache/hbase
@Test
public void testIncrementWithNonExistingFamily() throws IOException {
initHRegion(tableName, name.getMethodName(), fam1);
final Increment inc = new Increment(row);
inc.addColumn(fam1, qual1, 1);
inc.addColumn(fam2, qual2, 1);
inc.setDurability(Durability.ASYNC_WAL);
try {
region.increment(inc, HConstants.NO_NONCE, HConstants.NO_NONCE);
} catch (NoSuchColumnFamilyException e) {
final Get g = new Get(row);
final Result result = region.get(g);
assertEquals(null, result.getValue(fam1, qual1));
assertEquals(null, result.getValue(fam2, qual2));
} catch (Exception e) {
fail("Increment operation should fail with NoSuchColumnFamilyException.");
}
}
代码示例来源:origin: apache/hbase
try {
Increment odd = new Increment(rows[0]);
odd.setDurability(Durability.SKIP_WAL);
Increment even = new Increment(rows[0]);
even.setDurability(Durability.SKIP_WAL);
Increment all = new Increment(rows[0]);
all.setDurability(Durability.SKIP_WAL);
for (int i=0;i<numQualifiers;i++) {
if (i % 2 == 0) even.addColumn(families[0], qualifiers[i], 1);
代码示例来源:origin: apache/hbase
public static Increment incrementFromThrift(TIncrement in) throws IOException {
Increment out = new Increment(in.getRow());
for (TColumnIncrement column : in.getColumns()) {
out.addColumn(column.getFamily(), column.getQualifier(), column.getAmount());
}
if (in.isSetAttributes()) {
addAttributes(out,in.getAttributes());
}
if (in.isSetDurability()) {
out.setDurability(durabilityFromThrift(in.getDurability()));
}
if(in.getCellVisibility() != null) {
out.setCellVisibility(new CellVisibility(in.getCellVisibility().getExpression()));
}
if (in.isSetReturnResults()) {
out.setReturnResults(in.isReturnResults());
}
return out;
}
代码示例来源:origin: apache/hbase
@Test
public void testIncrementTimestampsAreMonotonic() throws IOException {
region = initHRegion(tableName, method, CONF, fam1);
ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge(edge);
edge.setValue(10);
Increment inc = new Increment(row);
inc.setDurability(Durability.SKIP_WAL);
inc.addColumn(fam1, qual1, 1L);
region.increment(inc);
Result result = region.get(new Get(row));
Cell c = result.getColumnLatestCell(fam1, qual1);
assertNotNull(c);
assertEquals(10L, c.getTimestamp());
edge.setValue(1); // clock goes back
region.increment(inc);
result = region.get(new Get(row));
c = result.getColumnLatestCell(fam1, qual1);
assertEquals(11L, c.getTimestamp());
assertEquals(2L, Bytes.toLong(c.getValueArray(), c.getValueOffset(), c.getValueLength()));
}
代码示例来源:origin: apache/metron
inc.setDurability(durability);
代码示例来源:origin: apache/metron
/**
* Creates an HBase Increment for a counter.
*
* @param rowKey The row key.
* @param cols The columns to include.
* @param durability The durability of the increment.
*/
private Increment createIncrement(byte[] rowKey, ColumnList cols, Durability durability) {
Increment inc = new Increment(rowKey);
inc.setDurability(durability);
cols.getCounters().forEach(cnt -> inc.addColumn(cnt.getFamily(), cnt.getQualifier(), cnt.getIncrement()));
return inc;
}
代码示例来源:origin: org.apache.hbase/hbase-client
/**
* Atomically increments a column value. If the column value already exists and is not a
* big-endian long, this could throw an exception. If the column value does not yet exist it is
* initialized to <code>amount</code> and written to the specified column.
* <p>
* Setting durability to {@link Durability#SKIP_WAL} means that in a fail scenario you will lose
* any increments that have not been flushed.
* @param row The row that contains the cell to increment.
* @param family The column family of the cell to increment.
* @param qualifier The column qualifier of the cell to increment.
* @param amount The amount to increment the cell with (or decrement, if the amount is negative).
* @param durability The persistence guarantee for this increment.
* @return The new value, post increment. The return value will be wrapped by a
* {@link CompletableFuture}.
*/
default CompletableFuture<Long> incrementColumnValue(byte[] row, byte[] family, byte[] qualifier,
long amount, Durability durability) {
Preconditions.checkNotNull(row, "row is null");
Preconditions.checkNotNull(family, "family is null");
return increment(
new Increment(row).addColumn(family, qualifier, amount).setDurability(durability))
.thenApply(r -> Bytes.toLong(r.getValue(family, qualifier)));
}
代码示例来源:origin: apache/metron
/**
* Creates an HBase Increment for a counter.
*
* @param rowKey The row key.
* @param cols The columns to include.
* @param durability The durability of the increment.
*/
private Increment createIncrement(byte[] rowKey, ColumnList cols, Durability durability, long timeToLiveMillis) {
Increment inc = new Increment(rowKey);
inc.setDurability(durability);
inc.setTTL(timeToLiveMillis);
cols.getCounters().forEach(cnt -> inc.addColumn(cnt.getFamily(), cnt.getQualifier(), cnt.getIncrement()));
return inc;
}
}
代码示例来源:origin: org.apache.hbase/hbase-client
/**
* Atomically increments a column value. If the column value already exists
* and is not a big-endian long, this could throw an exception. If the column
* value does not yet exist it is initialized to <code>amount</code> and
* written to the specified column.
*
* <p>Setting durability to {@link Durability#SKIP_WAL} means that in a fail
* scenario you will lose any increments that have not been flushed.
* @param row The row that contains the cell to increment.
* @param family The column family of the cell to increment.
* @param qualifier The column qualifier of the cell to increment.
* @param amount The amount to increment the cell with (or decrement, if the
* amount is negative).
* @param durability The persistence guarantee for this increment.
* @return The new value, post increment.
* @throws IOException if a remote or network exception occurs.
*/
default long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier,
long amount, Durability durability) throws IOException {
Increment increment = new Increment(row)
.addColumn(family, qualifier, amount)
.setDurability(durability);
Cell cell = increment(increment).getColumnLatestCell(family, qualifier);
return Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength());
}
代码示例来源:origin: org.apache.hbase/hbase-server
@Test
public void testIncrementWithNonExistingFamily() throws IOException {
initHRegion(tableName, name.getMethodName(), fam1);
final Increment inc = new Increment(row);
inc.addColumn(fam1, qual1, 1);
inc.addColumn(fam2, qual2, 1);
inc.setDurability(Durability.ASYNC_WAL);
try {
region.increment(inc, HConstants.NO_NONCE, HConstants.NO_NONCE);
} catch (NoSuchColumnFamilyException e) {
final Get g = new Get(row);
final Result result = region.get(g);
assertEquals(null, result.getValue(fam1, qual1));
assertEquals(null, result.getValue(fam2, qual2));
} catch (Exception e) {
fail("Increment operation should fail with NoSuchColumnFamilyException.");
}
}
代码示例来源:origin: com.aliyun.hbase/alihbase-thrift
public static Increment incrementFromThrift(TIncrement in) throws IOException {
Increment out = new Increment(in.getRow());
for (TColumnIncrement column : in.getColumns()) {
out.addColumn(column.getFamily(), column.getQualifier(), column.getAmount());
}
if (in.isSetAttributes()) {
addAttributes(out,in.getAttributes());
}
if (in.isSetDurability()) {
out.setDurability(durabilityFromThrift(in.getDurability()));
}
if(in.getCellVisibility() != null) {
out.setCellVisibility(new CellVisibility(in.getCellVisibility().getExpression()));
}
return out;
}
代码示例来源:origin: org.apache.hbase/hbase-thrift
public static Increment incrementFromThrift(TIncrement in) throws IOException {
Increment out = new Increment(in.getRow());
for (TColumnIncrement column : in.getColumns()) {
out.addColumn(column.getFamily(), column.getQualifier(), column.getAmount());
}
if (in.isSetAttributes()) {
addAttributes(out,in.getAttributes());
}
if (in.isSetDurability()) {
out.setDurability(durabilityFromThrift(in.getDurability()));
}
if(in.getCellVisibility() != null) {
out.setCellVisibility(new CellVisibility(in.getCellVisibility().getExpression()));
}
return out;
}
代码示例来源:origin: org.apache.hbase/hbase-server
@Test
public void testIncrementTimestampsAreMonotonic() throws IOException {
HRegion region = initHRegion(tableName, method, CONF, fam1);
ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge(edge);
edge.setValue(10);
Increment inc = new Increment(row);
inc.setDurability(Durability.SKIP_WAL);
inc.addColumn(fam1, qual1, 1L);
region.increment(inc);
Result result = region.get(new Get(row));
Cell c = result.getColumnLatestCell(fam1, qual1);
assertNotNull(c);
assertEquals(10L, c.getTimestamp());
edge.setValue(1); // clock goes back
region.increment(inc);
result = region.get(new Get(row));
c = result.getColumnLatestCell(fam1, qual1);
assertEquals(11L, c.getTimestamp());
assertEquals(2L, Bytes.toLong(c.getValueArray(), c.getValueOffset(), c.getValueLength()));
}
内容来源于网络,如有侵权,请联系作者删除!